public void OnConnect(NetworkMessage msg) { LobbyPlayer lobbyPlayer = new LobbyPlayer() { id = msg.conn.connectionId, charName = REX.Choice(DB.CharNames) }; lobbyPlayers.Add(lobbyPlayer); GameMsg.MsgPlayerLobbyUpdate playerLobbyUpdate = new GameMsg.MsgPlayerLobbyUpdate() { lobbyPlayer = lobbyPlayer }; for (int i = 0; i < NetworkServer.connections.Count; i++) { if (i == msg.conn.connectionId) { LobbyPlayer[] clients = lobbyPlayers.ToArray(); GameMsg.MsgPlayerLobbyList lobbyList = new GameMsg.MsgPlayerLobbyList() { lobbyPlayerList = clients, clientId = i }; NetworkServer.connections[i].Send(GameMsg.PlayerLobbyList, lobbyList); } else { NetworkServer.connections[i].Send(GameMsg.PlayerLobbyUpdate, playerLobbyUpdate); } } }
public void OnPlayerLobbyUpdate(NetworkMessage msg) { GameMsg.MsgPlayerLobbyUpdate update = msg.ReadMessage <GameMsg.MsgPlayerLobbyUpdate>(); LobbyPlayer lpWithId = new LobbyPlayer() { id = -1 }; foreach (LobbyPlayer lobbyPlayer in lobbyPlayers) { if (lobbyPlayer.id == update.lobbyPlayer.id) { lpWithId = lobbyPlayer; } } if (lpWithId.id == update.lobbyPlayer.id) { lpWithId.charClass = update.lobbyPlayer.charClass; lpWithId.charName = update.lobbyPlayer.charName; lobbyPlayers[lpWithId.id] = lpWithId; } else { lobbyPlayers.Add(update.lobbyPlayer); } NetworkServer.SendToAll(GameMsg.PlayerLobbyUpdate, update); }