void UpdateSanityChecks(UpdateGameEvent updateOperation) { if (updateOperation == null) { throw new ArgumentNullException("updateOperation"); } //if (updateOperation.InactiveUsers != null) //{ // Debug.Assert(this.GameServerPlayerCount != updateOperation.ActorCount // && updateOperation.InactiveCount != this.InactivePlayerCount, // "Inactive added but neither ActorCount nor InactiveCount changed"); //} // this may happen if user was not added on GS //if (updateOperation.RemovedUsers != null) //{ // Debug.Assert(this.GameServerPlayerCount != updateOperation.ActorCount || updateOperation.InactiveCount != this.InactivePlayerCount, // "Player removed but neither ActorCount nor InactiveCount changed"); //} //if (updateOperation.NewUsers != null) //{ // Debug.Assert(this.GameServerPlayerCount != updateOperation.ActorCount, "New added but ActorCount not changed"); //} }
public override bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer gameServerPeer, out GameState gameState) { // try to get the game state if (this.gameDict.TryGetValue(updateOperation.GameId, out gameState) == false) { if (updateOperation.Reinitialize) { if (log.IsDebugEnabled) { log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId); } gameState = new GameState(this.Lobby, updateOperation.GameId, 0, gameServerPeer); this.AddGameState(gameState); } else { if (log.IsDebugEnabled) { log.DebugFormat("Game not found: {0}", updateOperation.GameId); } return(false); } } bool oldVisible = gameState.IsVisbleInLobby; bool changed = gameState.Update(updateOperation); if (!changed) { return(false); } if (log.IsDebugEnabled) { LogGameState("UpdateGameState: ", gameState); } if (gameState.IsVisbleInLobby) { foreach (GameChannel channel in this.GameChannels.Values) { channel.OnGameUpdated(gameState); } return(true); } if (oldVisible) { foreach (GameChannel channel in this.GameChannels.Values) { channel.OnGameRemoved(gameState); } } return(true); }
private void HandleUpdateGameState(UpdateGameEvent operation, IncomingGameServerPeer incomingGameServerPeer) { try { GameState gameState; if (operation.Reinitialize && !this.GameList.ContainsGameId(operation.GameId)) { this.GameList.AddGameState( new GameState(operation.GameId, (byte)this.MaxPlayersDefault, incomingGameServerPeer)); } if (this.GameList.UpdateGameState(operation, out gameState) == false) { return; } this.SchedulePublishGameChanges(); this.OnGameStateChanged(gameState); } catch (Exception ex) { log.Error(ex); } }
private void HandleUpdateGameState(IEventData eventData) { if (log.IsDebugEnabled) { log.DebugFormat("HandleUpdateGameState"); } var updateEvent = new UpdateGameEvent(this.Protocol, eventData); if (updateEvent.IsValid == false) { string msg = updateEvent.GetErrorMessage(); log.ErrorFormat("UpdateGame contract error: {0}", msg); return; } if (log.IsDebugEnabled) { log.DebugFormat("HandleUpdateGameState: {0}, reinitialize: {1}", updateEvent.GameId, updateEvent.Reinitialize); } var ctx = this.Context; if (ctx != null) { ctx.HandleUpdateGameEvent(updateEvent); } }
protected virtual void UpdateGameStateOnMaster(byte?newMaxPlayer = null, bool?newIsOpen = null, bool?newIsVisble = null, object[] lobbyPropertyFilter = null, Hashtable gameProperties = null, string[] newUserId = null, string removedUserId = null, string[] inactiveList = null, ExcludedActorInfo[] excludedActorInfos = null, string[] expectedList = null, bool?checkUserIdOnJoin = null, byte replication = 0) { if (Log.IsDebugEnabled) { Log.DebugFormat("UpdateGameStateOnMaster: game - '{0}', reinitialize:{1}, replication:{2}", this.Name, replication > 0, replication); } var updateGameEvent = new UpdateGameEvent { GameId = this.Name, ActorCount = (byte)this.ActorsManager.ActiveActorsCount, Reinitialize = replication > 0, MaxPlayers = newMaxPlayer, IsOpen = newIsOpen, IsVisible = newIsVisble, IsPersistent = this.IsPersistent, InactiveCount = (byte)this.ActorsManager.InactiveActorsCount, PropertyFilter = lobbyPropertyFilter, CheckUserIdOnJoin = checkUserIdOnJoin, Replication = replication }; // TBD - we have to send this in case we are re-joining and we are creating the room (load) if (replication > 0) { updateGameEvent.LobbyId = this.LobbyId; updateGameEvent.LobbyType = (byte)this.LobbyType; } if (gameProperties != null && gameProperties.Count > 0) { updateGameEvent.GameProperties = gameProperties; } if (newUserId != null) { updateGameEvent.NewUsers = newUserId; } if (removedUserId != null) { updateGameEvent.RemovedUsers = new[] { removedUserId }; } if (excludedActorInfos != null) { updateGameEvent.ExcludedUsers = excludedActorInfos; } if (expectedList != null) { updateGameEvent.ExpectedUsers = expectedList; } this.UpdateGameStateOnMaster(updateGameEvent); }
protected virtual void UpdateGameStateOnMaster(UpdateGameEvent updateEvent) { var eventData = new EventData((byte)ServerEventCode.UpdateGameState, updateEvent); if (this.Application.MasterServerConnection != null) { this.Application.MasterServerConnection.SendEventIfRegistered(eventData, new SendParameters()); } }
public override bool UpdateGameState(UpdateGameEvent updateOperation, GameServerContext incomingGameServerPeer, out GameState gameState) { //use the exisiting values for the protected game parameters if (useStoredProcedures) { if (log.IsDebugEnabled) { log.DebugFormat("UpdateGameState {0}", updateOperation.GameId); } if (!this.gameDict.TryGetValue(updateOperation.GameId, out gameState)) { if (log.IsDebugEnabled) { log.Debug("Game not found"); } return(false); } if (gameState.Properties != null) { if (updateOperation.GameProperties == null) { updateOperation.GameProperties = new Hashtable(); } foreach (var key in protectedGameProperties) { if (gameState.Properties.ContainsKey(key)) { updateOperation.GameProperties[key] = gameState.Properties[key]; if (log.IsDebugEnabled) { log.DebugFormat("UpdateGameState, set key {0}/{1}", key, gameState.Properties[key]); } } else { updateOperation.GameProperties.Remove(key); if (log.IsDebugEnabled) { log.DebugFormat("UpdateGameState, removed key {0}", key); } } } } } if (base.UpdateGameState(updateOperation, incomingGameServerPeer, out gameState)) { if (gameState.IsJoinable) { this.gameDatabase.Update(gameState.Id, gameState.Properties); } return(true); } return(false); }
public bool UpdateGameState(UpdateGameEvent updateOperation, out GameState gameState) { // try to get the game state if (this.gameDict.TryGet(updateOperation.GameId, out gameState) == false) { if (updateOperation.Reinitialize) { if (log.IsDebugEnabled) { log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId); } this.AddGameState(gameState); } else { if (log.IsDebugEnabled) { log.DebugFormat("Game not found: {0}", updateOperation.GameId); } return(false); } } bool oldVisible = gameState.IsVisbleInLobby; bool changed = gameState.Update(updateOperation); if (changed) { if (gameState.IsVisbleInLobby) { this.changedGames[gameState.Id] = gameState; if (oldVisible == false) { this.removedGames.Remove(gameState.Id); } } else { if (oldVisible) { this.changedGames.Remove(gameState.Id); this.removedGames.Add(gameState.Id); } } if (log.IsDebugEnabled) { LogGameState("UpdateGameState: ", gameState); } } return(true); }
public void OnGameUpdateOnGameServer(UpdateGameEvent updateGameEvent, GameServerContext gameServer) { GameState gameState; lock (this.gameDict) { if (!this.gameDict.TryGetValue(updateGameEvent.GameId, out gameState)) { if (updateGameEvent.Reinitialize) { AppLobby lobby; string errorMsg; if (!this.LobbyFactory.GetOrCreateAppLobby(updateGameEvent.LobbyId, (AppLobbyType)updateGameEvent.LobbyType, out lobby, out errorMsg)) { // getting here should never happen if (log.IsWarnEnabled) { log.WarnFormat("Could not get or create lobby: name={0}, type={1}, ErrorMsg:{2}", updateGameEvent.LobbyId, (AppLobbyType)updateGameEvent.LobbyType, errorMsg); } return; } ErrorCode errorCode; var maxPlayers = updateGameEvent.MaxPlayers.GetValueOrDefault(0); this.GetOrCreateGame(updateGameEvent.GameId, lobby, maxPlayers, gameServer, out gameState, out errorCode, out errorMsg); if (errorCode != ErrorCode.Ok) { log.WarnFormat("Error during game creation initiated by GS. GameId:'{0}', AppId:{2}. ErrorMsg:{1}", updateGameEvent.GameId, errorMsg, this.ApplicationId); } } } } if (gameState != null) { if (gameState.GameServer != gameServer) { return; } gameState.CreateRequest = updateGameEvent; gameState.Lobby.UpdateGameState(updateGameEvent, gameServer); return; } if (log.IsDebugEnabled) { log.DebugFormat("Game to update not found: {0}", updateGameEvent.GameId); } }
public override bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState) { if (base.UpdateGameState(updateOperation, incomingGameServerPeer, out gameState)) { if (gameState.IsJoinable) { this.gameDatabase.Update(gameState.Id, gameState.Properties); return(true); } } return(false); }
public void OnGameUpdateEventHandled(UpdateGameEvent updateGameEvent) { if (this.IsReplicationComplete) { if (log.IsDebugEnabled) { log.DebugFormat("Replication complete. Got event:{0}", Newtonsoft.Json.JsonConvert.SerializeObject(updateGameEvent)); } if (updateGameEvent.IsReplicationEvent) { var msg = updateGameEvent.IsEmptyRoomReplication ? $"Got EMPTY game replication when " : $"Got game replication when " + $"replication finished. GameId:{updateGameEvent.GameId}" + $"AppId:{updateGameEvent.ApplicationId}/{updateGameEvent.ApplicationVersion}" + $" got replicas:{this.countOfUpdates}, expected replicas:{this.countOfExpectedUpdates}, context:{this.gameServerContext}"; log.Error(msg); } return; } if (log.IsDebugEnabled) { log.DebugFormat("Context got game update. ReplicationCode:{2}, gameId:{3}, json:{4}, replicated count:{0}, context:{1}", this.countOfUpdates, this.gameServerContext, updateGameEvent.Replication, updateGameEvent.GameId, Newtonsoft.Json.JsonConvert.SerializeObject(updateGameEvent)); } if (updateGameEvent.IsReplicationEvent) { ++this.countOfUpdates; if (log.IsDebugEnabled) { log.DebugFormat("Context got game replica. replicated count:{0}, context:{1}", this.countOfUpdates, this.gameServerContext); } if (this.IsReplicationComplete) { this.OnReplicationFinished(); if (log.IsInfoEnabled) { log.InfoFormat("Replication finsihed for server: {0}", this.gameServerContext); } } } }
protected virtual void UpdateGameStateOnMaster( byte?newMaxPlayer = null, bool?newIsOpen = null, bool?newIsVisble = null, object[] lobbyPropertyFilter = null, Hashtable gameProperties = null, string newPeerId = null, string removedPeerId = null, bool reinitialize = false) { if (reinitialize && Actors.Count == 0) { Log.WarnFormat("Reinitialize tried to update GameState with ActorCount = 0. " + this); return; } var updateGameEvent = new UpdateGameEvent { GameId = this.Name, ActorCount = (byte)this.Actors.Count, Reinitialize = reinitialize, MaxPlayers = newMaxPlayer, IsOpen = newIsOpen, IsVisible = newIsVisble, PropertyFilter = lobbyPropertyFilter }; if (reinitialize) { updateGameEvent.LobbyId = this.lobbyId; updateGameEvent.LobbyType = (byte)this.lobbyType; } if (gameProperties != null && gameProperties.Count > 0) { updateGameEvent.GameProperties = gameProperties; } if (newPeerId != null) { updateGameEvent.NewUsers = new[] { newPeerId }; } if (removedPeerId != null) { updateGameEvent.RemovedUsers = new[] { removedPeerId }; } this.UpdateGameStateOnMaster(updateGameEvent); }
private bool GetOrAddUpdatedGameState(UpdateGameEvent updateOperation, out GameState gameState) { // try to get the game state gameState = this.GetGameState(updateOperation.GameId); if (gameState == null) { if (updateOperation.Reinitialize) { // if game is empty, than we sent this message just to support replication if (updateOperation.IsEmptyRoomReplication) { if (log.IsDebugEnabled) { log.DebugFormat("Got replication for empty game. game:{0}, appId:{1}/{2}, ActorsCount:{3}, InactiveActors:{4}", updateOperation.GameId, updateOperation.ApplicationId, updateOperation.ApplicationVersion, updateOperation.ActorCount, updateOperation.InactiveCount); } return(false); } if (log.IsDebugEnabled) { log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId); } if (!this.Lobby.Application.TryGetGame(updateOperation.GameId, out gameState)) { if (log.IsDebugEnabled) { log.DebugFormat("Could not find game to reinitialize: {0}", updateOperation.GameId); } return(false); } this.AddGameState(gameState); } else { if (log.IsDebugEnabled) { log.DebugFormat("Game not found: {0}", updateOperation.GameId); } return(false); } } return(true); }
public void OnGameUpdateOnGameServer(UpdateGameEvent updateGameEvent, IncomingGameServerPeer gameServerPeer) { GameState gameState; lock (this.gameDict) { if (!this.gameDict.TryGetValue(updateGameEvent.GameId, out gameState)) { if (updateGameEvent.Reinitialize) { AppLobby lobby; if (!this.LobbyFactory.GetOrCreateAppLobby(updateGameEvent.LobbyId, (AppLobbyType)updateGameEvent.LobbyType, out lobby)) { // getting here should never happen if (log.IsWarnEnabled) { log.WarnFormat("Could not get or create lobby: name={0}, type={1}", updateGameEvent.LobbyId, (AppLobbyType)updateGameEvent.LobbyType); } return; } if (!this.gameDict.TryGetValue(updateGameEvent.GameId, out gameState)) { gameState = new GameState(lobby, updateGameEvent.GameId, updateGameEvent.MaxPlayers.GetValueOrDefault(0), gameServerPeer); this.gameDict.Add(updateGameEvent.GameId, gameState); } } } } if (gameState != null) { if (gameState.GameServer != gameServerPeer) { return; } gameState.Lobby.UpdateGameState(updateGameEvent, gameServerPeer); return; } if (log.IsDebugEnabled) { log.DebugFormat("Game to update not found: {0}", updateGameEvent.GameId); } }
protected virtual void UpdateGameStateOnMaster(UpdateGameEvent updateEvent) { var eventData = new EventData((byte)ServerEventCode.UpdateGameState, updateEvent); var connection = this.Application.MasterServerConnection; if (connection != null) { connection.SendEventIfRegistered(eventData, new SendParameters()); } else { if (Log.IsDebugEnabled) { Log.DebugFormat("Can not send game state update. Master connection is not set. Game:{0}", this.Name); } } }
protected virtual void HandleUpdateGameState(IEventData eventData) { if (log.IsDebugEnabled) { log.DebugFormat("HandleUpdateGameState"); } var updateEvent = new UpdateGameEvent(this.Protocol, eventData); if (updateEvent.IsValid == false) { string msg = updateEvent.GetErrorMessage(); log.ErrorFormat("UpdateGame contract error: {0}", msg); return; } this.application.DefaultApplication.OnGameUpdateOnGameServer(updateEvent, this); }
private void HandleUpdateGameState(UpdateGameEvent operation, GameServerContext incomingGameServer) { try { GameState gameState; if (this.GameList.UpdateGameState(operation, incomingGameServer, out gameState) == false) { return; } this.SchedulePublishGameChanges(); this.OnGameStateChanged(gameState); } catch (Exception ex) { log.Error(string.Format("Exception in AppLobby:{0}, Exception Msg:{1}", this, ex.Message), ex); } }
private void HandleUpdateGameState(UpdateGameEvent operation, IncomingGameServerPeer incomingGameServerPeer) { try { GameState gameState; if (this.GameList.UpdateGameState(operation, incomingGameServerPeer, out gameState) == false) { return; } this.SchedulePublishGameChanges(); this.OnGameStateChanged(gameState); } catch (Exception ex) { log.Error(ex); } }
protected bool GetOrAddUpdatedGameState(UpdateGameEvent updateOperation, out GameState gameState) { // try to get the game state gameState = GetGameState(updateOperation.GameId); if (gameState == null) { if (updateOperation.Reinitialize) { if (log.IsDebugEnabled) { log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId); } if (!this.Lobby.Application.TryGetGame(updateOperation.GameId, out gameState)) { if (log.IsDebugEnabled) { log.DebugFormat("Could not find game to reinitialize: {0}", updateOperation.GameId); } return(false); } this.AddGameState(gameState); } else { if (log.IsDebugEnabled) { log.DebugFormat("Game not found: {0}", updateOperation.GameId); } return(false); } } return(true); }
public virtual bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState) { if (!GetOrAddUpdatedGameState(updateOperation, out gameState)) { return(false); } bool oldVisible = gameState.IsVisbleInLobby; bool changed = gameState.Update(updateOperation); if (!changed) { return(false); } if (log.IsDebugEnabled) { LogGameState("UpdateGameState: ", gameState); } this.HandleVisibility(gameState, oldVisible); return(true); }
public bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState) { // try to get the game state if (this.gameDict.TryGet(updateOperation.GameId, out gameState) == false) { if (updateOperation.Reinitialize) { if (log.IsDebugEnabled) { log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId); } if (!this.Lobby.Application.TryGetGame(updateOperation.GameId, out gameState)) { if (log.IsDebugEnabled) { log.DebugFormat("Could not find game to reinitialize: {0}", updateOperation.GameId); } return(false); } this.gameDict.Add(updateOperation.GameId, gameState); if (this.IsGameJoinable(gameState)) { this.gameDatabase.InsertGameState(updateOperation.GameId, gameState.Properties); } } else { if (log.IsDebugEnabled) { log.DebugFormat("Game not found: {0}", updateOperation.GameId); } return(false); } } bool oldIsJoinable = this.IsGameJoinable(gameState); bool oldVisible = gameState.IsVisbleInLobby; bool changed = gameState.Update(updateOperation); if (changed) { if (gameState.IsVisbleInLobby) { this.changedGames[gameState.Id] = gameState; if (oldVisible == false) { this.removedGames.Remove(gameState.Id); } } else { if (oldVisible) { this.changedGames.Remove(gameState.Id); this.removedGames.Add(gameState.Id); } } if (log.IsDebugEnabled) { LogGameState("UpdateGameState: ", gameState); } var newIsJoinable = this.IsGameJoinable(gameState); if (newIsJoinable != oldIsJoinable) { if (newIsJoinable) { this.gameDatabase.InsertGameState(gameState.Id, gameState.Properties); if (log.IsDebugEnabled) { log.DebugFormat("GameState added to database: reason=Became joinable, gameId={0}", gameState.Id); } } else { this.gameDatabase.Delete(gameState.Id); if (log.IsDebugEnabled) { log.DebugFormat("GameState removed from database: reason=Became not joinable, gameId={0}", gameState.Id); } } } else { if (oldIsJoinable) { this.gameDatabase.Update(gameState.Id, gameState.Properties); } } } return(true); }
public virtual void HandleUpdateGameEvent(UpdateGameEvent updateGameEvent) { this.application.DefaultApplication.OnGameUpdateOnGameServer(updateGameEvent, this); this.replicationAssistant.OnGameUpdateEventHandled(updateGameEvent); }
public bool Update(UpdateGameEvent updateEvent) { this.lastUpdateEvent = Newtonsoft.Json.JsonConvert.SerializeObject(updateEvent); var peerCount = this.PlayerCount; if (updateEvent.Reinitialize) { if (log.IsDebugEnabled) { if (updateEvent.Replication == 1) { log.DebugFormat("Game is reinitialized. game:{0}", this.Id); } else { log.DebugFormat("Game is replicated. game:{0}", this.Id); } } this.StateCleanUp(); } if (log.IsDebugEnabled) { log.DebugFormat("Got update game event.content={0}", Newtonsoft.Json.JsonConvert.SerializeObject(updateEvent)); } this.ExpectsReplication = false; var changed = false; var notifyWaiters = false; if (this.HasBeenCreatedOnGameServer == false) { this.HasBeenCreatedOnGameServer = true; changed = true; notifyWaiters = true; } if (updateEvent.CheckUserIdOnJoin != null) { this.CheckUserIdOnJoin = updateEvent.CheckUserIdOnJoin.Value; } if (updateEvent.InactiveCount != this.InactivePlayerCount) { this.InactivePlayerCount = updateEvent.InactiveCount; changed = true; } if (this.GameServerPlayerCount != updateEvent.ActorCount) { this.GameServerPlayerCount = updateEvent.ActorCount; changed = true; } if (updateEvent.InactiveUsers != null) { foreach (var userId in updateEvent.InactiveUsers) { this.OnPeerLeftGameOnGameServer(userId, deactivate: true); } } if (updateEvent.NewUsers != null) { foreach (var userId in updateEvent.NewUsers) { this.OnPeerJoinedGameOnGameServer(userId); } } if (updateEvent.RemovedUsers != null) { foreach (var userId in updateEvent.RemovedUsers) { this.OnPeerLeftGameOnGameServer(userId); } } if (updateEvent.FailedToAdd != null) { foreach (var userId in updateEvent.FailedToAdd) { this.OnPeerFailedToJoinOnGameServer(userId); } } if (updateEvent.ExcludedUsers != null) { this.OnUsersExcluded(updateEvent.ExcludedUsers); changed = true; } if (updateEvent.ExpectedUsers != null) { changed |= this.OnExpectedListUpdated(updateEvent.ExpectedUsers); } if (updateEvent.MaxPlayers.HasValue && updateEvent.MaxPlayers.Value != this.MaxPlayer) { this.MaxPlayer = updateEvent.MaxPlayers.Value; this.properties[(byte)GameParameter.MaxPlayers] = this.MaxPlayer; changed = true; } if (updateEvent.IsOpen.HasValue && updateEvent.IsOpen.Value != this.IsOpen) { this.IsOpen = updateEvent.IsOpen.Value; this.properties[(byte)GameParameter.IsOpen] = updateEvent.IsOpen.Value; changed = true; } if (updateEvent.IsVisible.HasValue && updateEvent.IsVisible.Value != this.IsVisible) { this.IsVisible = updateEvent.IsVisible.Value; changed = true; } if (updateEvent.PropertyFilter != null) { var lobbyProperties = new HashSet <object>(updateEvent.PropertyFilter); var keys = new object[this.properties.Keys.Count]; this.properties.Keys.CopyTo(keys, 0); foreach (var key in keys) { if (lobbyProperties.Contains(key) == false) { this.properties.Remove(key); changed = true; } } // add max players even if it's not in the property filter // MaxPlayer is always reported to the client and available // for JoinRandom matchmaking this.properties[(byte)GameParameter.MaxPlayers] = this.MaxPlayer; } if (updateEvent.GameProperties != null) { changed |= this.UpdateProperties(updateEvent.GameProperties); } this.IsJoinable = this.CheckIsGameJoinable(); if (updateEvent.IsPersistent.HasValue && updateEvent.IsPersistent.Value != this.IsPersistent) { this.IsPersistent = updateEvent.IsPersistent.Value; changed = true; } if (updateEvent.Reinitialize) { if (log.IsDebugEnabled) { if (updateEvent.Replication == 1) { log.DebugFormat("Game reinitialization done. game:{0}", this.Id); } else { log.DebugFormat("Game replication done. game:{0}", this.Id); } } } if (peerCount != this.PlayerCount) { this.Lobby.GameList.OnPlayerCountChanged(this, peerCount); this.UpdateGameServerPlayerCount(peerCount); } /// we do notification after updating to correctly caculate players count if (notifyWaiters) { this.Lobby.NotifyWaitListOnGameCreated(this); this.waitList.Clear(); } return(changed); }
protected virtual void UpdateGameStateOnMaster(UpdateGameEvent updateEvent) { var eventData = new EventData((byte)ServerEventCode.UpdateGameState, updateEvent); GameApplication.Instance.MasterPeer.SendEvent(eventData, new SendParameters()); }
public bool Update(UpdateGameEvent updateOperation) { if (updateOperation.Reinitialize) { this.StateCleanUp(); } this.UpdateSanityChecks(updateOperation); var changed = false; if (this.HasBeenCreatedOnGameServer == false) { this.HasBeenCreatedOnGameServer = true; changed = true; } if (updateOperation.CheckUserIdOnJoin != null) { this.CheckUserIdOnJoin = updateOperation.CheckUserIdOnJoin.Value; } if (updateOperation.InactiveCount != this.InactivePlayerCount) { var oldPlayerCount = this.PlayerCount; this.InactivePlayerCount = updateOperation.InactiveCount; this.Lobby.GameList.OnPlayerCountChanged(this, oldPlayerCount); changed = true; } if (this.GameServerPlayerCount != updateOperation.ActorCount) { var oldPlayerCount = this.PlayerCount; this.GameServerPlayerCount = updateOperation.ActorCount; this.Lobby.GameList.OnPlayerCountChanged(this, oldPlayerCount); changed = true; } if (updateOperation.InactiveUsers != null) { foreach (var userId in updateOperation.InactiveUsers) { this.OnPeerLeftGameOnGameServer(userId, deactivate: true); } } if (updateOperation.NewUsers != null) { foreach (var userId in updateOperation.NewUsers) { this.OnPeerJoinedGameOnGameServer(userId); } } if (updateOperation.RemovedUsers != null) { foreach (var userId in updateOperation.RemovedUsers) { this.OnPeerLeftGameOnGameServer(userId); } } if (updateOperation.FailedToAdd != null) { foreach (var userId in updateOperation.FailedToAdd) { this.OnPeerFailedToJoinOnGameServer(userId); } } if (updateOperation.ExcludedUsers != null) { this.OnUsersExcluded(updateOperation.ExcludedUsers); changed = true; } if (updateOperation.ExpectedUsers != null) { this.OnExpectedListUpdated(updateOperation.ExpectedUsers); changed = true; } if (updateOperation.MaxPlayers.HasValue && updateOperation.MaxPlayers.Value != this.MaxPlayer) { this.MaxPlayer = updateOperation.MaxPlayers.Value; this.properties[(byte)GameParameter.MaxPlayers] = this.MaxPlayer; changed = true; } if (updateOperation.IsOpen.HasValue && updateOperation.IsOpen.Value != this.IsOpen) { this.IsOpen = updateOperation.IsOpen.Value; this.properties[(byte)GameParameter.IsOpen] = this.MaxPlayer; changed = true; } if (updateOperation.IsVisible.HasValue && updateOperation.IsVisible.Value != this.IsVisible) { this.IsVisible = updateOperation.IsVisible.Value; changed = true; } if (updateOperation.PropertyFilter != null) { var lobbyProperties = new HashSet <object>(updateOperation.PropertyFilter); var keys = new object[this.properties.Keys.Count]; this.properties.Keys.CopyTo(keys, 0); foreach (var key in keys) { if (lobbyProperties.Contains(key) == false) { this.properties.Remove(key); changed = true; } } // add max players even if it's not in the property filter // MaxPlayer is always reported to the client and available // for JoinRandom matchmaking this.properties[(byte)GameParameter.MaxPlayers] = (byte)this.MaxPlayer; } if (updateOperation.GameProperties != null) { changed |= this.UpdateProperties(updateOperation.GameProperties); } this.IsJoinable = this.CheckIsGameJoinable(); if (updateOperation.IsPersistent.HasValue && updateOperation.IsPersistent.Value != this.IsPersistent) { this.IsPersistent = updateOperation.IsPersistent.Value; changed = true; } return(changed); }
public void UpdateGameState(UpdateGameEvent operation, GameServerContext incomingGameServer) { this.ExecutionFiber.Enqueue(() => this.HandleUpdateGameState(operation, incomingGameServer)); }
public Task Handle(UpdateGameEvent notification, CancellationToken cancellationToken) { return(Task.CompletedTask); }
public bool Update(UpdateGameEvent updateOperation) { bool changed = false; if (this.IsCreatedOnGameServer == false) { this.IsCreatedOnGameServer = true; changed = true; } if (this.GameServerPlayerCount != updateOperation.ActorCount) { this.GameServerPlayerCount = updateOperation.ActorCount; changed = true; } if (updateOperation.NewUsers != null) { foreach (string userId in updateOperation.NewUsers) { this.OnPeerJoinedGameServer(userId); } } if (updateOperation.RemovedUsers != null) { foreach (string userId in updateOperation.RemovedUsers) { this.OnPeerLeftGameServer(userId); } } if (updateOperation.MaxPlayers.HasValue && updateOperation.MaxPlayers.Value != this.MaxPlayer) { this.MaxPlayer = updateOperation.MaxPlayers.Value; this.properties[(byte)GameParameter.MaxPlayer] = this.MaxPlayer; changed = true; } if (updateOperation.IsOpen.HasValue && updateOperation.IsOpen.Value != this.IsOpen) { this.IsOpen = updateOperation.IsOpen.Value; this.properties[(byte)GameParameter.IsOpen] = this.MaxPlayer; changed = true; } if (updateOperation.IsVisible.HasValue && updateOperation.IsVisible.Value != this.IsVisible) { this.IsVisible = updateOperation.IsVisible.Value; changed = true; } if (updateOperation.PropertyFilter != null) { var lobbyProperties = new HashSet <object>(updateOperation.PropertyFilter); var keys = new object[this.properties.Keys.Count]; this.properties.Keys.CopyTo(keys, 0); foreach (var key in keys) { if (lobbyProperties.Contains(key) == false) { this.properties.Remove(key); changed = true; } } // add max players even if it's not in the property filter // MaxPlayer is always reported to the client and available // for JoinRandom matchmaking this.properties[(byte)GameParameter.MaxPlayer] = (byte)this.MaxPlayer; } if (updateOperation.GameProperties != null) { changed |= this.UpdateProperties(updateOperation.GameProperties); } return(changed); }