public void OnFinalizationDataRetrieved(Dictionary <string, string> data)
        {
            if (!data.ContainsKey(MsfDictKeys.RoomId))
            {
                throw new Exception("Game server finalized, but didn't include room id");
            }

            var roomId = int.Parse(data[MsfDictKeys.RoomId]);

            var password = data.ContainsKey(MsfDictKeys.RoomPassword)
                ? data[MsfDictKeys.RoomPassword]
                : "";

            Msf.Client.Rooms.GetAccess(roomId, password, (access, error) =>
            {
                if (access == null)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                    DialogBoxData.CreateInfo("Failed to get access to room: " + error));

                    Logs.Error("Failed to get access to room: " + error);

                    return;
                }

                OnRoomAccessReceived(access);
            });
        }
示例#2
0
        public void OnJoinGameClick()
        {
            var selected = GetSelectedItem();

            if (selected == null)
            {
                return;
            }

            if (selected.IsLobby)
            {
                OnJoinLobbyClick(selected.RawData);
                return;
            }

            if (selected.IsPasswordProtected)
            {
                // If room is password protected
                var dialogData = DialogBoxData
                                 .CreateTextInput("Room is password protected. Please enter the password to proceed",
                                                  password => { Msf.Client.Rooms.GetAccess(selected.GameId, OnPassReceived, password); });

                if (!Msf.Events.Fire(Msf.EventNames.ShowDialogBox, dialogData))
                {
                    Logs.Error("Tried to show an input to enter room password, " +
                               "but nothing handled the event: " + Msf.EventNames.ShowDialogBox);
                }

                return;
            }

            // Room does not require a password
            Msf.Client.Rooms.GetAccess(selected.GameId, OnPassReceived);
        }
示例#3
0
        /// <summary>
        /// Invoked, when user changes the value of this controller
        /// </summary>
        public virtual void OnValueChanged()
        {
            var currentValue = Dropdown.captionText.text;

            // Ignore if this value was change by an update,
            // and not by the user
            if (LastValue == currentValue)
            {
                return;
            }

            var loadingPromise = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Updating");

            Lobby.JoinedLobby.SetLobbyProperty(RawData.PropertyKey, currentValue, (successful, error) =>
            {
                loadingPromise.Finish();

                if (!successful)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                    DialogBoxData.CreateInfo(error));
                    Logs.Error(error);
                    RestoreLastValue();
                }
            });
        }
示例#4
0
        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);
            });
        }
示例#5
0
 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));
 }
示例#6
0
        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."));
            });
        }
示例#7
0
        protected void OnStatusChange(SpawnStatus status)
        {
            //We'll display the current status of the request
            Debug.Log(string.Format("Progress: {0}/{1} ({2})", (int)Request.Status, (int)SpawnStatus.Finalized, Request.Status));

            //If game was aborted
            if (status < SpawnStatus.None)
            {
                Debug.Log("Game creation aborted");
                return;
            }

            //Once the SpawnStatus reaches the Finalized state we can get the data from the finished request
            if (status == SpawnStatus.Finalized)
            {
                Request.GetFinalizationData((data, error) =>
                {
                    if (data == null)
                    {
                        Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                        DialogBoxData.CreateInfo("Failed to retrieve completion data: " + error));

                        Logs.Error("Failed to retrieve completion data: " + error);

                        Request.Abort();
                        return;
                    }

                    // Completion data received
                    OnFinalizationDataRetrieved(data);
                });
            }
        }
示例#8
0
        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);
                }
            });
        }
        public void OnFinalizationDataRetrieved(Dictionary <string, string> data)
        {
            if (!data.ContainsKey(MsfDictKeys.RoomId))
            {
                throw new Exception("Game server finalized, but didn't include room id");
            }

            string roomId = data[MsfDictKeys.RoomId];

            Msf.Client.Rooms.GetAccess(roomId, (access, error) => {
                if (access == null)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                    DialogBoxData.CreateInfo("Failed to get access to room: " + error));

                    Logs.Error("Failed to get access to room: " + error);

                    return;
                }

                OnRoomAccessReceived(access);
            });

            if (Request != null)
            {
                Request.StatusChanged -= OnStatusChange;
            }
        }
        protected void OnStatusChange(SpawnStatus status)
        {
            if (status < SpawnStatus.None)
            {
                // If game was aborted
                Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                DialogBoxData.CreateInfo("Game creation aborted"));

                Logs.Error("Game creation aborted");

                // Hide the window
                gameObject.SetActive(false);
            }

            if (status == SpawnStatus.Finalized)
            {
                Request.GetFinalizationData((data, error) => {
                    if (data == null)
                    {
                        Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                        DialogBoxData.CreateInfo("Failed to retrieve completion data: " + error));

                        Logs.Error("Failed to retrieve completion data: " + error);

                        Request.Abort();
                        return;
                    }

                    // Completion data received
                    OnFinalizationDataRetrieved(data);
                });
            }
        }
示例#11
0
 public void handleErrorResponse(ResponseStatus status, IIncommingMessage rawMsg)
 {
     if (status != ResponseStatus.Success)
     {
         Debug.LogError(rawMsg.AsString());
         Events.Fire(EventNames.ShowDialogBox, DialogBoxData.CreateError(rawMsg.AsString()));
     }
 }
示例#12
0
        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);
            });
        }
示例#13
0
        public void ShowDialog(DialogBoxData data)
        {
            _wasDialogShown = true;
            ResetAll();

            _data = data;

            if (data == null || data.Message == null)
            {
                return;
            }

            // Show the dialog box
            gameObject.SetActive(true);

            Text.text = data.Message;

            var buttonCount = 0;

            if (!string.IsNullOrEmpty(data.LeftButtonText))
            {
                // Setup Left button
                Button1.gameObject.SetActive(true);
                Button1.GetComponentInChildren <Text>().text = data.LeftButtonText;
                buttonCount++;
            }

            if (!string.IsNullOrEmpty(data.MiddleButtonText))
            {
                // Setup Middle button
                Button2.gameObject.SetActive(true);
                Button2.GetComponentInChildren <Text>().text = data.MiddleButtonText;
                buttonCount++;
            }

            if (!string.IsNullOrEmpty(data.RightButtonText))
            {
                // Setup Right button
                Button3.gameObject.SetActive(true);
                Button3.GetComponentInChildren <Text>().text = data.RightButtonText;
            }
            else if (buttonCount == 0)
            {
                // Add a default "Close" button if there are no other buttons in the dialog
                Button3.gameObject.SetActive(true);
                Button3.GetComponentInChildren <Text>().text = "Close";
            }

            if (data.ShowInput)
            {
                Input.gameObject.SetActive(true);
                Input.text = data.DefaultInputText;
            }

            transform.SetAsLastSibling();
        }
示例#14
0
 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);
 }
示例#15
0
        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
        }
示例#16
0
        public static DialogBoxData CreateTextInput(string message, Action <string> onComplete,
                                                    string rightButtonText = "OK")
        {
            var data = new DialogBoxData(message);

            data.ShowInput       = true;
            data.RightButtonText = rightButtonText;
            data.InputAction     = onComplete;
            data.LeftButtonText  = "Close";
            return(data);
        }
示例#17
0
        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);
                }
            });
        }
示例#18
0
        /// <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);
                }
            });
        }
示例#19
0
        //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);
            });
        }
示例#20
0
        protected void OnSuccess()
        {
            // Hide registration form
            gameObject.SetActive(false);

            // Show the dialog box
            Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                            DialogBoxData.CreateInfo("Registration successful!"));

            // Show the login forum
            Msf.Events.Fire(Msf.EventNames.RestoreLoginForm, new LoginFormData {
                Username = Username.text,
                Password = ""
            });

            if (Msf.Client.Auth.AccountInfo != null && Msf.Client.Auth.AccountInfo.IsGuest)
            {
                Msf.Client.Auth.LogOut();
            }
        }
示例#21
0
        /// <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");
                }
            });
        }
示例#22
0
        public void GetAccess(int id)
        {
            Msf.Client.Rooms.GetAccess(id, (access, error) =>
            {
                if (access == null)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                    DialogBoxData.CreateInfo("Failed to get access to room: " + error));

                    Logs.Error("Failed to get access to room: " + error);

                    return;
                }
                GameObject.Find("Canvas").SetActive(false);
                SceneManager.LoadScene("online");
                this.access = access;
                SceneManager.sceneLoaded += OnSceneLoaded;
                //StartCoroutine(WaitSceneLoaded(access));
            }
                                       );
        }
示例#23
0
        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);
            });
        }
示例#24
0
 private void ShowError(string error)
 {
     Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error));
 }