From ea3c9c5580fdd31efdb618003fde8ad6d4baf45e Mon Sep 17 00:00:00 2001 From: Deathmax Date: Thu, 2 Jun 2011 12:14:32 +0800 Subject: [PATCH] Overhauled commands. Now everything is dumped into Commands.cs --- TShockAPI/Commands.cs | 333 +++++++++++++++++++++++ TShockAPI/TShock.cs | 532 +++++++++++++++++++------------------ TShockAPI/TShockAPI.csproj | 1 + 3 files changed, 611 insertions(+), 255 deletions(-) create mode 100644 TShockAPI/Commands.cs diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs new file mode 100644 index 00000000..acca91ac --- /dev/null +++ b/TShockAPI/Commands.cs @@ -0,0 +1,333 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Terraria; +using System.Text.RegularExpressions; + +namespace TShockAPI +{ + public class Commands + { + public delegate void CommandDelegate(CommandArgs args); + public struct CommandArgs + { + public string Message; + public int PlayerX; + public int PlayerY; + public int PlayerID; + + public CommandArgs(string message, int x, int y, int id) + { + Message = message; PlayerX = x; PlayerY = y; PlayerID = id; + } + } + public static void InitCommands() + { + TShock.commandList.Add("kick", new CommandDelegate(Kick)); + TShock.commandList.Add("ban", new CommandDelegate(Ban)); + TShock.commandList.Add("off", new CommandDelegate(Off)); + TShock.commandList.Add("reload", new CommandDelegate(Reload)); + TShock.commandList.Add("dropmeteor", new CommandDelegate(DropMeteor)); + TShock.commandList.Add("star", new CommandDelegate(Star)); + TShock.commandList.Add("bloodmoon", new CommandDelegate(Bloodmoon)); + TShock.commandList.Add("eater", new CommandDelegate(Eater)); + TShock.commandList.Add("eye", new CommandDelegate(Eye)); + TShock.commandList.Add("skeletron", new CommandDelegate(Skeletron)); + TShock.commandList.Add("hardcore", new CommandDelegate(Hardcore)); + TShock.commandList.Add("invade", new CommandDelegate(Invade)); + TShock.commandList.Add("password", new CommandDelegate(Password)); + TShock.commandList.Add("save", new CommandDelegate(Save)); + TShock.commandList.Add("spawn", new CommandDelegate(Spawn)); + TShock.commandList.Add("tp", new CommandDelegate(TP)); + TShock.commandList.Add("tphere", new CommandDelegate(TPHere)); + TShock.commandList.Add("spawnmob", new CommandDelegate(SpawnMob)); + TShock.commandList.Add("item", new CommandDelegate(Item)); + TShock.commandList.Add("give", new CommandDelegate(Give)); + TShock.commandList.Add("heal", new CommandDelegate(Heal)); + TShock.commandList.Add("butcher", new CommandDelegate(Butcher)); + TShock.commandList.Add("maxspawns", new CommandDelegate(MaxSpawns)); + TShock.commandList.Add("spawnrate", new CommandDelegate(SpawnRate)); + } + #region Command Methods + public static void Kick(CommandArgs args) + { + string plStr = args.Message.Remove(0, 5).Trim(); + int ply = args.PlayerID; + if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + { + Tools.Kick(Tools.FindPlayer(plStr), "You were kicked."); + Tools.Broadcast(plStr + " was kicked by " + Tools.FindPlayer(ply)); + } + } + public static void Ban(CommandArgs args) + { + string plStr = args.Message.Remove(0, 4).Trim(); + if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + { + FileTools.WriteBan(Tools.FindPlayer(plStr)); + Tools.Kick(Tools.FindPlayer(plStr), "You were banned."); + } + } + public static void Off(CommandArgs args) + { + Netplay.disconnect = true; + } + public static void Reload(CommandArgs args) + { + FileTools.SetupConfig(); + } + public static void DropMeteor(CommandArgs args) + { + WorldGen.spawnMeteor = false; + WorldGen.dropMeteor(); + } + public static void Star(CommandArgs args) + { + int penis56 = 12; + int penis57 = Main.rand.Next(Main.maxTilesX - 50) + 100; + penis57 *= 0x10; + int penis58 = Main.rand.Next((int)(Main.maxTilesY * 0.05)) * 0x10; + Microsoft.Xna.Framework.Vector2 vector = new Microsoft.Xna.Framework.Vector2((float)penis57, (float)penis58); + float speedX = Main.rand.Next(-100, 0x65); + float speedY = Main.rand.Next(200) + 100; + float penis61 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); + penis61 = ((float)penis56) / penis61; + speedX *= penis61; + speedY *= penis61; + Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, 12, 0x3e8, 10f, Main.myPlayer); + } + public static void Bloodmoon(CommandArgs args) + { + int ply = args.PlayerID; + Tools.Broadcast(Tools.FindPlayer(ply) + " turned on blood moon."); + Main.bloodMoon = true; + Main.time = 0; + Main.dayTime = false; + NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY); + NetMessage.syncPlayers(); + } + public static void Eater(CommandArgs args) + { + int x = args.PlayerX; + int y = args.PlayerY; + int ply = args.PlayerID; + Tools.NewNPC((int)ConfigurationManager.NPCList.WORLD_EATER, x, y, ply); + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eater of worlds!"); + } + public static void Eye(CommandArgs args) + { + int x = args.PlayerX; + int y = args.PlayerY; + int ply = args.PlayerID; + Tools.NewNPC((int)ConfigurationManager.NPCList.EYE, x, y, ply); + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!"); + } + public static void Skeletron(CommandArgs args) + { + int x = args.PlayerX; + int y = args.PlayerY; + int ply = args.PlayerID; + Tools.NewNPC((int)ConfigurationManager.NPCList.SKELETRON, x, y, ply); + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned skeletron!"); + } + public static void Hardcore(CommandArgs args) + { + int x = args.PlayerX; + int y = args.PlayerY; + int ply = args.PlayerID; + for (int i = 0; i <= 2; i++) + { + Tools.NewNPC(i, x, y, ply); + } + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned all 3 bosses!"); + } + public static void Invade(CommandArgs args) + { + int ply = args.PlayerID; + Tools.Broadcast(Main.player[ply].name + " started an invasion."); + TShock.StartInvasion(); + } + public static void Password(CommandArgs args) + { + int ply = args.PlayerID; + string passwd = args.Message.Remove(0, 9).Trim(); + Netplay.password = passwd; + Tools.SendMessage(ply, "Server password changed to: " + passwd); + } + public static void Save(CommandArgs args) + { + int ply = args.PlayerID; + WorldGen.saveWorld(); + Tools.SendMessage(ply, "World saved."); + } + public static void Spawn(CommandArgs args) + { + int ply = args.PlayerID; + TShock.Teleport(ply, Main.player[ply].SpawnX * 16, Main.player[ply].SpawnY * 16); + Tools.SendMessage(ply, "Teleported to your spawnpoint."); + } + public static void TP(CommandArgs args) + { + int ply = args.PlayerID; + string player = args.Message.Remove(0, 3).Trim(); + if (Tools.FindPlayer(player) != -1 && player != "") + { + TShock.Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X, Main.player[Tools.FindPlayer(player)].position.Y); + Tools.SendMessage(ply, "Teleported to " + player); + } + } + public static void TPHere(CommandArgs args) + { + int ply = args.PlayerID; + string player = args.Message.Remove(0, 7).Trim(); + if (Tools.FindPlayer(player) != -1 && player != "") + { + TShock.Teleport(Tools.FindPlayer(player), Main.player[ply].position.X, Main.player[ply].position.Y); + Tools.SendMessage(Tools.FindPlayer(player), "You were teleported to " + Tools.FindPlayer(ply) + "."); + Tools.SendMessage(ply, "You brought " + player + " here."); + } + } + public static void SpawnMob(CommandArgs args) + { + int x = args.PlayerX; + int y = args.PlayerY; + var msgargs = Regex.Split(args.Message, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + if (msgargs.Length >= 2 && msgargs.Length <= 3) + { + for (int i = 1; i < msgargs.Length; i++) + msgargs[i] = ((msgargs[i].TrimEnd('"')).TrimStart('"')); + string inputtype = ""; + int amount = 1; + int npcid = -1; + int type = -1; + inputtype = msgargs[1]; + if (msgargs.Length == 3) + int.TryParse(msgargs[2], out amount); + + if (!int.TryParse(inputtype, out type)) + type = TShock.GetNPCID(inputtype); + if (type >= 1 && type <= 43) + { + for (int i = 0; i < amount; i++) + npcid = NPC.NewNPC(x, y, type, 0); + Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount));; + } + } + } + public static void Item(CommandArgs args) + { + var msgargs = Regex.Split(args.Message, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")[1]; + int ply = args.PlayerID; + if (msgargs.Length >= 2) + { + msgargs = ((msgargs.TrimEnd('"')).TrimStart('"')); + int type = 0; + if (!int.TryParse(msgargs, out type)) + type = TShock.GetItemID(msgargs); + if (type >= 1 && type <= 235) + { + for (int i = 0; i < 40; i++) + { + if (!Main.player[ply].inventory[i].active) + { + Main.player[ply].inventory[i].SetDefaults(type); + Main.player[ply].inventory[i].stack = Main.player[ply].inventory[i].maxStack; + Tools.SendMessage(ply, "Got some " + Main.player[ply].inventory[i].name + "."); + TShock.UpdateInventories(); + break; + } + } + } + } + } + public static void Give(CommandArgs args) + { + var msgargs = Regex.Split(args.Message, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + int ply = args.PlayerID; + if (msgargs.Length == 3) + { + for (int i = 1; i < msgargs.Length; i++) + msgargs[i] = ((msgargs[i].TrimEnd('"')).TrimStart('"')); + int type = 0; + int player = -1; + if (!int.TryParse(msgargs[1], out type)) + type = TShock.GetItemID(msgargs[1]); + if (type >= 1 && type <= 235) + { + player = Tools.FindPlayer(msgargs[2]); + if (player != -1) + { + for (int i = 0; i < 40; i++) + { + if (!Main.player[player].inventory[i].active) + { + Main.player[player].inventory[i].SetDefaults(type); + Main.player[player].inventory[i].stack = Main.player[player].inventory[i].maxStack; + Tools.SendMessage(ply, string.Format("Gave {0} some {1}.", msgargs[2], Main.player[player].inventory[i].name)); + Tools.SendMessage(player, string.Format("{0} gave you some {1}.", Tools.FindPlayer(ply), Main.player[player].inventory[i].name)); + TShock.UpdateInventories(); + break; + } + } + } + } + } + } + public static void Heal(CommandArgs args) + { + int ply = args.PlayerID; + int x = args.PlayerX; + int y = args.PlayerY; + var msgargs = Regex.Split(args.Message, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + int player = ply; + if (msgargs.Length == 2) + player = Tools.FindPlayer((msgargs[1].TrimEnd('"')).TrimStart('"')); + if (player != ply) + { + Tools.SendMessage(ply, string.Format("You just healed {0}", (msgargs[1].TrimEnd('"')).TrimStart('"'))); + Tools.SendMessage(player, string.Format("{0} just healed you!", Tools.FindPlayer(ply))); + } + else + Tools.SendMessage(ply, "You just got healed!"); + for (int i = 0; i < 20; i++) + { + int itemid = Terraria.Item.NewItem(1, 1, 1, 1, 58); + Main.item[itemid].position.X = (float)x; + Main.item[itemid].position.Y = (float)y; + NetMessage.SendData(21, -1, -1, "", itemid, 0f, 0f, 0f); + } + } + public static void Butcher(CommandArgs args) + { + int killcount = 0; + for (int i = 0; i < Main.npc.Length; i++) + { + if (Main.npc[i].townNPC || !Main.npc[i].active) + continue; + else + { + Main.npc[i].StrikeNPC(99999, 90f, 1); + NetMessage.SendData(28, -1, -1, "", i, (float)99999, 90f, 1); + killcount++; + } + } + Tools.Broadcast("Killed " + killcount.ToString() + " NPCs."); + } + public static void MaxSpawns(CommandArgs args) + { + int ply = args.PlayerID; + int amount = Convert.ToInt32(args.Message.Remove(0, 10)); + NPC.maxSpawns = amount; + Tools.Broadcast(Tools.FindPlayer(ply) + " changed the maximum spawns to: " + amount); + } + public static void SpawnRate(CommandArgs args) + { + int ply = args.PlayerID; + int amount = Convert.ToInt32(args.Message.Remove(0, 10)); + NPC.spawnRate = amount; + Tools.Broadcast(Tools.FindPlayer(ply) + " changed the spawn rate to: " + amount); + } + #endregion + } +} diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index aeda4ffb..94d0a210 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -2,6 +2,7 @@ using System.IO; using System.Net; using System.Text.RegularExpressions; +using System.Collections.Generic; using Microsoft.Xna.Framework; using Terraria; using TerrariaAPI; @@ -19,6 +20,8 @@ namespace TShockAPI public static bool shownVersion = false; + public static Dictionary commandList = new Dictionary(); + public override Version Version { get { return VersionNum; } @@ -60,6 +63,7 @@ namespace TShockAPI NetHooks.OnPreGetData += GetData; NetHooks.OnGreetPlayer += new NetHooks.GreetPlayerD(OnGreetPlayer); NpcHooks.OnStrikeNpc += new NpcHooks.StrikeNpcD(NpcHooks_OnStrikeNpc); + Commands.InitCommands(); } public override void DeInitialize() @@ -157,193 +161,243 @@ namespace TShockAPI int x = (int)Main.player[ply].position.X; int y = (int)Main.player[ply].position.Y; - if (Tools.IsAdmin(ply)) + //if (Tools.IsAdmin(ply)) + //{ + if (msg.StartsWith("/")) { - if (msg.Length > 5 && msg.Substring(0, 5) == "/kick") + if (Tools.IsAdmin(ply)) { - string plStr = msg.Remove(0, 5).Trim(); - if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + Commands.CommandArgs args = new Commands.CommandArgs(msg, x, y, ply); + Commands.CommandDelegate command; + if (commandList.TryGetValue(msg.Split(' ')[0].TrimStart('/'), out command)) + command.Invoke(args); + else + Tools.SendMessage(ply, "Invalid command! Try /help.", new float[] { 255f, 0f, 0f }); + handler.Handled = true; + } + else if (!Tools.IsAdmin(ply) && msg != "/help") + { + Tools.SendMessage(ply, "You don't have permissions to do that!", new float[] { 255f, 0f, 0f }); + handler.Handled = true; + } + } + /*if (msg.Length > 5 && msg.Substring(0, 5) == "/kick") + { + string plStr = msg.Remove(0, 5).Trim(); + if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + { + Tools.Kick(Tools.FindPlayer(plStr), "You were kicked."); + Tools.Broadcast(plStr + " was kicked by " + Tools.FindPlayer(ply)); + } + handler.Handled = true; + } + + if (msg.Length > 4 && msg.Substring(0, 4) == "/ban") + { + string plStr = msg.Remove(0, 4).Trim(); + if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + { + FileTools.WriteBan(Tools.FindPlayer(plStr)); + Tools.Kick(Tools.FindPlayer(plStr), "You were banned."); + } + handler.Handled = true; + } + + if (msg == "/off") + { + Netplay.disconnect = true; + handler.Handled = true; + } + + if (msg == "/reload") + { + FileTools.SetupConfig(); + handler.Handled = true; + } + + if (msg == "/dropmeteor") + { + WorldGen.spawnMeteor = false; + WorldGen.dropMeteor(); + handler.Handled = true; + } + + if (msg == "/star") + { + int penis56 = 12; + int penis57 = Main.rand.Next(Main.maxTilesX - 50) + 100; + penis57 *= 0x10; + int penis58 = Main.rand.Next((int)(Main.maxTilesY * 0.05)) * 0x10; + Microsoft.Xna.Framework.Vector2 vector = new Microsoft.Xna.Framework.Vector2((float)penis57, (float)penis58); + float speedX = Main.rand.Next(-100, 0x65); + float speedY = Main.rand.Next(200) + 100; + float penis61 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); + penis61 = ((float)penis56) / penis61; + speedX *= penis61; + speedY *= penis61; + Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, 12, 0x3e8, 10f, Main.myPlayer); + handler.Handled = true; + } + if (msg == "/bloodmoon") + { + Tools.Broadcast(Tools.FindPlayer(ply) + " turned on blood moon."); + Main.bloodMoon = true; + Main.time = 0; + Main.dayTime = false; + NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY); + NetMessage.syncPlayers(); + handler.Handled = true; + handler.Handled = true; + } + if (msg == "/eater") + { + Tools.NewNPC((int)ConfigurationManager.NPCList.WORLD_EATER, x, y, ply); + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eater of worlds!"); + handler.Handled = true; + } + if (msg == "/eye") + { + Tools.NewNPC((int)ConfigurationManager.NPCList.EYE, x, y, ply); + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!"); + handler.Handled = true; + } + if (msg == "/skeletron") + { + Tools.NewNPC((int)ConfigurationManager.NPCList.SKELETRON, x, y, ply); + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned skeletron!"); + handler.Handled = true; + } + if (msg == "/hardcore") + { + for (int i = 0; i <= 2; i++) + { + Tools.NewNPC(i, x, y, ply); + } + Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned all 3 bosses!"); + handler.Handled = true; + } + if (msg == "/invade") + { + Tools.Broadcast(Main.player[ply].name + " started an invasion."); + StartInvasion(); + handler.Handled = true; + } + if (msg.Length > 9 && msg.Substring(0, 9) == "/password") + { + string passwd = msg.Remove(0, 9).Trim(); + Netplay.password = passwd; + Tools.SendMessage(ply, "Server password changed to: " + passwd); + handler.Handled = true; + } + if (msg == "/save") + { + WorldGen.saveWorld(); + Tools.SendMessage(ply, "World saved."); + handler.Handled = true; + } + if (msg == "/spawn") + { + Teleport(ply, Main.player[ply].SpawnX * 16, Main.player[ply].SpawnY * 16); + Tools.SendMessage(ply, "Teleported to your spawnpoint."); + handler.Handled = true; + } + if (msg.Length > 3 && msg.Substring(0, 3) == "/tp") + { + string player = msg.Remove(0, 3).Trim(); + if (Tools.FindPlayer(player) != -1 && player != "") + { + Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X, Main.player[Tools.FindPlayer(player)].position.Y); + Tools.SendMessage(ply, "Teleported to " + player); + handler.Handled = true; + } + } + if (msg.Length > 7 && msg.Substring(0, 7) == "/tphere") + { + string player = msg.Remove(0, 7).Trim(); + if (Tools.FindPlayer(player) != -1 && player != "") + { + Teleport(Tools.FindPlayer(player), Main.player[ply].position.X, Main.player[ply].position.Y); + Tools.SendMessage(Tools.FindPlayer(player), "You were teleported to " + Tools.FindPlayer(ply) + "."); + Tools.SendMessage(ply, "You brought " + player + " here."); + handler.Handled = true; + } + } + if (msg.StartsWith("/spawnmob")) + { + var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + if (args.Length >= 2 && args.Length <= 3) + { + for (int i = 1; i < args.Length; i++) + args[i] = ((args[i].TrimEnd('"')).TrimStart('"')); + string inputtype = ""; + int amount = 1; + int npcid = -1; + int type = -1; + inputtype = args[1]; + if (args.Length == 3) + int.TryParse(args[2], out amount); + + if (!int.TryParse(inputtype, out type)) + type = GetNPCID(inputtype); + if (type >= 1 && type <= 43) { - Tools.Kick(Tools.FindPlayer(plStr), "You were kicked."); - Tools.Broadcast(plStr + " was kicked by " + Tools.FindPlayer(ply)); - } - handler.Handled = true; - } - - if (msg.Length > 4 && msg.Substring(0, 4) == "/ban") - { - string plStr = msg.Remove(0, 4).Trim(); - if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) - { - FileTools.WriteBan(Tools.FindPlayer(plStr)); - Tools.Kick(Tools.FindPlayer(plStr), "You were banned."); - } - handler.Handled = true; - } - - if (msg == "/off") - { - Netplay.disconnect = true; - handler.Handled = true; - } - - if (msg == "/reload") - { - FileTools.SetupConfig(); - handler.Handled = true; - } - - if (msg == "/dropmeteor") - { - WorldGen.spawnMeteor = false; - WorldGen.dropMeteor(); - handler.Handled = true; - } - - if (msg == "/star") - { - int penis56 = 12; - int penis57 = Main.rand.Next(Main.maxTilesX - 50) + 100; - penis57 *= 0x10; - int penis58 = Main.rand.Next((int)(Main.maxTilesY * 0.05)) * 0x10; - Microsoft.Xna.Framework.Vector2 vector = new Microsoft.Xna.Framework.Vector2((float)penis57, (float)penis58); - float speedX = Main.rand.Next(-100, 0x65); - float speedY = Main.rand.Next(200) + 100; - float penis61 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); - penis61 = ((float)penis56) / penis61; - speedX *= penis61; - speedY *= penis61; - Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, 12, 0x3e8, 10f, Main.myPlayer); - handler.Handled = true; - } - if (msg == "/bloodmoon") - { - Tools.Broadcast(Tools.FindPlayer(ply) + " turned on blood moon."); - Main.bloodMoon = true; - Main.time = 0; - Main.dayTime = false; - NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY); - NetMessage.syncPlayers(); - handler.Handled = true; - handler.Handled = true; - } - if (msg == "/eater") - { - Tools.NewNPC((int)ConfigurationManager.NPCList.WORLD_EATER, x, y, ply); - Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eater of worlds!"); - handler.Handled = true; - } - if (msg == "/eye") - { - Tools.NewNPC((int)ConfigurationManager.NPCList.EYE, x, y, ply); - Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!"); - handler.Handled = true; - } - if (msg == "/skeletron") - { - Tools.NewNPC((int)ConfigurationManager.NPCList.SKELETRON, x, y, ply); - Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned skeletron!"); - handler.Handled = true; - } - if (msg == "/hardcore") - { - for (int i = 0; i <= 2; i++) - { - Tools.NewNPC(i, x, y, ply); - } - Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned all 3 bosses!"); - handler.Handled = true; - } - if (msg == "/invade") - { - Tools.Broadcast(Main.player[ply].name + " started an invasion."); - StartInvasion(); - handler.Handled = true; - } - if (msg.Length > 9 && msg.Substring(0, 9) == "/password") - { - string passwd = msg.Remove(0, 9).Trim(); - Netplay.password = passwd; - Tools.SendMessage(ply, "Server password changed to: " + passwd); - handler.Handled = true; - } - if (msg == "/save") - { - WorldGen.saveWorld(); - Tools.SendMessage(ply, "World saved."); - handler.Handled = true; - } - if (msg == "/spawn") - { - Teleport(ply, Main.player[ply].SpawnX * 16, Main.player[ply].SpawnY * 16); - Tools.SendMessage(ply, "Teleported to your spawnpoint."); - handler.Handled = true; - } - if (msg.Length > 3 && msg.Substring(0, 3) == "/tp") - { - string player = msg.Remove(0, 3).Trim(); - if (Tools.FindPlayer(player) != -1 && player != "") - { - Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X, Main.player[Tools.FindPlayer(player)].position.Y); - Tools.SendMessage(ply, "Teleported to " + player); + for (int i = 0; i < amount; i++) + npcid = NPC.NewNPC(x, y, type, 0); + Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount)); handler.Handled = true; } } - if (msg.Length > 7 && msg.Substring(0, 7) == "/tphere") + } + if (msg.StartsWith("/item")) + { + var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")[1]; + if (args.Length >= 2) { - string player = msg.Remove(0, 7).Trim(); - if (Tools.FindPlayer(player) != -1 && player != "") + args = ((args.TrimEnd('"')).TrimStart('"')); + int type = 0; + if (!int.TryParse(args, out type)) + type = GetItemID(args); + if (type >= 1 && type <= 235) { - Teleport(Tools.FindPlayer(player), Main.player[ply].position.X, Main.player[ply].position.Y); - Tools.SendMessage(Tools.FindPlayer(player), "You were teleported to " + Tools.FindPlayer(ply) + "."); - Tools.SendMessage(ply, "You brought " + player + " here."); - handler.Handled = true; - } - } - if (msg.StartsWith("/spawnmob")) - { - var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); - if (args.Length >= 2 && args.Length <= 3) - { - for (int i = 1; i < args.Length; i++) - args[i] = ((args[i].TrimEnd('"')).TrimStart('"')); - string inputtype = ""; - int amount = 1; - int npcid = -1; - int type = -1; - inputtype = args[1]; - if (args.Length == 3) - int.TryParse(args[2], out amount); - - if (!int.TryParse(inputtype, out type)) - type = GetNPCID(inputtype); - if (type >= 1 && type <= 43) + for (int i = 0; i < 40; i++) { - for (int i = 0; i < amount; i++) - npcid = NPC.NewNPC(x, y, type, 0); - Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount)); - handler.Handled = true; + if (!Main.player[ply].inventory[i].active) + { + Main.player[ply].inventory[i].SetDefaults(type); + Main.player[ply].inventory[i].stack = Main.player[ply].inventory[i].maxStack; + Tools.SendMessage(ply, "Got some " + Main.player[ply].inventory[i].name + "."); + UpdateInventories(); + handler.Handled = true; + break; + } } } } - if (msg.StartsWith("/item")) + } + if (msg.StartsWith("/give")) + { + var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + if (args.Length == 3) { - var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")[1]; - if (args.Length >= 2) + for (int i = 1; i < args.Length; i++) + args[i] = ((args[i].TrimEnd('"')).TrimStart('"')); + int type = 0; + int player = -1; + if (!int.TryParse(args[1], out type)) + type = GetItemID(args[1]); + if (type >= 1 && type <= 235) { - args = ((args.TrimEnd('"')).TrimStart('"')); - int type = 0; - if (!int.TryParse(args, out type)) - type = GetItemID(args); - if (type >= 1 && type <= 235) + player = Tools.FindPlayer(args[2]); + if (player != -1) { for (int i = 0; i < 40; i++) { - if (!Main.player[ply].inventory[i].active) + if (!Main.player[player].inventory[i].active) { - Main.player[ply].inventory[i].SetDefaults(type); - Main.player[ply].inventory[i].stack = Main.player[ply].inventory[i].maxStack; - Tools.SendMessage(ply, "Got some " + Main.player[ply].inventory[i].name + "."); + Main.player[player].inventory[i].SetDefaults(type); + Main.player[player].inventory[i].stack = Main.player[player].inventory[i].maxStack; + Tools.SendMessage(ply, string.Format("Gave {0} some {1}.", args[2], Main.player[player].inventory[i].name)); + Tools.SendMessage(player, string.Format("{0} gave you some {1}.", Tools.FindPlayer(ply), Main.player[player].inventory[i].name)); UpdateInventories(); handler.Handled = true; break; @@ -352,93 +406,61 @@ namespace TShockAPI } } } - if (msg.StartsWith("/give")) - { - var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); - if (args.Length == 3) - { - for (int i = 1; i < args.Length; i++) - args[i] = ((args[i].TrimEnd('"')).TrimStart('"')); - int type = 0; - int player = -1; - if (!int.TryParse(args[1], out type)) - type = GetItemID(args[1]); - if (type >= 1 && type <= 235) - { - player = Tools.FindPlayer(args[2]); - if (player != -1) - { - for (int i = 0; i < 40; i++) - { - if (!Main.player[player].inventory[i].active) - { - Main.player[player].inventory[i].SetDefaults(type); - Main.player[player].inventory[i].stack = Main.player[player].inventory[i].maxStack; - Tools.SendMessage(ply, string.Format("Gave {0} some {1}.", args[2], Main.player[player].inventory[i].name)); - Tools.SendMessage(player, string.Format("{0} gave you some {1}.", Tools.FindPlayer(ply), Main.player[player].inventory[i].name)); - UpdateInventories(); - handler.Handled = true; - break; - } - } - } - } - } - } - if (msg.StartsWith("/heal")) - { - var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); - int player = ply; - if (args.Length == 2) - player = Tools.FindPlayer((args[1].TrimEnd('"')).TrimStart('"')); - if (player != ply) - { - Tools.SendMessage(ply, string.Format("You just healed {0}", (args[1].TrimEnd('"')).TrimStart('"'))); - Tools.SendMessage(player, string.Format("{0} just healed you!", Tools.FindPlayer(ply))); - } - else - Tools.SendMessage(ply, "You just got healed!"); - for (int i = 0; i < 20; i++) - { - int itemid = Item.NewItem(1, 1, 1, 1, 58); - Main.item[itemid].position.X = (float)x; - Main.item[itemid].position.Y = (float)y; - NetMessage.SendData(21, -1, -1, "", itemid, 0f, 0f, 0f); - } - handler.Handled = true; - } - if (msg == "/butcher") - { - int killcount = 0; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].townNPC || !Main.npc[i].active) - continue; - else - { - Main.npc[i].StrikeNPC(99999, 90f, 1); - NetMessage.SendData(28, -1, -1, "", i, (float)99999, 90f, 1); - killcount++; - } - } - Tools.Broadcast("Killed " + killcount.ToString() + " NPCs."); - handler.Handled = true; - } - if (msg.Length > 10 && msg.Substring(0, 10) == "/maxspawns") - { - int amount = Convert.ToInt32(msg.Remove(0, 10)); - NPC.maxSpawns = amount; - Tools.Broadcast(Tools.FindPlayer(ply) + " changed the maximum spawns to: " + amount); - handler.Handled = true; - } - if (msg.Length > 10 && msg.Substring(0, 10) == "/spawnrate") - { - int amount = Convert.ToInt32(msg.Remove(0, 10)); - NPC.spawnRate = amount; - Tools.Broadcast(Tools.FindPlayer(ply) + " changed the spawn rate to: " + amount); - handler.Handled = true; - } } + if (msg.StartsWith("/heal")) + { + var args = Regex.Split(msg, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + int player = ply; + if (args.Length == 2) + player = Tools.FindPlayer((args[1].TrimEnd('"')).TrimStart('"')); + if (player != ply) + { + Tools.SendMessage(ply, string.Format("You just healed {0}", (args[1].TrimEnd('"')).TrimStart('"'))); + Tools.SendMessage(player, string.Format("{0} just healed you!", Tools.FindPlayer(ply))); + } + else + Tools.SendMessage(ply, "You just got healed!"); + for (int i = 0; i < 20; i++) + { + int itemid = Item.NewItem(1, 1, 1, 1, 58); + Main.item[itemid].position.X = (float)x; + Main.item[itemid].position.Y = (float)y; + NetMessage.SendData(21, -1, -1, "", itemid, 0f, 0f, 0f); + } + handler.Handled = true; + } + if (msg == "/butcher") + { + int killcount = 0; + for (int i = 0; i < Main.npc.Length; i++) + { + if (Main.npc[i].townNPC || !Main.npc[i].active) + continue; + else + { + Main.npc[i].StrikeNPC(99999, 90f, 1); + NetMessage.SendData(28, -1, -1, "", i, (float)99999, 90f, 1); + killcount++; + } + } + Tools.Broadcast("Killed " + killcount.ToString() + " NPCs."); + handler.Handled = true; + } + if (msg.Length > 10 && msg.Substring(0, 10) == "/maxspawns") + { + int amount = Convert.ToInt32(msg.Remove(0, 10)); + NPC.maxSpawns = amount; + Tools.Broadcast(Tools.FindPlayer(ply) + " changed the maximum spawns to: " + amount); + handler.Handled = true; + } + if (msg.Length > 10 && msg.Substring(0, 10) == "/spawnrate") + { + int amount = Convert.ToInt32(msg.Remove(0, 10)); + NPC.spawnRate = amount; + Tools.Broadcast(Tools.FindPlayer(ply) + " changed the spawn rate to: " + amount); + handler.Handled = true; + }*/ + //} if (msg == "/help") { Tools.SendMessage(ply, "TShock Commands:"); diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 9c04a324..b50ce75a 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -49,6 +49,7 @@ +