Esempio n. 1
0
        public static void _OnClose_Prefix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsInMultiplayerMenu && Multiplayer.Session.IsInLobby)
            {
                Log.Info($"Closing listening Socket");
                Multiplayer.ShouldReturnToJoinMenu = false;
                Multiplayer.Session.IsInLobby      = false;
                Multiplayer.LeaveGame();

                UIVirtualStarmap_Transpiler.customBirthStar   = -1;
                UIVirtualStarmap_Transpiler.customBirthPlanet = -1;

                // restore main menu if needed.
                if (GameMain.localStar.id != MainMenuStarID && MainMenuStarID != -1)
                {
                    GameMain.data.ArriveStar(GameMain.data.galaxy.StarById(MainMenuStarID));
                }

                // close planet detail view
                UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false);
            }

            // cant check anymore if we are in multiplayer or not, so just do this without check. will not do any harm C:
            RectTransform galaxySelectRect = __instance.gameObject.GetComponent <RectTransform>();

            galaxySelectRect.Find("star-count").gameObject.SetActive(true);
            galaxySelectRect.Find("resource-multiplier").gameObject.SetActive(true);
            galaxySelectRect.Find("galaxy-seed").GetComponentInChildren <InputField>().enabled = true;
            galaxySelectRect.Find("random-button").gameObject.SetActive(true);
        }
Esempio n. 2
0
 public static void HandleApplicationQuit_Prefix()
 {
     if (Multiplayer.IsActive)
     {
         Log.Warn("Multiplayer is still running, closing now...");
         Multiplayer.LeaveGame();
     }
     DiscordManager.Cleanup();
 }
Esempio n. 3
0
 public static void QuitGame()
 {
     if (Multiplayer.IsActive)
     {
         // Because GameSave.SaveAsLastExit() is disable, we have to save game here to match the vanilla behavior.
         GameSave.SaveCurrentGame(GameSave.LastExit);
         PlanetFactory_Transpiler.CheckPopupPresent.Clear();
         PlanetFactory_Transpiler.FaultyVeins.Clear();
         Multiplayer.LeaveGame();
     }
 }
Esempio n. 4
0
        private void ClientSocket_OnClose(object sender, CloseEventArgs e)
        {
            serverConnection = null;

            UnityDispatchQueue.RunOnMainThread(() =>
            {
                // If the client is Quitting by himself, we don't have to inform him of his disconnection.
                if (e.Code == (ushort)DisconnectionReason.ClientRequestedDisconnect)
                {
                    return;
                }

                // Opens the pause menu on disconnection to prevent NRE when leaving the game
                if (Multiplayer.Session?.IsGameLoaded ?? false)
                {
                    GameMain.instance._paused = true;
                }

                if (e.Code == (ushort)DisconnectionReason.ModIsMissing)
                {
                    InGamePopup.ShowWarning(
                        "Mod Mismatch",
                        $"You are missing mod {e.Reason}",
                        "OK".Translate(),
                        Multiplayer.LeaveGame);
                    return;
                }

                if (e.Code == (ushort)DisconnectionReason.ModIsMissingOnServer)
                {
                    InGamePopup.ShowWarning(
                        "Mod Mismatch",
                        $"Server is missing mod {e.Reason}",
                        "OK".Translate(),
                        Multiplayer.LeaveGame);
                    return;
                }

                if (e.Code == (ushort)DisconnectionReason.ModVersionMismatch)
                {
                    string[] versions = e.Reason.Split(';');
                    InGamePopup.ShowWarning(
                        "Mod Version Mismatch",
                        $"Your mod {versions[0]} version is not the same as the Host version.\nYou:{versions[1]} - Remote:{versions[2]}",
                        "OK".Translate(),
                        Multiplayer.LeaveGame);
                    return;
                }

                if (e.Code == (ushort)DisconnectionReason.GameVersionMismatch)
                {
                    string[] versions = e.Reason.Split(';');
                    InGamePopup.ShowWarning(
                        "Game Version Mismatch",
                        $"Your version of the game is not the same as the one used by the Host.\nYou:{versions[0]} - Remote:{versions[1]}",
                        "OK".Translate(),
                        Multiplayer.LeaveGame);
                    return;
                }

                if (e.Code == (ushort)DisconnectionReason.ProtocolError && websocketAuthenticationFailure)
                {
                    InGamePopup.AskInput(
                        "Server Requires Password",
                        "Server is protected. Please enter the correct password:"******"Connection Lost",
                        $"You have been disconnected from the server.\n{e.Reason}",
                        "Quit",
                        Multiplayer.LeaveGame);
                    if (Multiplayer.Session.IsInLobby)
                    {
                        Multiplayer.ShouldReturnToJoinMenu = false;
                        Multiplayer.Session.IsInLobby      = false;
                        UIRoot.instance.galaxySelect.CancelSelect();
                    }
                }
                else
                {
                    InGamePopup.ShowWarning(
                        "Server Unavailable",
                        $"Could not reach the server, please try again later.",
                        "OK".Translate(),
                        Multiplayer.LeaveGame);
                }
            });
        }