<div>Hey all, first post!</div>
<div>&nbsp;</div>
<div>I was looking around and Enet appears to be what I&#39;m after. I&#39;m making a game using a server/client model, but there are a few things I&#39;m unsure about.</div>
<div>&nbsp;</div>
<div>What is the best way to manage peers from the server end? So I can store peers, and associate them with a particular player. Basically, when a player joins the server, I&#39;d like the server to add this peer to a list, and assign it an ID so I can link it with a player. Then, when they disconnect, I&#39;d like them to be taken off the list.</div>

<div>&nbsp;</div>
<div>At first I tried making:&nbsp;std::vector&lt;ENetPeer*&gt; peers;</div>
<div>&nbsp;</div>
<div>and each time a player joins, scanning through this vector, checking: </div>
<div>if(peers[i] == NULL) peers[i] = event.peer;</div>
<div>&nbsp;</div>
<div>thus replacing that peer. Then, when a peer disconnects, looping through this vector, checking: </div>
<div>if(peers[i]-&gt;address.host == event.peer-&gt;address.host &amp;&amp; peers[i]-&gt;address.port == event.peer-&gt;address.port) peers[i] = NULL;</div>
<div>&nbsp;</div>
<div>Then, the way I associate each peer with it&#39;s corresponding player object is simply that they both share the same index in their respective vectors. So player[7] would belong to peers[7].</div>
<div>&nbsp;</div>
<div>ANNYWAY.. this doesn&#39;t seem to be the best method. Because&nbsp;some&nbsp;people in the archives&nbsp;have mentioned that the host actually has it&#39;s own list of peers. And that it does all this for you? And that when a new peer connects, you can get the index of the new peer like:</div>

<div>&nbsp;</div>
<div>case ENET_EVENT_TYPE_CONNECT:</div>
<div>int index = (int)(event.peer - host-&gt;peers);</div>
<div>...</div>
<div>&nbsp;</div>
<div>So my questions are (there&#39;s a lot, I know.. sorry):</div>
<div>&nbsp;</div>
<div>1) is my original way a good way? Or should I use host-&gt;peers instead?<br></div>
<div>2) If I use host-&gt;peers.. will the host also manage the deleting of peers when it gets a disconnect? If it does,&nbsp;does it rearrange the array?&nbsp;So if I have 3 peersconnected, and then the 2nd one leaves.. will I still be able to access the third player with host-&gt;peers[2] or will it get dropped down to the 2nd position&nbsp;at host-&gt;peers[1]?&nbsp;Furthermore, would it be best to save the playerID into the data field?</div>

<div>&nbsp;</div>
<div>3) Is the array size of host-&gt;peers set by the 2nd parameter in enet_host_create? So if I put in 64, will that mean 64 clients can be connected at once?</div>
<div>&nbsp;</div>
<div>4) I want my game to have a dedicated and a non-dedicated server option. If it&#39;s non-dedicated, then you will control player[0]. Thus it would be convenient if I could also block off host-&gt;peers[0] (or my original peers[0]) with a &#39;dummy&#39; connection to itself. Is this possible? Is it wise? Like, upon creating the host, could I go:</div>

<div>&nbsp;</div>
<div>if(!dedicated) host-&gt;peers[0] = enet_host_connect(host,&amp;address,2);</div>
<div>&nbsp;</div>
<div>5) LAN vs Internet vs same computer. At the moment, all I&#39;m able to do is get 2 applications on the same computer connecting. Is this because I&#39;m using enet_address_set_host(&amp;address, &quot;<a href="http://127.0.0.1">127.0.0.1</a>&quot;) when creating the server? If I wanted the server to be recognisable on LAN what address would I use? How about the net? or both at the same time? Would I just use address.host = ENET_HOST_ANY? If so, how do I know which IP to search for on the clients end?</div>

<div>&nbsp;</div>
<div>Ok.. that&#39;s all for now. If you can answer any questions at all, that&#39;d be great :)<br><br>Loving Enet so far, hopefully I can get past these basic concepts and get into it more!</div>
<div>&nbsp;</div>
<div>Thanks,</div>
<div>Ben.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>