Paul Pelzl wrote:
* Using the client state + command name to find the correct method to call for a given command
Can you elaborate on that? My server has one method per command... are you just suggesting that those methods should be broken up into smaller functions?
Suppose the client state can be any one of: "init", "unauth", "authenticated", "playing", "observing". If the client issues the command "join mygame", you will probably want to take different action depending on which state the client is in. I'm trying to model it as a state machine: commands are transitions that move you from state to state, and some commands only make sense when you are in a certain state.
So if you are in the "authenticated" state and you receive a "join mygame" command, it would call the "authenticated_join" method. "authenticated_join" is different from "playing_join" because "playing_join" has to remove the player from the old game before joining the new game, etc.
If you put everything into a single "join" method, then you will probably end up with:
if client.state == foo: ... elif client.state == bar: ...
And you run the risk of forgetting about a state that gets added later.
-- Conor Davis conor@xxxxxxxxxxx