protected virtual void OnOnlineInterfaceTerminate() { GameStateManager.TransitionToState(_specificDefinition.gameStateIfReturn); DebugScreenMessage.DisplayMessage("Disconnected from online service. Check your connection."); Log.Warning("[" + ToString() + "] OnlineInterface has terminated itself without user intent."); }
void OnSessionInterfaceTerminated() { ClearSessionInterface(); DebugScreenMessage.DisplayMessage("You were disconnected from the game."); GameStateManager.TransitionToState(_specificDefinition.gameStateIfDisconnect); }
static IEnumerator StartServer(QuickStartSettings settings) { LoadingScreenUIController.DisplayedStatus = "Waiting for online services..."; OnlineService.SetTargetRole(OnlineRole.Server); while (OnlineService.IsChangingRole || OnlineService.CurrentRole != OnlineRole.Server || OnlineService.ServerInterface == null) { yield return(null); } if (string.IsNullOrEmpty(settings.serverName)) { LoadingScreenUIController.DisplayedStatus = "Loading..."; GameStateManager.TransitionToState(Assets.lobbyServer); } else { // Create session int success = -1; // -1 -> waiting for result 0 -> failure 1 -> success LoadingScreenUIController.DisplayedStatus = "Creating session ..."; OnlineService.ServerInterface.CreateSession(settings.serverName, (bool r, string message) => { if (r) { success = 1; } else { success = 0; } }); // wait for creation result while (success == -1) { yield return(null); } if (success == 0) { string message = "Failed server quickstart. Could not create session [" + settings.serverName + "]."; DebugScreenMessage.DisplayMessage(message); Log.Error(message); GameStateManager.TransitionToState(Assets.rootMenu); } else { // success! LoadingScreenUIController.DisplayedStatus = "Loading ..."; GameStateManager.TransitionToState(Assets.inGameServer, new GameStateParamLevelName(settings.level)); } } }
public void ReceiveLargeData(NetMessageChatMessage netMessage, INetworkInterfaceConnection source) { if (netMessage.message.Length < 100) { DebugScreenMessage.DisplayMessage(netMessage.message); } else { DebugScreenMessage.DisplayMessage(netMessage.message.Length.ToString()); } }
void OnClick_Join() { if (_selectedSession != null) { ((GameStateLobbyClient)GameStateManager.currentGameState).JoinSession(_selectedSession, null); } else { string message = "Cannot join null session"; DebugScreenMessage.DisplayMessage(message); Log.Error(message); } }
void OnJoinSessionResult(bool success, string message) { _createSessionCallback?.Invoke(success, message); WaitSpinnerService.Disable(this); if (success) { GameStateManager.TransitionToState(_specificDefinition.gameStateIfCreateSession); } else { DebugScreenMessage.DisplayMessage("Failed to create the session: " + message); Log.Info("[GameStateLobbyServer] Failed to create session: " + message); } }
CoroutineOperation SyncSimulationWithServer() { if (IsSynchronizing) { Log.Warning("Trying to start a SimSync process while we are already in one"); return(null); } Debug.Log($"Starting sync (old world was at {_simWorldSystem.SimulationWorld.GetLastTickIdFromEntity()})"); _tickSystem.PauseSimulation(key: "sync"); _receiveTickSystem.ClearAccumulatedTicks(); _receiveTickSystem.StartShelvingTicks(); var newWorld = _simWorldSystem.CreateNewReplacementWorld(); _ongoingSyncOp = new SimulationSyncFromTransferClientOperation(_session, newWorld); _ongoingSyncOp.OnTerminateCallback = (op) => { // restore ticks we received while syncing _receiveTickSystem.StopShelvingTicks(); _tickSystem.UnpauseSimulation(key: "sync"); }; _ongoingSyncOp.OnSucceedCallback = (op) => { DebugScreenMessage.DisplayMessage($"Transfered sim. {op.Message}"); Debug.Log($"Post sync, restore shelve from {newWorld.GetLastTickIdFromEntity() + 1} (new world is at {newWorld.GetLastTickIdFromEntity()})"); _receiveTickSystem.ClearAccumulatedTicks(); _receiveTickSystem.RestoreTicksFromShelf(newWorld.GetLastTickIdFromEntity() + 1); _simWorldSystem.RequestReplaceSimWorld(newWorld); }; _ongoingSyncOp.OnFailCallback = (op) => { DebugScreenMessage.DisplayMessage($"Failed to sync sim. {op.Message}"); }; _ongoingSyncOp.Execute(); return(_ongoingSyncOp); }
private static void Cmd_PostSimSave_Internal(string locationTxt) { s_commandInstance._tickSystem.PauseSimulation("save_cmd"); s_commandInstance._ongoingCmdOperation.OnTerminateCallback = (op) => s_commandInstance._tickSystem.UnpauseSimulation("save_cmd"); s_commandInstance._ongoingCmdOperation.OnSucceedCallback = (op) => { DebugScreenMessage.DisplayMessage($"Saved sim to {locationTxt}. {op.Message}"); }; s_commandInstance._ongoingCmdOperation.OnFailCallback = (op) => { DebugScreenMessage.DisplayMessage($"Could not save sim to {locationTxt}. {op.Message}"); }; // start operation s_commandInstance._ongoingCmdOperation.Execute(); }
private static void Cmd_PostSimLoad_Internal(string locationTxt, SimulationWorld newWorld) { s_commandInstance._tickSystem.PauseSimulation("load_cmd"); s_commandInstance._ongoingCmdOperation.OnTerminateCallback = (op) => s_commandInstance._tickSystem.UnpauseSimulation("load_cmd"); s_commandInstance._ongoingCmdOperation.OnSucceedCallback = (op) => { DebugScreenMessage.DisplayMessage($"Loaded sim from {locationTxt}. {op.Message}"); s_commandInstance._simulationWorldSystem.RequestReplaceSimWorld(newWorld); }; s_commandInstance._ongoingCmdOperation.OnFailCallback = (op) => { DebugScreenMessage.DisplayMessage($"Could not load sim from {locationTxt}. {op.Message}"); }; s_commandInstance._ongoingCmdOperation.Execute(); }
static IEnumerator StartClient(QuickStartSettings settings) { LoadingScreenUIController.DisplayedStatus = "Waiting for online services..."; OnlineService.SetTargetRole(OnlineRole.Client); while (OnlineService.IsChangingRole || OnlineService.CurrentRole != OnlineRole.Client || OnlineService.ClientInterface == null) { yield return(null); } if (string.IsNullOrEmpty(settings.serverName)) { LoadingScreenUIController.DisplayedStatus = "Loading..."; GameStateManager.TransitionToState(Assets.lobbyClient); } else { LoadingScreenUIController.DisplayedStatus = "Looking for server [" + settings.serverName + "] ..."; INetworkInterfaceSession foundSession = null; IEnumerator WaitForServerToAppear() { float elapsedTime = 0; while (foundSession == null && (elapsedTime < Assets.searchForSeverTimeout || Assets.searchForSeverTimeout == -1) && OnlineService.ClientInterface != null) { foreach (INetworkInterfaceSession session in OnlineService.ClientInterface.AvailableSessions) { if (session.HostName == settings.serverName) { foundSession = session; break; } } elapsedTime += Time.unscaledDeltaTime; yield return(null); } } yield return(WaitForServerToAppear()); if (foundSession == null) { string message = "Failed client quickstart. Could not find server with name [" + settings.serverName + "] in time."; DebugScreenMessage.DisplayMessage(message); Log.Warning(message); GameStateManager.TransitionToState(Assets.rootMenu); } else { LoadingScreenUIController.DisplayedStatus = "Connecting to server [" + settings.serverName + "] ..."; int success = -1; // -1 -> waiting for result 0 -> failure 1 -> success OnlineService.ClientInterface.ConnectToSession(foundSession, (bool r, string message) => { if (r) { success = 1; } else { success = 0; } }); // wait for connection result while (success == -1) { yield return(null); } if (success == 0) { string message = "Failed client quickstart. Could not connect to server [" + settings.serverName + "]."; DebugScreenMessage.DisplayMessage(message); Log.Error(message); GameStateManager.TransitionToState(Assets.rootMenu); } else { // success! LoadingScreenUIController.DisplayedStatus = "Loading..."; GameStateManager.TransitionToState(Assets.inGameClient); } } } }
void OnReceiveMessage(TestMessage msg, INetworkInterfaceConnection sender) { DebugScreenMessage.DisplayMessage("Received TestMessage:\n" + msg); }