/// <summary> /// Adds a player to the passive Observers list /// </summary> /// <param name="character">the character to add</param> /// <returns></returns> public virtual bool AddObserver(ServerCharacterInfo character, ref string msg) { lock (m_Game.AllObserversSyncRoot) { if (!CanAddObserver(character, ref msg)) { return(false); } Observers.Add(character.ID, character); character.SetCurrentGame(this); AllObservers = (List <ICharacterInfo>)Observers.Values.ToList <ICharacterInfo>(); OnObserverAdded(character); } return(true); }
/// <summary> /// Gets called when a player is removed from the game /// </summary> /// <param name="character"></param> protected virtual void OnPlayerRemoved(ServerCharacterInfo toon, string reason, bool playerInitiated) { toon.SetCurrentGame(null); // Update game stats in game listing DB DB.Instance.Lobby_UpdateGameForServer(this); // Send notification to player that player left, including game state update. Player is no longer part of "AllPlayers" list at this point, so we // have to manually send this notification to them. SendGamePropertiesUpdateToPlayer(toon, this.Properties.ID, this.Properties.AllProperties); SendMatchChangeNotificationToPlayer(toon, MatchNotificationType.PlayerRemoved, toon, reason, false); // Broadcast to all remaining players SendMatchChangeNotificationToPlayers(MatchNotificationType.PlayerRemoved, toon, reason, false); SendGamePropertiesUpdateToPlayers(this.Properties.ID, this.Properties.AllProperties); // Set new game owner if necessary if (Owner == toon.ID) { if (AllPlayers.Count > 0) { Owner = AllPlayers[0].ID; BroadcastGameInfoMessage(AllPlayers[0].CharacterName + " is now the owner of this game.", true); PropertyBag props = new PropertyBag(); props.SetProperty("NewOwner", Owner); BroadcastGameMessage((int)LobbyGameMessageSubType.NewOwner, props, true, false, false); } } // when a player leaves the game, they go back to Central if (CurrentGameState == GameState.Lobby || CurrentGameState == GameState.Started) { string address = ""; int port = 0; string serverId = ""; if (!GSLobbyInboundPlayerConnection.GetCentralHandoffAddress(ref address, ref port, ref serverId)) { toon.OwningAccount.MyConnection.KillConnection("Unable to host player on this server. No lobby server found to hand off too after leaving game."); return; } toon.OwningAccount.TransferToServerUnassisted(address, port, Guid.Empty, "Lobby Server", serverId); } }
/// <summary> /// Adds a player to the active Players list /// </summary> /// <param name="character">the character to add</param> /// <returns></returns> public virtual bool AddPlayer(ServerCharacterInfo character, ref string msg) { lock (m_Game.AllPlayersSyncRoot) { if (Players.ContainsKey(character.ID) || !CanAddPlayer(character, ref msg)) { return(false); } if (CurrentGameState == GameState.Started) { // player was adde after game started. add to active list EverActivePlayers.Remove(character.ID); EverActivePlayers.Add(character.ID, character); } Players.Add(character.ID, character); character.SetCurrentGame(this); AllPlayers = (List <ICharacterInfo>)Players.Values.ToList <ICharacterInfo>(); OnPlayerAdded(character); } return(true); }
/// <summary> /// Gets called when a player is removed from the observers /// </summary> /// <param name="character">the player that was removed</param> protected virtual void OnObserverRemoved(ServerCharacterInfo character) { character.SetCurrentGame(null); SendMatchChangeNotificationToPlayers(MatchNotificationType.ObserverRemoved, character, "", false); DB.Instance.Lobby_UpdateGameForServer(this); }