[ENet-discuss] Object unique ID's

Emmanuel Astier eastier at ubisoft.fr
Mon Mar 17 08:59:36 PDT 2008


To get the Id of a EnetPeer, I just take the index of this peer in the peers array of the ENetHost.

When the server gets a message, he receives a Peer in the event. 
So I just use this function to get the ID from the peer :

uint8 NET_Server_Enet::ucGetIdFromPeer( ENetPeer* pPeer ) {
	int result = pPeer - mpo_EnetServer->peers;
	if ( result < 0 || result > NET_k_MAX_CLIENTS )
		return NET_Invalid_Client_Id;
	return uint8( result );
}

Where mpo_EnetServer is my ENetHost pointer.


With this, you can mark your car with the client Id when receiving a car Request.


Hope it helps ( and that it is the right way to go ), 


Emmanuel

-----Message d'origine-----
De : enet-discuss-bounces at cubik.org [mailto:enet-discuss-bounces at cubik.org] De la part de Ruud van Gaal
Envoyé : lundi 17 mars 2008 11:32
À : enet-discuss at cubik.org
Objet : Re: [ENet-discuss] Object unique ID's

Hi Martin,

Thanks for that. Indeed your method is what I attempt to do. The only thing
left is to determine which client actually owns the car after the new-car
message comes in. The flow:

- client1 requests car
- server accepts, sends newCar message (with unique car.NetworkID) to all
clients
- client1 sees the newCar message and creates the car

Now how does client1 know that it's his car and not a car from another
client? A useful method then would be if clients also had an ID that would
be the same on each computer. That way you can say 'newCar with networkID
<x> and ownerClient <y>' which would work on all clients.
You'd need the following (I really think I'll add that to ENet):
- server starts
- client attempts connect to server
- server generates unique ID for client and replies connectOK with uniqueID

If this happens in connection phase (inside ENet) that would help in
debugging connections.

How would you determine whether the car just generated was owned by the
requesting client?

Cheers,
Ruud
(who now goes to have a look at the enet source to see if there's something
in the structures that could help)

> Date: Sun, 16 Mar 2008 19:38:22 +0000
> From: Martin Sherburn <spacedude at konggame.co.uk>
> Subject: Re: [ENet-discuss] Object unique ID's
> To: Discussion of the ENet library <enet-discuss at cubik.org>
> Message-ID: <47DD772E.1060600 at konggame.co.uk>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Hi Ruud,
> 
> I think this is beyond the scope of what enet is for. But 
> it's really not that hard to implement some ID tracking 
> system yourself once you get your head around it.
> 
> As your are implementing a client/server system, the server 
> should be in charge of creating objects in the game (e.g. 
> cars) and telling all the clients about it. So here is what 
> you can do:
> 
> 1) Server creates car and assigns it a unique ID
> 2) Server tells clients about this new car that was created 
> and sends the ID it assigned to it
> 3) All clients create a copy of the car and assign it the ID 
> the server gave
> 
> So the basic rule is, only the server should generate IDs. 
> The clients will always receive the ID from the server.
> 
> In the case where the client may want to spawn a new car by 
> joining the game. Then the client should send a request to 
> the server to create the car (without generating an ID for 
> it). If the server accepts the request, it will create a car 
> and generate and ID for it and tell all the clients about it 
> including the one that sent the request in the first place.
> 
> Martin.
> 
> Ruud van Gaal wrote:
> > Hi,
> >
> > I'm re-designing part of my multiplayer game to improve 
> object updates.
> > Before using ENet, I had a UDP connection scheme where every client 
> > would get sent a unique ID from the server. The server was 
> for example 
> > ID 70, the first connected client got 71 etc. This way, on all 
> > connected computers you could see who was who and you could 
> simply send updates for ID <x>.

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
 

_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss



More information about the ENet-discuss mailing list