public override void ProcessServer()
 {
     if (!ChatCommandService.ProcessServerMessage(SenderSteamId, PlayerId, TextCommand))
     {
         //MyAPIGateway.Utilities.SendMessage(SenderSteamId, "CHECK", "ProcessServerMessage failed.");
     }
 }
Exemple #2
0
        public override bool Invoke(ChatData chatData)
        {
            var brief = chatData.TextCommand.StartsWith("/?", StringComparison.InvariantCultureIgnoreCase);

            var match = Regex.Match(chatData.TextCommand, @"(/help|/?)\s{1,}(?<Key>[^\s]+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var ret = ChatCommandService.Help(chatData.SenderSteamId, match.Groups["Key"].Value, brief);
                if (!ret)
                {
                    MyAPIGateway.Utilities.ShowMessage("help", "could not find specified command.");
                }
                return(true);
            }

            if (ChatCommandService.UserSecurity == ChatCommandSecurity.User)
            {
                // Split help details. Regular users, get one list.
                var commands = new List <string>(ChatCommandService.GetUserListCommands(chatData.SenderSteamId));
                commands.Sort();

                if (brief)
                {
                    MyAPIGateway.Utilities.ShowMessage("help", string.Join(", ", commands));
                }
                else
                {
                    MyAPIGateway.Utilities.ShowMissionScreen($"{MySampleModConsts.ModTitle} Commands", "Help : Available commands", " ", "Commands: " + string.Join(", ", commands), null, "OK");
                }
            }
            else
            {
                // Split help details. Admins users, get two lists.
                var commands = new List <string>(ChatCommandService.GetUserListCommands(chatData.SenderSteamId));
                commands.Sort();

                var nonUserCommands = new List <string>(ChatCommandService.GetNonUserListCommands(chatData.SenderSteamId));
                nonUserCommands.Sort();

                if (brief)
                {
                    MyAPIGateway.Utilities.ShowMessage("user help", string.Join(", ", commands));
                    MyAPIGateway.Utilities.ShowMessage("help", string.Join(", ", nonUserCommands));
                }
                else
                {
                    MyAPIGateway.Utilities.ShowMissionScreen($"{MySampleModConsts.ModTitle} Commands", "Help : Available commands", " ",
                                                             $"User commands:\r\n{string.Join(", ", commands)}\r\n\r\nAdmin commands:\r\n{string.Join(", ", nonUserCommands)}"
                                                             , null, "OK");
                }
            }

            return(true);
        }
Exemple #3
0
 public override void ProcessClient()
 {
     // should only ever be sent from the server.
     if (MyAPIGateway.Multiplayer.ServerId == SenderSteamId)
     {
         if (!ChatCommandService.ProcessClientMessage(TextCommand))
         {
             //MyAPIGateway.Utilities.SendMessage(SenderSteamId, "CHECK", "ProcessServerMessage failed.");
         }
     }
 }
 public override void ProcessServer()
 {
     if (!ChatCommandService.ProcessServerMessage(
             new ChatData(
                 SenderSteamId,
                 SenderDisplayName,
                 SenderLanguage,
                 IdentityId,
                 TextCommand)))
     {
         //MyAPIGateway.Utilities.SendMessage(SenderSteamId, "CHECK", "ProcessServerMessage failed.");
     }
 }
Exemple #5
0
        public override void ProcessClient()
        {
            switch (CommandAction)
            {
            case CommandActions.Level:
                foreach (CommandStruct command in Commands)
                {
                    ChatCommandService.UpdateCommandSecurity(command);
                }
                break;

            case CommandActions.List:
                CommandPermission.ShowCommandList(Commands);
                break;
            }
        }
Exemple #6
0
 public override void ProcessClient()
 {
     // should only ever be sent from the server.
     if (MyAPIGateway.Multiplayer.ServerId == SenderSteamId)
     {
         if (!ChatCommandService.ProcessClientMessage(
                 new ChatData(
                     MyAPIGateway.Session.Player.SteamUserId,
                     MyAPIGateway.Session.Player.DisplayName,
                     (int)MyAPIGateway.Session.Config.Language,
                     MyAPIGateway.Session.Player.IdentityId,
                     TextCommand)))
         {
             //MyAPIGateway.Utilities.SendMessage(SenderSteamId, "CHECK", "ProcessServerMessage failed.");
         }
     }
 }
Exemple #7
0
        public static void CommandDetails()
        {
            // dictionary of commands
            Dictionary <string, string> commandDetails = new Dictionary <string, string>()
            {
                { "command", "nil" },
                { "parent", "nil" },
                { "helpText", "nil" },
                { "shortCut", "nil" },
                { "level", "nil" },
                { "parameters", "nil" }
            };

            Regex regex = new Regex("\t\n\v\f\r");

            var chatServer  = ChatServer.Obj;
            var chatManager = GetFieldValue(chatServer, "netChatManager");
            ChatCommandService chatCommandService = (ChatCommandService)GetFieldValue(chatManager, "chatCommandService");

            IEnumerable <ChatCommand> commands = chatCommandService.GetAllCommands();

            foreach (var com in commands)
            {
                if (com.Key == "dumpdetails")
                {
                    continue;
                }

                var command = $"/{Localizer.DoStr(com.ParentKey)}{(Localizer.DoStr(com.ParentKey) == "" ? Localizer.DoStr(com.Name) : " " + Localizer.DoStr(com.Name))}";
                if (!EveryCommand.ContainsKey(command))
                {
                    EveryCommand.Add(command, new Dictionary <string, string>(commandDetails));
                    EveryCommand[command]["command"] = "'" + Localizer.DoStr(com.Key) + "'";

                    if (com.ParentKey != null && com.ParentKey != "")
                    {
                        EveryCommand[command]["parent"] = "'" + Localizer.DoStr(com.ParentKey) + "'";
                    }

                    EveryCommand[command]["helpText"] = "'" + Localizer.DoStr(JSONStringSafe(com.HelpText)) + "'";
                    EveryCommand[command]["shortCut"] = "'" + Localizer.DoStr(com.ShortCut) + "'";
                    EveryCommand[command]["level"]    = "'" + Localizer.DoStr(com.AuthLevel.ToString()) + "'";


                    MethodInfo method = com.Method;
                    if (method == null)
                    {
                        continue;
                    }

                    ParameterInfo[] parameters = method.GetParameters();

                    if (parameters == null)
                    {
                        continue;
                    }

                    Dictionary <string, string> pars = new Dictionary <string, string>();

                    foreach (var p in parameters)
                    {
                        if (p.Name == "user")
                        {
                            continue;
                        }

                        string pos = "Arg" + p.Position.ToString();
                        pars[pos] = "'" + p.Name + "', '" + p.ParameterType.Name + "'";

                        if (p.HasDefaultValue)
                        {
                            pars[pos] += ", '" + p.DefaultValue + "'";
                        }
                    }
                    EveryCommand[command]["parameters"] = WriteDictionaryAsSubObject(pars, 1);
                }
            }

            // writes to WikiItems.txt to the Eco Server directory.
            WriteDictionaryToFile("Wiki_Module_CommandData.txt", "commands", EveryCommand);
        }