Permalink
Browse files

Added Command Callback support

  • Loading branch information...
1 parent f22ee0c commit 51e19916431b443446d8e21ca71b90194fad0eea Zack Piispanen committed Jun 1, 2012
Showing with 27 additions and 0 deletions.
  1. +15 −0 TShockAPI/Commands.cs
  2. +12 −0 TShockAPI/TSPlayer.cs
View
15 TShockAPI/Commands.cs
@@ -195,6 +195,7 @@ public static void InitCommands()
add(Permissions.cfg, WorldInfo, "world");
add(Permissions.savessi, SaveSSI, "savessi");
add(Permissions.savessi, OverrideSSI, "overridessi", "ossi");
+ add(null, TestCallbackCommand, "test");
}
public static bool HandleCommand(TSPlayer player, string text)
@@ -212,6 +213,13 @@ public static bool HandleCommand(TSPlayer player, string text)
if (cmd == null)
{
+ if( player.AwaitingResponse.ContainsKey(cmdName))
+ {
+ Action<CommandArgs> call = player.AwaitingResponse[cmdName];
+ player.AwaitingResponse.Remove(cmdName);
+ call( new CommandArgs(cmdText, player, args));
+ return true;
+ }
player.SendErrorMessage("Invalid command entered. Type /help for a list of valid commands.");
return true;
}
@@ -312,6 +320,13 @@ private static bool IsWhiteSpace(char c)
return c == ' ' || c == '\t' || c == '\n';
}
+ private static void TestCallbackCommand(CommandArgs args)
+ {
+ Action<CommandArgs> a = (s) => args.Player.Spawn();
+ args.Player.AddResponse( "yes", a);
+ args.Player.SendInfoMessage( "Type yes to spawn." );
+ }
+
#region Account commands
public static void AttemptLogin(CommandArgs args)
View
12 TShockAPI/TSPlayer.cs
@@ -43,6 +43,7 @@ public class TSPlayer
public DateTime LastPvpChange;
public Point[] TempPoints = new Point[2];
public int AwaitingTempPoint { get; set; }
+ public Dictionary<string, Action<CommandArgs>> AwaitingResponse;
public bool AwaitingName { get; set; }
public DateTime LastThreat { get; set; }
public DateTime LastTileChangeNotify { get; set; }
@@ -212,6 +213,7 @@ public TSPlayer(int index)
Index = index;
Group = new Group(TShock.Config.DefaultGuestGroupName);
IceTiles = new List<Point>();
+ AwaitingResponse = new Dictionary<string, Action<CommandArgs>>();
}
protected TSPlayer(String playerName)
@@ -522,6 +524,16 @@ public virtual bool SendRawData(byte[] data)
return TShock.SendBytes(Netplay.serverSock[Index], data);
}
+
+ public void AddResponse( string name, Action<CommandArgs> callback)
+ {
+ if( AwaitingResponse.ContainsKey(name))
+ {
+ AwaitingResponse.Remove(name);
+ }
+
+ AwaitingResponse.Add(name, callback);
+ }
}
public class TSRestPlayer : TSServerPlayer

0 comments on commit 51e1991

Please sign in to comment.