The online racing simulator
.NET - InSim.NET - InSim library
(730 posts, started )
I knew there was something I was missing. I'd forgotten I wasn't using the release :-)

One issue I've found is that when specifying UdpPort, the library tries to bind the local socket to the host's IP address. There is no way to provide the local IP address to be used instead.

By the way, thanks for producing this awesome library.
Hello again DarkTimes,
any ideas what is best way to get laptime correct format like
minutes:seconds:ms
and hope they come correct format so output is like: 4:32:34
where 4 is minute , 32 is seconds and 34 is after seconds
i dont know what thats called english but i think you got what i mean.
Thanks again for you awesome library thats is realy nice to make insim programs.
All times in InSim.NET are represented by .NET TimeSpan structs, so you can specify a custom format for them.

For instance if you wanted to output the lap time, you could do:


<?php 
void LapCompleted
(InSim insimIS_LAP packet) {
    var 
lapTimeStr packet.LTime.ToString(@"mm\:ss\.fff");

    
Console.WriteLine(lapTimeStr);
}
?>

That would output the time the same way as LFS does in game, which would be "1:23.374".
well i know i can trus you awesome work and awesome lib and awesome you make this kinda stuff for free thanks again that help me alot...
But... i tested that but i got string is only that mm\:ss\.fff
maybe i do something wrong but that you example not work for me .
another hard for me is how i can get that track name if i use darktimes cruise example?
i know there is that packet where is track name but my brain locked how i can add that example user.trackname variable?
If someone can help i m more than happy.
Thanks thanks
I don't know what the problem is. Does this piece of code work on its own?


<?php 
var ts TimeSpan.FromSeconds(123.456);

Console.WriteLine(ts.ToString(@"mm\:ss\.fff"));
?>

Just create a new console application, paste that into the main method and run it.
Yeah thanks again i solve that problem
i need take that var ts from milliseconds not seconds.
Thats work thaank man.
Btw do you have good idea how i keep insim program open when i change track?
Thanks for help.
Quote from Nasty! :
Btw do you have good idea how i keep insim program open when i change track?
Thanks for help.

I don't understand the question. Please explain exactly what the problem is with as much detail as possible.
well if i use yours sparkcruise insim that crash when server change track.
any idea to keep insim run when track change.
I don't believe this is in any way InSim.NET's fault. When a track is changed, LFS just sends a packet to notify InSim applications of the change. Assuming you wrote your application in C# or VB.NET you should get an exception which can help you track the problem down.
I haven't touched SparkCruise for years, it was intended as an example program, nothing else. It uses an old version of InSim.NET that isn't supported anymore, and I don't even think I have the source code for it. As MadCatX says there must be a bug in the IS_STA handler that causes it to crash.
yeah sorry to disturb u guys i find that problem. Somehow that use old sparkcruise extension and i dont see that and think inximdot net is used...i start look where is problems cos cant bind new collision packets etc. So thanks my problem solved.
Sry for eng.
Thx for interesting tool (tested it a lot some time ago).
Should this lib work on 0.6E? Cause after connection to insim and starting race getting lots of wrong size init packet errors.
Can't even open source project in VS 2008, project type not supported(.
Any updates soon?
Hi there,
I tried to use IS_NPL.SetF to get Information about traction control. But it seems InSim.NET only reports a value of 0 for this flag where it should be a value greater than 0.
Has anyone other experiences with this flag?
I might be wrong, but there appears to be a bug in the IS_NPL constructor. IS_NPL is defined like this in "insim.h"

<?php 
struct IS_NPL 
{
...
    
byte      Pass;        // passengers byte
    
int       Spare;       // 4 bytes long
    
byte      SetF;        // setup flags (see below)
...
}
?>

The IS_NPL constructor in InSim.NET however does this:

<?php 
public IS_NPL(byte[] buffer)
    : 
this() {
    
PacketReader reader = new PacketReader(buffer);
    ...
    
Pass = (PassengerFlags)reader.ReadByte();
    
reader.Skip(1); // This is probably intended to skip the Spare variable, but it skips only 1 byte instead of 4
    
SetF = (SetupFlags)reader.ReadByte();
    ...
}
?>

Quote :Hi there,
I tried to use IS_NPL.SetF to get Information about traction control. But it seems InSim.NET only reports a value of 0 for this flag where it should be a value greater than 0.
Has anyone other experiences with this flag?

A few months ago I experienced the same issue. I failed to report it thinking my code was to blame. MadCatX has found the culprit it seems, hopefully DarkTimes will take a look into it.

Other than that so far I can only praise InSim.NET. My InSim app is running on my server as we speak, bombarding InSim.NET while remaining rockstable (at least it has been for several weeks now)

Unrelated to the npl.SetF issue, I wondered if there is a way to bind packets more efficiently when there are several InSim instances created at once, 8 being the limit:

InsimInstance[0].Bind<IS_NCN>(new_NCN1);
InsimInstance[1].Bind<IS_NCN>(new_NCN2);
InsimInstance[2].Bind<IS_NCN>(new_NCN3);
InsimInstance[3].Bind<IS_NCN>(new_NCN4);
InsimInstance[4].Bind<IS_NCN>(new_NCN5);
InsimInstance[5].Bind<IS_NCN>(new_NCN6);
InsimInstance[6].Bind<IS_NCN>(new_NCN7);
InsimInstance[7].Bind<IS_NCN>(new_NCN8);

private void new_NCN1(InSim insim, IS_NCN ncn) { }
private void new_NCN2(InSim insim, IS_NCN ncn) { }
private void new_NCN3(InSim insim, IS_NCN ncn) { }
private void new_NCN4(InSim insim, IS_NCN ncn) { }
private void new_NCN5(InSim insim, IS_NCN ncn) { }
private void new_NCN6(InSim insim, IS_NCN ncn) { }
private void new_NCN7(InSim insim, IS_NCN ncn) { }
private void new_NCN8(InSim insim, IS_NCN ncn) { }

Is there a convenient way to use a loop instead?
Quote from sicotange :
Unrelated to the npl.SetF issue, I wondered if there is a way to bind packets more efficiently when there are several InSim instances created at once, 8 being the limit:

InsimInstance[0].Bind<IS_NCN>(new_NCN1);
InsimInstance[1].Bind<IS_NCN>(new_NCN2);
InsimInstance[2].Bind<IS_NCN>(new_NCN3);
InsimInstance[3].Bind<IS_NCN>(new_NCN4);
InsimInstance[4].Bind<IS_NCN>(new_NCN5);
InsimInstance[5].Bind<IS_NCN>(new_NCN6);
InsimInstance[6].Bind<IS_NCN>(new_NCN7);
InsimInstance[7].Bind<IS_NCN>(new_NCN8);

private void new_NCN1(InSim insim, IS_NCN ncn) { }
private void new_NCN2(InSim insim, IS_NCN ncn) { }
private void new_NCN3(InSim insim, IS_NCN ncn) { }
private void new_NCN4(InSim insim, IS_NCN ncn) { }
private void new_NCN5(InSim insim, IS_NCN ncn) { }
private void new_NCN6(InSim insim, IS_NCN ncn) { }
private void new_NCN7(InSim insim, IS_NCN ncn) { }
private void new_NCN8(InSim insim, IS_NCN ncn) { }

Is there a convenient way to use a loop instead?

If you insist on having a different handler for each instance, I don't think it will make much of a difference, but perhaps something like this might work?


<?php 
List<Action<InSimIS_NCN>> IS_NCN_Handlers = new List<Action<InSimIS_NCN>>();
IS_NCN_Handlers.Add(this.myNCN1);
IS_NCN_Handlers.Add(this.myNCN2);
...

for (
int i 0InsimInstance.Counti++) {
    
InsimInstance[i].Bind<IS_NCN>(IS_NCN_Handlers[i]);
}
?>

I have no idea if InSim.NET will accept this syntax of if it will work properly with non-static methods.

EDIT: You might be interested in reading this: http://stackoverflow.com/quest ... -dynamically-calling-them

EDIT2: I have corrected the sample code to use Action instead of Func (Func apparently has to return a value whereas Action is what is usually called a procedure)
Ok thanks, I will look into it in dept but it doesn't seem to be an easy "plug & play".
-
(DarkTimes) DELETED by DarkTimes : Posting when drunk, I'll post properly tomorrow. :)
hi
when a player has a lag - the server receives a flood
TCP ERROR: INSIM LIMIT
TCP ERROR: WOULDBLOCK

I added a check in MCI void

<?php 
string lagg 
car.Info.ToString ();
if (!
lagg.Contains("CCI_LAG"))
?>

but this is not helped. NLP is not used, only MCI, interval 100
would someone be able to tell me what this means breifly


<?php 
1
/30/2013 8:06:06 PMSystem.NullReferenceExceptionObject reference not set to an instance of an object.
   
at InSimDotNet.BindingManager.PacketBinding`1.Execute(InSim insim, IPacket packet)
   at InSimDotNet.BindingManager.Execute(InSim insim, IPacket packet)
   at InSimDotNet.InSim.RaisePacketEvent(IPacket packet)
   at InSimDotNet.InSim.tcpSocket_PacketDataReceived(Object sender, PacketDataEventArgs e)
   at InSimDotNet.TcpSocket.OnPacketDataReceived(PacketDataEventArgs e)
   at InSimDotNet.TcpSocket.HandlePackets(SocketState state)
   at InSimDotNet.TcpSocket.ReceiveCallback(IAsyncResult asyncResult)
?>


i think its coming from MCI, im having issues with CompCar Speed, bassicly the insim just dissconnects after a certain amount of seconds, and that is in the log

EDIT: Problem Solved, Thanks Povo!
Hi,

Attached are two versions of a patch (one for the last release and one for hg head) to remove the use of native Windows methods in kernel32.dll for converting to LFS encoding. .Net methods are used instead.

This allows it to run properly under Mono on a non-Windows system.
Attached files
nativefixhead.diff.txt - 10.3 KB - 317 views
nativefixstable.diff.txt - 10.3 KB - 337 views
Hello There,

I got a question.

Wanted to start coding my own insim on Insim.Net , and was looking a bit at Spark's Cruise Insim.

Thing is , when someone gets spectated for stealing , or if IP is not correctly setted up , or any other error , insim directly closes , and the error message just appears 0.5 seconds in the CMD box.

Why does this happen? Outdated .dll? Not sure , i'm new in Insim.Net.

Hope you can help me :

Best Regards,

*Refered file attached below*
Attached files
SparkCruise.zip - 135.4 KB - 386 views
Hi!

I was messing around with insim.NET trying to keep track of connections (as you often would)


<?php 
Dictionary
<intIS_NCNPLAYERS
?>



<?php 
        
static void ConnJoin(InSim insimIS_NCN ncn)
        {
            
PLAYERS.Add(ncn.UCIDncn);
        }
?>

This works well as it should. However, what am I to do when a player renames himself?


<?php 
        
static void ConnRename(InSim insimIS_CPR cpr)
        {
            
PLAYERS[cpr.UCID].PName cpr.PName
        }
?>

This won't work as all properties in the IS_NCN class only have getters and no setters. What I'm most baffled about is that there is a property that does have a setter, the UCID. Why would you even want to be able change that if all the other properties are read-only?
public IS_NCN(byte[] buffer)
: this() {
PacketReader reader = new PacketReader(buffer);
Size = reader.ReadByte();
Type = (PacketType)reader.ReadByte();
ReqI = reader.ReadByte();
UCID = reader.ReadByte();
UName = reader.ReadString(24);
PName = reader.ReadString(24);
Admin = reader.ReadBoolean();
Total = reader.ReadByte();
Remote = (reader.ReadByte() & [B][SIZE="7"]2[/SIZE][/B]) > 0; // bit 2: remote

Is it correct? May be we must put it value.
Remote = (reader.ReadByte() & [B]4[/B]) > 0; // bit 2: remote

Quote from repeat83 :
public IS_NCN(byte[] buffer)
: this() {
PacketReader reader = new PacketReader(buffer);
Size = reader.ReadByte();
Type = (PacketType)reader.ReadByte();
ReqI = reader.ReadByte();
UCID = reader.ReadByte();
UName = reader.ReadString(24);
PName = reader.ReadString(24);
Admin = reader.ReadBoolean();
Total = reader.ReadByte();
Remote = (reader.ReadByte() & [B][SIZE="7"]2[/SIZE][/B]) > 0; // bit 2: remote

Is it correct? May be we must put it value.
Remote = (reader.ReadByte() & [B]4[/B]) > 0; // bit 2: remote


Yup, I just found this exact same bug. You're correct, it should be 4.

There's a very similar bug in the PlayerTypes enum, PLT_REMOTE = 3 should be PLT_REMOTE = 4, as it's another bit flag.

Great library though, just started using it, but working nicely.

.NET - InSim.NET - InSim library
(730 posts, started )
FGED GREDG RDFGDR GSFDG