Client.hh

00001 /*
00002 ** Stechec project is free software; you can redistribute it and/or modify
00003 ** it under the terms of the GNU General Public License as published by
00004 ** the Free Software Foundation; either version 2 of the License, or
00005 ** (at your option) any later version.
00006 **
00007 ** The complete GNU General Public Licence Notice can be found as the
00008 ** `NOTICE' file in the root directory.
00009 **
00010 ** Copyright (C) 2007 Prologin
00011 */
00012 
00013 #ifndef CLIENT_HH_
00014 # define CLIENT_HH_
00015 
00016 # include <string>
00017 
00018 class Cx;
00019 class CoachErrorCustom;
00020 
00030 class ClientStatistic
00031 {
00032 public:
00033   ClientStatistic()
00034     : id_(-1), ext_id_(-1), custom_(NULL)
00035   {}
00036 
00037   int           id_;
00038   int                   ext_id_;
00039   std::string           fail_reason_;
00040   CoachErrorCustom*     custom_;
00041 };
00042 
00043 
00044 BEGIN_NS(server);
00045 
00046 
00051 class Client
00052 {
00053   friend class Server;
00054   friend class GameHosting;
00055   
00056 public:
00057   Client(Cx* cx);
00058   virtual ~Client();
00059 
00060   int           getId() const;
00061   int           getLeagueId() const;
00062   bool          isCoach() const;
00063   void          setFailReason(const std::string& msg, int prio);
00064 
00065   void          begin();
00066   void          commit();
00067   void          send(const Packet* p);
00068     
00069 private:
00070   Cx*           cx_;
00071 
00072   bool          init_pkt_received_;
00073   bool          game_joined_;
00074 
00075   int           id_;
00076   int           league_id_;
00077   bool          is_coach_;
00078   bool          is_ready_;              
00079 
00082   int           fail_priority_;              
00083   ClientStatistic st_;
00084 };
00085 
00086 END_NS(server);
00087 
00088 
00089 
00090 /*
00091 ** Implementation.
00092 */
00093 
00094 # include "datatfs/Cx.hh"
00095 
00096 BEGIN_NS(server);
00097 
00098 inline Client::Client(Cx* cx)
00099   : cx_(cx),
00100     init_pkt_received_(false),
00101     game_joined_(false),
00102     id_(-1),
00103     league_id_(-1),
00104     is_coach_(false),
00105     is_ready_(false),
00106     fail_priority_(-1)
00107 {
00108 }
00109 
00110 inline Client::~Client()
00111 {
00112   delete cx_;
00113 }
00114 
00115 inline int Client::getId() const
00116 {
00117   return id_;
00118 }
00119 
00120 inline int Client::getLeagueId() const
00121 {
00122   return league_id_;
00123 }
00124 
00125 inline bool Client::isCoach() const
00126 {
00127   return is_coach_;
00128 }
00129 
00130 inline void Client::setFailReason(const std::string& msg, int prio)
00131 {
00132   if (fail_priority_ < prio)
00133     {
00134       st_.fail_reason_ = msg;
00135       fail_priority_ = prio;
00136     }
00137 }
00138 
00139 inline void Client::begin()
00140 {
00141   cx_->begin();
00142 }
00143 
00144 inline void Client::commit()
00145 {
00146   try {
00147     cx_->commit();
00148   } catch (const NetError& e) {
00149     setFailReason(e.what(), 0);
00150   }
00151 }
00152 
00153 inline void Client::send(const Packet* p)
00154 {
00155   try {
00156     cx_->send(*p);
00157   } catch (const NetError& e) {
00158     setFailReason(e.what(), 0);
00159   }
00160 }
00161 
00162 END_NS(server);
00163 
00164 #endif /* !CLIENT_HH_ */

Generated on Sat Jun 23 16:07:22 2007 for Stechec/TBT by  doxygen 1.4.7