예제 #1
0
        /// <summary>
        /// Removes a player from the active Players list
        /// </summary>
        /// <param name="character">the character to add</param>
        public virtual void RemovePlayer(ServerCharacterInfo character, string reason, bool playerInitiated)
        {
            //Task t = new Task((state) =>
            {
                lock (m_Game.AllPlayersSyncRoot)
                {
                    if (Players.Remove(character.ID))
                    {
                        Log1.Logger("SERVER").Info("Removed player [#" + character.CharacterName + "] from game [" + Name + "] [" + GameID.ToString() + "].");
                        AllPlayers = (List <ICharacterInfo>)Players.Values.ToList <ICharacterInfo>();

                        if (CurrentGameState == GameState.Started && !Solved)
                        {
                            // player quit after we started the game, but before we finished the match
                            AddToQuittersRoster(character);
                        }

                        OnPlayerRemoved(character, reason, playerInitiated);

                        // What's the state of the game after player left?
                        if (CurrentGameState == GameState.Lobby)
                        {
                            GameStartStrategy.NotifyPlayerLeftLobby(character.ID);
                        }
                        else if (CurrentGameState == GameState.Started)
                        {
                            GameAbortStrategy.NotifyPlayerLeftGame(character.ID);
                        }
                    }
                }
            }    //, "Remove Player from game" + character.ToString(), TaskCreationOptions.LongRunning);
            //m_NetQ.AddTask(t);
        }
예제 #2
0
 private void Init(Game game)
 {
     m_Game            = game;
     GameStartStrategy = new GameStartStrategy();
     GameAbortStrategy = new GameAbortStrategy();
     RegisterGamePacketHandler((int)LobbyGameMessageSubType.Chat, OnPlayerChat);
     RegisterGamePacketHandler((int)LobbyGameMessageSubType.SeatChangeRequest, OnPlayerSeatChangeRequest);
     RegisterGamePacketHandler((int)LobbyGameMessageSubType.ClientLevelLoaded, OnPlayerClientLevelLoaded);
 }
예제 #3
0
        /// <summary>
        /// Gets called when a player was added to the game
        /// </summary>
        /// <param name="toon">the character that was added to the game</param>
        protected virtual void OnPlayerAdded(ServerCharacterInfo toon)
        {
            DB.Instance.Lobby_UpdateGameForServer(this);
            SendMatchChangeNotificationToPlayers(MatchNotificationType.PlayerAdded, toon, "", false);

            lock (m_Game.CurrentGameStateSyncRoot)
            {
                if (CurrentGameState == GameState.Lobby)
                {
                    GameStartStrategy.NotifyPlayerAddedToLobby(toon);
                }
                else if (CurrentGameState == GameState.Started)
                {
                    GameAbortStrategy.NotifyPlayerAddedToGame(toon);
                }
            }
        }