00001 #ifdef HAVE_SDL_NET
00002
00003 #ifndef CLIENT_INFO_H
00004 #define CLIENT_INFO_H
00005
00006 #include "../constants.h"
00007 #include "../persist.h"
00008 #include "server.h"
00009 #include "tcputil.h"
00010 #include "commands.h"
00011
00012 using namespace std;
00013
00014 int clientInfoLoop(void *data);
00015
00016 class Server;
00017
00018 class Message {
00019 public:
00020 char *message;
00021 int length;
00022 Message(char *message, int length);
00023 ~Message();
00024 };
00025
00026 class ClientInfo : public CommandInterpreter {
00027 public:
00028 enum {
00029 RECEIVE=0,
00030 SEND
00031 };
00032
00033 Server *server;
00034 bool dead;
00035 TCPsocket socket;
00036 int id;
00037 char *username;
00038 char desc[80];
00039 bool threadRunning;
00040 SDL_Thread *thread;
00041 SDL_mutex *mutex;
00042 queue<Message*> messageQueue;
00043 map<int,Uint32> lagMap;
00044 Commands *commands;
00045 CreatureInfo* characterInfo;
00046
00047 Uint32 totalLag, lastLagCheck;
00048 float aveLag;
00049
00050
00051 static const int MAX_SCHEDULED_LAG_MESSAGES = 25;
00052
00053 ClientInfo(Server *server, TCPsocket socket, int id, char *username);
00054 virtual ~ClientInfo();
00055 inline int getId() { return id; }
00056 inline void setId(int id) { this->id = id; }
00057 inline char *getUsername() { return username; }
00058 char *describe();
00059 void sendMessageAsync(char *s, int length=0);
00060 void setLagTimer(int frame, Uint32 n);
00061 Uint32 updateLag(int frame);
00062
00063
00064 void chat(char *message);
00065 void logout();
00066 void ping(int frame);
00067 void handleUnknownMessage();
00068 void processGameState(int frame, char *p);
00069 void serverClosing();
00070 void character(char *bytes, int length);
00071 void addPlayer(Uint32 id, char *bytes, int length);
00072
00073
00074 void receiveTCP();
00075 void sendTCP(char *message, int length);
00076 inline SDL_mutex *getMutex() { return mutex; }
00077 inline TCPsocket getSocket() { return socket; }
00078 inline bool isThreadRunning() { return threadRunning && !dead; }
00079 inline queue<Message*> *getMessageQueue() { return &messageQueue; }
00080 inline Commands *getCommands() { return commands; }
00081 };
00082
00083 #endif
00084 #endif