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 OnDisconnect(NetworkMessage msg) { LobbyPlayer discPlayer = new LobbyPlayer() { id = -1 }; foreach (LobbyPlayer lp in lobbyPlayers) { if (lp.id == msg.conn.connectionId) { discPlayer = lp; } } if (discPlayer.id > -1) { lobbyPlayers.Remove(discPlayer); } LobbyPlayer[] clients = lobbyPlayers.ToArray(); for (int i = 0; i < NetworkServer.connections.Count; i++) { GameMsg.MsgPlayerLobbyList lobbyList = new GameMsg.MsgPlayerLobbyList() { lobbyPlayerList = clients, clientId = i }; if (NetworkServer.connections[i] != null) { NetworkServer.connections[i].Send(GameMsg.PlayerLobbyList, lobbyList); } } }
public void OnLobbyList(NetworkMessage msg) { GameMsg.MsgPlayerLobbyList list = msg.ReadMessage <GameMsg.MsgPlayerLobbyList>(); lobbyPlayers.Clear(); lobbyPlayers.AddRange(list.lobbyPlayerList); Game.peerId = list.clientId; }