Beispiel #1
0
 protected override void OnClientBan(ref MyControlBanClientMsg data, ulong sender)
 {
     if ((data.BannedClient == Sync.MyId) && data.Banned)
     {
         MySessionLoader.UnloadAndExitToMenu();
         StringBuilder messageCaption = MyTexts.Get(MyCommonTexts.MessageBoxCaptionKicked);
         MyStringId?   okButtonText   = null;
         okButtonText = null;
         okButtonText = null;
         okButtonText = null;
         Vector2?size = null;
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, MyTexts.Get(MyCommonTexts.MessageBoxTextYouHaveBeenBanned), messageCaption, okButtonText, okButtonText, okButtonText, okButtonText, null, 0, MyGuiScreenMessageBox.ResultEnum.YES, true, size));
     }
     else
     {
         if (data.Banned)
         {
             base.AddBannedClient(data.BannedClient);
         }
         else
         {
             base.RemoveBannedClient(data.BannedClient);
         }
         if (this.m_members.Contains(data.BannedClient) && data.Banned)
         {
             base.RaiseClientLeft(data.BannedClient, MyChatMemberStateChangeEnum.Banned);
         }
     }
 }
Beispiel #2
0
        public void SendPlayerData(string clientName)
        {
            uint num;
            uint num2;
            ConnectedClientDataMsg msg = new ConnectedClientDataMsg {
                SteamID          = Sync.MyId,
                Name             = clientName,
                Join             = true,
                ExperimentalMode = this.ExperimentalMode
            };

            byte[] buffer = new byte[0x400];
            if (MyGameService.GetAuthSessionTicket(out num2, buffer, out num))
            {
                msg.Token = new byte[num];
                Array.Copy(buffer, msg.Token, (long)num);
                base.ReplicationLayer.SendClientConnected(ref msg);
            }
            else
            {
                MySessionLoader.UnloadAndExitToMenu();
                StringBuilder messageCaption = MyTexts.Get(MyCommonTexts.MessageBoxCaptionError);
                MyStringId?   okButtonText   = null;
                okButtonText = null;
                okButtonText = null;
                okButtonText = null;
                Vector2?size = null;
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, MyTexts.Get(MyCommonTexts.MultiplayerErrorConnectionFailed), messageCaption, okButtonText, okButtonText, okButtonText, okButtonText, null, 0, MyGuiScreenMessageBox.ResultEnum.YES, true, size));
            }
        }
        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();
                MySessionLoader.UnloadAndExitToMenu();
                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 = 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))
            {
                MySessionLoader.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);
        }
Beispiel #5
0
        private static void CheckDx11AndJoin(MyObjectBuilder_World world, MyMultiplayerBase multiplayer)
        {
            bool needsDx11 = world.Checkpoint.RequiresDX >= 11;

            if (!needsDx11 || MySandboxGame.IsDirectX11)
            {
                if (multiplayer.Battle)
                {
                    if (multiplayer.BattleCanBeJoined)
                    {
                        MySessionLoader.LoadMultiplayerBattleWorld(world, multiplayer);
                    }
                    else
                    {
                        MyLog.Default.WriteLine("World downloaded but battle game ended");
                        MySessionLoader.UnloadAndExitToMenu();
                        MyGuiSandbox.Show(MyCommonTexts.MultiplayerErrorSessionEnded);
                        multiplayer.Dispose();
                    }
                }
                else if (multiplayer.Scenario)
                {
                    MySessionLoader.LoadMultiplayerScenarioWorld(world, multiplayer);
                }
                else
                {
                    MySessionLoader.LoadMultiplayerSession(world, multiplayer);
                }
            }
            else
            {
                HandleDx11Needed();
            }
        }
        private void OnExitToMainMenuClick(MyGuiControlButton sender)
        {
            if (!Sync.IsServer)
            {
                MySessionLoader.UnloadAndExitToMenu();
                return;
            }

            this.CanBeHidden = false;
            MyGuiScreenMessageBox messageBox;

            if (MyCampaignManager.Static.IsCampaignRunning)
            {
                messageBox = MyGuiSandbox.CreateMessageBox(
                    buttonType: MyMessageBoxButtonsType.YES_NO,
                    messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextCampaignBeforeExit),
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit),
                    callback: OnExitToMainMenuFromCampaignMessageBoxCallback);
            }
            else
            {
                messageBox = MyGuiSandbox.CreateMessageBox(
                    buttonType: MyMessageBoxButtonsType.YES_NO_CANCEL,
                    messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextSaveChangesBeforeExit),
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit),
                    callback: OnExitToMainMenuMessageBoxCallback);
            }
            messageBox.SkipTransition = true;
            messageBox.InstantClose   = false;
            MyGuiSandbox.AddScreen(messageBox);
        }
Beispiel #7
0
        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");
            StringBuilder text     = MyTexts.Get(MyCommonTexts.DialogTextJoiningWorld);

            MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel);

            MyGuiSandbox.AddScreen(progress);
            progress.ProgressCancelled += () =>
            {
                multiplayer.Dispose();
                MySessionLoader.UnloadAndExitToMenu();
                if (MyMultiplayer.Static != null)
                {
                    MyMultiplayer.Static.Dispose();
                }
            };

            multiplayer.OnJoin += delegate
            {
                MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo()
                {
                    EnterState = LobbyEnterResponseEnum.Success
                }, multiplayer);
            };

            VRage.Profiler.MyRenderProfiler.GetProfilerFromServer = MyMultiplayer.Static.DownloadProfiler;
        }
Beispiel #8
0
        // unregisters callbacks and runs new mission when the session is being unloaded.
        public void LoadNextCampaignMission()
        {
            // Only server can switch missions
            if (MyMultiplayer.Static != null && !MyMultiplayer.Static.IsServer)
            {
                return;
            }

            // Save inventories
            SavePlayersInventories();

            var savePath   = MySession.Static.CurrentPath;
            var folderName = Path.GetDirectoryName(savePath.Replace(MyFileSystem.SavesPath + "\\", ""));

            // Campaign is finished
            if (m_runningCampaignSM.Finished)
            {
                // Disconnect and close clients
                CallCloseOnClients();
                // Return to main menu
                MySessionLoader.UnloadAndExitToMenu();

                // Call event OnCampaignFinished
                MyCampaignManager.Static.NotifyCampaignFinished();

                // Start Credits when the vanilla game ends.
                if (MyCampaignManager.Static.ActiveCampaign.IsVanilla)
                {
                    MyScreenManager.AddScreen(new MyGuiScreenGameCredits());
                }

                return;
            }

            // Load new level if campaign mode is still active
            // In case of exit to main menu
            UpdateStateMachine();

            // Check the state data
            var currentCampaignNode = m_runningCampaignSM.CurrentNode as MyCampaignStateMachineNode;

            Debug.Assert(currentCampaignNode != null);
            var sessionPathToLoad = currentCampaignNode.SavePath;

            Debug.Assert(!string.IsNullOrEmpty(sessionPathToLoad), "ERROR: Missing campaign world file!");

            // Reconnect clients to new session
            CallReconnectOnClients();

            // Load new session and add this session component to it
            MyCampaignManager.Static.LoadSessionFromActiveCampaign(sessionPathToLoad, () =>
            {
                // Recycle this component
                MySession.Static.RegisterComponent(this, MyUpdateOrder.NoUpdate, 555);
                LoadPlayersInventories();
            }, folderName
                                                                   );
        }
Beispiel #9
0
 public void Connect(string address)
 {
     MySessionLoader.UnloadAndExitToMenu();
     MyGameService.OnPingServerResponded       -= ServerResponded;
     MyGameService.OnPingServerFailedToRespond -= ServerFailedToRespond;
     MyGameService.OnPingServerResponded       += ServerResponded;
     MyGameService.OnPingServerFailedToRespond += ServerFailedToRespond;
     MyGameService.PingServer(address);
 }
Beispiel #10
0
 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("##,#")));
         MySessionLoader.UnloadAndExitToMenu();
     }
 }
        void MyMultiplayerClient_HostLeft()
        {
            m_clientJoined = false;
            CloseSession();

            MySessionLoader.UnloadAndExitToMenu();
            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                       messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft)));
        }
        public override bool Update(bool hasFocus)
        {
            if (!hasFocus)
            {
                return(base.Update(hasFocus));
            }

            if (m_childScreenLaunched && hasFocus)
            {
                CloseScreenNow();
            }

            if (m_childScreenLaunched)
            {
                return(base.Update(hasFocus));
            }

            if (MyInput.Static.IsKeyPress(MyKeys.Escape))
            {
                MySessionLoader.UnloadAndExitToMenu();
                return(base.Update(hasFocus));
            }

            switch (m_quickLaunchType)
            {
            case MyQuickLaunchType.LAST_SANDBOX:
            {
                var lastSessionPath = MyLocalCache.GetLastSessionPath();
                if (lastSessionPath != null && System.IO.Directory.Exists(lastSessionPath))
                {
                    MySessionLoader.LoadSingleplayerSession(lastSessionPath);
                }
                else
                {
                    MySandboxGame.AfterLogos();
                }
                m_childScreenLaunched = true;
            }
            break;

            case MyQuickLaunchType.NEW_SANDBOX:
            {
                QuickstartSandbox(null, null);
                m_childScreenLaunched = true;
            }
            break;

            default:
            {
                throw new InvalidBranchException();
            }
            }

            return(base.Update(hasFocus));
        }
Beispiel #13
0
 private void Matchmaking_LobbyChatUpdate(IMyLobby lobby, ulong changedUser, ulong makingChangeUser, MyChatMemberStateChangeEnum stateChange)
 {
     if (lobby.LobbyId == this.m_lobby.LobbyId)
     {
         if (stateChange == MyChatMemberStateChangeEnum.Entered)
         {
             object[] objArray1 = new object[] { "Player entered: ", MyGameService.GetPersonaName(changedUser), " (", changedUser, ")" };
             MySandboxGame.Log.WriteLineAndConsole(string.Concat(objArray1));
             MyGameService.Peer2Peer.AcceptSession(changedUser);
             if ((Sync.Clients == null) || !Sync.Clients.HasClient(changedUser))
             {
                 base.RaiseClientJoined(changedUser);
                 if (this.Scenario && (changedUser != Sync.MyId))
                 {
                     base.SendAllMembersDataToClient(changedUser);
                 }
             }
             if (MySandboxGame.IsGameReady && (changedUser != base.ServerId))
             {
                 MyHudNotification notification = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 0x1388, "Blue", MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, 0, MyNotificationLevel.Important);
                 object[]          arguments    = new object[] { MyGameService.GetPersonaName(changedUser) };
                 notification.SetTextFormatArguments(arguments);
                 MyHud.Notifications.Add(notification);
             }
         }
         else
         {
             if ((Sync.Clients == null) || Sync.Clients.HasClient(changedUser))
             {
                 base.RaiseClientLeft(changedUser, stateChange);
             }
             if (changedUser == base.ServerId)
             {
                 base.RaiseHostLeft();
                 MySessionLoader.UnloadAndExitToMenu();
                 StringBuilder messageCaption = MyTexts.Get(MyCommonTexts.MessageBoxCaptionError);
                 MyStringId?   okButtonText   = null;
                 okButtonText = null;
                 okButtonText = null;
                 okButtonText = null;
                 Vector2?size = null;
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft), messageCaption, okButtonText, okButtonText, okButtonText, okButtonText, null, 0, MyGuiScreenMessageBox.ResultEnum.YES, true, size));
             }
             else if (MySandboxGame.IsGameReady)
             {
                 MyHudNotification notification = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 0x1388, "Blue", MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, 0, MyNotificationLevel.Important);
                 object[]          arguments    = new object[] { MyGameService.GetPersonaName(changedUser) };
                 notification.SetTextFormatArguments(arguments);
                 MyHud.Notifications.Add(notification);
             }
         }
     }
 }
Beispiel #14
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);

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

                        MySessionLoader.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)
                        {
                            MySessionLoader.UnloadAndExitToMenu();
                        }
                    }));
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
Beispiel #15
0
        private static bool LoadMultiplayerSession(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");
            if (!MyWorkshop.CheckLocalModsAllowed(world.Checkpoint.Mods, allowLocalMods: false))
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer)));
                MyLog.Default.WriteLine("LoadSession() - End");
                return(false);
            }
            MyWorkshop.DownloadModsAsync(world.Checkpoint.Mods, delegate(bool success)
            {
                if (success)
                {
                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(16);
                    if (MySession.Static != null)
                    {
                        MySession.Static.Unload();
                        MySession.Static = null;
                    }

                    string CustomBackgroundImage = null;
                    GetCustomLoadingScreenPath(world.Checkpoint.Mods, out CustomBackgroundImage);

                    MySessionLoader.StartLoading(delegate
                    {
                        LoadMultiplayer.Invoke(null, new object[] { world, multiplayerSession });
                        //MySession.LoadMultiplayer(world, multiplayerSession);
                    }, null, CustomBackgroundImage, null);
                }
                else
                {
                    multiplayerSession.Dispose();
                    MySessionLoader.UnloadAndExitToMenu();
                    if (MyGameService.IsOnline)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed)));
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: new StringBuilder(string.Format(MyTexts.GetString(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline), MySession.GameServiceName))));
                    }
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            }, delegate
            {
                multiplayerSession.Dispose();
                MySessionLoader.UnloadAndExitToMenu();
            });

            return(false);
        }
Beispiel #16
0
 private void OnExitToMainMenuFromCampaignMessageBoxCallback(MyGuiScreenMessageBox.ResultEnum callbackReturn)
 {
     if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
     {
         MyAudio.Static.Mute = true;
         MyAudio.Static.StopMusic();
         MySessionLoader.UnloadAndExitToMenu();
     }
     else
     {
         base.CanBeHidden = true;
     }
 }
Beispiel #17
0
        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)
            {
                MySessionLoader.UnloadAndExitToMenu();
            }
        }
Beispiel #18
0
            public void JoinServer(string address)
            {
                if (MySandboxGame.IsDedicated && IsServer)
                {
                    return;
                }

                System.Net.IPEndPoint endpoint;
                if (System.Net.IPAddressExtensions.TryParseEndpoint(address, out endpoint))
                {
                    MySessionLoader.UnloadAndExitToMenu();
                    MySandboxGame.Services.SteamService.SteamAPI.PingServer(System.Net.IPAddressExtensions.ToIPv4NetworkOrder(endpoint.Address), (ushort)endpoint.Port);
                }
            }
        private void OnExitToMainMenuFromCampaignMessageBoxCallback(MyGuiScreenMessageBox.ResultEnum callbackReturn)
        {
            switch (callbackReturn)
            {
            case MyGuiScreenMessageBox.ResultEnum.YES:
                MyAudio.Static.Mute = true;
                MyAudio.Static.StopMusic();
                MySessionLoader.UnloadAndExitToMenu();
                break;

            default:
                this.CanBeHidden = true;
                break;
            }
        }
        public static string Connect(List <string> args)
        {
            if (args.Count < 1)
            {
                return("Not enough arguments!");
            }

            try
            {
                string[] array = args[0].Trim().Split(new char[]
                {
                    ':'
                });
                ushort num;
                if (array.Length < 2)
                {
                    num = 27016;
                }
                else
                {
                    num = ushort.Parse(array[1]);
                }
                IPAddress[] hostAddresses = Dns.GetHostAddresses(array[0]);

                StringBuilder text = MyTexts.Get(MyCommonTexts.DialogTextJoiningWorld);
                m_progressScreen = new MyGuiScreenProgress(text, new MyStringId?(MyCommonTexts.Cancel), false, true);
                MyGuiSandbox.AddScreen(m_progressScreen);
                m_progressScreen.ProgressCancelled += delegate
                {
                    CloseHandlers();
                    MySessionLoader.UnloadAndExitToMenu();
                };
                MyGameService.OnPingServerResponded       += new EventHandler <MyGameServerItem>(ServerResponded);
                MyGameService.OnPingServerFailedToRespond += new EventHandler(ServerFailedToRespond);
                MyGameService.PingServer(hostAddresses[0].ToIPv4NetworkOrder(), num);

                MyGameService.OnPingServerResponded       += new EventHandler <MyGameServerItem>(ServerResponded);
                MyGameService.OnPingServerFailedToRespond += new EventHandler(ServerFailedToRespond);
                MyGameService.PingServer(hostAddresses[0].ToIPv4NetworkOrder(), num);
            }
            catch (Exception ex)
            {
                MyGuiSandbox.Show(MyTexts.Get(MyCommonTexts.MultiplayerJoinIPError), MyCommonTexts.MessageBoxCaptionError, MyMessageBoxStyleEnum.Error);
            }

            return("Attempting to join server: ");
        }
        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);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        protected override void OnClientKick(ref MyControlKickClientMsg data, ulong kicked)
        {
            RaiseClientKicked(data.KickedClient);

            if (data.KickedClient == Sync.MyId)
            {
                MySessionLoader.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionKicked),
                                           messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextYouHaveBeenKicked)));
            }
            else
            {
                AddKickedClient(data.KickedClient);
                RaiseClientLeft(data.KickedClient, ChatMemberStateChangeEnum.Kicked);
            }
        }
Beispiel #24
0
        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();
        }
Beispiel #25
0
 private void Matchmaking_LobbyChatUpdate(IMyLobby lobby, ulong changedUser, ulong makingChangeUser, MyChatMemberStateChangeEnum stateChange)
 {
     if (lobby.LobbyId == this.Lobby.LobbyId)
     {
         if (stateChange != MyChatMemberStateChangeEnum.Entered)
         {
             if ((Sync.Clients == null) || Sync.Clients.HasClient(changedUser))
             {
                 base.RaiseClientLeft(changedUser, stateChange);
             }
             if (changedUser == base.ServerId)
             {
                 base.RaiseHostLeft();
                 MySessionLoader.UnloadAndExitToMenu();
                 MyGuiScreenServerReconnector.ReconnectToLastSession();
             }
             else if (MySandboxGame.IsGameReady)
             {
                 MyHudNotification notification = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 0x1388, "Blue", MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, 0, MyNotificationLevel.Important);
                 object[]          arguments    = new object[] { MyGameService.GetPersonaName(changedUser) };
                 notification.SetTextFormatArguments(arguments);
                 MyHud.Notifications.Add(notification);
             }
         }
         else
         {
             object[] objArray1 = new object[] { "Player entered: ", MyGameService.GetPersonaName(changedUser), " (", changedUser, ")" };
             MySandboxGame.Log.WriteLineAndConsole(string.Concat(objArray1));
             MyGameService.Peer2Peer.AcceptSession(changedUser);
             if ((Sync.Clients == null) || !Sync.Clients.HasClient(changedUser))
             {
                 base.RaiseClientJoined(changedUser);
             }
             if (MySandboxGame.IsGameReady && (changedUser != base.ServerId))
             {
                 MyHudNotification notification = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 0x1388, "Blue", MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, 0, MyNotificationLevel.Important);
                 object[]          arguments    = new object[] { MyGameService.GetPersonaName(changedUser) };
                 notification.SetTextFormatArguments(arguments);
                 MyHud.Notifications.Add(notification);
             }
         }
     }
 }
Beispiel #26
0
 public static void HandleDx11Needed()
 {
     MySessionLoader.UnloadAndExitToMenu();
     if (MyDirectXHelper.IsDx11Supported())
     {
         // Has DX11, ask for switch or selecting different scenario
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    callback: OnDX11SwitchRequestAnswer,
                                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                    messageText: MyTexts.Get(MySpaceTexts.QuickstartDX11SwitchQuestion),
                                    buttonType: MyMessageBoxButtonsType.YES_NO));
     }
     else
     {
         // No DX11, ask for selecting another scenario
         var text = MyTexts.Get(MySpaceTexts.QuickstartNoDx9SelectDifferent);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));
         MyGuiSandbox.AddScreen(mb);
     }
 }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        private void OnExitToMainMenuMessageBoxCallback(MyGuiScreenMessageBox.ResultEnum callbackReturn)
        {
            switch (callbackReturn)
            {
            case MyGuiScreenMessageBox.ResultEnum.YES:
                MyAudio.Static.Mute = true;
                MyAudio.Static.StopMusic();
                MyAsyncSaving.Start(callbackOnFinished : delegate() { MySandboxGame.Static.OnScreenshotTaken += UnloadAndExitAfterScreeshotWasTaken; });
                break;

            case MyGuiScreenMessageBox.ResultEnum.NO:
                MyAudio.Static.Mute = true;
                MyAudio.Static.StopMusic();
                MySessionLoader.UnloadAndExitToMenu();
                break;

            case MyGuiScreenMessageBox.ResultEnum.CANCEL:
                this.CanBeHidden = true;
                break;
            }
        }
        private void OnLoadException(Exception e, StringBuilder errorText, float heightMultiplier = 1.0f)
        {
            MySandboxGame.Log.WriteLine("ERROR: Loading screen failed");
            MySandboxGame.Log.WriteLine(e);
            m_screenToLoad = null;

            // GamePlayScreen might not have been unloaded, so check this here
            if (MyGuiScreenGamePlay.Static != null)
            {
                MyGuiScreenGamePlay.Static.UnloadData();
                MyGuiScreenGamePlay.Static.UnloadContent();
            }
            // Reset this to true so we have sounds
            MySandboxGame.IsUpdateReady    = true;
            MySandboxGame.AreClipmapsReady = true;

            try
            {
                MySessionLoader.UnloadAndExitToMenu();
            }
            catch (Exception ex)
            {
                MySession.Static = null;
                MySandboxGame.Log.WriteLine("ERROR: failed unload after exception in loading !");
                MySandboxGame.Log.WriteLine(ex);
            }

            var errorScreen = MyGuiSandbox.CreateMessageBox(
                messageText: errorText,
                messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));

            var size = errorScreen.Size.Value;

            size.Y          *= heightMultiplier;
            errorScreen.Size = size;
            errorScreen.RecreateControls(false);

            MyGuiSandbox.AddScreen(errorScreen);
        }
Beispiel #30
0
 private void UnloadAndExitAfterScreeshotWasTaken(object sender, EventArgs e)
 {
     MySandboxGame.Static.OnScreenshotTaken -= UnloadAndExitAfterScreeshotWasTaken;
     MySessionLoader.UnloadAndExitToMenu();
 }