public static void OnJoinScenario(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer) { MyLog.Default.WriteLine(String.Format("Lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState)); if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && multiplayer.GetOwner() != Sync.MyId) { // Create session with empty world if (MySession.Static != null) { MySession.Static.Unload(); MySession.Static = null; } MySession.CreateWithEmptyWorld(multiplayer); progress.CloseScreen(); MyScreenManager.CloseAllScreensNowExcept(null); MyLog.Default.WriteLine("Scenario lobby joined"); if (MyPerGameSettings.GUI.ScenarioLobbyClientScreen != null) MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.ScenarioLobbyClientScreen)); else Debug.Fail("No scenario lobby client screen"); } else { string status = "ServerHasLeft"; if (joinResult != Result.OK) { status = joinResult.ToString(); } else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success) { status = enterInfo.EnterState.ToString(); } OnJoinBattleFailed(progress, multiplayer, status); } }
public static void DownloadBattleWorld(MyMultiplayerBase multiplayer) { StringBuilder text = MyTexts.Get(MyCommonTexts.MultiplayerStateConnectingToServer); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel); MyGuiSandbox.AddScreen(progress); // Set focus to different control than Cancel button (because focused Cancel button can be unexpectedly pressed when sending a chat message - in case server has just started game). progress.FocusedControl = progress.RotatingWheel; progress.ProgressCancelled += () => { MySessionLoader.UnloadAndExitToMenu(); }; DownloadWorld(progress, multiplayer); }
private static void DownloadWorld(MyGuiScreenProgress progress, MyMultiplayerBase multiplayer) { if (progress.Text != null) { progress.Text.Clear(); progress.Text.Append(MyTexts.Get(MyCommonTexts.MultiplayerStateConnectingToServer)); } MyLog.Default.WriteLine("World requested"); const float worldRequestTimeout = 40; // in seconds Stopwatch worldRequestTime = Stopwatch.StartNew(); ulong serverId = multiplayer.GetOwner(); bool connected = false; progress.Tick += () => { P2PSessionState state = default(P2PSessionState); Peer2Peer.GetSessionState(multiplayer.ServerId, ref state); if (!connected && state.ConnectionActive) { MyLog.Default.WriteLine("World requested - connection alive"); connected = true; if (progress.Text != null) { progress.Text.Clear(); progress.Text.Append(MyTexts.Get(MyCommonTexts.MultiplayerStateWaitingForServer)); } } //progress.Text.Clear(); //progress.Text.AppendLine("Connecting: " + state.Connecting); //progress.Text.AppendLine("ConnectionActive: " + state.ConnectionActive); //progress.Text.AppendLine("Relayed: " + state.UsingRelay); //progress.Text.AppendLine("Bytes queued: " + state.BytesQueuedForSend); //progress.Text.AppendLine("Packets queued: " + state.PacketsQueuedForSend); //progress.Text.AppendLine("Last session error: " + state.LastSessionError); //progress.Text.AppendLine("Original server: " + serverId); //progress.Text.AppendLine("Current server: " + multiplayer.Lobby.GetOwner()); //progress.Text.AppendLine("Game version: " + multiplayer.AppVersion); if (serverId != multiplayer.GetOwner()) { MyLog.Default.WriteLine("World requested - failed, server changed"); progress.Cancel(); MyGuiSandbox.Show(MyCommonTexts.MultiplayerErrorServerHasLeft); multiplayer.Dispose(); } if (worldRequestTime.IsRunning && worldRequestTime.Elapsed.TotalSeconds > worldRequestTimeout) { MyLog.Default.WriteLine("World requested - failed, server changed"); progress.Cancel(); MyGuiSandbox.Show(MyCommonTexts.MultiplaterJoin_ServerIsNotResponding); multiplayer.Dispose(); } }; var downloadResult = multiplayer.DownloadWorld(); downloadResult.ProgressChanged += (result) => { worldRequestTime.Stop(); OnDownloadProgressChanged(progress, result, multiplayer); }; progress.ProgressCancelled += () => { downloadResult.Cancel(); multiplayer.Dispose(); //var joinScreen = MyScreenManager.GetScreenWithFocus() as MyGuiScreenJoinGame; //if (joinScreen != null) // joinScreen.ReloadList(); }; }
public static void OnJoinBattle(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer) { MyLog.Default.WriteLine(String.Format("Battle lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState)); bool battleCanBeJoined = multiplayer != null && multiplayer.BattleCanBeJoined; if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && battleCanBeJoined && multiplayer.GetOwner() != Sync.MyId) { // Create session with empty world Debug.Assert(MySession.Static == null); MySession.CreateWithEmptyWorld(multiplayer); MySession.Static.Settings.Battle = true; progress.CloseScreen(); MyLog.Default.WriteLine("Battle lobby joined"); if (MyPerGameSettings.GUI.BattleLobbyClientScreen != null) MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleLobbyClientScreen)); else Debug.Fail("No battle lobby client screen"); } else { bool statusFullMessage = true; string status = MyTexts.GetString(MyCommonTexts.MultiplayerErrorServerHasLeft); if (joinResult != Result.OK) { status = joinResult.ToString(); statusFullMessage = false; } else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success) { status = enterInfo.EnterState.ToString(); statusFullMessage = false; } else if (!battleCanBeJoined) { if (MyFakes.ENABLE_JOIN_STARTED_BATTLE) { status = status = MyTexts.GetString(MyCommonTexts.MultiplayerErrorSessionEnded); statusFullMessage = true; } else { status = "GameStarted"; statusFullMessage = false; } } MyLog.Default.WriteLine("Battle join failed: " + status); OnJoinBattleFailed(progress, multiplayer, status, statusFullMessage: statusFullMessage); } }
private static void OnDownloadProgressChanged(MyGuiScreenProgress progress, MyDownloadWorldResult result, MyMultiplayerBase multiplayer) { switch (result.State) { case MyDownloadWorldStateEnum.Success: progress.CloseScreen(); var world = multiplayer.ProcessWorldDownloadResult(result); if (MyFakes.ENABLE_BATTLE_SYSTEM && multiplayer.Battle) { MyGuiScreenLoadSandbox.LoadMultiplayerBattleWorld(world, multiplayer); } else if (multiplayer.Scenario) { MyGuiScreenLoadSandbox.LoadMultiplayerScenarioWorld(world, multiplayer); } else { MyGuiScreenLoadSandbox.LoadMultiplayerSession(world, multiplayer); } break; case MyDownloadWorldStateEnum.InProgress: if (result.ReceivedBlockCount == 1) { MyLog.Default.WriteLine("First world part received"); } string percent = (result.Progress * 100).ToString("0."); float size = result.ReceivedDatalength; string prefix = MyUtils.FormatByteSizePrefix(ref size); string worldSize = size.ToString("0.") + " " + prefix + "B"; if (progress.Text != null) { progress.Text.Clear(); } if (float.IsNaN(result.Progress)) { MyLog.Default.WriteLine("World requested - preemble received"); if (progress.Text != null) { progress.Text.Append(MyTexts.Get(MySpaceTexts.DialogWaitingForWorldData)); } } else { if (progress.Text != null) { progress.Text.AppendFormat(MyTexts.GetString(MySpaceTexts.DialogTextDownloadingWorld), percent, worldSize); } } break; case MyDownloadWorldStateEnum.WorldNotAvailable: MyLog.Default.WriteLine("World requested - world not available"); progress.Cancel(); MyGuiSandbox.Show(MySpaceTexts.DialogDownloadWorld_WorldDoesNotExists); multiplayer.Dispose(); break; case MyDownloadWorldStateEnum.ConnectionFailed: MyLog.Default.WriteLine("World requested - connection failed"); progress.Cancel(); MyGuiSandbox.Show(MyTexts.AppendFormat(new StringBuilder(), MySpaceTexts.MultiplayerErrorConnectionFailed, result.ConnectionError)); multiplayer.Dispose(); break; case MyDownloadWorldStateEnum.DeserializationFailed: case MyDownloadWorldStateEnum.InvalidMessage: MyLog.Default.WriteLine("World requested - message invalid (wrong version?)"); progress.Cancel(); MyGuiSandbox.Show(MySpaceTexts.DialogTextDownloadWorldFailed); multiplayer.Dispose(); break; default: throw new InvalidBranchException(); } }
public static void OnJoin(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer) { // HACK: To hide multiplayer from ME //if (!MySandboxGame.Services.SteamService.IsActive || MySandboxGame.Services.SteamService.AppId * 2 == 667900) // return; MyLog.Default.WriteLine(String.Format("Lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState)); if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && multiplayer.GetOwner() != Sync.MyId) { DownloadWorld(progress, multiplayer); } else { string status = "ServerHasLeft"; if (joinResult != Result.OK) { status = joinResult.ToString(); } else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success) { status = enterInfo.EnterState.ToString(); } OnJoinFailed(progress, multiplayer, status); } }
public static void JoinBattleGame(ulong lobbyId) { StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningWorld); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => MyGuiScreenMainMenu.ReturnToMainMenu(); MyLog.Default.WriteLine("Joining battle lobby: " + lobbyId); var result = MyMultiplayer.JoinLobby(lobbyId); result.JoinDone += (joinResult, info, multiplayer) => OnJoinBattle(progress, joinResult, info, multiplayer); progress.ProgressCancelled += () => result.Cancel(); }
private static void OnDownloadProgressChanged(MyGuiScreenProgress progress, MyDownloadWorldResult result, MyMultiplayerBase multiplayer) { switch (result.State) { case MyDownloadWorldStateEnum.Success: progress.CloseScreen(); var world = multiplayer.ProcessWorldDownloadResult(result); CheckDx11AndJoin(world, multiplayer); break; case MyDownloadWorldStateEnum.InProgress: if (result.ReceivedBlockCount == 1) MyLog.Default.WriteLine("First world part received"); string percent = (result.Progress * 100).ToString("0."); float size = result.ReceivedDatalength; string prefix = MyUtils.FormatByteSizePrefix(ref size); string worldSize = size.ToString("0.") + " " + prefix + "B"; if (progress.Text != null) progress.Text.Clear(); if (float.IsNaN(result.Progress)) { MyLog.Default.WriteLine("World requested - preemble received"); if (progress.Text != null) progress.Text.Append(MyTexts.Get(MyCommonTexts.DialogWaitingForWorldData)); } else { if (progress.Text != null) progress.Text.AppendFormat(MyTexts.GetString(MyCommonTexts.DialogTextDownloadingWorld), percent, worldSize); } break; case MyDownloadWorldStateEnum.WorldNotAvailable: MyLog.Default.WriteLine("World requested - world not available"); progress.Cancel(); MyGuiSandbox.Show(MyCommonTexts.DialogDownloadWorld_WorldDoesNotExists); multiplayer.Dispose(); break; case MyDownloadWorldStateEnum.ConnectionFailed: MyLog.Default.WriteLine("World requested - connection failed"); progress.Cancel(); MyGuiSandbox.Show(MyTexts.AppendFormat(new StringBuilder(), MyCommonTexts.MultiplayerErrorConnectionFailed, result.ConnectionError)); multiplayer.Dispose(); break; case MyDownloadWorldStateEnum.DeserializationFailed: case MyDownloadWorldStateEnum.InvalidMessage: MyLog.Default.WriteLine("World requested - message invalid (wrong version?)"); progress.Cancel(); MyGuiSandbox.Show(MyCommonTexts.DialogTextDownloadWorldFailed); multiplayer.Dispose(); break; default: throw new InvalidBranchException(); } }
public static void OnJoinBattle(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer) { MyLog.Default.WriteLine(String.Format("Battle lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState)); bool battleCanBeJoined = multiplayer != null && multiplayer.BattleCanBeJoined; if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && battleCanBeJoined && multiplayer.GetOwner() != MySteam.UserId) { // Create session with empty world Debug.Assert(MySession.Static == null); MySession.CreateWithEmptyWorld(multiplayer); MySession.Static.Settings.Battle = true; progress.CloseScreen(); MyLog.Default.WriteLine("Battle lobby joined"); if (MyPerGameSettings.GUI.BattleLobbyClientScreen != null) MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleLobbyClientScreen)); else Debug.Fail("No battle lobby client screen"); } else { string status = "ServerHasLeft"; if (joinResult != Result.OK) { status = joinResult.ToString(); } else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success) { status = enterInfo.EnterState.ToString(); } else if (!battleCanBeJoined) { status = "Started battle cannot be joined"; } OnJoinBattleFailed(progress, multiplayer, status); } }
private static void OnJoinBattleFailed(MyGuiScreenProgress progress, MyMultiplayerBase multiplayer, string status) { MyGuiScreenMainMenu.UnloadAndExitToMenu(); progress.Cancel(); StringBuilder error = new StringBuilder(); error.AppendFormat(MySpaceTexts.DialogTextJoinBattleLobbyFailed, status); MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: error, messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError)); MyGuiSandbox.AddScreen(mb); }
private static void Reconnect() { // Store previous server data m_ownerId = MyMultiplayer.Static.ServerId; m_elapsedMs = 0; m_oldLobbyId = (MyMultiplayer.Static as MyMultiplayerLobbyClient).LobbyId; // Get to main menu MySessionLoader.UnloadAndExitToMenu(); // Show loading wheel StringBuilder text = MyTexts.Get(MyCommonTexts.LoadingDialogServerIsLoadingWorld); var progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel); MyGuiSandbox.AddScreen(progress); // Start checking for new lobby Parallel.Start(FindLobby); }
public static void JoinGame(GameServerItem server) { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Join); if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION) { var sb = new StringBuilder(); sb.AppendFormat(MyTexts.GetString(MySpaceTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion); MyGuiSandbox.Show(sb, MySpaceTexts.MessageBoxCaptionError); return; } if (MyFakes.ENABLE_MP_DATA_HASHES) { var serverHash = server.GetGameTagByPrefix("datahash"); if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64()) { MyGuiSandbox.Show(MySpaceTexts.MultiplayerError_DifferentData); MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + serverHash); return; } } UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; SteamAPI.Instance.AddFavoriteGame(server.AppID, System.Net.IPAddressExtensions.ToIPv4NetworkOrder(server.NetAdr.Address), (UInt16)server.NetAdr.Port, (UInt16)server.NetAdr.Port, FavoriteEnum.History, unixTimestamp); MyMultiplayerClient multiplayer = new MyMultiplayerClient(server, new MySyncLayer(new MyTransportLayer(MyMultiplayer.GameEventChannel))); MyMultiplayer.Static = multiplayer; MyMultiplayer.Static.SyncLayer.AutoRegisterGameEvents = false; MyMultiplayer.Static.SyncLayer.RegisterGameEvents(); multiplayer.SendPlayerData(MySteam.UserName); string gamemode = server.GetGameTagByPrefix("gamemode"); if (MyFakes.ENABLE_BATTLE_SYSTEM && gamemode == "B") { StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningBattleLobby); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => { multiplayer.Dispose(); MyGuiScreenMainMenu.ReturnToMainMenu(); }; multiplayer.OnJoin += delegate { MyJoinGameHelper.OnJoinBattle(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer); }; } else { StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningWorld); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => { multiplayer.Dispose(); MyGuiScreenMainMenu.ReturnToMainMenu(); }; multiplayer.OnJoin += delegate { MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer); }; } }
private static void OnJoinFailed(MyGuiScreenProgress progress, MyMultiplayerBase multiplayer, string status) { if (multiplayer != null) { multiplayer.Dispose(); } progress.Cancel(); StringBuilder error = new StringBuilder(); error.AppendFormat(MyCommonTexts.DialogTextJoinWorldFailed, status); MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: error, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError)); MyGuiSandbox.AddScreen(mb); }
public static void DownloadBattleWorld(MyMultiplayerBase multiplayer) { StringBuilder text = MyTexts.Get(MySpaceTexts.MultiplayerStateConnectingToServer); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => { MyGuiScreenMainMenu.ReturnToMainMenu(); }; DownloadWorld(progress, multiplayer); }
private static void OnJoinBattleFailed(MyGuiScreenProgress progress, MyMultiplayerBase multiplayer, string status, bool statusFullMessage = false) { MySessionLoader.UnloadAndExitToMenu(); progress.Cancel(); StringBuilder error = new StringBuilder(); if (statusFullMessage) error.Append(status); else error.AppendFormat(MySpaceTexts.DialogTextJoinBattleFailed, status); MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: error, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError)); MyGuiSandbox.AddScreen(mb); }
public static void JoinScenarioGame(ulong lobbyId) { StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningScenario); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => MySessionLoader.UnloadAndExitToMenu(); MyLog.Default.WriteLine("Joining scenario lobby: " + lobbyId); var result = MyMultiplayer.JoinLobby(lobbyId); result.JoinDone += (joinResult, info, multiplayer) => OnJoinScenario(progress, joinResult, info, multiplayer); progress.ProgressCancelled += () => result.Cancel(); }
public static void JoinGame(GameServerItem server) { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Join); if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION) { var sb = new StringBuilder(); sb.AppendFormat(MyTexts.GetString(MyCommonTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion); MyGuiSandbox.Show(sb, MyCommonTexts.MessageBoxCaptionError); return; } if (MyFakes.ENABLE_MP_DATA_HASHES) { var serverHash = server.GetGameTagByPrefix("datahash"); if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64()) { MyGuiSandbox.Show(MyCommonTexts.MultiplayerError_DifferentData); MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + serverHash); return; } } UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; SteamAPI.Instance.AddFavoriteGame(server.AppID, System.Net.IPAddressExtensions.ToIPv4NetworkOrder(server.NetAdr.Address), (UInt16)server.NetAdr.Port, (UInt16)server.NetAdr.Port, FavoriteEnum.History, unixTimestamp); MyMultiplayerClient multiplayer = new MyMultiplayerClient(server, new MySyncLayer(new MyTransportLayer(MyMultiplayer.GameEventChannel))); MyMultiplayer.Static = multiplayer; MyMultiplayer.Static.SyncLayer.AutoRegisterGameEvents = false; MyMultiplayer.Static.SyncLayer.RegisterGameEvents(); multiplayer.SendPlayerData(MySteam.UserName); string gamemode = server.GetGameTagByPrefix("gamemode"); if (MyFakes.ENABLE_BATTLE_SYSTEM && gamemode == "B") { StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningBattle); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => { multiplayer.Dispose(); MySessionLoader.UnloadAndExitToMenu(); }; multiplayer.OnJoin += delegate { MyJoinGameHelper.OnJoinBattle(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer); }; } else { StringBuilder text = MyTexts.Get(MyCommonTexts.DialogTextJoiningWorld); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => { multiplayer.Dispose(); if (MyMultiplayer.Static != null) { MyMultiplayer.Static.Dispose(); } }; multiplayer.OnJoin += delegate { MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer); }; } }
public static void OnJoinBattle(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer) { MyLog.Default.WriteLine(String.Format("Battle lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState)); bool battleCanBeJoined = multiplayer != null && multiplayer.BattleCanBeJoined; if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && battleCanBeJoined && multiplayer.GetOwner() != Sync.MyId) { // Create session with empty world Debug.Assert(MySession.Static == null); MySession.CreateWithEmptyWorld(multiplayer); MySession.Static.Settings.Battle = true; progress.CloseScreen(); MyLog.Default.WriteLine("Battle lobby joined"); if (MyPerGameSettings.GUI.BattleLobbyClientScreen != null) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleLobbyClientScreen)); } else { Debug.Fail("No battle lobby client screen"); } } else { bool statusFullMessage = true; string status = MyTexts.GetString(MyCommonTexts.MultiplayerErrorServerHasLeft); if (joinResult != Result.OK) { status = joinResult.ToString(); statusFullMessage = false; } else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success) { status = enterInfo.EnterState.ToString(); statusFullMessage = false; } else if (!battleCanBeJoined) { if (MyFakes.ENABLE_JOIN_STARTED_BATTLE) { status = status = MyTexts.GetString(MyCommonTexts.MultiplayerErrorSessionEnded); statusFullMessage = true; } else { status = "GameStarted"; statusFullMessage = false; } } MyLog.Default.WriteLine("Battle join failed: " + status); OnJoinBattleFailed(progress, multiplayer, status, statusFullMessage: statusFullMessage); } }