The online racing simulator
NEW InSim : TCP / multiple clients / new features
Hello programmers. This new version is in a good enough state now to make a special
thread. The changes are extensive - all old InSim programs will need to be updated as
they will not work at all with this new improved version of InSim.

CHANGES since W9

The guaranteed delivery system has been removed from the UDP version of InSim.
You may now connect using TCP, and this is recommended for guaranteed delivery.

Up to 8 InSim clients can connect, but only one of them can use the UDP method.

You no longer send an acknowledgment every time you receive a race tracking packet.
If you need guaranteed delivery (e.g. if you are race tracking remotely over the
internet) then you should use TCP. You can connect using TCP, or send a UDP packet
and LFS will communicate with your program using the chosen protocol.

The "regular" packets IS_NLP and IS_MCI are a special case - which may be sent
using UDP, if you wish, even if you connected via TCP. The idea is that those
particular packets represent car positions, so you do not need guaranteed
delivery - if you miss one packet, you just want the next packet that arrives.
This approach is similar to the use of UDP packets in LFS for car positions.
To enable this, supply a UDP port number in the IS_INI (InSimInit) packet.
To receive NLP and MCI packets using TCP, set the UDPPort field to zero.

To guarantee delivery over the internet, you must use the TCP method of connection.
UDP can be reliable on LAN and provides an easier upgrade path to the new system.

As TCP is a continuous stream rather than separate packets, every packet now starts
with a size byte, which you must compare with the read data stored in a buffer, to
know if you have a complete packet to process.

All packet headers have changed from the old 4 char header, to a new style of header
suitable for TCP. The first 4 bytes of all packets now follow a common pattern.

Size - total packet size
Type - packet identification byte from the ISP_ enumeration
ReqI - request id specified by an InSim program and returned in a requested packet
Xxxx - different in each case, often zero in the case of converted packets

All sizes are a multiple of 4 bytes. Two examples of smallest possible packets :

e.g. 1 : An IS_TINY packet equivalent to the old IS_REN (Race ENd) packet

Size : 4
Type : 3 from ISP_ enum : ISP_TINY (a general 4 byte packet)
ReqI : 0 not a requested packet
SubT : 11 from TINY_ enum : TINY_REN

e.g. 2 : The new IS_PLP packet

Size : 4
Type : 22 from ISP_ enum : ISP_PLP
ReqI : 0 not a requested packet (sent when a player pits, not on request)
PLID : 8 an example unique id (the unique id of the player who pitted)

NOTES on changes, to help convert existing InSim programs :

Most "InSimPack" packets now use the new IS_TINY, some use IS_SMALL
All packet headers have changed to the new style (Size, Type, ReqI, Xxxx)
Connections now have a unique identifier, called UCID, assigned in IS_NCN
Any mention of "Conn" or "ConnNum" is removed - use UCID from now on
Player's unique identifier "UniqueId" is renamed to PLID
Any mention of "PlyNum" is removed - use PLID in all cases
MSS (message out split) packet has been removed - use MSO instead
MSO (message out) has new info added to take the place of MSS
NPL (new player) has been reduced and rearranged a bit
LAP and SPX packets have been reduced and rearranged
You can get some info about insim's state by typing /insim
FIN (finished) and RES (result) are now two separate packets
You can specify a custom command prefix in the IS_ISI packet
The IS_REO packet can now be used to reorder a race before the start

CHANGES W to W9

changed packets (size not changed) :

IS_NPL : Handicap and passenger info added
IS_PEN : Penalty reason byte added
IS_FLG : Added unique id of obstructed player
Player flags : Added SHIFTER, AXIS_CLUTCH, CUSTOM_VIEW

new packets :

IS_CCH : sent when a player's selected camera changes
IS_III : info /i message sent by user to host's InSim

CHANGES V to W

VERSION : InSim version increased to 3

changed packets (size not changed) :

IS_RST - Added race flags (MUST_PIT, etc)
IS_NPL - CName now 4 chars + added skin name and tyre compounds
IS_LAP - CName now 4 chars + added number of laps / flags / penalty / stops
IS_RES - New FIN version of this is sent immediately on finishing race

new packets :

IS_PIT (pit stop)
IS_PSF (pit stop finished)
IS_PEN (penalty)
IS_TOC (take over car)
IS_FLG (yellow or blue flags)
IS_PFL (player help flags)

DOWNLOAD W14 TEST :

client and dedi exe only - requires W10 from test patch forum
no other changes - only get this if you are testing InSim

[ EDIT : link removed - new version available below : http://www.lfsforum.net/showthread.php?p=403965#post403965 ]

DOCUMENTATION :

Ful documentation is provided in the attached ISPackets.txt file, best read in a text editor with tab size
set to 4 spaces. In fact it's a C++ header file, used in LFS, renamed to .txt so I could attach it to the forum.

[ EDIT : attachment removed - new version available below : http://www.lfsforum.net/showthread.php?p=403965#post403965 ]

STILL TO BE DONE :

I still want to add a proposed button interface allowing InSim software to add buttons to your
screen for the purposes of displaying info or providing menu services.
*platonic hug*
8 connection :wow:

edit: in the IS_ISI struct the size comment should be 44 now

edit2: works pretty good

now if I only could figure out the right sector markers...
So if I use TCP and UDP for MCI packets only one Client can connect this way?!?
If it´s right I can´t be ever sure if LFS sockts (UDP or TCP) are full and I could maybe use a differen connection way. (Never thought of that in the current stable version)

EDIT: Scawen couldn´t you change NodeSecs in IS_ISI to NodeMs and in milliseconds? So most times it is needed in a smaller intervall then 1 second and we don´t have to send one more packet.
And can you also send a version packet after IS_ISI? I don´t know what could be against that.
Quote from CLRS530 :So if I use TCP and UDP for MCI packets only one Client can connect this way?!?
If it´s right I can´t be ever sure if LFS sockts (UDP or TCP) are full and I could maybe use a differen connection way. (Never thought of that in the current stable version)

You can connect up 8 Clients on TCP only or on TCP with UDP. (tested)
Quote from CLRS530 :So if I use TCP and UDP for MCI packets only one Client can connect this way?!?

No, that's wrong (as GeForz already said).

Only one client can connect using UDP for ALL packets.
Up to eight can connect with TCP, using UDP to receive NLP and MCI if they want to.

About your other requests, I'll consider them.
Quote from Scawen :I still want to add a proposed button interface allowing InSim software to add buttons to your
screen for the purposes of displaying info [...]

Buttons and text boxes would indeed be a nice feature. I can imagine not only hardcore insim programmers but also host admins would make use of this feature (motd, rules, general info., etc).
Quote from GeForz :You can connect up 8 Clients on TCP only or on TCP with UDP. (tested)

Nice to read I thought with UDP it´s a general thing

isn´t the player flag in IS_LAP needless? Also penalty in IS_SPX, but maybe you think over it and its good for someone who didn´t save all events and only want to check it.

EDIT2: Sorry but I went through the txt file and write everything I found
Why do you don´t change the MCI packet now use a own word for the lap number?
Quote from felplacerad :Buttons and text boxes would indeed be a nice feature. I can imagine not only hardcore insim programmers but also host admins would make use of this feature (motd, rules, general info., etc).

You know I'm all over that!
Some updates - W15
Here are some small changes and improvements :

ISPackets.txt : fixed errors / tidied / changed some names
IS_ISI - NodeSecs removed - Interval added (NLP / MCI ms delay)
IS_VER can now be sent in respose to IS_ISI (if ReqI is non-zero)
Separate option flags for NLP and MCI (so the relay can get both)
NLP - now can take up to 32 cars - packet size 140
REO - now can take up to 32 cars - packet size 36
MCI - node and lap now have their own words - packet size 236

[ EDIT : link removed, new update : http://www.lfsforum.net/showthread.php?p=403965#post403965 ]
I'm not InSim programmer (at least not yet), but had a quick look. Some things I noticed...

struct IS_NLP // Node and Lap Packet
{
.....
word NumNodes; // total number of nodes in the path
word FinishLine; // the node number of the finish line
....
};

So I understand two words NumNodes and FinishLine are sent in each IS_NLP/IS_MCI, but those cannot change during race? Why not have a special packet for track info, including there also nodes for split lines, possibly some other info about track (total length comes to mind)?

// RaceLaps (rl) : (various meanings depending on range)

// 0 : practice
// 1-99 : number of laps... laps = rl
// 100-190 : 100 to 1000 laps... laps = (rl - 100) * 10 + 100
// 191-238 : 1 to 48 hours... hours = rl - 190

Dunno, is there really need to squeeze this into one byte and also limit possible race lengths? Just word for laps and/or minutes would seem more logical. This is same also in replays so is it also what LFS internally uses?
Yes thought about both things also. Maybe you want later add laps like 101, 102... wich isn´t possible to show in InSim this way. Now there is the only time I think to fix those things wich were done to use the same packet size.

You now give the split number out in IS_SPX wich is indeed very good. But its also hard to test really seavly for the split count, so it would be good to have nodeNum and split count and yes also split1node... in this.
But that packet has to be sent also if you join after race start.

Couldn´t the finishlineNode be deleted and change the Node to 0 after start to NumNode (finishLine) or do you use this also in your code?
Thats one thing I never understood and wich is very buggy
Quote from hackerx :So I understand two words NumNodes and FinishLine are sent in each IS_NLP/IS_MCI, but those cannot change during race? Why not have a special packet for track info, including there also nodes for split lines

Good point. I have now removed those from the NLP and MCI, to save bandwidth. And these are now in the IS_RST along with the split lines. I'm uploading it in a minute.
Quote from hackerx :
// RaceLaps (rl) : (various meanings depending on range)

// 0 : practice
// 1-99 : number of laps... laps = rl
// 100-190 : 100 to 1000 laps... laps = (rl - 100) * 10 + 100
// 191-238 : 1 to 48 hours... hours = rl - 190

Dunno, is there really need to squeeze this into one byte and also limit possible race lengths? Just word for laps and/or minutes would seem more logical. This is same also in replays so is it also what LFS internally uses?

Yes, it is how it is internally in LFS.

Quote from CLRS530 :But that packet has to be sent also if you join after race start.

OK, I've also added a request TINY_RST to request an IS_RST.

Quote from CLRS530 :Couldn´t the finishlineNode be deleted and change the Node to 0 after start to NumNode (finishLine) or do you use this also in your code?
Thats one thing I never understood and wich is very buggy

It's not really buggy, it's just that the paths don't actually have a loop point which is at the finish line, from when they are created. I agree this can cause difficulty at times. There are some reasons why I don't really want to change it, as it does work ok now.
Could the insim password also be separated from the server password? Many insim app users now seem to be confused what it means when the connection is rejected due to some old password they used for a server.

Maybe the password setting could be in the options, or maybe insim connections coming from localhost (127.*) could always be allowed without providing a password (An application running on the same machine could read the password from the config file or memory anyway so security wise it would not be much different).
More updates - W16
Here are some small changes and improvements :

ISPackets.txt : fixed errors / tidied / changed some names
IS_ISI - NodeSecs removed - Interval added (NLP / MCI ms delay)
IS_VER can now be sent in respose to IS_ISI (if ReqI is non-zero)
Separate option flags for NLP and MCI (so the relay can get both)
NLP - now can take up to 32 cars
REO - now can take up to 32 cars
MCI - node and lap now have their own words
NLP and MCI - removed number of nodes and finish line node
RST - added number of nodes, split nodes and finish line node
Added TINY_RST - request a RST packet after race start

[ EDIT : removed download link, new version available in test patch forum : http://www.lfsforum.net/showthread.php?t=23457 ]
I want to describe my problems with the current node system and I see that LFS itselvs has some same problems because the positions are often for one moment wrong:

I use a realtime position calculation.
So I change the lap number and Node with every MCI packet. here is "problem" number one I have to do


if (currentNode <= finishLineNode)
currentNode += numNodes;

to have a constant higher node from start to finish line.

If I need a position I sort the players first with the lap and if thats equal with the Nodes. So here problem number two. Sometimes a lap increase comes before finishLineNode, sometimes on it and another time after the node so a second correction


[SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][SIZE=2] nearBeforeFinishLine = currentNode <= finishLineNode && currentNode + 10 >= finishLineNode;[/SIZE]
[SIZE=2][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (!nearBeforeFinishLine)
nodePositions[i].lap++;
[/SIZE][/SIZE]

Thats nearly save for me with the positions but it could have faster the same


I only want to mentione it now, if you don´t want to change it I can deal with it
I want to thank you for the changes you did (for me) they are really helpful
You could get your own version of current node like this :

nice_current_node = (lfs_current_node + number_of_nodes - finish_line_node) % number_of_nodes;

That gives your node relative to the finish line.

It looks like you are using C++ or something like it, so you know what % means.
If anyone else doesn't know, that % sign is not "percent" it is "remainder after division" (aka "mod").
Is it intentional that you removed the "first player in this mci" packet value?
It was a cheap way to find out the number of valid CompCar strucs in the packet and only having the total number of players makes it more complicated for the programmer.

Personally I would even prefer a "number of valid structs" in this packet value in byte4.
OK, I am changing that byte.

I'm also fillling in the PLID for those players who are in the pits (so it doesn't fill in the car info). It was completely blank before - now at least you will see the PLID in the otherwise blank slot.
Because I don´t have time to test it now, is the splitnode 2 and 3 in IS_RST 0 if they don´t exist (or better 65536)?
If not can you do this?
Not zero, but 65535 (aka -1).

Zero is a possible value for a finish line or a split.
Thanks and yes for this case my edit

EDIT (also here): Sure has to be 65535
hello Scawen,

would it be possible to include the absolute time into the LAP/SPX packets? If a program wants to calculate the gap between 2 cars, it would have to add up the times of all driven laps. But this is not possible if the program is missing the start of the race (eg. if a spectator connected to the server after some laps).

regards Sören
This thread is closed

FGED GREDG RDFGDR GSFDG