Ejemplo n.º 1
0
 public CommandPayload(ICommandService commandServ, ICommand command, string parameters, TCRClientUser userExecutor)
 {
     CommandServ  = commandServ;
     Command      = command;
     Parameters   = parameters;
     UserExecutor = userExecutor;
     Executed     = false;
 }
Ejemplo n.º 2
0
 public string Execute(string input = null, TCRClientUser whoRanCommand = null)
 {
     return(string.Join("</br></br>",
                        Core.CommandServ.Commands
                        .Where(x => x.Value.DefaultPermissionLevel <= whoRanCommand.PermissionLevel)
                        .OrderBy(x => x.Value.DefaultPermissionLevel)
                        .Select(x => $"</quote></b>{(x.Value.DefaultPermissionLevel == Permission.User ? "" : $"[{x.Value.DefaultPermissionLevel.ToString()}] - ")}{x.Value.CommandKey}</b> - {x.Value.Description}</br></quote>     </b>Example:</b> </code>{x.Value.Usage}</code>")
                        ));
 }
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            var players = Terraria.Main.player.Where(x => x.name.Length != 0);

            if (players.Count() == 0)
            {
                return($"</b>Players Online:</b> {players.Count()} / {Terraria.Main.maxNetPlayers}</br></box>No players online!</box>");
            }
            return($"</b>Players Online:</b> {players.Count()} / {Terraria.Main.maxNetPlayers}" + "</br></box>" + string.Join(", ", players.Select(x => x.name)).Replace("`", "") + "</box>");
        }
Ejemplo n.º 4
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            input = input.ToLower();

            String[] spearator = { ", " };
            Int32    count     = 3;

            String[] parameters = input.Split(spearator, count, StringSplitOptions.RemoveEmptyEntries);

            if (parameters.Count() < 2)
            {
                return("Specify a player Name to spawn NPC. Example: \"sm AnOnlinePlayer, npcname, amount\"");
            }

            if (parameters[1] == null || parameters[1] == "")
            {
                return("Specify a NPC ID or name. Example: \"sm AnOnlinePlayer, Wyvern, 2\"");
            }

            for (var i = 0; i < Main.player.Length; i++)
            {
                if (Main.player[i].name.ToLower() == parameters[0])
                {
                    var npcs = TShock.Utils.GetNPCByIdOrName(parameters[1]);
                    if (npcs.Count == 0)
                    {
                        return("Invalid mob type!");
                    }
                    else if (npcs.Count > 1)
                    {
                        return("Matched with more than one npc!");
                    }
                    else
                    {
                        var npc = npcs[0];
                        if (npc.type >= 1 && npc.type < Main.maxNPCTypes && npc.type != 113)
                        {
                            input = parameters[0].Remove(0, Main.player[i].name.Length - 1);

                            if (int.TryParse(parameters[2], out int amount))
                            {
                                TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, TShock.Players[i].TileX, TShock.Players[i].TileY, 35, 10);
                            }
                            else
                            {
                                TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, 1, TShock.Players[i].TileX, TShock.Players[i].TileY, 35, 10);
                            }
                            return("Command Executed.");
                        }
                    }
                }
            }
            return("Player not found.");
        }
Ejemplo n.º 5
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            string terraria = "";

#if TSHOCK
            terraria = "TShock - v";
#endif
#if TMODLOADER
            terraria = "tModLoader 1.3 - v";
#endif

            return("</b>TerrariaChatRelay Version:</b> " + terraria + typeof(Core).Assembly.GetName().Version.ToString());
        }
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            input = input.ToLower();
            if (!int.TryParse(input, out int banId))
            {
                return($"Invalid Ticket Number.");
            }

            if (TShockAPI.TShock.Bans.RemoveBan(banId))
            {
                TShockAPI.TShock.Log.ConsoleInfo($"Ban {banId} has been revoked by \"TerrariaRelayChat : {whoRanCommand.Username}\".");
                return($"Ban {banId} has now been marked as expired.");
            }

            return("");
        }
Ejemplo n.º 7
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            input = input.Replace("<@", "");
            input = input.Replace("!", "");
            input = input.Replace(">", "");

            if (ulong.TryParse(input, out ulong userId))
            {
                Main.Config.ManagerUserIds.Add(userId);
                Main.Config.SaveJson();
                return("User successfully added.");
            }
            else
            {
                return("Could not find user. Example: addadmin @UserToGivePermissions");
            }
        }
Ejemplo n.º 8
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            if (input == null || input == "")
            {
                return("Please designate a player to kill. Example: \"kill Unlucky Player\"");
            }

            for (var i = 0; i < Main.player.Length; i++)
            {
                if (Main.player[i].name == input)
                {
                    NetMessage.SendPlayerDeath(i, PlayerDeathReason.LegacyDefault(), 99999, (new Random()).Next(-1, 1), false, -1, -1);
                    return("");
                }
            }
            return("Player not found!");
        }
Ejemplo n.º 9
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            input = input.ToLower();
            if (input == null || input == "")
            {
                return("Specify a player to kick. Example: \"kick AnOnlinePlayer\"");
            }

            for (var i = 0; i < Main.player.Length; i++)
            {
                if (Main.player[i].name.ToLower() == input)
                {
                    input = input.Remove(0, Main.player[i].name.Length - 1);
                    TShockAPI.TShock.Players[i].Kick(input, true, false, whoRanCommand.Username, true);
                    return("");
                }
            }
            return("Player not found.");
        }
Ejemplo n.º 10
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            var worldinfo = new System.Text.StringBuilder();

            worldinfo.Append("</b>Information about the currently running world</b> </br>");
            worldinfo.Append($"</box>World Name: {TerrariaChatRelay.Game.World.GetName()} </br>");
            worldinfo.Append($"Evil: {TerrariaChatRelay.Game.World.GetEvilType()} </br>");
#if TSHOCK
            worldinfo.Append($"Difficulty: {(TerrariaChatRelay.Game.World.IsMasterMode() ? "Master" : (TerrariaChatRelay.Game.World.IsExpertMode() ? "Expert" : "Normal"))} </br>");
#endif
            worldinfo.Append($"Hardmode: {(TerrariaChatRelay.Game.World.IsHardMode() ? "Yes" : "No")} </br>");
            worldinfo.Append($"World Size: {TerrariaChatRelay.Game.World.getWorldSize()}");

#if TSHOCK
            if (Global.Config.ShowWorldSeed)
            {
                worldinfo.Append($"</br>World Seed : {TerrariaChatRelay.Game.World.GetWorldSeed()}");
            }
#endif

            worldinfo.Append("</box>");
            return(worldinfo.ToString());
        }
Ejemplo n.º 11
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            input = input.Replace("<@", "");
            input = input.Replace("!", "");
            input = input.Replace(">", "");

            if (ulong.TryParse(input, out ulong userId))
            {
                if (Main.Config.ManagerUserIds.Contains(userId))
                {
                    Main.Config.AdminUserIds.Remove(userId);
                    Main.Config.SaveJson();
                    return("User successfully deleted.");
                }
                else
                {
                    return("Could not find user in admin database.");
                }
            }
            else
            {
                return("Could not find user. Example: removeadmin @UserToRemovePermissions");
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Parses data when Discord sends a message.
        /// </summary>
        private void Socket_OnDataReceived(object sender, MessageEventArgs e)
        {
            try
            {
                var json = e.Data;

                if (json == null)
                {
                    return;
                }
                if (json.Length <= 1)
                {
                    return;
                }

                if (debug)
                {
                    Console.WriteLine("\n" + json + "\n");
                }

                if (!DiscordMessageFactory.TryParseDispatchMessage(json, out var msg))
                {
                    return;
                }
                LastSequenceNumber = msg.SequenceNumber;

                var chatmsg = msg.GetChatMessageData();
                if (chatmsg != null && chatmsg.Message != "" && Channel_IDs.Contains(chatmsg.ChannelId))
                {
                    if (!chatmsg.Author.IsBot)
                    {
                        string msgout = chatmsg.Message;

                        // Lazy add commands until I take time to design a command service properly
                        //if (ExecuteCommand(chatmsg))
                        //    return;

                        if (!Core.CommandServ.IsCommand(msgout, Main.Config.CommandPrefix))
                        {
                            msgout = chatParser.ConvertUserIdsToNames(msgout, chatmsg.UsersMentioned);
                            msgout = chatParser.ShortenEmojisToName(msgout);
                        }

                        Permission userPermission;
                        if (chatmsg.Author.Id == Main.Config.OwnerUserId)
                        {
                            userPermission = Permission.Owner;
                        }
                        else if (Main.Config.AdminUserIds.Contains(chatmsg.Author.Id))
                        {
                            userPermission = Permission.Admin;
                        }
                        else if (Main.Config.ManagerUserIds.Contains(chatmsg.Author.Id))
                        {
                            userPermission = Permission.Manager;
                        }
                        else
                        {
                            userPermission = Permission.User;
                        }

                        var user = new TCRClientUser("Discord", chatmsg.Author.Username, userPermission);
                        TerrariaChatRelay.Core.RaiseClientMessageReceived(this, user, "[c/7489d8:Discord] - ", msgout, Main.Config.CommandPrefix, chatmsg.ChannelId);

                        msgout = $"<{chatmsg.Author.Username}> {msgout}";

                        if (Channel_IDs.Count > 1)
                        {
                            messageQueue.QueueMessage(
                                Channel_IDs.Where(x => x != chatmsg.ChannelId),
                                $"**[Discord]** <{chatmsg.Author.Username}> {chatmsg.Message}");
                        }

                        Console.ForegroundColor = ConsoleColor.Blue;
                        Console.Write("[Discord] ");
                        Console.ResetColor();
                        Console.Write(msgout);
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                PrettyPrint.Log("Discord", ex.Message, ConsoleColor.Red);
            }
        }
Ejemplo n.º 13
0
 public string Execute(string input = null, TCRClientUser whoRanCommand = null)
 {
     return("**Administrators for TerrariaChatRelay:**\n" + string.Join("\n", Main.Config.AdminUserIds.Where(x => x != 0).Select(x => $"<@{x}> - ID: {x}\n")));
 }
Ejemplo n.º 14
0
        public string Execute(string input = null, TCRClientUser whoRanCommand = null)
        {
            input = input.ToLower();

            if (input == null || input == "")
            {
                return("Specify a player to ban. Example: ban AnOnlinePlayer, s/l, hacking, 2d");
            }

            String[] spearator = { ", " };
            Int32    count     = 4;

            String[] parameters = input.Split(spearator, count, StringSplitOptions.RemoveEmptyEntries);

            AddBanResult banResult;
            string       reason     = "Banned.";
            string       duration   = null;
            var          result     = new System.Text.StringBuilder();
            DateTime     expiration = DateTime.MaxValue;


            if (parameters.Count() < 3)
            {
                return("Invalid syntax. Example : ban AnOnlinePlayer, s/l, hacking, 2d");
            }

            if (parameters.Count() == 4)
            {
                duration = parameters[3];
            }

            if (parameters.Count() >= 3)
            {
                reason = parameters[2];
            }

            if (TShockAPI.TShock.Utils.TryParseTime(duration, out int seconds))
            {
                expiration = DateTime.UtcNow.AddSeconds(seconds);
            }

            var players = TShockAPI.TSPlayer.FindByNameOrID(parameters[0]);

            if (players.Count > 1)
            {
                return("Found more than one matching players.");
            }

            if (players.Count < 1)
            {
                return("Could not find the target specified. Check that you have the correct spelling.");
            }
            var player = players[0];

            string[] identifier = { $"acc:{player.Name}", $"ip:{player.IP}", $"uuid:{player.UUID}", $"name:{player.Account.Name}" };

            for (int i = 0; i <= 3; i++)
            {
                banResult = TShockAPI.TShock.Bans.InsertBan(identifier[i], reason, $"TerrariaChatRelay : {whoRanCommand.Username}", DateTime.UtcNow, expiration);
                if (parameters[1] == "loud" || parameters[1] == "l")
                {
                    if (banResult.Ban != null)
                    {
                        result.Append($"Ban added. Ticket Number {banResult.Ban.TicketNumber} was created for identifier {identifier[i]}.\n");
                    }
                    else
                    {
                        result.Append($"Failed to add ban for identifier: {identifier[i]}\n");
                        result.Append($"Reason: {banResult.Message}\n");
                    }
                }
            }
            player.Disconnect($"You have been banned: {reason}.\n");

            if (parameters[1] == "silent" || parameters[1] == "s")
            {
                return("Command Executed!");
            }

            return(result.ToString());
        }
Ejemplo n.º 15
0
 public string Execute(string input = null, TCRClientUser whoRanCommand = null)
 {
     return($"</b>Mod List:</b></br></box>{string.Join(", ", ModLoader.Mods.Select(x => x.DisplayName).Where(x => x != "tModLoader"))}</box>");
 }
Ejemplo n.º 16
0
 public string Execute(string input = null, TCRClientUser whoRanCommand = null)
 {
     input = $"/{input}";
     TShockAPI.Commands.HandleCommand(new ConsoleRunner(), input);
     return("");
 }