public virtual void OnLoginClick() { if (Msf.Client.Auth.IsLoggedIn) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("You're already logged in")); Logs.Error("You're already logged in"); return; } // Disable error ErrorText.gameObject.SetActive(false); // Ignore if didn't pass validation if (!ValidateInput()) { return; } HandleRemembering(); Msf.Client.Auth.LogIn(Username.text, Password.text, (accountInfo, error) => { if (accountInfo == null && (error != null)) { ShowError(error); } }); }
protected virtual void OnJoinLobbyClick(GameInfoPacket packet) { var loadingPromise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Joining lobby"); Msf.Client.Lobbies.JoinLobby(packet.Id, (lobby, error) => { loadingPromise.Finish(); if (lobby == null) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); return; } // Hide this window gameObject.SetActive(false); var lobbyUi = FindObjectOfType <LobbyUi>(); if (lobbyUi == null && MsfUi.Instance != null) { lobbyUi = MsfUi.Instance.LobbyUi; } if (lobbyUi == null) { Logs.Error("Couldn't find appropriate UI element to display lobby data in the scene. " + "Override OnJoinLobbyClick method, if you want to handle this differently"); return; } lobbyUi.gameObject.SetActive(true); lobby.SetListener(lobbyUi); }); }
public static void ShowError(string error) { // Fire an event to display a dialog box. // We're not opening it directly, in case there's a custom // dialog box event handler Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); }
public void OnSendCodeClick() { var email = Email.text.ToLower().Trim(); if (email.Length < 3 || !email.Contains("@")) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Invalid e-mail address provided")); return; } var promise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Requesting reset code"); Msf.Client.Auth.RequestPasswordReset(email, (successful, error) => { promise.Finish(); if (!successful) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); return; } Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateInfo( "Reset code has been sent to the provided e-mail address.")); }); }
public void handleErrorResponse(ResponseStatus status, IIncommingMessage rawMsg) { if (status != ResponseStatus.Success) { Debug.LogError(rawMsg.AsString()); Events.Fire(EventNames.ShowDialogBox, DialogBoxData.CreateError(rawMsg.AsString())); } }
public void OnCreateClick() { if (ProgressUi == null) { Logs.Error("You need to set a ProgressUi"); return; } if (RequireAuthentication && !Msf.Client.Auth.IsLoggedIn) { ShowError("You must be logged in to create a room"); return; } var name = RoomName.text.Trim(); if (string.IsNullOrEmpty(name) || (name.Length < MinNameLength) || (name.Length > MaxNameLength)) { ShowError(string.Format("Invalid length of game name, shoul be between {0} and {1}", MinNameLength, MaxNameLength)); return; } var maxPlayers = 0; int.TryParse(MaxPlayers.captionText.text, out maxPlayers); if ((maxPlayers < MaxPlayersLowerLimit) || (maxPlayers > MaxPlayersUpperLimit)) { ShowError(string.Format("Invalid number of max players. Value should be between {0} and {1}", MaxPlayersLowerLimit, MaxPlayersUpperLimit)); return; } var settings = new Dictionary <string, string> { { MsfDictKeys.MaxPlayers, maxPlayers.ToString() }, { MsfDictKeys.RoomName, name }, { MsfDictKeys.MapName, GetSelectedMap().Name }, { MsfDictKeys.SceneName, GetSelectedMap().Scene.SceneName } }; Msf.Client.Spawners.RequestSpawn(settings, "", (requestController, errorMsg) => { if (requestController == null) { ProgressUi.gameObject.SetActive(false); Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Failed to create a game: " + errorMsg)); Logs.Error("Failed to create a game: " + errorMsg); } ProgressUi.Display(requestController); }); }
public bool serverResponseSuccess(ResponseStatus status, IIncommingMessage rawMsg) { if (status != ResponseStatus.Success) { Events.Fire(EventNames.ShowDialogBox, DialogBoxData.CreateError(rawMsg.AsString("Unkown error"))); Debug.LogError(status + " - " + rawMsg.AsString("Unkown error")); return(false); } return(true); }
protected virtual void OnPassReceived(RoomAccessPacket packet, string errorMessage) { if (packet == null) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(errorMessage)); Logs.Error(errorMessage); } // Hope something handles the event }
public void OnGuestAccessClick() { var promise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Logging in"); Msf.Client.Auth.LogInAsGuest((accInfo, error) => { promise.Finish(); if (accInfo == null) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); Logs.Error(error); } }); }
/// <summary> /// Invoked, when user clicks a "Join" button /// </summary> public virtual void OnJoinClick() { var loadingPromise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Switching teams"); Lobby.JoinedLobby.JoinTeam(Name, (successful, error) => { loadingPromise.Finish(); if (!successful) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); Logs.Error(error); } }); }
//This will be called when we click the button that this script will be attached to public void OnCreateClick() { //LOG IN AS GUEST //This is part of the error in judgment. In order for the serverside code to work //and the gameServer to connect to the client properly, it needs to be authenticated. //To get around this, we're going to trigger the "Guest access" by default before we //spawn the gameserver. //I will provide a tutorial at a later date to explain how the authModule works and how //to write your own. if (promise == null) { OnGuestLogin(); } //There can be more or fewer settings included, we're going to keep this simple. var settings = new Dictionary <string, string> { { MsfDictKeys.MaxPlayers, "20" }, { MsfDictKeys.RoomName, map.Name }, { MsfDictKeys.MapName, map.Name }, { MsfDictKeys.SceneName, map.Scene.SceneName } }; //The actual request message sent to the Spawner. //This returns a callback containing the SpawnRequestController that will allow us to track //the progress of the spawn request Msf.Client.Spawners.RequestSpawn(settings, "", (requestController, errorMsg) => { //If something went wrong, the request will return "null" and an error will be included if (requestController == null) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Failed to create a game: " + errorMsg)); Logs.Error("Failed to create a game: " + errorMsg); } //If the Controller is not null, we can track its progress TrackRequest(requestController); }); }
/// <summary> /// Invoked, when user clicks a "Create" button /// </summary> public virtual void OnCreateClick() { var properties = new Dictionary <string, string>() { { MsfDictKeys.LobbyName, Name.text }, { MsfDictKeys.SceneName, GetSelectedMap() }, { MsfDictKeys.MapName, MapDropdown.captionText.text } }; var loadingPromise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Sending request"); var factory = GetSelectedFactory(); Msf.Client.Lobbies.CreateAndJoin(factory, properties, (lobby, error) => { loadingPromise.Finish(); if (lobby == null) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); Logs.Error(error + " (Factory: " + factory + ")"); return; } // Hide this window gameObject.SetActive(false); if (LobbyUi != null) { // Show the UI LobbyUi.gameObject.SetActive(true); // Set the lobby Ui as current listener lobby.SetListener(LobbyUi); } else { Logs.Error("Please set LobbyUi property in the inspector"); } }); }
private void ShowError(string error) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); }
public void OnResetClick() { var email = Email.text.Trim().ToLower(); var code = ResetCode.text; var newPassword = Password.text; if (Password.text != PasswordRepeat.text) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Passwords do not match")); return; } if (newPassword.Length < 3) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Password is too short")); return; } if (string.IsNullOrEmpty(code)) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Invalid code")); return; } if (email.Length < 3 || !email.Contains("@")) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Invalid e-mail address provided")); return; } var data = new PasswordChangeData { Email = email, Code = code, NewPassword = newPassword }; var promise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Changing a password"); Msf.Client.Auth.ChangePassword(data, (successful, error) => { promise.Finish(); if (!successful) { Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error)); return; } Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateInfo( "Password changed successfully")); Msf.Events.Fire(Msf.EventNames.RestoreLoginForm, new LoginFormData { Username = null, Password = "" }); gameObject.SetActive(false); }); }