got command handling implemented

This commit is contained in:
Maverick Motherfucker 2011-06-03 22:50:30 -07:00
parent bf0a95f656
commit 4aa5c71b5b
2 changed files with 22 additions and 11 deletions

View file

@ -54,6 +54,11 @@ namespace TShockAPI
command(args); command(args);
return true; return true;
} }
public string Name()
{
return name;
}
} }
public static void InitCommands() public static void InitCommands()

View file

@ -377,21 +377,27 @@ namespace TShockAPI
if (msg.StartsWith("/")) if (msg.StartsWith("/"))
{ {
Commands.CommandArgs args = new Commands.CommandArgs(msg, x, y, ply); //Commands.CommandArgs args = new Commands.CommandArgs(msg, x, y, ply);
var commands = commandList; Commands.Command cmd = null;
if (TShock.players[ply].IsAdmin()) for (int i = 0; i < Commands.commands.Count; i++)
commands = admincommandList;
Commands.CommandDelegate command;
if (commands.TryGetValue(msg.Split(' ')[0].TrimStart('/'), out command))
{ {
Log.Info(Tools.FindPlayer(ply) + " executed " + msg); if (Commands.commands[i].Name().Equals(msg.Split(' ')[0].TrimStart('/')))
command.Invoke(args); {
cmd = Commands.commands[i];
}
}
if (cmd == null)
{
Tools.SendMessage(ply, "That command does not exist, try /help", new float[] { 255, 0, 0 });
} }
else else
{ {
Log.Info(Tools.FindPlayer(ply) + " tried to execute " + msg); if (!cmd.Run(msg, players[ply]))
Tools.SendMessage(ply, "Invalid command or no permissions! Try /help.", new float[] { 255f, 0f, 0f }); {
Log.Info(Tools.FindPlayer(ply) + " tried to execute " + cmd.Name() + " that s/he did not have access to!");
Tools.SendMessage(ply, "YOU DO NOT HAVE ACCESS TO THAT COMMAND YOU LITTLE SHIT!", new float[] { 255, 0, 0 });
}
} }
handler.Handled = true; handler.Handled = true;
} }