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;
     }
 }
Example #3
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            this.Update_Received   += ExampleMod_Update_Received;
            this.Event_ChatMessage += ExampleMod_Event_HandleLottoChatMessage;
            this.Event_GameEvent   += ExampleMod_Event_GameEvent;
            this.Event_Statistics  += PlayerDied_Event_Statistics;
            this.ChatCommands.Add(new ChatCommand(@"/repeat (?<repeat>\S+)", ChatCommand_TestMessage));
            this.ChatCommands.Add(new ChatCommand(@"!loudly (?<yellthis>.+)", (data, args) => {
                var msg = new IdMsgPrio()
                {
                    id  = data.playerId,
                    msg = $"{args["yellthis"].ToUpper()}!!!!!"
                };
                this.Request_InGameMessage_SinglePlayer(msg);
            }));

            this.ChatCommands.Add(new ChatCommand(@"/explosion", (data, __) => {
                var dialogData = new DialogBoxData()
                {
                    Id            = data.playerId,
                    MsgText       = "BOOM!",
                    PosButtonText = "yes",
                    NegButtonText = "No"
                };
                this.Request_ShowDialog_SinglePlayer(dialogData, (result) => {
                    var resultInterpreted = result.Value == 0 ? "YES": "NO";
                    this.Request_InGameMessage_SinglePlayer(resultInterpreted.ToIdMsgPrio(data.playerId));
                });
            }, "blows it up", PermissionType.Moderator));



            this.ChatCommands.Add(new ChatCommand(@"/help", (data, __) => {
                this.Request_Player_Info(data.playerId.ToId(), (info) =>
                {
                    var playerPermissionLevel = (PermissionType)info.permission;
                    var header = $"Commands available to {info.playerName}; permission level {playerPermissionLevel}\n";

                    var lines = this.GetChatCommandsForPermissionLevel(playerPermissionLevel)
                                .Select(x => x.ToString())
                                .OrderBy(x => x.Length).ToList();

                    lines.Insert(0, header);


                    var dialogData = new DialogBoxData()
                    {
                        Id      = data.playerId,
                        MsgText = String.Join("\n", lines.ToArray())
                    };

                    Request_ShowDialog_SinglePlayer(dialogData);
                });
            }));
        }
Example #4
0
        public void ClickCreateProfileName()
        {
            if (string.IsNullOrEmpty(_profileInput.text))
            {
                var msg = DialogBoxData.CreateInfo("Profile name cant be empty");
                UiDialogBox.Instance.ShowDialog(msg);
                return;
            }

            _profileSelection.TryCreateProfile(_profileInput.text);
        }
Example #5
0
        public void CheckCanCreateProfile()
        {
            if (_profileDataHandler.CachedProfileData.CanAddProfile() == false)
            {
                var msg = DialogBoxData.CreateInfo("Max profile reached. \n Delete one first.");
                UiDialogBox.Instance.ShowDialog(msg);
                return;
            }

            _profileUi.OpenProfileCreation();
        }
    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
    }
Example #7
0
 public void TryCreateProfile(string profileName)
 {
     if (_profileDataHandler.CachedProfileData.ProfileExist(profileName))
     {
         var msg = DialogBoxData.CreateInfo("You already have a profile \n with this name.");
         UiDialogBox.Instance.ShowDialog(msg);
         return;
     }
     _profileDataHandler.CachedProfileData.AddNewProfile(profileName);
     _profileDataHandler.SaveData();
     OpenProfileList();
 }
        public override void Initialize(ModGameAPI dediAPI)
        {
            this.verbose = true;

            this.Event_Player_Connected    += PlayerConnnectedHandler;
            this.Event_Player_Disconnected += RemovePlayerInfoFromCache;
            this.Event_Player_Info         += CachePlayerInfo;


            var ownMailboxCommand = new ChatCommand(
                @"/at mailbox", HandleOpenMailboxCall, "open your mailbox"
                );

            var otherPlayerMailboxCommand = new ChatCommand(
                @"/at mailbox (?<playerName>.+)", HandleOtherMailboxCall, "open the mailbox for {playerName}", PermissionType.Moderator
                );

            var teleportCommand = new ChatCommand(
                @"/at teleport (?<targetName>.+) to (?<destinationName>.+)",
                HandleTeleportCommand,
                @"teleports player with {targetName} to the location of player with {destinationName}." +
                @"Use ""me"" to indicate yourself.",
                PermissionType.Moderator
                );

            this.ChatCommands.Add(teleportCommand);
            this.ChatCommands.Add(ownMailboxCommand);
            this.ChatCommands.Add(otherPlayerMailboxCommand);

            this.ChatCommands.Add(new ChatCommand(@"/at help", (data, __) => {
                this.Request_Player_Info(data.playerId.ToId(), (info) =>
                {
                    var playerPermissionLevel = (PermissionType)info.permission;
                    var header = $"Commands available to {info.playerName}; permission level {playerPermissionLevel}\n";

                    var lines = this.GetChatCommandsForPermissionLevel(playerPermissionLevel)
                                .Select(x => x.ToString())
                                .OrderBy(x => x.Length).ToList();

                    lines.Insert(0, header);

                    var msg = new DialogBoxData()
                    {
                        Id      = data.playerId,
                        MsgText = String.Join("\n", lines.ToArray())
                    };
                    Request_ShowDialog_SinglePlayer(msg);
                });
            }));
        }
Example #9
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 = "";
        }
Example #11
0
        public static void Request_ShowDialog_SinglePlayer(DialogBoxData arg, Action <IdAndIntValue> callback = null, Action <ErrorInfo> onError = null)
        {
            Action <CmdId, object> wiredCallback = null;

            if (callback != null)
            {
                wiredCallback = (_, val) => callback((IdAndIntValue)val);
            }

            var apiCmd = new GenericAPICommand(
                CmdId.Request_ShowDialog_SinglePlayer,
                arg,
                wiredCallback,
                onError ?? noOpErrorHandler
                );

            Broker.Execute(apiCmd);
        }
Example #12
0
    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);
        });
    }
Example #13
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());
        }
Example #14
0
    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"));
        });
    }
Example #15
0
        public void DeleteProfile()
        {
            var profileName = _profileDataHandler.CachedProfileData.LastUsedProfile;

            var dialogData = DialogBoxData.CreateActionBox
                             (
                "Delete the save " + profileName + " ?",
                () =>
            {
                _profileDataHandler.CachedProfileData.RemoveProfile(profileName);
                _profileDataHandler.SaveData();
                OpenProfileList();
            },
                () =>
            {
                //Cancel
            },
                "Delete"
                             );

            UiDialogBox.Instance.ShowDialog(dialogData);
        }
Example #16
0
        public void ClickBuy()
        {
            if (_cachedSelection == null)
            {
                return;
            }

            if (_cachedSelection.HasValidBuyPrice())
            {
                if (_purchaseRequireConfirmation)
                {
                    string translatedMsg = Language.Localization.Translate("Buy");
                    translatedMsg += " " + _cachedSelection.LocalizedItemName() + "?";

                    var msg = DialogBoxData.CreateActionBox
                              (
                        translatedMsg,
                        () =>
                    {
                        TryBuySelection(1);
                    },
                        () =>
                    {
                        //cancel
                    },
                        Language.Localization.Translate("Buy")
                              );

                    UiDialogBox.Instance.ShowDialog(msg);
                }
                else
                {
                    TryBuySelection(1);
                }
            }
        }
Example #17
0
 public async Task <IdAndIntValue> Request_ShowDialog_SinglePlayer(DialogBoxData arg, CancellationToken ct)
 {
     return(await Broker.SendRequestAsync <DialogBoxData, IdAndIntValue>(CmdId.Request_ShowDialog_SinglePlayer, arg, ct));
 }
Example #18
0
 public static Task <IdAndIntValue> Request_ShowDialog_SinglePlayer(DialogBoxData param, Action <IdAndIntValue> callback, Action <ErrorInfo> onError = null)
 {
     return(Broker.CreateCommandWithArgAndReturn <DialogBoxData, IdAndIntValue>(CmdId.Request_ShowDialog_SinglePlayer, param, callback, onError));
 }
        public override void Initialize(IModApi modAPI, ModGameAPI legacyAPI)
        {
            Logger.logLevel = LogLevel.Debug;

            this.Update_Received += ExampleMod_Update_Received;
            modAPI.Application.ChatMessageSent += ExampleMod_Event_HandleLottoChatMessage;

            Broker.Event_ConsoleCommand += Broker_Event_ConsoleCommand;

            modAPI.GameEvent        += ModAPI_GameEvent;
            Broker.Event_Statistics += PlayerDied_Event_Statistics;

            this.ChatCommands.Add(new ChatCommand(@"!repeat (?<repeat>\S+)", ChatCommand_TestMessage));
            this.ChatCommands.Add(new ChatCommand(@"!loudly (?<yellthis>.+)", (data, args) => {
                var msg = new MessageData()
                {
                    Channel    = MsgChannel.Global,
                    Text       = $"{args["yellthis"].ToUpper()}!!!!!",
                    SenderType = SenderType.System
                };
                this.GameAPI.Application.SendChatMessage(msg);
            }));

            this.ChatCommands.Add(new ChatCommand(@"!explosion", async(data, __) => {
                var dialogData = new DialogBoxData()
                {
                    Id            = data.SenderEntityId,
                    MsgText       = "BOOM!",
                    PosButtonText = "yes",
                    NegButtonText = "No"
                };
                var result = await Broker.Request_ShowDialog_SinglePlayer(dialogData);

                var resultInterpreted = result.Value == 0 ? "YES": "NO";
                MessagePlayer(data.SenderEntityId, resultInterpreted);
            }, "blows it up", PermissionType.Moderator));

            var t = new System.Timers.Timer(15000);

            t.Elapsed += T_Elapsed;
            Debugger.Break();

            t.Start();

            this.ChatCommands.Add(new ChatCommand(@"!help", async(data, __) =>
            {
                var info = await Broker.Request_Player_Info(data.SenderEntityId.ToId());

                var playerPermissionLevel = (PermissionType)info.permission;
                var header = $"Commands available to {info.playerName}; permission level {playerPermissionLevel}\n";

                var lines = this.GetChatCommandsForPermissionLevel(playerPermissionLevel)
                            .Select(x => x.ToString())
                            .OrderBy(x => x.Length).ToList();

                lines.Insert(0, header);

                var dialogData = new DialogBoxData()
                {
                    Id      = data.SenderEntityId,
                    MsgText = String.Join("\n", lines.ToArray())
                };

                Broker.Request_ShowDialog_SinglePlayer(dialogData);
            }));

            Logger.log("example mod init complete");
        }
Example #20
0
 public void Request_ShowDialog_SinglePlayer(DialogBoxData arg, Action <IdAndIntValue> callback = null, Action <ErrorInfo> onError = null)
 {
     Broker.Request_ShowDialog_SinglePlayer(arg, callback, onError);
 }
Example #21
0
 public static Task <IdAndIntValue> Request_ShowDialog_SinglePlayer(DialogBoxData param)
 {
     return(Broker.CreateCommandWithArgAndReturn <DialogBoxData, IdAndIntValue>(CmdId.Request_ShowDialog_SinglePlayer, param));
 }
Example #22
0
 /// <summary>
 /// Sends a message to a player that will be shown as a message box with up to 2 buttons. Callback delegate will receive which button was selected.
 /// </summary>
 /// <param name="data"></param>
 /// <param name="callback">Callback to receive the IdAndIntValue response. Id will be the entity ID of the player that responded and int will be the button that was selected.
 /// 0 refers to the positive button (PosButtonText) and 1 refers to the negative button (NegButtonText).</param>
 public void RequestShowDialogSinglePlayer(DialogBoxData data, Action <IdAndIntValue> callback)
 {
     AddCallback(CmdId.Event_DialogButtonIndex, callback);
     EmpyrionExtension.LegacyApi.Game_Request(CmdId.Request_ShowDialog_SinglePlayer, SequenceNumber, data);
 }
Example #23
0
    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();
            }
        }
    }