private static void OnJoinGameButtonClick() { string[] parts = hostIPAdressInput.text.Split(':'); string ip = parts[0].Trim(); int port; //remove copy and paste mistakes and update the textbox to prevent user confusion in case of invalid ip address hostIPAdressInput.text = parts.Length == 1 ? ip : ip + ":" + parts[1].Trim(); if (parts.Length == 1) { port = Config.DefaultPort; } else if (!int.TryParse(parts[1], out port)) { Log.Info($"Port must be a valid number above 1024"); return; } // TODO: Should display a loader during the connection and only open the game once the player is connected to the server. multiplayerMenu.gameObject.SetActive(false); Log.Info($"Connecting to server... {ip}:{port}"); if (!ConnectToServer(ip, port)) { //re-enabling the menu again after failed connect attempt Log.Warn($"Was not able to connect to {hostIPAdressInput.text}"); InGamePopup.ShowWarning("Connect failed", $"Was not able to connect to {hostIPAdressInput.text}", "OK"); multiplayerMenu.gameObject.SetActive(true); } }
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(); }); } }); }
private void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) { IsConnected = false; serverConnection = null; InGamePopup.ShowWarning( "Connection Lost", $"You have been disconnect of the server.\nReason{disconnectInfo.Reason}", "Quit", "Reconnect", () => { LocalPlayer.LeaveGame(); }, () => { Reconnect(); }); }
private static IEnumerator TryConnectToServer(string ip, int port) { InGamePopup.ShowInfo("Connecting", $"Connecting to server {ip}:{port}...", null, null); multiplayerMenu.gameObject.SetActive(false); // We need to wait here to have time to display the Connecting popup since the game freezes during the connection. yield return(new WaitForSeconds(0.5f)); if (!ConnectToServer(ip, port)) { InGamePopup.FadeOut(); //re-enabling the menu again after failed connect attempt InGamePopup.ShowWarning("Connect failed", $"Was not able to connect to {hostIPAdressInput.text}", "OK"); multiplayerMenu.gameObject.SetActive(true); } else { InGamePopup.FadeOut(); } }
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); }); }); } }
public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn) { if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length > 1) // if host does not use GS2 we send a null byte { LocalPlayer.GS2ApplySettings(packet.CompressedGS2Settings); } else if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length == 1) { InGamePopup.ShowWarning("Galactic Scale - Server not supported", "The server does not seem to use Galactic Scale. Make sure that your mod configuration matches.", "Close"); return; } GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); DSPGame.StartGameSkipPrologue(gameDesc); LocalPlayer.IsMasterClient = false; LocalPlayer.SetPlayerData(packet.LocalPlayerData); InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null); }
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; } }); }
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); } }); }