00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef GAME_HOSTING_HH_
00014 # define GAME_HOSTING_HH_
00015
00016 # include "tools.hh"
00017 # include "datatfs/CxPool.hh"
00018 # include "datatfs/FileCx.hh"
00019 # include "xml/xml_config.hh"
00020 # include "BaseSRules.hh"
00021 # include "PacketSender.hh"
00022
00023 BEGIN_NS(server);
00024
00025 class Client;
00026
00029 enum eGameState {
00030 eStarting = 0,
00031 eWaiting,
00032 ePlaying,
00033 eFinishing,
00034 eFinished,
00035 eCrashed,
00036 };
00037
00047 class GameHosting : public PacketSender
00048 {
00049 public:
00050 GameHosting(int game_uid, const xml::XMLConfig& cfg, BaseSRules* rules);
00051 ~GameHosting();
00052
00055 void addClient(Client* cl);
00056
00058 enum eGameState getState() const;
00059
00062 pthread_t getThreadId() const;
00063
00066 virtual void sendPacket(const Packet& p);
00067
00070 static void* startThread(void* gh_inst);
00071
00072 private:
00073 void outputStatistics();
00074 void run(Log& log);
00075
00076 void spectatorReadiness(Client* cl);
00077 void servePlaying(Client* cl);
00078 void killClient(Client *cl, const std::string& msg);
00079 void waitCoaches();
00080 void playGame();
00081
00082 typedef std::vector<Client*> ClientList;
00083 typedef std::map<Cx*, Client*> ClientMapList;
00084
00085 const xml::XMLConfig& cfg_;
00086 FileCx log_;
00087
00088 CxPool<Cx> cl_pool_;
00089 ClientList cl_;
00090 ClientMapList cl_map_;
00091 ClientList coach_;
00092
00093 BaseSRules* rules_;
00094 int game_uid_;
00095 int nb_coach_;
00096 int nb_waited_coach_;
00097 int nb_team_;
00098 int viewer_base_uid_;
00099 int nb_viewer_;
00100 int nb_waited_viewer_;
00101 enum eGameState state_;
00102
00103 pthread_t self_;
00104 pthread_mutex_t lock_;
00105 };
00106
00107 END_NS(server);
00108
00109 #endif