rendered paste bodyusing System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Server;
using Server.Network;
namespace Server.GUI.Commands
{
public delegate void InputInvoker( string[] args );
public class InputHandler
{
private static Dictionary<string, InputDelegate> _commandTable;
public static void Initialize()
{
_commandTable = new Dictionary<string, InputDelegate>();
Register("online", new InputInvoker(OnlineCommand));
Register("save", new InputInvoker(SaveCommand));
}
public static void HandleInput(string p)
{
p = p.ToLower();
string[] args = p.Split(' ');
if (args.Length > 0 && _commandTable.ContainsKey(args[0]))
_commandTable[args[0]](args);
}
public static void Register(string keyword, InputDelegate deleg)
{
if (_commandTable.ContainsKey(keyword))
{
MessageBox.Show(keyword + ": is already a registered command", "Error registering command");
return;
}
_commandTable.Add(keyword, deleg);
}
private static void SaveCommand(string[] args)
{
World.Save();
}
private static void OnlineCommand(string[] args)
{
GConsole.WriteLine();
GConsole.WriteLine("Requesting Clients");
GConsole.WriteLine("=================");
for (int i = 0; i < NetState.Instances.Count; i++)
if (NetState.Instances[i] != null)
GConsole.WriteLine("Client {0}: {1} - {2}", i + 1, NetState.Instances[i].Address.ToString(), NetState.Instances[i].Mobile.Name);
GConsole.WriteLine("Online Count: {0}", NetState.Instances.Count);
GConsole.WriteLine("=================");
GConsole.WriteLine();
}
}
}