Maelstrom: The network layer pulls player information from the game info.

https://github.com/libsdl-org/Maelstrom/commit/5162505a03da9ed184f7cd2ce1734ba0b8e72e96

From 5162505a03da9ed184f7cd2ce1734ba0b8e72e96 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 19 Nov 2011 19:28:13 -0500
Subject: [PATCH] The network layer pulls player information from the game
 info.

---
 game/gameinfo.h  |  5 +++++
 game/lobby.cpp   | 13 -------------
 game/main.cpp    |  1 -
 game/netplay.cpp | 49 ++++++++++++++----------------------------------
 game/netplay.h   |  3 ---
 5 files changed, 19 insertions(+), 52 deletions(-)

diff --git a/game/gameinfo.h b/game/gameinfo.h
index a460e9b5..372baa9c 100644
--- a/game/gameinfo.h
+++ b/game/gameinfo.h
@@ -140,6 +140,11 @@ class GameInfo
 	const GameInfoPlayer *GetPlayer(int index) const {
 		return &players[index];
 	}
+	const IPaddress &GetPlayerAddress(int index) const {
+		const GameInfoPlayer *player = GetPlayer(index);
+		const GameInfoNode *node = GetNodeByID(player->nodeID);
+		return node->address;
+	}
 	void RemovePlayer(int index);
 
 	bool IsHosting() const;
diff --git a/game/lobby.cpp b/game/lobby.cpp
index bec0c041..1b8af021 100644
--- a/game/lobby.cpp
+++ b/game/lobby.cpp
@@ -155,19 +155,6 @@ LobbyDialogDelegate::OnHide()
 	// Start the game!
 	if (m_dialog->GetDialogStatus() > 0) {
 		SetState(STATE_PLAYING);
-
-		for (int i = 0; i < MAX_PLAYERS; ++i) {
-			const GameInfoPlayer *player = m_game.GetPlayer(i);
-			if (!player->nodeID) {
-				continue;
-			}
-			if (player->nodeID == m_game.localID) {
-				AddLocalPlayer(i);
-			} else {
-				const GameInfoNode *node = m_game.GetNodeByID(player->nodeID);
-				AddNetworkPlayer(i, node->address);
-			}
-		}
 		NewGame();
 	} else {
 		SetState(STATE_NONE);
diff --git a/game/main.cpp b/game/main.cpp
index 10a3b102..9a6643fb 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -67,7 +67,6 @@ static void RunSinglePlayerGame()
 	if (InitNetData(false) < 0) {
 		return;
 	}
-	AddLocalPlayer(0);
 	NewGame();
 	HaltNetData();
 }
diff --git a/game/netplay.cpp b/game/netplay.cpp
index 6bebbf2b..f3d2acad 100644
--- a/game/netplay.cpp
+++ b/game/netplay.cpp
@@ -36,9 +36,7 @@ int   gNumPlayers;
 int   gOurPlayer;
 UDPsocket gNetFD;
 
-static int            GotPlayer[MAX_PLAYERS];
 static IPaddress      PlayAddr[MAX_PLAYERS];
-static int            FoundUs;
 static Uint32         NextFrame;
 UDPpacket            *OutBound[2];
 static int            CurrOut;
@@ -110,10 +108,9 @@ int InitNetData(bool hosting)
 	}
 
 	/* Initialize network game variables */
-	FoundUs   = 0;
+	gNumPlayers = 0;
 	gOurPlayer  = -1;
 	for ( i=0; i<MAX_PLAYERS; ++i ) {
-		GotPlayer[i] = 0;
 		SyncPtrs[0][i] = NULL;
 		SyncPtrs[1][i] = NULL;
 	}
@@ -145,48 +142,31 @@ void HaltNetData(void)
 	SDLNet_Quit();
 }
 
-void AddLocalPlayer(int playernum)
-{
-	gOurPlayer = playernum;
-	FoundUs = 1;
-	GotPlayer[playernum] = 1;
-}
-
-void AddNetworkPlayer(int playernum, const IPaddress &address)
-{
-	PlayAddr[playernum] = address;
-	GotPlayer[playernum] = 1;
-}
-
 /* This MUST be called after command line options have been processed. */
 int CheckPlayers(void)
 {
 	int i;
 
-	/* Check to make sure we have all the players */
-	for ( i=0, gNumPlayers=0; i<MAX_PLAYERS; ++i ) {
-		if ( GotPlayer[i] )
+	gNumPlayers = 0;
+	gOurPlayer  = -1;
+	for ( i=0; i<MAX_PLAYERS; ++i ) {
+		if (gGameInfo.IsValidPlayer(i)) {
+			if (gGameInfo.IsLocalPlayer(i)) {
+				gOurPlayer = i;
+			} else {
+				PlayAddr[i] = gGameInfo.GetPlayerAddress(i);
+			}
 			++gNumPlayers;
-	}
-	for ( i=0; i<gNumPlayers; ++i ) {
-		if ( ! GotPlayer[i] ) {
-			error("Player %d not specified!\r\n", i+1);
-			return(-1);
 		}
 	}
-	if ( ! FoundUs ) {
-		error("Which player are you?\r\n");
+	if (gNumPlayers == 0) {
+		error("No players specified!\r\n");
 		return(-1);
 	}
-	if ( (gOurPlayer+1) > gNumPlayers ) {
-		error("You cannot be player %d in a %d player game.\r\n",
-						gOurPlayer+1, gNumPlayers);
+	if (gOurPlayer < 0) {
+		error("Which player are you?\r\n");
 		return(-1);
 	}
-	if ( (gNumPlayers == 1) && gGameInfo.deathMatch ) {
-		error("Warning: No deathmatch in a single player game!\r\n");
-		gGameInfo.deathMatch = 0;
-	}
 
 	/* Now, so we can send to ourselves... */
 	PlayAddr[gOurPlayer] = *SDLNet_UDP_GetPeerAddress(gNetFD, -1);
@@ -202,7 +182,6 @@ int CheckPlayers(void)
 	return(0);
 }
 
-
 void QueueKey(unsigned char Op, unsigned char Type)
 {
 	/* Drop keys on a full buffer (assumed never to really happen) */
diff --git a/game/netplay.h b/game/netplay.h
index ded9463e..d44f3289 100644
--- a/game/netplay.h
+++ b/game/netplay.h
@@ -25,9 +25,6 @@
 /* Functions in netplay.cpp */
 extern int   InitNetData(bool hosting);
 extern void  HaltNetData(void);
-extern int   AddPlayer(const char *playerstr);
-extern void  AddLocalPlayer(int playernum);
-extern void  AddNetworkPlayer(int playernum, const IPaddress &address);
 extern int   CheckPlayers(void);
 extern void  QueueKey(unsigned char Op, unsigned char Type);
 extern int   SyncNetwork(void);