00001 #ifndef COMMANDS_H
00002 #define COMMANDS_H
00003
00004 #include "../constants.h"
00005 #include "../persist.h"
00006
00007 using namespace std;
00008
00009 class CommandInterpreter {
00010 public:
00011 virtual void chat(char *message) = 0;
00012 virtual void logout() = 0;
00013 virtual void ping(int frame) = 0;
00014 virtual void processGameState(int frame, char *p) = 0;
00015 virtual void handleUnknownMessage() = 0;
00016 virtual void serverClosing() = 0;
00017 virtual void character(char *bytes, int length) = 0;
00018 virtual void addPlayer(Uint32 id, char *bytes, int length) = 0;
00019 };
00020
00021 class TestCommandInterpreter : public CommandInterpreter {
00022 public:
00023 TestCommandInterpreter();
00024 virtual ~TestCommandInterpreter();
00025 void chat(char *message);
00026 void logout();
00027 void ping(int frame);
00028 void processGameState(int frame, char *p);
00029 void handleUnknownMessage();
00030 void serverClosing();
00031 void character(char *bytes, int length);
00032 void addPlayer(Uint32 id, char *bytes, int length);
00033 };
00034
00035 class Commands {
00036 private:
00037 CommandInterpreter *ci;
00038 int lastGameFrameReceived;
00039 int lastCommand;
00040 public:
00041
00042 enum {
00043 CHAT=0,
00044 LOGOUT,
00045 PING,
00046 STATE,
00047 CLOSING,
00048 CHARACTER,
00049 ADD_PLAYER,
00050
00051
00052 COMMAND_COUNT
00053 };
00054
00055 Commands(CommandInterpreter *ci);
00056 ~Commands();
00057
00058 inline int getLastGameFrameReceived() { return lastGameFrameReceived; }
00059 void interpret(char *rawMessage, int length);
00060 inline int getLastCommand() { return lastCommand; }
00061
00062 static void buildGameState(char *buff, int frame, char *state);
00063 static void buildChat(char *buff, char *username, char *message);
00064 static void buildLogin(char *buff, char *username);
00065
00066 void buildPing(char *buff);
00067 static void buildBytesCharacter(char *buff, int size, char *info, int *messageSize);
00068 static void buildBytesAddPlayer(char *buff, int size, char *info, int id, int *messageSize);
00069 };
00070
00071 #endif