Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

server.h

00001 #ifdef HAVE_SDL_NET
00002 
00003 #ifndef SERVER_H
00004 #define SERVER_H
00005 
00006 #include "../constants.h"
00007 #include "tcputil.h"
00008 #include "clientinfo.h"
00009 #include "gamestatehandler.h"
00010 #include "testgamestatehandler.h"
00011 #include "broadcast.h"
00012 
00013 using namespace std;
00014 
00015 int serverLoop(void *data);
00016 
00017 class ClientInfo;
00018 
00019 class Server {
00020  private:
00021   IPaddress ip;
00022   int port;
00023   static const int MAX_CLIENT_COUNT = 4;
00024   SDLNet_SocketSet set;
00025   bool stopThread;
00026   TCPsocket tcpSocket;
00027   SDL_Thread *thread;
00028   ClientInfo *clients[4];
00029   int clientCount;
00030   GameStateHandler *gsh;
00031   int currentFrame;
00032   Broadcast *broadcast;
00033 
00034  public:
00035   static const Uint32 SERVER_LOOP_DELAY = 1000;
00036 
00037   Server(int port);
00038   virtual ~Server();
00039 
00040   inline void setGameStateHandler(GameStateHandler *gsh) { this->gsh = gsh; }
00041   inline GameStateHandler *getGameStateHandler() { return gsh; }
00042   void sendGameState();
00043 
00044   // server params (called by serverLoop)
00045   inline bool getStopThread() { return stopThread; }
00046   inline SDL_Thread *getThread() { return thread; }
00047   inline TCPsocket getTCPSocket() { return tcpSocket; }
00048   inline SDLNet_SocketSet getSocketSet() { return set; }
00049   inline int getClientCount() { return clientCount; }
00050   inline ClientInfo *getClient(int index) { return clients[index]; }
00051 
00052   // handle clients (called by serverLoop)
00053   void initTCPConnection(TCPsocket socket);
00054   void handleTCPConnection(int clientIndex);
00055   void removeDeadClients();
00056 
00057   void sendToAllTCP(char *message, int length=0, ClientInfo *exclude=NULL);
00058   inline Broadcast *getBroadcast() { return broadcast; }
00059 
00060  protected:
00061   void initTCPSocket();
00062 };
00063 
00064 #endif
00065 
00066 #endif

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0