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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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
                {
                    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();
            }
        }
    private void CreateMainMenuControls()
    {
        MyStringId optionsScreen_Help_Menu = MySpaceTexts.OptionsScreen_Help_Menu;
        Vector2    vector = new Vector2(0.001f, (0f - m_size.Value.Y) / 2f + 0.126f);
        int        num    = 0;
        MyObjectBuilder_LastSession lastSession = MyLocalCache.GetLastSession();

        if (lastSession != null && (lastSession.Path == null || MyPlatformGameSettings.GAME_SAVES_TO_CLOUD || Directory.Exists(lastSession.Path)) && (!lastSession.IsLobby || MyGameService.LobbyDiscovery.ContinueToLobbySupported))
        {
            MyGuiControlButton myGuiControlButton = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonContinueGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                MyObjectBuilder_LastSession mySession = MyLocalCache.GetLastSession();
                if (mySession == null)
                {
                    return;
                }
                if (mySession.IsOnline)
                {
                    if (mySession.IsLobby)
                    {
                        MyJoinGameHelper.JoinGame(ulong.Parse(mySession.ServerIP));
                        return;
                    }
                    MyGameService.Service.RequestPermissions(Permissions.Multiplayer, attemptResolution : true, delegate(PermissionResult granted)
                    {
                        switch (granted)
                        {
                        case PermissionResult.Granted:
                            MyGameService.Service.RequestPermissions(Permissions.CrossMultiplayer, attemptResolution : true, delegate(PermissionResult crossGranted)
                            {
                                switch (crossGranted)
                                {
                                case PermissionResult.Granted:
                                    MyGameService.Service.RequestPermissions(Permissions.UGC, attemptResolution : true, delegate(PermissionResult ugcGranted)
                                    {
                                        switch (ugcGranted)
                                        {
                                        case PermissionResult.Granted:
                                            JoinServer(mySession);
                                            break;

                                        case PermissionResult.Error:
                                            MySandboxGame.Static.Invoke(delegate
                                            {
                                                MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                            }, "New Game screen");
                                            break;
                                        }
                                    });
                                    break;

                                case PermissionResult.Error:
                                    MySandboxGame.Static.Invoke(delegate
                                    {
                                        MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                    }, "New Game screen");
                                    break;
                                }
                            });
                            break;

                        case PermissionResult.Error:
                            MySandboxGame.Static.Invoke(delegate
                            {
                                MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                            }, "New Game screen");
                            break;
                        }
                    });
                }
                else if (!m_parallelLoadIsRunning)
                {
                    m_parallelLoadIsRunning            = true;
                    MyGuiScreenProgress progressScreen = new MyGuiScreenProgress(MyTexts.Get(MySpaceTexts.ProgressScreen_LoadingWorld));
                    MyScreenManager.AddScreen(progressScreen);
                    Parallel.StartBackground(delegate
                    {
                        MySessionLoader.LoadLastSession();
                    }, delegate
                    {
                        progressScreen.CloseScreen();
                        m_parallelLoadIsRunning = false;
                    });
                }
            });

            myGuiControlButton.GamepadHelpTextId = optionsScreen_Help_Menu;
            Controls.Add(myGuiControlButton);
            m_elementGroup.Add(myGuiControlButton);
        }
        else
        {
            num--;
        }

        MyGuiControlButton myGuiControlButton2 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonCampaign), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenNewGame>(new object[3] {
                true, true, true
            }));
        });

        myGuiControlButton2.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton2);
        m_elementGroup.Add(myGuiControlButton2);



        MyGuiControlButton myGuiControlButton3 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonLoadGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            MyGuiSandbox.AddScreen(new MyGuiScreenLoadSandbox());
        });

        myGuiControlButton3.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton3);
        m_elementGroup.Add(myGuiControlButton3);


        if (MyPerGameSettings.MultiplayerEnabled)
        {
            MyGuiControlButton myGuiControlButton4 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonJoinGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                if (MyGameService.IsOnline)
                {
                    MyGameService.Service.RequestPermissions(Permissions.Multiplayer, attemptResolution : true, delegate(PermissionResult granted)
                    {
                        switch (granted)
                        {
                        case PermissionResult.Granted:
                            MyGameService.Service.RequestPermissions(Permissions.UGC, attemptResolution : true, delegate(PermissionResult ugcGranted)
                            {
                                switch (ugcGranted)
                                {
                                case PermissionResult.Granted:
                                    MyGameService.Service.RequestPermissions(Permissions.CrossMultiplayer, attemptResolution : true, delegate(PermissionResult crossGranted)
                                    {
                                        MyGuiScreenJoinGame myGuiScreenJoinGame = new MyGuiScreenJoinGame(crossGranted == PermissionResult.Granted);
                                        myGuiScreenJoinGame.Closed += joinGameScreen_Closed;
                                        MyGuiSandbox.AddScreen(myGuiScreenJoinGame);
                                    });
                                    break;

                                case PermissionResult.Error:
                                    MySandboxGame.Static.Invoke(delegate
                                    {
                                        MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                    }, "New Game screen");
                                    break;
                                }
                            });
                            break;

                        case PermissionResult.Error:
                            MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                            break;
                        }
                    });
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: new StringBuilder().AppendFormat(MyTexts.GetString(MyGameService.IsActive ? MyCommonTexts.SteamIsOfflinePleaseRestart : MyCommonTexts.ErrorJoinSessionNoUser), MySession.GameServiceName)));
                }
            });
            myGuiControlButton4.GamepadHelpTextId = optionsScreen_Help_Menu;
            Controls.Add(myGuiControlButton4);
            m_elementGroup.Add(myGuiControlButton4);
        }

        MyGuiControlButton myGuiControlButton5 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonOptions), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            bool flag = !MyPlatformGameSettings.LIMITED_MAIN_MENU;

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyOldOptionsAccessMenu>(new object[1] {
                !flag
            }));
        });

        myGuiControlButton5.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton5);
        m_elementGroup.Add(myGuiControlButton5);

        if (MyFakes.ENABLE_MAIN_MENU_INVENTORY_SCENE)
        {
            MyGuiControlButton myGuiControlButton6 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonInventory), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                if (MyGameService.IsActive)
                {
                    if (MyGameService.Service.GetInstallStatus(out var _))
                    {
                        if (MySession.Static == null)
                        {
                            MyGuiScreenLoadInventory inventory = MyGuiSandbox.CreateScreen <MyGuiScreenLoadInventory>(Array.Empty <object>());
                            MyGuiScreenLoading screen          = new MyGuiScreenLoading(inventory, null);
                            MyGuiScreenLoadInventory myGuiScreenLoadInventory = inventory;
                            myGuiScreenLoadInventory.OnLoadingAction          = (Action)Delegate.Combine(myGuiScreenLoadInventory.OnLoadingAction, (Action) delegate
                            {
                                MySessionLoader.LoadInventoryScene();
                                MySandboxGame.IsUpdateReady = true;
                                inventory.Initialize(inGame: false, null);
                            });
                            MyGuiSandbox.AddScreen(screen);
                        }
                        else
                        {
                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenLoadInventory>(new object[2] {
                                false, null
                            }));
                        }
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionInfo), messageText: MyTexts.Get(MyCommonTexts.InventoryScreen_InstallInProgress)));
                    }
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.SteamIsOfflinePleaseRestart)));
                }
            });
        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 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 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);
            }
        }
Example #8
0
    private void ContinueGameInternal()
    {
        MyObjectBuilder_LastSession mySession = MyLocalCache.GetLastSession();

        if (mySession == null)
        {
            return;
        }
        if (mySession.IsOnline)
        {
            if (mySession.IsLobby)
            {
                MyJoinGameHelper.JoinGame(ulong.Parse(mySession.ServerIP));
                return;
            }
            MyGameService.Service.RequestPermissions(Permissions.Multiplayer, attemptResolution : true, delegate(PermissionResult granted)
            {
                switch (granted)
                {
                case PermissionResult.Granted:
                    MyGameService.Service.RequestPermissions(Permissions.CrossMultiplayer, attemptResolution : true, delegate(PermissionResult crossGranted)
                    {
                        switch (crossGranted)
                        {
                        case PermissionResult.Granted:
                            MyGameService.Service.RequestPermissions(Permissions.UGC, attemptResolution : true, delegate(PermissionResult ugcGranted)
                            {
                                switch (ugcGranted)
                                {
                                case PermissionResult.Granted:
                                    JoinServer(mySession);
                                    break;

                                case PermissionResult.Error:
                                    MySandboxGame.Static.Invoke(delegate
                                    {
                                        MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                    }, "New Game screen");
                                    break;
                                }
                            });
                            break;

                        case PermissionResult.Error:
                            MySandboxGame.Static.Invoke(delegate
                            {
                                MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                            }, "New Game screen");
                            break;
                        }
                    });
                    break;

                case PermissionResult.Error:
                    MySandboxGame.Static.Invoke(delegate
                    {
                        MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                    }, "New Game screen");
                    break;
                }
            });
        }
        else if (!m_parallelLoadIsRunning)
        {
            m_parallelLoadIsRunning = true;
            MyGuiScreenProgress progressScreen = new MyGuiScreenProgress(MyTexts.Get(MySpaceTexts.ProgressScreen_LoadingWorld));
            MyScreenManager.AddScreen(progressScreen);
            Parallel.StartBackground(delegate
            {
                MySessionLoader.LoadLastSession();
            }, delegate
            {
                progressScreen.CloseScreen();
                m_parallelLoadIsRunning = false;
            });
        }
    }
 private static void ServerResponded(object sender, MyGameServerItem serverItem)
 {
     CloseHandlers();
     m_progressScreen.CloseScreen();
     MyJoinGameHelper.JoinGame(serverItem, true);
 }
Example #10
0
        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);
            }
        }
Example #11
0
        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);
            }
        }