public void startSpawnerPressed()
    {
        if (!Msf.Connection.IsConnected)
        {
            Logs.Error("You must first connect to master");

            // Show a dialog box with error
            Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                            DialogBoxData.CreateError("You must first connect to master"));
            return;
        }

        // Set the default executable path
        // It's called "Default", because it's used if "-msfExe"
        // argument doesn't override it (change it)
        spawnerBehaviour.DefaultExePath = gameServerField.text;

        // Make sure that exe path is not overriden in editor
        spawnerBehaviour.OverrideExePathInEditor = false;

        // Set default machine IP
        spawnerBehaviour.DefaultMachineIp = "127.0.0.1";

        // Start the spawner
        spawnerBehaviour.StartSpawner();
    }
 //If the GetAccess call returns properly, everything will be handled automatically, otherwise, we display the error
 protected virtual void OnPassReceived(RoomAccessPacket packet, string errorMessage)
 {
     if (packet == null)
     {
         Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(errorMessage));
         Logs.Error(errorMessage);
         status = "ERROR: No valid room access packet, please try again";
         return;
     }
 }
    protected virtual void OnPassReceived(RoomAccessPacket packet, string errorMessage)
    {
        if (packet == null)
        {
            Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(errorMessage));
            Logs.Error(errorMessage);
            return;
        }

        // Hope something handles the event
    }
Exemple #4
0
    public void OnClickCreateGame()
    {
        uiCreateGameProgress = uiCreateGameProgress ?? FindObjectOfType <CreateGameProgressUi>();

        var selectedMap      = GetSelectedMap();
        var selectedGameRule = GetSelectedGameRule();

        if (selectedMap == null)
        {
            return;
        }

        var defaultBotCount   = selectedGameRule == null ? 0 : selectedGameRule.DefaultBotCount;
        var defaultMatchTime  = selectedGameRule == null ? 0 : selectedGameRule.DefaultMatchTime;
        var defaultMatchKill  = selectedGameRule == null ? 0 : selectedGameRule.DefaultMatchKill;
        var defaultMatchScore = selectedGameRule == null ? 0 : selectedGameRule.DefaultMatchScore;
        var botCount          = inputBotCount == null ? defaultBotCount : int.Parse(inputBotCount.text);
        var matchTime         = inputMatchTime == null ? defaultMatchTime : int.Parse(inputMatchTime.text);
        var matchKill         = inputMatchKill == null ? defaultMatchKill : int.Parse(inputMatchKill.text);
        var matchScore        = inputMatchScore == null ? defaultMatchScore : int.Parse(inputMatchScore.text);
        var gameRuleName      = selectedGameRule == null ? "" : selectedGameRule.name;

        var settings = new Dictionary <string, string> {
            { MsfDictKeys.RoomName, inputRoomName == null ? "" : inputRoomName.text },
            { MsfDictKeys.SceneName, selectedMap.scene.SceneName },
            { MsfDictKeys.MapName, selectedMap.scene.SceneName },
            { MsfDictKeys.MaxPlayers, inputMaxPlayer == null ? "0" : inputMaxPlayer.text },
            { MsfDictKeys.IsPublic, true.ToString() },
            { IOGamesModule.IsFirstRoomKey, false.ToString() },
            { IOGamesModule.RoomSpawnTypeKey, IOGamesModule.RoomSpawnTypeUser },
            { BaseNetworkGameRule.BotCountKey, botCount.ToString() },
            { BaseNetworkGameRule.MatchTimeKey, matchTime.ToString() },
            { BaseNetworkGameRule.MatchKillKey, matchKill.ToString() },
            { BaseNetworkGameRule.MatchScoreKey, matchScore.ToString() },
            { IOGamesModule.GameRuleNameKey, gameRuleName },
        };

        Msf.Client.Spawners.RequestSpawn(settings, "", (requestController, errorMsg) =>
        {
            if (requestController == null)
            {
                uiCreateGameProgress.gameObject.SetActive(false);
                Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError("Failed to create a game: " + errorMsg));

                Debug.LogError("Failed to create a game: " + errorMsg);
            }
            uiCreateGameProgress.Display(requestController);
        });
    }
        public void loginButtonPressed()
        {
            Msf.Connection.SendMessage((short)CustomMasterServerMSG.adminLogin, pwField.text, ((r, m) => {
                if (r != ResponseStatus.Success)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(m.AsString()));
                    Debug.LogError(m.ToString());
                }
                else
                {
                    handleValidLogin();
                }
            }));

            pwField.text = "";
        }
    public void OnConfirmClick()
    {
        Msf.Client.Auth.ConfirmEmail(Code.text, (successful, error) => {
            if (!successful)
            {
                Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                DialogBoxData.CreateError("Confirmation failed: " + error));
                Logs.Error("Confirmation failed: " + error);
                return;
            }

            Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                            DialogBoxData.CreateInfo("Email confirmed successfully"));

            // Hide the window
            gameObject.SetActive(false);
        });
    }
Exemple #7
0
        //Run on button click. If success the event OnLoggedInWill be triggered
        public void OnLoginClick()
        {
            loadingScreen.startLoadingScreen("Login in", "Please wait...", 2, 5, () => {
                handleLoginCallback(false, "Abort");
            },
                                             () => handleLoginCallback(false, "Login took to long..."));

            setInteracteable(false);
            HandleRemembering();
            waitingForLoginResponse = true;

            Msf.Client.Auth.LoginAsAlbotUser((accInfo, error) => {
                if (accInfo == null)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error));
                }
                handleLoginCallback(accInfo != null, error);
            },
                                             Username.text.Trim(), Password.text, ConnectionToMaster.getAlbotVersion());
        }
    public void OnResendClick()
    {
        ResendButton.interactable = false;

        Msf.Client.Auth.RequestEmailConfirmationCode((successful, error) => {
            if (!successful)
            {
                Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                DialogBoxData.CreateError("Confirmation code request failed: " + error));

                Logs.Error("Confirmation code request failed: " + error);

                ResendButton.interactable = true;
                return;
            }

            Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                            DialogBoxData.CreateInfo("Confirmation code was sent to your e-mail. " +
                                                     "It should arrive within few minutes"));
        });
    }
    private IEnumerator JoinGame()
    {
        // Checks to see if client is connected to master server
        if (!Msf.Connection.IsConnected)
        {
            Debug.Log("You must be connected to master server");
            status = "ERROR: No connection to master server, please try again";
            yield break;
        }

        // Login as guest
        var  promise         = Msf.Events.FireWithPromise(Msf.EventNames.ShowLoading, "Logging in");
        bool loggedInAsGuest = false;

        status = "Logging in as guest";
        Msf.Client.Auth.LogInAsGuest((accInfo, error) =>
        {
            promise.Finish();

            loggedInAsGuest = true;

            if (accInfo == null)
            {
                Msf.Events.Fire(Msf.EventNames.ShowDialogBox, DialogBoxData.CreateError(error));
                Logs.Error(error);
                status = "ERROR: Unable to login as guest, please try again";
                return;
            }
        });

        while (loggedInAsGuest == false)
        {
            yield return(null);
        }

        // Gets list of active games from master server
        Debug.Log("Retrieving gamelist");
        List <GameInfoPacket> gamesList = null;
        bool gotGamesList = false;

        status = "Retrieving game list";
        Msf.Client.Matchmaker.FindGames(games =>
        {
            gotGamesList = true;
            gamesList    = games;
        });

        while (gotGamesList == false)
        {
            yield return(null);
        }

        Debug.Log("Game list retrieved");
        status = "Game list retrieved";
        // Tries to find an avaliable game.
        // If none are found, make a new game.
        if (gamesList.Count == 0)
        {
            Debug.Log("Game not found, creating a game");
            status = "No avaliable games found, creating a game";
            CreateGame();
        }
        else
        {
            // Trys to find an open game
            Debug.Log("There seems to be avaliable games, hold on a sec");
            status = "Possible avaliable game, please hold";
            GameInfoPacket gameToJoin = null;
            foreach (GameInfoPacket i in gamesList)
            {
                if (i.OnlinePlayers < i.MaxPlayers)
                {
                    gameToJoin = i;
                    break;
                }
            }

            // If there is a game to join, connect to the game
            // Else, create a new game
            if (gameToJoin != null)
            {
                status = "Game found! Joining!";
                Msf.Client.Rooms.GetAccess(gameToJoin.Id, OnPassReceived);
            }
            else
            {
                Debug.Log("Game not found, creating a game");
                status = "No avaliable games found, creating a game";
                CreateGame();
            }
        }
    }