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(); }