<div>Hey all, first post!</div>
<div> </div>
<div>I was looking around and Enet appears to be what I'm after. I'm making a game using a server/client model, but there are a few things I'm unsure about.</div>
<div> </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'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'd like them to be taken off the list.</div>
<div> </div>
<div>At first I tried making: std::vector<ENetPeer*> peers;</div>
<div> </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> </div>
<div>thus replacing that peer. Then, when a peer disconnects, looping through this vector, checking: </div>
<div>if(peers[i]->address.host == event.peer->address.host && peers[i]->address.port == event.peer->address.port) peers[i] = NULL;</div>
<div> </div>
<div>Then, the way I associate each peer with it'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> </div>
<div>ANNYWAY.. this doesn't seem to be the best method. Because some people in the archives have mentioned that the host actually has it'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> </div>
<div>case ENET_EVENT_TYPE_CONNECT:</div>
<div>int index = (int)(event.peer - host->peers);</div>
<div>...</div>
<div> </div>
<div>So my questions are (there's a lot, I know.. sorry):</div>
<div> </div>
<div>1) is my original way a good way? Or should I use host->peers instead?<br></div>
<div>2) If I use host->peers.. will the host also manage the deleting of peers when it gets a disconnect? If it does, does it rearrange the array? So if I have 3 peersconnected, and then the 2nd one leaves.. will I still be able to access the third player with host->peers[2] or will it get dropped down to the 2nd position at host->peers[1]? Furthermore, would it be best to save the playerID into the data field?</div>
<div> </div>
<div>3) Is the array size of host->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> </div>
<div>4) I want my game to have a dedicated and a non-dedicated server option. If it's non-dedicated, then you will control player[0]. Thus it would be convenient if I could also block off host->peers[0] (or my original peers[0]) with a 'dummy' connection to itself. Is this possible? Is it wise? Like, upon creating the host, could I go:</div>
<div> </div>
<div>if(!dedicated) host->peers[0] = enet_host_connect(host,&address,2);</div>
<div> </div>
<div>5) LAN vs Internet vs same computer. At the moment, all I'm able to do is get 2 applications on the same computer connecting. Is this because I'm using enet_address_set_host(&address, "<a href="http://127.0.0.1">127.0.0.1</a>") 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> </div>
<div>Ok.. that's all for now. If you can answer any questions at all, that'd be great :)<br><br>Loving Enet so far, hopefully I can get past these basic concepts and get into it more!</div>
<div> </div>
<div>Thanks,</div>
<div>Ben.</div>
<div> </div>
<div> </div>