public static void AllGamesBlocked() { Player newPlayer = WorldLoadingPlayer; WorldLoadingPlayer = null; new Thread(() => { // Wait to get all remaining packets processed, because unprocessed packets // before saving may end in an desynced game for the joining client Thread.Sleep(2000); // Create game save in the main thread AsyncAction action = SimulationManager.instance.AddAction(SaveHelpers.SaveServerLevel); // Wait until the save action is queued and the game is saved while (!action.completed || SaveHelpers.IsSaving()) { Thread.Sleep(10); } Command.SendToClient(newPlayer, new WorldTransferCommand { World = SaveHelpers.GetWorldFile() }); newPlayer.Status = ClientStatus.Loading; }).Start(); }
public static void PrepareWorldLoad(Player newPlayer) { newPlayer.Status = ClientStatus.Downloading; // Open status window ThreadHelper.dispatcher.Dispatch(() => { ClientJoinPanel clientJoinPanel = UIView.GetAView().FindUIComponent <ClientJoinPanel>("MPClientJoinPanel"); if (clientJoinPanel != null) { clientJoinPanel.isVisible = true; clientJoinPanel.StartCheck(); } else { clientJoinPanel = (ClientJoinPanel)UIView.GetAView().AddUIComponent(typeof(ClientJoinPanel)); } clientJoinPanel.Focus(); }); // Inform other clients about the joining client Command.SendToOtherClients(new ClientJoiningCommand { JoiningFinished = false }, newPlayer); MultiplayerManager.Instance.GameBlocked = true; SimulationManager.instance.SimulationPaused = true; // Get a serialized version of the server world to send to the player. SaveHelpers.SaveServerLevel(); new Thread(() => { while (SaveHelpers.IsSaving()) { Thread.Sleep(100); } Command.SendToClient(newPlayer, new WorldTransferCommand { World = SaveHelpers.GetWorldFile() }); newPlayer.Status = ClientStatus.Loading; }).Start(); }
public static void PrepareWorldLoad(Player newPlayer) { newPlayer.Status = ClientStatus.Downloading; MultiplayerManager.Instance.BlockGame(newPlayer.Username); SimulationManager.instance.SimulationPaused = true; // Inform other clients about the joining client Command.SendToOtherClients(new ClientJoiningCommand { JoiningFinished = false, JoiningUsername = newPlayer.Username }, newPlayer); /* * Wait to get all remaining pakets processed, because unprocessed packets * before saving may end in an desynced game for the joining client */ Thread.Sleep(2000); // Get a serialized version of the server world to send to the player. SaveHelpers.SaveServerLevel(); new Thread(() => { while (SaveHelpers.IsSaving()) { Thread.Sleep(100); } Command.SendToClient(newPlayer, new WorldTransferCommand { World = SaveHelpers.GetWorldFile() }); newPlayer.Status = ClientStatus.Loading; }).Start(); }