I am currently working on a server that handles specific "Commands" from connected clients. Something akin to what's below:
switch CommandType.Command {
case CommandType.A:
//do something
break;
case CommandType.B
//do something
break;
}
A thread constantly reads commands from the clients and the server deals with them appropriately. Sometimes when a specific command is dealt with the server will want a very specific Command from the client, and to ignore everything else until that command has been received. My issue lies with this. One option is to have a variable such as "CommandBeingWaitedFor" or something like that. When the server wants a specific command from the clients it will set that variable to the required command. This method feels awful because it means that for every command in the switch statement we must first check against this variable to see if there is something currently being specifically waited on. As the number of different possible commands gets bigger this feels like there will be a lot of repeated code. Ideally, there is a simpler and more efficient way to deal with this sort of interaction.
Any help would be greatly appreciated.