[ENet-discuss] Question about peers

James Bunting nicedelta at yahoo.co.uk
Wed Jun 15 17:52:55 PDT 2005


I am a little bit confused about how to link peers to each game player.
 
I have an array of players containg all client player data and a single ENetPeer*.  I have put the player number in the peer->data field.
 
I am assuming that when I create each client peer on the server it somehow connects it to the server socket.
 
Here is a more hands on example:
 
while( enet_host_service( LocalHost, &event, 50) > 0)
{
    switch (event.type)
    {
         case ENET_EVENT_TYPE_CONNECT:
    
         if(GameData.NumPlayers < DAT_options.MaxNetPlayers)
         {
               // * connect new player *
             MSG_Message("Client connected from %s", event.peer->address);
 
             GameData.NumPlayers++;
 
             // set player peer (reassign peer pointer)
             PlayerPeers[ GameData.NumPlayers-1] = event.peer;
             event.peer = NULL;
            
            // store player number in peer (so that we can tell where packets came from)
           NET_BindPlayerNumberToPeer( PlayerPeers[ GameData.NumPlayers-1], GameData.NumPlayers-1);
 ......
 
You see I need to store the player number in each peer so that I can determine which player the packet arrived from when calling enet_host_serivce on the server.
 
The big question is:
Is this a viable way of doing this or should I be doing things another way (I wanted to avoid storing player data in each "peer", if possible I would simply like to store the player number)?
 
James.
 

		
---------------------------------
Yahoo! Messenger NEW - crystal clear PC to PCcalling worldwide with voicemail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.puremagic.com/pipermail/enet-discuss/attachments/20050616/717eadf2/attachment.html


More information about the ENet-discuss mailing list