[ENet-discuss] Question about peers
LoneSock
lonesock at gmail.com
Thu Jun 16 17:32:10 PDT 2005
Hi, James.
I'm not entirely sure if I understand, so I'll just point out some things:
1) each ENetHost stores the list of peers already, in an array called
"peers" (unexpected, I know [8^), so storing ENetPeer* in your array
PlayerPeers is not necessary.
2) the ENetPeer has the data pointer available (as you already
mentioned). In fact, from this sentence, it seems you are already
doing it:
"I have put the player number in the peer->data field"
I would probably just do a "event.peer.data = new int;" and store
GameData.NumPlayers there.
3) When you set up your host, you can specify the maximum number of
connections. So this line:
" if(GameData.NumPlayers < DAT_options.MaxNetPlayers)"
isn't strictly necessary
hope this helped,
Jonathan
On 6/15/05, James Bunting <nicedelta at yahoo.co.uk> wrote:
> 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 PC calling worldwide with
> voicemail
>
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
>
--
Piranha are people too.
More information about the ENet-discuss
mailing list