private void RenderJoinServerDialog(int windowId) { Event e = Event.current; if (e.isKey) { switch (e.keyCode) { case KeyCode.Return: multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), new AuthenticationContext(username)); break; case KeyCode.Escape: StopMultiplayerClient(); break; } } GUISkinUtils.RenderWithSkin(GetGUISkin("menus.server", 80), () => { using (new GUILayout.VerticalScope("Box")) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Username:"******"usernameField"); username = GUILayout.TextField(username); } if (GUILayout.Button("Join")) { multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), new AuthenticationContext(username)); } if (GUILayout.Button("Cancel")) { joiningServer = false; StopMultiplayerClient(); } } }); if (shouldFocus) { GUI.FocusControl("usernameField"); shouldFocus = false; } }
private void OnJoinClick() { Text playerNameText = playerSettingsPanel.RequireTransform("InputField/Text").GetComponent <Text>(); string playerName = playerNameText.text; //https://regex101.com/r/eTWiEs/2/ if (!Regex.IsMatch(playerName, @"^[a-zA-Z0-9._-]{3,25}$")) { NotifyUser("Please enter a valid player name !\n\n It must not contain any space or doubtful characters\n Allowed characters : A-Z a-z 0-9 _ . -\nLength : [3, 25]"); return; } uGUI_ColorPicker colorPicker = playerSettingsPanel.GetComponentInChildren <uGUI_ColorPicker>(); Color playerColor = colorPicker.currentColor; SetCurrentPreference(playerName, playerColor); PlayerSettings playerSettings = new PlayerSettings(playerColor.ToDto()); AuthenticationContext authenticationContext; if (passwordEntered) { authenticationContext = new AuthenticationContext(playerName, serverPassword); } else { authenticationContext = new AuthenticationContext(playerName); } multiplayerSession.RequestSessionReservation(playerSettings, authenticationContext); }
private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionState state) { switch (state.CurrentStage) { case MultiplayerSessionConnectionStage.AwaitingReservationCredentials: AuthenticationContext authenticationContext = new AuthenticationContext(userName); multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), authenticationContext); break; case MultiplayerSessionConnectionStage.SessionReserved: multiplayerSession.ConnectionStateChanged -= SessionConnectionStateChangedHandler; Multiplayer.Main.StartSession(); break; case MultiplayerSessionConnectionStage.SessionReservationRejected: Log.InGame($"Cannot join server: {multiplayerSession.Reservation.ReservationState.ToString()}"); multiplayerSession.Disconnect(); break; case MultiplayerSessionConnectionStage.Disconnected: multiplayerSession.ConnectionStateChanged -= SessionConnectionStateChangedHandler; break; default: Log.InGame($"Current Stage: {multiplayerSession.CurrentState.CurrentStage}"); break; } }
private void OnJoinClick() { string playerName = playerNameInputField.text; //https://regex101.com/r/eTWiEs/2/ if (!Regex.IsMatch(playerName, @"^[a-zA-Z0-9._-]{3,25}$")) { NotifyUser(Language.main.Get("Nitrox_InvalidUserName")); return; } preferencesManager.SetPreference(serverIp, new PlayerPreference(playerName, colorPicker.currentColor)); AuthenticationContext authenticationContext = passwordEntered ? new AuthenticationContext(playerName, serverPassword) : new AuthenticationContext(playerName); multiplayerSession.RequestSessionReservation(new PlayerSettings(colorPicker.currentColor.ToDto()), authenticationContext); }
private void OnJoinClick() { Text playerNameText = playerSettingsPanel.RequireTransform("InputField/Text").GetComponent <Text>(); string playerName = playerNameText.text; if (string.IsNullOrEmpty(playerName)) { NotifyUser("Please enter a player name and colour before trying to join a server"); return; } uGUI_ColorPicker colorPicker = playerSettingsPanel.GetComponentInChildren <uGUI_ColorPicker>(); Color playerColor = colorPicker.currentColor; SetCurrentPreference(playerName, playerColor); PlayerSettings playerSettings = new PlayerSettings(playerColor.ToDto()); AuthenticationContext authenticationContext = new AuthenticationContext(playerName); multiplayerSession.RequestSessionReservation(playerSettings, authenticationContext); }
private void OnJoinClick() { Text playerNameText = playerSettingsPanel.RequireTransform("InputField/Text").GetComponent <Text>(); string playerName = playerNameText.text; if (string.IsNullOrEmpty(playerName)) { NotifyUser("Survival is a systemic initiative, but even the lowliest of cogs needs a designation in order to effectively coordinate the collective effort towards a - desireable, outcome.\n\n" + "Please identify yourself so that your presence may be indexed with local Survivor PDA telemetry instruments..."); return; } uGUI_ColorPicker colorPicker = playerSettingsPanel.GetComponentInChildren <uGUI_ColorPicker>(); Color playerColor = colorPicker.currentColor; SetCurrentPreference(playerName, playerColor); PlayerSettings playerSettings = new PlayerSettings(playerColor); AuthenticationContext authenticationContext = new AuthenticationContext(playerName); multiplayerSession.RequestSessionReservation(playerSettings, authenticationContext); }