The online racing simulator
InSim Relay client information
(56 posts, started )
InSim Relay client information
Hello programmers,

This thread is meant to inform you about how the InSim Relay works and how you can connect to it.

First off, the relay will connect to any subscribed host (people can do this at lfsworld).
When you then connect to the relay, you can request a hostlist and select a host to receive its insim data from.
You can connect either as a 'guest client' (you will only be able to receive insim data) or as an admin, if you know the admin password of a host. You can then also send packets to the host.

When you connect to the relay, you must do that at :
tcp://isrelay.lfs.net:47474

Or using WebSockets :
ws://isrelay.lfs.net:47474/connect

NOTE : the domain name isrelay.lfs.net can resolve to both IPv4 and IPv6

Following now is the information needed to construct your relay selection packets :

// InSimRelay for LFS InSim version 4 (LFS 0.5X and up)
//
// The Relay code below can be seen as an extension to the regular
// InSim protocol, as the packets are constructed in the same
// manner as regular InSim packets.
//
// Connect your client to isrelay.lfs.net:47474 with TCP
// or ws://isrelay.lfs.net:47474/connect with a JS WebSocket.
// After you are connected you can request a hostlist, so you can see
// which hosts you can connect to.
// Then you can send a packet to the Relay to select a host. After that
// the Relay will send you all insim data from that host.

// Some hosts require a spectator password in order to be selectable.

// You do not need to specify a spectator password if you use a valid administrator password.

// If you connect with an administrator password, you can send just about every
// regular InSim packet there is available in LFS, just like as if you were connected
// to the host directly. For a full list, see end of document.




// Packet types used for the Relay

#define IRP_ARQ 250 // Send : request if we are host admin (after connecting to a host)
#define IRP_ARP 251 // Receive : replies if you are admin (after connecting to a host)
#define IRP_HLR 252 // Send : To request a hostlist
#define IRP_HOS 253 // Receive : Hostlist info
#define IRP_SEL 254 // Send : To select a host
#define IRP_ERR 255 // Receive : An error number


// To request a hostlist from the Relay, send this packet :

struct IR_HLR // HostList Request
{
byte Size; // 4
byte Type; // IRP_HLR
byte ReqI;
byte Sp0;
};


// That will return (multiple) packets containing hostnames and some information about them

// The following struct is a subpacket of the IR_HOS packet

struct HInfo // Sub packet for IR_HOS. Contains host information
{
char HName[32]; // Name of the host

char Track[6]; // Short track name
byte Flags; // Info flags about the host - see NOTE 1) below
byte NumConns; // Number of people on the host
};

// NOTE 1)

#define HOS_SPECPASS 1 // Host requires a spectator password
#define HOS_LICENSED 2 // Bit is set if host is licensed
#define HOS_S1 4 // Bit is set if host is S1
#define HOS_S2 8 // Bit is set if host is S2
#define HOS_CRUISE 32 // Bit is set if host is Cruise
#define HOS_FIRST 64 // Indicates the first host in the list
#define HOS_LAST 128 // Indicates the last host in the list


struct IR_HOS // Hostlist (hosts connected to the Relay)
{
byte Size; // 4 + NumHosts * 40
byte Type; // IRP_HOS
byte ReqI; // As given in IR_HLR
byte NumHosts; // Number of hosts described in this packet

HInfo Info[6]; // Host info for every host in the Relay. 1 to 6 of these in a IR_HOS
};


// To select a host in the Relay, send this packet :

struct IR_SEL // Relay select - packet to select a host, so relay starts sending you data.
{
byte Size; // 68
byte Type; // IRP_SEL
byte ReqI; // If non-zero Relay will reply with an IS_VER packet
byte Zero; // 0

char HName[32]; // Hostname to receive data from - may be colourcode stripped
char Admin[16]; // Admin password (to gain admin access to host)
char Spec[16]; // Spectator password (if host requires it)

};


// To request if we are an admin send:

struct IR_ARQ // Admin Request
{
byte Size; // 4
byte Type; // IRP_ARQ
byte ReqI;
byte Sp0;
};


// Relay will reply to admin status request :

struct IR_ARP // Admin Response
{
byte Size; // 4
byte Type; // IRP_ARP
byte ReqI;
byte Admin; // 0- no admin; 1- admin
};


// If you specify a wrong value, like invalid packet / hostname / adminpass / specpass,
// the Relay returns an error packet :

struct IR_ERR
{
byte Size; // 4
byte Type; // IRP_ERR
byte ReqI; // As given in RL_SEL, otherwise 0
byte ErrNo; // Error number - see NOTE 2) below
};

// NOTE 2) Error numbers :

#define IR_ERR_PACKET 1 // Invalid packet sent by client (wrong structure / length)
#define IR_ERR_PACKET2 2 // Invalid packet sent by client (packet was not allowed to be forwarded to host)
#define IR_ERR_HOSTNAME 3 // Wrong hostname given by client
#define IR_ERR_ADMIN 4 // Wrong admin pass given by client
#define IR_ERR_SPEC 5 // Wrong spec pass given by client
#define IR_ERR_NOSPEC 6 // Spectator pass required, but none given

==============================================
Regular insim packets that a relay client can send to host :

For anyone
TINY_VER
TINY_PING
TINY_SCP
TINY_SST
TINY_GTH
TINY_ISM
TINY_NCN
TINY_NPL
TINY_RES
TINY_REO
TINY_RST
TINY_AXI

Admin only
TINY_VTC
ISP_MST
ISP_MSX
ISP_MSL
ISP_MTC
ISP_SCH
ISP_BFN
ISP_BTN

The relay will also accept, but not forward
TINY_NONE // for relay-connection maintenance

I hope that helps,

Victor
-
(Gegry1992) DELETED by the_angry_angel : Thread tidy
-
(the_angry_angel) DELETED by the_angry_angel : Thread tidy
-
(Gegry1992) DELETED by the_angry_angel : Thread tidy
-
(sun) DELETED by Bob Smith : unnecessary
-
(mcgas001) DELETED by mcgas001 : meh, No answer :x
I love how it still says new in the title, when this was posted LAST year, but it was updated in march of this year.
Is a libary for use this? I'm new C# programmer and I have problems with use packets.
I have a question about the host list request.

As far as I can see there is no (proper) way to determine when the last HInfo packet is received. There is no FIRST and LAST flag like in the CompCar packet.

Can you please add them, or did I miss something?
hmm no there's no indication of which is the first and which the last. Unfortunately I cannot simply add that without breaking compatibility either; there are currently no spare bytes or bits in IR_HOS :/
If I try to select a spec pass protected host without specifying a spec password in my packet the relay returns error number 6 which is undocumented?
ah, that means 'spectator pass required, but none given'.
Quote from T-RonX :I have a question about the host list request.

As far as I can see there is no (proper) way to determine when the last HInfo packet is received. There is no FIRST and LAST flag like in the CompCar packet.

Can you please add them, or did I miss something?

struct IR_HOS // Hostlist (hosts connected to the Relay)
{
byte Size; // 4 + ([b]NumHosts[/b] * 40)
byte Type; // IRP_HOS
byte ReqI; // As given in IR_HLR
byte [b]NumHosts;[/b] // Number of hosts described in this packet

HInfo Info[6]; // Host info for every host in the Relay. 1 to 6 of these in a IR_HOS
};

If NumHosts is Less Then 6;
You have reached the last packet, that contains the last host.

However, if you have a total number of hosts on that happens to be divisible by 6, this this becomes unreliable.

If the devs add a packet that has the number of hosts on the relay it would make it more reliable, but the information would be several milliseconds out of date.
Quote from Dygear :If NumHosts is Less Then 6;
You have reached the last packet, that contains the last host.

However, if you have a total number of hosts on that happens to be divisible by 6, this this becomes unreliable.

Yes, so to me that way is no option. I resolved the issue by sending 2 requests, both with a different request id, if I received the first packet with the last request id, I assume the first request to be completed.
Quote from T-RonX :Yes, so to me that way is no option. I resolved the issue by sending 2 requests, both with a different request id, if I received the first packet with the last request id, I assume the first request to be completed.

Interesting workaround.
why so intersting ?
its just how to conect why is it so intersting?
quick question, does usemaster have to be set to yes before the relay will stay connected? i'm trying to connect one to one of my servers temporarily until i get home and flip the switch, but it keeps going to "dead".

thanks
Yes you need to use the master. It's a check to prevent illegal hosts from using the relay.
Quote from Victor :Yes you need to use the master. It's a check to prevent illegal hosts from using the relay.

fair enough. i'll wait till i get home then.
about types

you forgot write



#define IRP_HARQ 250 // Receive : Admin mod Request
#define IRP_HARS 251 // Send : Response on IRP_HARQ

struct IR_HARQ // Admin Request
{
byte Size; // 4
byte Type; // IRP_HARQ
byte ReqI;
byte Sp0;
};

struct IR_HARS // Admin Response
{
byte Size; // 4
byte Type; // IRP_HARS
byte ReqI;
byte Admin; // 0- no admin; 1- admin
};



Quote from denis-takumi :about types

you forgot write



#define IRP_HARQ 250 // Receive : Admin mod Request
#define IRP_HARS 251 // Send : Response on IRP_HARQ

struct IR_HARQ // Admin Request
{
byte Size; // 4
byte Type; // IRP_HARQ
byte ReqI;
byte Sp0;
};

struct IR_HARS // Admin Response
{
byte Size; // 4
byte Type; // IRP_HARS
byte ReqI;
byte Admin; // 0- no admin; 1- admin
};




I've never seen these packets before, and would they not fall under an ISP_TINY packet.
after IR_SEL you can send IR_HARQ and get response IR_HARS

In this way you can give to user the rights to simply look for those who on the server, or give him the rights to manage the server, as is done on http://www.lfsworld.net/remote
Quote from denis-takumi :after IR_SEL you can send IR_HARQ and get response IR_HARS

In this way you can give to user the rights to simply look for those who on the server, or give him the rights to manage the server, as is done on http://www.lfsworld.net/remote

since that sounds a bit misleading to me :

You can ask the relay if you are an admin of the host you are connected to or not.
This cannot be used to make you an admin. Only a valid admin password when selecting a host will make you admin.

I've updated the text of the original post.
I think it would be useful if there was a bit to tell you which was the first and last HInfo in the IS_HOS packet, as currently it's hard to figure out when you have the full host list.

#define HOS_SPECPASS 1 // Host requires a spectator password
#define HOS_LICENSED 2 // Bit is set if host is licensed
#define HOS_S1 4 // Bit is set if host is S1
#define HOS_S2 8 // Bit is set if host is S2
[b]#define HOS_FIRST 16
#define HOS_LAST 32[/b]

right. I've added that (but haven't tested, though I'm sure it's fine). The values chosen are 64 and 128 though, as 16 will be used for future S3 hosts.
First post is updated with the info.
Great, thanks!
Just tested it, while FIRST works OK, I don't seem to get any hosts with the LAST flag.
hmm right, try now
Eh.. I don't seem to be getting any HOS packets at all now and no errors are being reported. Nothing is sent when I request the host list.
messed that up good didn't i ...

ok fixed that and tested it too now.

InSim Relay client information
(56 posts, started )
FGED GREDG RDFGDR GSFDG