[ENet-discuss] Object unique ID's

Ruud van Gaal ruud at racer.nl
Mon Mar 17 14:41:12 PDT 2008


@Bjørn
...
> I really don't see why you couldn't just have the server 
> create and send the ID right after ENet set up the connection.

I just don't like half-finished structures halfway a connection, but I guess
that could work.
I now use the peer index as the ID when a connection event comes along
(adding a base number to make sure I don't start using the numbers by
mistake as indices):

   on ENET_EVENT_TYPE_CONNECT:
     id=event.peer->incomingPeerID+BASE_ID;

> As for solving the problem without having to set up client IDs, what 
> about sending the client that requested the car a single additional 
> message telling him his car ID?
> 
> - client1 requests car
> - server creates car
> - server sends carRequestReply to client1 with its car ID
> - client1 stores this ID locally
...

Here things get hairy, since I can have 1 client requesting more than 1 car.
This could mean that multiple ID's need to be stored before the newCar
messages arrive (requesting 3 cars to enter the game for example).

> If you want to avoid having to remember the variable, you 
> might as well 
> just have a yourNewChar message in addition to the newCar 
> message, and 
> send that to client1 instead of the newChar message.

I now take the solution of including an ownerClientID in the newCar message;
I send the exact same message to all clients, but the client which is the
owner knows its own clientID:

  if(pkt.ownerClientID==client->id) then car_is_ours();

That seems to work great sofar, although the order of cars may be a problem
later. It also helps that now, all clients know which car belongs to which
clientID (I have 3 screens on my desk for 3 computers, so it helps seeing
all the ID's on all screens for a quick check on how things are going).

Thanks all for the help, things are looking good at the moment!

Cheers,
Ruud

No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.519 / Virus Database: 269.21.7/1331 - Release Date: 16/03/2008
10:34
 




More information about the ENet-discuss mailing list