Esempio n. 1
0
        public bool RejoinClient(NetworkConnection client)
        {
            bool couldRejoin = false;
            // rejoin is only justified if the client connection died. If it's still connected we want to avoid rejoin since this would get messy
            bool   rejoinJustified = !Network.ClientStillConnected(client.ClientSession.SessionID);
            Client correctClient   = null;

            foreach (Client c in Clients)
            {
                if (c.SessionID == client.ClientSession.SessionID)
                {
                    correctClient = c;
                }
            }
            Logger.GameLog("Client rejoin was requested: " + client.ClientSession.SessionID.ToString());
            if (GameState != GameStates.Finished && rejoinJustified && correctClient != null)
            {
                ServerInitializeGameResponse packet = new ServerInitializeGameResponse();
                packet.m_field   = GameStructure.GameField;
                packet.m_ball    = GameStructure.Ball;
                packet.m_players = new Player[GameStructure.PlayersCount];
                Array.Copy(GameStructure.GetAllPlayers(), packet.m_players, GameStructure.PlayersCount);

                foreach (Player p in packet.m_players)
                {
                    foreach (Player player in correctClient.Players)
                    {
                        p.Controllable = (player.ID == p.ID);
                    }
                }
                Logger.GameLog("Rejoin succeeded sending the ServerSessionResponse with GameReconnect Flag set to true to the Client");
                ServerSessionResponse response = new ServerSessionResponse();
                response.ClientSessionID = client.ClientSession.SessionID;
                response.GameReconnect   = true;
                client.SendTCP(response);
                Logger.GameLog("Rejoin succeeded sending the ServerInitializeGameResponse to the Client");
                client.SendTCP(packet);
                couldRejoin = true;
                Logger.GameLog("Since Client just rejoined he isn't aware of the current score, therefore sending a score package");
                client.SendTCP(GenerateScorePackage());
                Network.AddClientConnection(client);
            }
            return(couldRejoin);
        }