The online racing simulator
JInSim is only the Java implementation of the LFS InSim interface, and I think it should work the same way as InSim is described in Scawens documentation.

I understand your problem, with the player id and the connection id, but I don't think that a solution should be part of JInSim.

It would be better to create a new project that is a higher level object oriented api to communicate with LFS and uses JInSim as basis.
For example: When you want the list of all drivers you call a 'List<Driver> getDrivers()' method that returns a list driver object.
And the InSim documenation (or Scawen) tells you how to name, or more importantly document, functions in your library? :wtf2:
:banghead:

Sorry, i though you want only one unique id for a driver (combine connection id and player id). I should read the posts more carefully

If you will create a patch that rename the getId methods and replaces it with a more readable getConnectionId or getPlayerId, then I'm on your site and will include the patch in JInSim.

(Note to me: first read, then think, then write an answer)
Quote from Brilwing ::banghead:

Sorry, i though you want only one unique id for a driver (combine connection id and player id). I should read the posts more carefully

If you will create a patch that rename the getId methods and replaces it with a more readable getConnectionId or getPlayerId, then I'm on your site and will include the patch in JInSim.

(Note to me: first read, then think, then write an answer)


Good to read that, I just thought I had pissed off the devs.

Ok, I'll try to clear things up a bit and provide some patches.
Are you using Eclipse as IDE?
Any thoughts about switching to SVN?

Cheers,
buk
Quote from bukhem :
Are you using Eclipse as IDE?

Yes

Quote from bukhem :
Any thoughts about switching to SVN?

Not really. I don't see lots of changes coming to JInSim in the near future, so I think CVS is fine for now. (If I'm wrong, I have no problems switching to SVN)

If you provide patches in the future for JInSim it is also very likely that you get access to the source control
Hi!

I'm a completly n00b on InSim and I'm starting with this library as I'm a bit familiar with Java (at least more than I'm with C :nod

I'm trying to get some info of time splits and time laps and I'm missing some info.
I've been able (thanks for that nice examples ) to get a button showing split times, but I would like to show the name (the LFS-World nick) of the player too. I'm capturing the SplitTimeResponse and I see that it have a playerId field, but I don't know how to get the rest of info about that Player... I think I miss a Player VO class or something

If you can tell me how to get all the info about one player via this PlayerId field I would be very pleased

Thanks a lot in advance and sorry for my crappy english
With the NewPlayerResponse you get the playername, car name, plate, skin etc.


public void packetReceived(InSimResponse response) {
if (response instanceof NewConnectionResponse) {
// here you get the connection id
} else if (response instanceof NewPlayerResponse) {
// here you get the player id and the player name etc.
}
}

Quote from Brilwing :With the NewPlayerResponse you get the playername, car name, plate, skin etc.


public void packetReceived(InSimResponse response) {
if (response instanceof NewConnectionResponse) {
// here you get the connection id
} else if (response instanceof NewPlayerResponse) {
// here you get the player id and the player name etc.
}
}


hmmm I've tried that, but maybe I've made something wrong
That packet NewPlayerResponse when is supposed to be sent? When a player connects to server? I'm testing my little app via HotLap... then, when I restart a HL that packet is sent again?

The app I'm trying to make is a kind of LFS-Lapper... but I'm going slowly so while I learn the basics I'm just testing with HL's on local, not on a server with several players

P.S: Don't know if this is the correct thread to comment this type of things, maybe I should open another thread requesting help on the problems I find during my develop and kee this one only for the library per se
I'm not sure when it is send when you are hotlapping. At an multiplayer race the NewConnectionResponse is send when a player connects (here you get the connection id). When the player leave the pits or the race is restarted, the NewPlayerResponse is send.
I think that the NewPlayerResonse is also send when you start hotlapping, but I have not tested it.

Just output all responses then you'll see what responses are send:

public void packetReceived(InSimResponse response) {
System.out.println(response);
}

Quote from Brilwing :I'm not sure when it is send when you are hotlapping. At an multiplayer race the NewConnectionResponse is send when a player connects (here you get the connection id). When the player leave the pits or the race is restarted, the NewPlayerResponse is send.
I think that the NewPlayerResonse is also send when you start hotlapping, but I have not tested it.

Just output all responses then you'll see what responses are send:

public void packetReceived(InSimResponse response) {
System.out.println(response);
}


Nice, thanks a lot!

Then I supposed I may have a Map of the players connected (I'm seriously thinking of having a PlayerVO just for making things easier ) and then searching on that map with the id to retrieve the PlayerVO containing all the data of the Player.
Then mantaining that Map when a player connects and when a player leaves the server

Another question (that I've didn't test it yet) it's about buttons... I'm showing split times on buttons, but I don't know how this could work on a multiplayer environment... may I set the button to a playerID for only that player sees the button of his split time and none of the others players?
Maybe this will help.


// tracking HashMaps
Map<Byte, Connection> connections = new HashMap<Byte, Connection>();
Map<Byte, Player> players = new HashMap<Byte, Player>();


// handle new connections
if (pck instanceof NewConnectionResponse)
{
if (!connections.containsKey(connid))
{
connections.put(connid, new Connection(connid, ncr.isAdmin(), username));
}
}


// handle new players
if (pck instanceof NewPlayerResponse)
{
if (!players.containsKey(plyid))
{
players.put(plyid, new Player(npr, (Connection)connections.get(connid), b));
}
}

There might be better ways to do this, but this works for me.
About Button with Split times and a PlayerVO object...
I'm currently working on a tool that I call RaceControl, that does this stuff. But it is not stable enough to release it. RaceControl is OpenSource (Apache 2.0 License) so you can investigate my code here: https://openbakery.org/svn/repos/trunk/racecontrol/

The PlayerControl.java class is where I create my Driver object (=PlayerVO).
You can investigate the Board.java class, here I display the last three laps with button to the current driver.
Thanks for the responses, they solved most of my doubts

Another question... can a single program connect to several LFS-Servers and listen to all of their responses or may I run one execution of my app for each of the servers I want to receive data from?
Quote from RocksGt :
Another question... can a single program connect to several LFS-Servers and listen to all of their responses or may I run one execution of my app for each of the servers I want to receive data from?

It should be doable, but jinsim has no support to identify from which server the packet comes from, so you have to keep track of this by yourself.
I keep working on my little app

One more doubt... Is there any way to connect to a server by his name. I mean, now I'm connecting by the server IP but it would be much better if I could connect using only the server name. Maybe connecting to the Master Server and asking him to resolve the IP by the name?

Thanks a lot, and very good job with JInSim, the more I work with it the more I apreciate the effort you put on it
Quote from RocksGt :
One more doubt... Is there any way to connect to a server by his name. I mean, now I'm connecting by the server IP but it would be much better if I could connect using only the server name. Maybe connecting to the Master Server and asking him to resolve the IP by the name?

AFAIK you cannot resolve the IP using the master server, so you need to know the IP adress or the hostname.
You can also use the insim relay. Here you can connect using the server name. You will get all InSim data through the relay, but sending insim request packets is limited. (see RelayClient.java in the jinsim source code)
JInSim also contains an example how to connect to a host via the insim relay.
Quote from Brilwing :AFAIK you cannot resolve the IP using the master server, so you need to know the IP adress or the hostname.
You can also use the insim relay. Here you can connect using the server name. You will get all InSim data through the relay, but sending insim request packets is limited. (see RelayClient.java in the jinsim source code)
JInSim also contains an example how to connect to a host via the insim relay.

Yes, I have looked at it already, but the servers I want to connect to are not in the relay system

Well, I'll put the IP's in a parameters file and let's hope there will be no need to change it usually
More problems

The server I'm trying to connect to is on a host where more servers are running, all with the same IP and each one on a different port.

I can connect to the server passing that port as the InSim port, I mean:

public JInSimClient(String name, String hostname, int port, String adminPassword)

hostname: The IP
port: the port where that actual server is listening

But then it seems I can get no data as the InSim port is another one

I've seen that the Client class have an udpPort, but no way of getting it working...

I've tried (stupid I think but meh... need to try ) passing IPort as hostname, but didn't work


Any help?
I also have multiple hosts running on one machine and this should not be a problem at all. When you have one host running on port 29999 and the other on 29998, and you specify 29999 as port in jinsim, all should be working fine an the communication should all run on the port 29999.

You do not need the udp port for the insim communication, only when you use outgauge and outsim then the udp port is needed as far as i remember.
Quote from Brilwing :I also have multiple hosts running on one machine and this should not be a problem at all. When you have one host running on port 29999 and the other on 29998, and you specify 29999 as port in jinsim, all should be working fine an the communication should all run on the port 29999.

You do not need the udp port for the insim communication, only when you use outgauge and outsim then the udp port is needed as far as i remember.

I think the problem is that ports that I want to use in InSim are not open on the firewall / router of the server :doh:

I've asked the server owner to open that ports and today (maybe tomorrow) will test if it's working

Again, thanks a lot for the support
Hi!

I've found a little error in ReorderResponse.java:

public void construct(ByteBuffer buffer) throws BufferUnderflowException {
super.construct(buffer);
numberPlayers = buffer.get();
for (int i = 1; i < MAX_PLAYERS; i++) {
playerPositions.add(new Byte(buffer.get()));
}
}

There sould be "int i = 0" in the for loop. If i == 1, then the list will only contain 31 elements (or there should be "<=" instead of "<").

I've written a Class for sending a reorder packet to LFS.
You can find it here: http://mihu86.uw.hu/lfs/SendReorderRequest.java

Mihu
In a server-side InSim, is there a way to get the host name?

What I'm trying to do is connect to several servers, and mantain a Map of JInSimClient identified by the host name, so when I receive a packet from LFS I can link the host from where the packet is sent

Maybe this could be done by the connectionId or something like that, but the responses don't include a field like that I think

So the idea is to override the public void packetReceived(InSimResponse response) method in my Client (the one that implements the JInsimClient) and call to my packetProcessor linking the hostName (or some identifier) to get access to the correct client (send messages back to the server, buttons, etc...)

If you can get me a tip it would be very nice


******** SOLVED **********

Finally I've used an Integer as clientId

Each Client (extended JInsimClient) has a clientId. In the main class I read the config file with the host list and I link each client with an Id (starting at 1). Then I keep a static Map<Integer, Client> at the requestProcessor, so when a packet is received each client do this:

public void packetReceived(InSimResponse response) {

RequestProcessor.getInstance().process(response, clientId);

}

So I can get the client from the Map if the process of that packet Type require it

Anyway... I think I need to override some methods as the setVisible of Button cause it calls to JInsimClient.getInstance() and in my environment I have several JInsimClients objects...

I don't know if the JInSim have a better method to deal with an multi server app
Quote from RocksGt :
I don't know if the JInSim have a better method to deal with an multi server app

No, JInSim dones not have a code to deal with multiple clients. If you have such code and you would share it, I could include in the future version of JInSim.
Hi, I'm trying to get this information from NewConnectionResponse and ConnectionLeaveResponse but I can't figure it out:


struct IS_NCN // New ConN
{
byte Size; // 56
byte Type; // ISP_NCN
byte ReqI; // 0 unless this is a reply to a TINY_NCN request
byte UCID; // new connection's unique id (0 = host)

char UName[24]; // username
char PName[24]; // nickname

byte Admin; // 1 if admin
byte Total; // number of connections including host
[COLOR=Red]byte Flags; // bit 2 : remote[/COLOR]
byte Sp3;
};

struct IS_CNL // ConN Leave
{
byte Size; // 8
byte Type; // ISP_CNL
byte ReqI; // 0
byte UCID; // unique id of the connection which left

[COLOR=Red]byte Reason; // leave reason (see below)[/COLOR]
byte Total; // number of connections including host
byte Sp2;
byte Sp3;
};

Please help
-
(DarkTimes) DELETED by DarkTimes
I checked the jinsim source and both flags are not implemented yet in jinsim :ashamed:

I've added this to my todo list for the next release, but I cannot give you any estimation when this will be done.

FGED GREDG RDFGDR GSFDG