The online racing simulator
Quote from DarkTimes :What's the exception that gets thrown? Also does the error occur when receiving a string or sending a string?

It occurs when sending a string.

I will check the exception in 15 mins. On the phone now.
System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
at InSimDotNet.EncodingHelper.GetBytes(String value, Byte[] buffer, Int32 index, Int32 length) in G:\Users\Povilas\Desktop\InSimDotNet\EncodingHelper.cs:line 94
at InSimDotNet.PacketWriter.Write(String value, Int32 length) in G:\Users\Povilas\Desktop\InSimDotNet\PacketWriter.cs:line 108
at InSimDotNet.Packets.IS_BTN.GetBuffer() in G:\Users\Povilas\Desktop\InSimDotNet\Packets\IS_BTN.cs:line 121
at InSimDotNet.InSim.Send(ISendable packet) in G:\Users\Povilas\Desktop\InSimDotNet\InSim.cs:line 231
at LsCruise.Processor.QueueButton(String Text, ButtonStyles ButtonStyles, Byte ClickID, Byte H, Byte W, Byte T, Byte L, Byte ReqI, Byte UCID) in G:\Users\Povilas\Desktop\Visual Studio 2010\RC_new\ConsoleApplication1\Processor.cs:line 26
at LsCruise.Program.bttHandler(InSim InSim, IS_BTT BTT) in G:\Users\Povilas\Desktop\Visual Studio 2010\RC_new\ConsoleApplication1\eventHandlers\bttHandler.cs:line 48

The error
Try this version and see if it works any better.

Edit: removed.
Quote from DarkTimes :Try this version and see if it works any better.

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
at InSimDotNet.EncodingHelper.GetBytes(String value, Byte[] buffer, Int32 index, Int32 length) in G:\Users\Povilas\Desktop\InSimDotNet\EncodingHelper.cs:line 94
at InSimDotNet.PacketWriter.Write(String value, Int32 length) in G:\Users\Povilas\Desktop\InSimDotNet\PacketWriter.cs:line 108
at InSimDotNet.Packets.IS_BTN.GetBuffer() in G:\Users\Povilas\Desktop\InSimDotNet\Packets\IS_BTN.cs:line 121
at InSimDotNet.InSim.Send(ISendable packet) in G:\Users\Povilas\Desktop\InSimDotNet\InSim.cs:line 231
at LsCruise.Processor.QueueButton(String Text, ButtonStyles ButtonStyles, Byte ClickID, Byte H, Byte W, Byte T, Byte L, Byte ReqI, Byte UCID) in G:\Users\Povilas\Desktop\Visual Studio 2010\RC_new\ConsoleApplication1\Processor.cs:line 26
at LsCruise.Program.bttHandler(InSim InSim, IS_BTT BTT) in G:\Users\Povilas\Desktop\Visual Studio 2010\RC_new\ConsoleApplication1\eventHandlers\bttHandler.cs:line 48

Is the guy with this name on your server, or do you have a replay with his name in it? I can't seem to figure this out, I need some debug info (a replay would be ideal).

The place where this error occurs is not where I would expect, it seems likely to be the symptom of an error somewhere else, but to find that place I need more information.
I don't have a replay directly from the user, but I know the characters that cause the same error, so I recreated the error.

It involves an IS_PLP, IS_NPL, 2 IS_BTT's (second one is the one that catches), lots of IS_MSO's.

Hopefully it's enough

Good luck.
Attached files
Fail.mpr - 11.3 KB - 408 views
Great thanks, that causes the bug for me. You don't need all those packets by the way, just hook up an MSO handler that sends any messages received back to LFS.

I'll look into the exact cause later.
I've figured out where the bug is, but it will take me some time to fix it, I need to think about it for a while.
Great! Good luck

Can't wait for the release If you need any testing drop a PM, I'll be more than happy to contribute.
OK - I've pushed some fixes onto CodePlex, you can pull the latest version from the repository.

The bug was caused because the size of the BTN packet was being determined before the string had been converted into bytes, which meant that any string where the number of bytes > number of characters would cause it to crash. Anyway, I've fixed it, I hope.

I also fixed the new MTC packet to make it variable sized, plus made a couple of tweaks to IS_CON.
I am just having my insim running on my client, on a server that's not mine. And when I crashed into the person with the following nickname: "GaZ" (quotes included in nickname) , I get the following error:

Message: Index was outside the bounds of the array.

StackTrace: at InSimDotNet.EncodingHelper.GetBytes(String value, Byte[] buffer, Int32 index, Int32 length) in C:\Users\Loran\Desktop\Random\InSimDotNet\insimdotnet_6b678d6ab605\InSimDotNet\EncodingHelper.cs:line 92
at InSimDotNet.PacketWriter.Write(String value, Int32 length) in C:\Users\Loran\Desktop\Random\InSimDotNet\insimdotnet_6b678d6ab605\InSimDotNet\PacketWriter.cs:line 121
at InSimDotNet.Packets.IS_MST.GetBuffer() in C:\Users\Loran\Desktop\Random\InSimDotNet\insimdotnet_6b678d6ab605\InSimDotNet\Packets\IS_MST.cs:line 50
at InSimDotNet.InSim.Send(ISendable packet) in C:\Users\Loran\Desktop\Random\InSimDotNet\insimdotnet_6b678d6ab605\InSimDotNet\InSim.cs:line 231
at InSimDotNet.InSim.Send(String message, Object[] args) in C:\Users\Loran\Desktop\Random\InSimDotNet\insimdotnet_6b678d6ab605\InSimDotNet\InSim.cs:line 265
at Dizplay_Cruise.Dizplay.iSendMsg(String Message) in D:\Loran\Programming\C#\Live for Speed\Dizplay\Cruise A.0.1\Dizplay Cruise\Dizplay Cruise\Dizplay.cs:line 240
at Dizplay_Cruise.Dizplay.Received_CON(InSim InSim, IS_CON CON) in D:\Loran\Programming\C#\Live for Speed\Dizplay\Cruise A.0.1\Dizplay Cruise\Dizplay Cruise\Dizplay.cs:line 553

Target: Int32 GetBytes(System.String, Byte[], Int32, Int32)

Line 553 in Dizplay.cs:

<?php 
                iSendMsg
("^7Crash: " A.NCN.PName " ^7>< " B.NCN.PName " ^7(" Speed " km/h)");
?>

iSendMsg in Dizplay.cs:

<?php 
        
public static void iSendMsg(string Message)
        {
            
InSim.Send(Globals.MS Message); // This is line 240
        
}
?>

Is that you or me?

Edit: It happened before and after I updated to that last update in the repository. But I couldn't copy the error from the previous version. Also, if needed, I could save the replay and send it to you. In fact I will save it now, you say if you want me to upload it here.
OK send me the replay.

Edit: It works fine for me, so the bug must be somewhere else, so I need the replay.

private static void Collision(InSim insim, IS_CON con) {
IS_NPL a = _players[con.A.PLID];
IS_NPL b = _players[con.B.PLID];
double speed = MathHelper.MpsToKph((con.SpClose & 0x00ff) * 0.1);

insim.Send("^7Crash: " + a.PName + " ^7>< " + b.PName + " ^7(" + speed + " km/h)");
}

Also what does the Globals.MS string contain?
-
(MariusMM) DELETED by MariusMM
Awhh! Sorry, forgot to save the replay.. :doh:
I've been distracted the whole day today, couldn't do a thing normally..

Globals.MS is simply the server message start character, to make the messages from the InSim app differ from normal text..:

<?php 
public static readonly string MS "^3» ";
?>

But IS_CON fails rarely. Also, it used to disconnect from the host, before I decided to catch the exceptions thrown from it. And just that - it disconnected, without crashing my app.

Sorry for being zero help, really, I don't know how I forgot to do that! Just.. stupid.. ;d
Anyway, I'll make sure to get a replay if/when it happens again.
Quote from broken :Awhh! Sorry, forgot to save the replay.. :doh:
I've been distracted the whole day today, couldn't do a thing normally..

Globals.MS is simply the server message start character, to make the messages from the InSim app differ from normal text..:

<?php 
public static readonly string MS "^3» ";
?>

Sorry for being zero help, really, I don't know how I forgot to do that! Just.. stupid.. ;d
Anyway, I'll make sure to get a replay if/when it happens again.

What I need to know is the name of the two players. The error occurs in part of the code that converts a string into bytes, so I need to know what the string actually was to figure out what happened.

Quote :But IS_CON fails rarely. Also, it used to disconnect from the host, before I decided to catch the exceptions thrown from it. And just that - it disconnected, without crashing my app.

That's probably because the error is being thrown on the background thread, as I've said before you need to hook up an event to InSim.InSimError to catch those. Once an error is thrown InSim.NET can't really continue, can it, it doesn't know what state the program is in any more, so it disconnects.
Ah, could be my nickname too, yes.. Didn't think about that.
My nickname is this: ¡¸THC¡áBroken¡¸, OR

I even made a quick log to give me the nickname and the base64 value of it. There it is, all from the app, originally:
^7☆THC﹥^3Broken^7☆

Base64 encoded: XjfimIZUSEPvuaVeM0Jyb2tlbl434piG

Edit: If I need to hook up an event to InSim.InSimError, wouldn't that mean going into multithreading? I'll try... But after I get some sleep, because it's totally not my day today!
Attached images
Capture.PNG
What's the name of the other player in the crash? I need to know both of them.

Quote :If I need to hook up an event to InSim.InSimError, wouldn't that mean going into multithreading?

Um, no, the library is already multithreaded. If an exception gets thrown on a background thread you have no way of knowing. It will unwind that threads callstack and stops execution, but as each thread has its own callstack this won't affect your main program thread. Because of this I added the InSim.InSimError event that allows you to catch exceptions on background threads. You should pretty much always catch and log any errors raised by InSimError.
"GaZ" (quotes included in nickname). I said that in a previous reply, as I was reporting this tho, but nevermind.
Ah, I musta missed that, sorry. Anyway I've recreated the string and it does indeed cause a crash, but I have no effing idea why. I'm looking into it.

^3» ^7Crash: ^7☆THC﹥^3Broken^7☆ ^7>< ^tGaz^t ^7(0.00 km/h)

I should save all these strings and make some unit tests or something.
OK I think I've fixed the bug. It was another issue with the string length. You can get the latest revision from CodePlex.

The string encoding seems a little fragile, I'm thinking I may need to do something more to improve its robustness.

Edit: another push to CodePlex, fixed small bug introduced with this bug fix.
I think that fixed it. Will reply if things get odd again.
I have started to port my InSim app from LFSExternal, to this.

Great lib,

I have a trouble, and I don´t know why.

Reading MSO packets, if I write in server "!top" ( without slashes )

mso.Msg contains: "Player_Name ( without colours ) : !top" ( without slashes )..

I´m using 7d364ad0ddce with Z30 host.

And another question, If I want to send a MTC, it fails if lenght(msg)%4==0, and to solve this I have to add \0 at msg end. Wouldn´t be easier checking this internally, and add if necessary \0 in the own lib?
Quote from NeOn_sp :I have started to port my InSim app from LFSExternal, to this.

Great lib,

I have a trouble, and I don´t know why.

Reading MSO packets, if I write in server "!top" ( without slashes )

mso.Msg contains: "Player_Name ( without colours ) : !top" ( without slashes )..

Sorry, I don't understand what the problem is. Maybe you could try to go into more detail? As far as I can see that's working correctly.

If you want to process commands, you need to first set the Prefix char in InSimSettings.

insim.Initialize(new InSimSettings { Prefix = '!' });

Then to process the command:

void MessageOut(InSim insim, IS_MSO mso) {
if (mso.UserType == UserType.MSO_PREFIX) {
string command = mso.Msg.Substring(mso.TextStart);
if (command == "!top") {
// Do something...
}
}
}

Quote :And another question, If I want to send a MTC, it fails if lenght(msg)%4==0, and to solve this I have to add \0 at msg end. Wouldn´t be easier checking this internally, and add if necessary \0 in the own lib?

Sorry, that is a bug that was added in the latest revision, I've reverted the change.

Obviously if you pull the latest revision you should expect some bugs.
The problem is that mso.Msg should contain just my msg "!top" instead of "nickname : !top"
Quote from NeOn_sp :The problem is that mso.Msg should contain just my msg "!top" instead of "nickname : !top"

The problem is your code.

I use the latest version from CodePlex on my cruise server 24/7 and everything works fine.
Quote from PoVo :The problem is your code.

I use the latest version from CodePlex on my cruise server 24/7 and everything works fine.

Lastest oficial version or last uploaded to source code? Anyway, I'll recheck later

Edit:

With this code:

static void MessageOut(InSim insim, IS_MSO mso)
{
try
{
if (mso.UCID != 0)
{
var npl = players[mso.PLID];
var nco = players_info[mso.UCID];

if (mso.UserType == UserType.MSO_PREFIX)
{

insim.Send("/msg MSG=" + mso.Msg);

I write: "!info " and I get: MSG=NeoN Xspa™ : !info

Edit2: Downloaded new revision 801736de8371, MTC working fine now, thanks Waiting for MSO thing..

FGED GREDG RDFGDR GSFDG