MCPcopy Create free account
hub / github.com/TASEmulators/fceux / AddClientToGame

Function AddClientToGame

fceux-server/server.cpp:598–684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596}
597
598static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64]) throw()
599{
600 int wg;
601 GameEntry *game,*fegame;
602
603retry:
604
605 game = NULL;
606 fegame = NULL;
607
608 /* First, find an available game. */
609 for(wg=0; wg<ServerConfig.MaxClients; wg++)
610 {
611 if(!Games[wg].MaxPlayers && !fegame)
612 {
613 if(!fegame)
614 fegame=&Games[wg];
615 }
616 else if(!memcmp(Games[wg].id,id,16)) /* A match was found! */
617 {
618 game = &Games[wg];
619 break;
620 }
621 }
622
623 if(!game) /* Hmm, no game found. Guess we'll have to create one. */
624 {
625 game=fegame;
626 printf("Game %d added\n",game-Games);
627 memset(game, 0, sizeof(GameEntry));
628 game->MaxPlayers = 4;
629 memcpy(game->id, id, 16);
630 memcpy(game->ExtraInfo, extra, 64);
631 }
632
633 int n;
634 for(n = 0; n < game->MaxPlayers; n++)
635 if(game->Players[n])
636 {
637 try
638 {
639 uint8 b[5];
640 b[4] = 0x81;
641 MakeSendTCP(game->Players[n], b, 5);
642 break;
643 }
644 catch(int i)
645 {
646 KillClient(game->Players[n]);
647 /* All right, now the client we sent the request to is killed. I HOPE YOU'RE HAPPY! */
648 /* Since killing a client can destroy a game, we'll need to see if the game was trashed.
649 If it was, then "goto retry", and try again. Ugly, yes. I LIKE UGLY.
650 */
651 if(!game->MaxPlayers)
652 goto retry;
653 }
654 }
655

Callers 1

CheckNBTCPReceiveFunction · 0.85

Calls 3

MakeSendTCPFunction · 0.85
KillClientFunction · 0.85
TextToClientFunction · 0.85

Tested by

no test coverage detected