private void ClientSocket_OnClose(object sender, CloseEventArgs e)
        {
            IsConnected      = false;
            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;
                }

                if (e.Code == (ushort)DisconnectionReason.ModVersionMismatch)
                {
                    string[] versions = e.Reason.Split(';');
                    InGamePopup.ShowWarning(
                        "Mod Version Mismatch",
                        $"Your Nebula Multiplayer Mod is not the same as the Host version.\nYou:{versions[0]} - Remote:{versions[1]}",
                        "OK",
                        OnDisconnectPopupCloseBeforeGameLoad);
                    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",
                        OnDisconnectPopupCloseBeforeGameLoad);
                    return;
                }

                if (SimulatedWorld.IsGameLoaded)
                {
                    InGamePopup.ShowWarning(
                        "Connection Lost",
                        $"You have been disconnected from the server.\n{e.Reason}",
                        "Quit",
                        () => LocalPlayer.LeaveGame());
                }
                else
                {
                    InGamePopup.ShowWarning(
                        "Server Unavailable",
                        $"Could not reach the server, please try again later.",
                        "OK",
                        () =>
                    {
                        LocalPlayer.IsMasterClient = false;
                        SimulatedWorld.Clear();
                        DestroySession();
                        OnDisconnectPopupCloseBeforeGameLoad();
                    });
                }
            });
        }
Exemple #2
0
 protected override void OnError(ErrorEventArgs e)
 {
     // TODO: seems like clients erroring out in the sync process can lock the host with the joining player message, maybe this fixes it
     NebulaModel.Logger.Log.Info($"Client disconnected because of an error: {ID}, reason: {e.Exception}");
     UnityDispatchQueue.RunOnMainThread(() =>
     {
         // This is to make sure that we don't try to deal with player disconnection
         // if it is because we have stopped the server and are not in a multiplayer game anymore.
         if (Multiplayer.IsActive)
         {
             PlayerManager.PlayerDisconnected(new NebulaConnection(Context.WebSocket, Context.UserEndPoint, PacketProcessor));
         }
     });
 }
Exemple #3
0
            protected override void OnClose(CloseEventArgs e)
            {
                // If the reason of a client disonnect is because we are still loading the game,
                // we don't need to inform the other clients since the disconnected client never
                // joined the game in the first place.
                if (e.Code == (short)DisconnectionReason.HostStillLoading)
                {
                    return;
                }

                NebulaModel.Logger.Log.Info($"Client disconnected: {Context.UserEndPoint}, reason: {e.Reason}");
                UnityDispatchQueue.RunOnMainThread(() =>
                {
                    playerManager.PlayerDisconnected(new NebulaConnection(Context.WebSocket, Context.UserEndPoint, packetProcessor));
                });
            }
Exemple #4
0
            protected override void OnClose(CloseEventArgs e)
            {
                // If the reason of a client disconnect is because we are still loading the game,
                // we don't need to inform the other clients since the disconnected client never
                // joined the game in the first place.
                if (e.Code == (short)DisconnectionReason.HostStillLoading)
                {
                    return;
                }

                NebulaModel.Logger.Log.Info($"Client disconnected: {ID}, reason: {e.Reason}");
                UnityDispatchQueue.RunOnMainThread(() =>
                {
                    // This is to make sure that we don't try to deal with player disconnection
                    // if it is because we have stopped the server and are not in a multiplayer game anymore.
                    if (Multiplayer.IsActive)
                    {
                        PlayerManager.PlayerDisconnected(new NebulaConnection(Context.WebSocket, Context.UserEndPoint, PacketProcessor));
                    }
                });
            }
Exemple #5
0
        private void ClientSocket_OnClose(object sender, CloseEventArgs e)
        {
            IsConnected      = false;
            serverConnection = null;

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

            if (SimulatedWorld.IsGameLoaded)
            {
                UnityDispatchQueue.RunOnMainThread(() =>
                {
                    InGamePopup.ShowWarning(
                        "Connection Lost",
                        $"You have been disconnect of the server.\n{e.Reason}",
                        "Quit", "Reconnect",
                        () => { LocalPlayer.LeaveGame(); },
                        () => { Reconnect(); });
                });
            }
            else
            {
                UnityDispatchQueue.RunOnMainThread(() =>
                {
                    InGamePopup.ShowWarning(
                        "Server Unavailable",
                        $"Could not reach the server, please try again later.",
                        "OK",
                        () =>
                    {
                        GameObject overlayCanvasGo = GameObject.Find("Overlay Canvas");
                        Transform multiplayerMenu  = overlayCanvasGo?.transform?.Find("Nebula - Multiplayer Menu");
                        multiplayerMenu?.gameObject?.SetActive(true);
                    });
                });
            }
        }
Exemple #6
0
        public NgrokManager(int port, string authtoken = null, string region = null)
        {
            _ngrokConfigPath = Path.Combine(Path.GetDirectoryName(_ngrokPath), "ngrok.yml");
            _port            = port;
            _authtoken       = authtoken ?? Config.Options.NgrokAuthtoken;
            _region          = region ?? Config.Options.NgrokRegion;

            if (!NgrokEnabled)
            {
                return;
            }

            if (string.IsNullOrEmpty(_authtoken))
            {
                NebulaModel.Logger.Log.WarnInform("Ngrok support was enabled, however no Authtoken was provided");
                return;
            }

            // Validate the Ngrok region
            string[] availableRegions = { "us", "eu", "au", "ap", "sa", "jp", "in" };
            if (!string.IsNullOrEmpty(_region) && !availableRegions.Any(_region.Contains))
            {
                NebulaModel.Logger.Log.WarnInform("Unsupported Ngrok region was provided, defaulting to autodetection");
                _region = null;
            }

            // Start this stuff in it's own thread, as we require async and we dont want to freeze up the GUI when freeze up when Downloading and installing ngrok
            Task.Run(async() =>
            {
                if (!IsNgrokInstalled())
                {
                    var downloadAndInstallConfirmationSource = new TaskCompletionSource <bool>();

                    UnityDispatchQueue.RunOnMainThread(() =>
                    {
                        InGamePopup.ShowWarning(
                            "Ngrok download and installation confirmation",
                            "Ngrok support is enabled, however it has not been downloaded and installed yet, do you want to automatically download and install Ngrok?",
                            "Accept",
                            "Reject",
                            () => downloadAndInstallConfirmationSource.TrySetResult(true),
                            () => downloadAndInstallConfirmationSource.TrySetResult(false)
                            );
                    });

                    var hasDownloadAndInstallBeenConfirmed = await downloadAndInstallConfirmationSource.Task;
                    if (!hasDownloadAndInstallBeenConfirmed)
                    {
                        NebulaModel.Logger.Log.Warn("Failed to download or install Ngrok, because user rejected Ngrok download and install confirmation!");
                        return;
                    }

                    try
                    {
                        await DownloadAndInstallNgrok();
                    }
                    catch
                    {
                        NebulaModel.Logger.Log.WarnInform("Failed to download or install Ngrok!");
                        throw;
                    }
                }

                if (!StartNgrok())
                {
                    NebulaModel.Logger.Log.WarnInform($"Failed to start Ngrok tunnel! LastErrorCode: {NgrokLastErrorCode}");
                    return;
                }

                if (!IsNgrokActive())
                {
                    NebulaModel.Logger.Log.WarnInform($"Ngrok tunnel has exited prematurely! LastErrorCode: {NgrokLastErrorCode}");
                    return;
                }
            });
        }
Exemple #7
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);
                }
            });
        }