To keep it short: I am making a server program for a game that I am developping. To control the server I want to make use of commands. Something like "/Server Start 5555". These commands are send to the server in string format. This is my code:
ServerCommandsClass ServerCommands = new ServerCommandsClass();
Type Service = typeof(ServerCommandsClass);
MethodInfo method = Service.GetMethod(Signals[Count].MessageArray[0]);
List<object> ObjectList = new List<object>();
for (int i = 1; i < Signals[Count].MessageArray.Length; i++)
{
ObjectList.Add(Signals[Count].MessageArray[i]);
}
string result = Convert.ToString(method.Invoke(ServerCommands, ObjectList.ToArray()));
It looks messy, because it is...
Basically what I got is a class (SignalClass) which stores new messages/commands. First I determine if a message is a command. If so, this code is ran. My MessageArray contains the message word by word using the string.split function.
This works, but I feel this is a bit of a work-around.
What I want is a command infrastructure (somewhat like in minecraft) which is easy to adjust to my needs. Like in minecraft you can type: "/tp 1000 64 1000" and "/tp someplayer 1000 64 1000". In mine you can't due to the limitations of my code. I would have to make a new method "tp2" or something to be able to take that extra parameter.
I hope someone can help me with this problem, because it's very annoying.
b.t.w. I used .Net 4.5.1 to programm this. And if I'm a little vague somewhere, just ask me and I will clarify.
Dion Dokter