Example #1
0
        public static void Postfix(MyGuiScreenMainMenu __instance, Vector2 leftButtonPositionOrigin, ref Vector2 lastButtonPosition)
        {
            MyGuiControlButton lastBtn = null;

            foreach (var control in __instance.Controls)
            {
                if (control is MyGuiControlButton btn && btn.Position == lastButtonPosition)
                {
                    lastBtn = btn;
                    break;
                }
            }

            Vector2 position;

            if (lastBtn == null)
            {
                position = lastButtonPosition + MyGuiConstants.MENU_BUTTONS_POSITION_DELTA;
            }
            else
            {
                position         = lastBtn.Position;
                lastBtn.Position = lastButtonPosition + MyGuiConstants.MENU_BUTTONS_POSITION_DELTA;
            }

            MyGuiControlButton openBtn = new MyGuiControlButton(position, MyGuiControlButtonStyleEnum.StripeLeft, originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM, text: new StringBuilder("Plugins"), onButtonClick: _ => MyGuiScreenPluginConfig.OpenMenu())
            {
                BorderEnabled          = false,
                BorderSize             = 0,
                BorderHighlightEnabled = false,
                BorderColor            = Vector4.Zero
            };

            __instance.Controls.Add(openBtn);
        }
Example #2
0
        public void SendPlayerData(string clientName)
        {
            ConnectedClientDataMsg msg = new ConnectedClientDataMsg();

            msg.SteamID = Sync.MyId;
            msg.Name    = clientName;
            msg.Join    = true;

            var  buffer = new byte[1024];
            uint length;
            uint ticketHandle; // TODO: Store handle and end auth session on end

            if (!MySteam.API.GetAuthSessionTicket(out ticketHandle, buffer, out length))
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorConnectionFailed)));
                return;
            }

            msg.Token = new byte[length];
            Array.Copy(buffer, msg.Token, length);

            ReplicationLayer.SendClientConnected(ref msg);
        }
Example #3
0
        protected override void OnClientBan(ref MyControlBanClientMsg data, ulong sender)
        {
            if (data.BannedClient == Sync.MyId && data.Banned == true)
            {
                // We don't want to send disconnect message because the clients will disconnect the client automatically upon receiving on the MyControlBanClientMsg
                m_clientJoined = false;

                Dispose();
                MyGuiScreenMainMenu.ReturnToMainMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionKicked),
                                           messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextYouHaveBeenBanned)));
            }
            else
            {
                if (data.Banned)
                {
                    AddBannedClient(data.BannedClient);
                }
                else
                {
                    RemoveBannedClient(data.BannedClient);
                }

                if (m_members.Contains(data.BannedClient) && data.Banned == true)
                {
                    RaiseClientLeft(data.BannedClient, ChatMemberStateChangeEnum.Banned);
                }
            }
        }
        public void SendPlayerData(string clientName)
        {
            ConnectedClientDataMsg msg = new ConnectedClientDataMsg();

            msg.SteamID = MySteam.UserId;
            msg.Name    = clientName;
            msg.Join    = true;

            var  buffer = new byte[1024];
            uint length = 0;

            if (!MySteam.API.GetAuthSessionTicket(buffer, ref length))
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.MultiplayerErrorConnectionFailed)));
                return;
            }

            msg.Token = new byte[length];
            Array.Copy(buffer, msg.Token, length);

            SyncLayer.SendMessageToServer(ref msg);
        }
 public static void Postfix(ref MyGuiScreenMainMenu __instance)
 {
     if (__instance.GetType() == typeof(MyGuiScreenMainMenu))
     {
         SpeedLimitFix.Shared.MenuHidden();
     }
 }
        protected override void Canceling()
        {
            if (MySession.Static != null && MySession.Static.Player != null)
            {
                MySession.Static.Player.RestoreHealth();
            }

            MyGuiScreenMainMenu.UnloadAndExitToMenu();
        }
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    RaiseClientJoined(changedUser);

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        var playerJoined = new MyHudNotification(MySpaceTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                        playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerJoined);
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientLeft(changedUser, stateChange);
                    }

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MySpaceTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
 public override void UpdateAfterSimulation()
 {
     if (Enabled && MySandboxGame.IsGameReady && MySession.Static != null && MySession.Static.ElapsedPlayTime.TotalSeconds > 5)
     {
         GC.Collect(2, GCCollectionMode.Forced);
         MySandboxGame.Log.WriteLine(String.Format("RELOAD TEST, Game GC: {0} B", GC.GetTotalMemory(false).ToString("##,#")));
         MySandboxGame.Log.WriteLine(String.Format("RELOAD TEST, Game WS: {0} B", Process.GetCurrentProcess().PrivateMemorySize64.ToString("##,#")));
         MyGuiScreenMainMenu.UnloadAndExitToMenu();
     }
 }
        public override void HandleInput(bool receivedFocusInThisUpdate)
        {
            base.HandleInput(receivedFocusInThisUpdate);

            if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape))
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                MyGuiScreenMainMenu.AddMainMenu();
            }
        }
Example #10
0
        void MyMultiplayerClient_HostLeft()
        {
            m_clientJoined = false;
            CloseClient();

            MyGuiScreenMainMenu.UnloadAndExitToMenu();
            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                       messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft)));
        }
        void OnFriendsSectorsClick(MyGuiControlButton sender)
        {
            var enterFriendSectorMapScreen = new MyGuiScreenEnterFriendSectorMap(MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS, MyTextsWrapperEnum.StartGameInProgressPleaseWait, m_closeAfterSuccessfulEnter);

            enterFriendSectorMapScreen.CustomLoadAction = sector => StartSandbox(sector);

            string lastname = MyConfig.LastFriendName;
            MyMwcSelectSectorRequestTypeEnum startRequest = String.IsNullOrEmpty(lastname) ? MyMwcSelectSectorRequestTypeEnum.RANDOM_FRIENDS : MyMwcSelectSectorRequestTypeEnum.FIND_BY_PLAYER_NAME_FULLTEXT;

            MyGuiScreenMainMenu.AddLoginScreen(new MyGuiScreenSelectSandboxProgress(startRequest, MyTextsWrapperEnum.SelectSandboxInProgressPleaseWait,
                                                                                    enterFriendSectorMapScreen, lastname, enterFriendSectorMapScreen.AddFriendSectorsResponse));
        }
Example #12
0
        private static void LoadMission(CheckpointData data)
        {
            var checkpoint = data.Checkpoint;

            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success, string mismatchMods)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;

                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);

                    MyGuiScreenLoadSandbox.CheckMismatchmods(mismatchMods, callback : delegate(VRage.Game.ModAPI.ResultEnum val)
                    {
                        // May be called from gameplay, so we must make sure we unload the current game
                        if (MySession.Static != null)
                        {
                            MySession.Static.Unload();
                            MySession.Static = null;
                        }

                        //seed 0 has special meaning - please randomize at mission start. New seed will be saved and game will run with it ever since.
                        //  if you use this, YOU CANNOT HAVE ANY PROCEDURAL ASTEROIDS ALREADY SAVED
                        if (checkpoint.Settings.ProceduralSeed == 0)
                        {
                            checkpoint.Settings.ProceduralSeed = MyRandom.Instance.Next();
                        }

                        MyGuiScreenGamePlay.StartLoading(delegate
                        {
                            checkpoint.Settings.Scenario = true;
                            MySession.LoadMission(data.SessionPath, checkpoint, data.CheckpointSize, data.PersistentEditMode);
                        });
                    });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed).ToString());
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                               messageText : MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed),
                                               buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (MyFakes.QUICK_LAUNCH != null)
                        {
                            MyGuiScreenMainMenu.ReturnToMainMenu();
                        }
                    }));
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
 private void ButtonClickAction(MySolarSystemAreaEnum solarSystemArea)
 {
     m_areaToTravel = solarSystemArea;
     if (MyClientServer.LoggedPlayer != null)
     {
         StartTravelCallback();
     }
     else
     {
         MyGuiManager.RemoveScreen(this, true);
         MyGuiScreenMainMenu.AddLoginScreenDrmFree(new Action(StartTravelCallback));
     }
 }
Example #14
0
        public static void AfterLogos()
        {
            MyGuiManager.BackToMainMenu();

            if (MySteam.IsActive)
            {
                MyGuiScreenMainMenu.AddLoginScreenDrmFree((MyGuiScreenBase)null);
            }
            else
            {
                MyGuiScreenMainMenu.AddAutologinScreen();
            }
        }
        public void OnCancelClick(MyGuiControlButton sender)
        {
            if (!MyGuiManager.IsMainMenuScreenOpened())
            {
                MyGuiScreenMainMenu.SkipAutologin();
                MyGuiManager.BackToMainMenu();
            }

            MyGuiManager.UpdateDemoAccessScreen();

            //  Just close the screen, ignore any change
            CloseScreen();
        }
        protected override void OnClosed()
        {
            MySyncScenario.PlayerReadyToStartScenario -= MySyncScenario_PlayerReady;
            MySyncScenario.TimeoutReceived            -= MySyncScenario_SetTimeout;
            MySyncScenario.CanJoinRunningReceived     -= MySyncScenario_SetCanJoinRunning;
            m_canJoinRunning.IsCheckedChanged         -= OnJoinRunningChecked;

            m_readyPlayers.Clear();
            base.OnClosed();
            if (Cancelled)
            {
                MyGuiScreenMainMenu.ReturnToMainMenu();
            }
        }
Example #17
0
 protected override void OnClientKick(ref MyControlKickClientMsg data, ulong kicked)
 {
     if (data.KickedClient == MySteam.UserId)
     {
         MyGuiScreenMainMenu.ReturnToMainMenu();
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionKicked),
                                    messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextYouHaveBeenKicked)));
     }
     else
     {
         AddKickedClient(data.KickedClient);
         RaiseClientLeft(data.KickedClient, ChatMemberStateChangeEnum.Kicked);
     }
 }
        private void ButtonClickAction(MyMissionID missionId)
        {
            if (MinerWars.AppCode.Game.Sessions.MyMultiplayerGameplay.IsRunning)
            {
                MinerWars.AppCode.Game.Sessions.MyMultiplayerGameplay.Static.Shutdown();
            }

            m_missionIdToStart = missionId;
            if (MyClientServer.LoggedPlayer != null)
            {
                StartMissionCallback();
            }
            else
            {
                MyGuiManager.RemoveScreen(this, true);
                MyGuiScreenMainMenu.AddLoginScreenDrmFree(new Action(StartMissionCallback));
            }
        }
        protected override void OnClientKick(ref MyControlKickClientMsg data, ulong sender)
        {
            if (data.KickedClient == MySteam.UserId)
            {
                // We don't want to send disconnect message because the clients will disconnect the client automatically upon receiving on the MyControlKickClientMsg
                m_clientJoined = false;

                Dispose();
                MyGuiScreenMainMenu.ReturnToMainMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionKicked),
                                           messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextYouHaveBeenKicked)));
            }
            else
            {
                AddKickedClient(data.KickedClient);
                RaiseClientLeft(data.KickedClient, ChatMemberStateChangeEnum.Kicked);
            }
        }
        void ChooseSandbox(MyMwcStartSessionRequestTypeEnum sessionRequestType, bool global)
        {
            MyMwcSectorTypeEnum sectorType = MyMwcClientServer.GetSectorTypeFromSessionType(sessionRequestType);

            var selectSectorScreen = new MyGuiScreenEnterSectorMap(m_closeAfterSuccessfulEnter, sessionRequestType, MyTextsWrapperEnum.StartGameInProgressPleaseWait, MyConfig.LastSandboxSector);

            selectSectorScreen.CustomLoadAction = StartSandbox;

            bool isOfficialSandbox = sessionRequestType == MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS && global;

            if (isOfficialSandbox)
            {
                selectSectorScreen.SetSectorSourceAction(MyLocalCache.GetOfficialMultiplayerSectorIdentifiers);
                MyGuiManager.AddScreen(selectSectorScreen);
            }
            else
            {
                MyGuiScreenMainMenu.AddLoginScreen(new MyGuiScreenLoadSectorIdentifiersProgress(sectorType, global, selectSectorScreen));
            }
        }
 private void ValidateAllMissionsClick()
 {
     MyGuiManager.RemoveScreen(this, true);
     MyGuiScreenMainMenu.AddLoginScreenDrmFree(new Action(ValidateAllMissionsCallback));
 }
 void OnTravelToAnywhere(MyMwcVector3Int sector)
 {
     MyGuiManager.CloseAllScreensExcept(MyGuiScreenGamePlay.Static);
     m_sectorToTravel = sector;
     MyGuiScreenMainMenu.AddLoginScreenDrmFree(new Action(TravelToSectorCallback));
 }
Example #23
0
        void OnUserJoined(ref JoinResultMsg msg)
        {
            if (msg.JoinResult == JoinResult.OK)
            {
                if (OnJoin != null)
                {
                    OnJoin();
                    OnJoin         = null;
                    m_clientJoined = true;
                }
            }
            else if (msg.JoinResult == JoinResult.NotInGroup)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                Dispose();

                ulong  groupId   = Server.GetGameTagByPrefixUlong("groupId");
                string groupName = MySteam.API.Friends.GetClanName(groupId);

                var messageBox = MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                    messageText: new StringBuilder(string.Format(
                                                       MyTexts.GetString(MyCommonTexts.MultiplayerErrorNotInGroup), groupName)),
                    buttonType: MyMessageBoxButtonsType.YES_NO);
                messageBox.ResultCallback = delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        MySteam.API.OpenOverlayUser(groupId);
                    }
                    ;
                };
                MyGuiSandbox.AddScreen(messageBox);
            }
            else if (msg.JoinResult == JoinResult.BannedByAdmins)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                Dispose();

                ulong admin = msg.Admin;

                if (admin != 0)
                {
                    var messageBox = MyGuiSandbox.CreateMessageBox(
                        messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                        messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorBannedByAdminsWithDialog),
                        buttonType: MyMessageBoxButtonsType.YES_NO);
                    messageBox.ResultCallback = delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MySteam.API.OpenOverlayUser(admin);
                        }
                        ;
                    };
                    MyGuiSandbox.AddScreen(messageBox);
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                               messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorBannedByAdmins)));
                }
            }
            else
            {
                MyStringId resultText = MyCommonTexts.MultiplayerErrorConnectionFailed;

                switch (msg.JoinResult)
                {
                case JoinResult.AlreadyJoined:
                    resultText = MyCommonTexts.MultiplayerErrorAlreadyJoined;
                    break;

                case JoinResult.ServerFull:
                    resultText = MyCommonTexts.MultiplayerErrorServerFull;
                    break;

                case JoinResult.SteamServersOffline:
                    resultText = MyCommonTexts.MultiplayerErrorSteamServersOffline;
                    break;

                case JoinResult.TicketInvalid:
                    resultText = MyCommonTexts.MultiplayerErrorTicketInvalid;
                    break;

                case JoinResult.GroupIdInvalid:
                    resultText = MyCommonTexts.MultiplayerErrorGroupIdInvalid;
                    break;

                case JoinResult.TicketCanceled:
                    resultText = MyCommonTexts.MultiplayerErrorTicketCanceled;
                    break;

                case JoinResult.TicketAlreadyUsed:
                    resultText = MyCommonTexts.MultiplayerErrorTicketAlreadyUsed;
                    break;

                case JoinResult.LoggedInElseWhere:
                    resultText = MyCommonTexts.MultiplayerErrorLoggedInElseWhere;
                    break;

                case JoinResult.NoLicenseOrExpired:
                    resultText = MyCommonTexts.MultiplayerErrorNoLicenseOrExpired;
                    break;

                case JoinResult.UserNotConnected:
                    resultText = MyCommonTexts.MultiplayerErrorUserNotConnected;
                    break;

                case JoinResult.VACBanned:
                    resultText = MyCommonTexts.MultiplayerErrorVACBanned;
                    break;

                case JoinResult.VACCheckTimedOut:
                    resultText = MyCommonTexts.MultiplayerErrorVACCheckTimedOut;
                    break;

                default:
                    System.Diagnostics.Debug.Fail("Unknown JoinResult");
                    break;
                }

                Dispose();
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(resultText)));
                return;
            }
        }
 private void OnLeaveClicked(MyGuiControlButton sender)
 {
     CloseScreen();
     MyGuiScreenMainMenu.UnloadAndExitToMenu();
 }
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    // When some clients connect at the same time then some of them can have already added clients
                    // (see function MySyncLayer.RegisterClientEvents which registers all Members in Lobby).
                    if (Sync.Clients == null || !Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientJoined(changedUser);

                        // Battles - send all clients, identities, players, factions as first message to client
                        if (Sync.IsServer && (Battle || Scenario) && changedUser != MySteam.UserId)
                        {
                            SendAllMembersDataToClient(changedUser);
                        }
                    }

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        // Player is able to connect to the battle which already started - player is then kicked and we do not want to show connected message in HUD.
                        bool showMsg = true;
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static != null && MySession.Static.Battle && !BattleCanBeJoined)
                        {
                            showMsg = false;
                        }

                        if (showMsg)
                        {
                            var playerJoined = new MyHudNotification(MySpaceTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                            playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                            MyHud.Notifications.Add(playerJoined);
                        }
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients == null || Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientLeft(changedUser, stateChange);
                    }

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MySpaceTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
Example #26
0
 public void BackToMainMenu()
 {
     AddIntroScreen();
     MyGuiScreenMainMenu.AddMainMenu();
 }
        public static void LoadMission(string sessionPath, bool multiplayer, MyOnlineModeEnum onlineMode, short maxPlayers)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");
            MyLog.Default.WriteLine(sessionPath);

            ulong checkpointSizeInBytes;
            var   checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSizeInBytes);

            checkpoint.Settings.OnlineMode       = onlineMode;
            checkpoint.Settings.MaxPlayers       = maxPlayers;
            checkpoint.Settings.Scenario         = true;
            checkpoint.Settings.GameMode         = MyGameModeEnum.Survival;
            checkpoint.Settings.ScenarioEditMode = false;

            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (checkpoint.BriefingVideo != null && checkpoint.BriefingVideo.Length > 0)
            {
                MyGuiSandbox.OpenUrlWithFallback(checkpoint.BriefingVideo, "Scenario briefing video");
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }


            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;

                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);

                    // May be called from gameplay, so we must make sure we unload the current game
                    if (MySession.Static != null)
                    {
                        MySession.Static.Unload();
                        MySession.Static = null;
                    }

                    //seed 0 has special meaning - please randomize at mission start. New seed will be saved and game will run with it ever since.
                    //  if you use this, YOU CANNOT HAVE ANY PROCEDURAL ASTEROIDS ALREADY SAVED
                    if (checkpoint.Settings.ProceduralSeed == 0)
                    {
                        checkpoint.Settings.ProceduralSeed = MyRandom.Instance.Next();
                    }

                    MyGuiScreenGamePlay.StartLoading(delegate
                    {
                        checkpoint.Settings.Scenario = true;
                        MySession.LoadMission(sessionPath, checkpoint, checkpointSizeInBytes);
                    });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed).ToString());
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                               messageText : MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed),
                                               buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (MyFakes.QUICK_LAUNCH != null)
                        {
                            MyGuiScreenMainMenu.ReturnToMainMenu();
                        }
                    }));
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
Example #28
0
 public static void Postfix(MyGuiScreenMainMenu __instance, Vector2 leftButtonPositionOrigin, ref Vector2 lastButtonPosition)
 {
     Patch_CreateMainMenu.Postfix(__instance, leftButtonPositionOrigin, ref lastButtonPosition);
 }