[1666] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008 |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[3214] | 29 | #ifndef _NETWORK_Host_H__ |
---|
| 30 | #define _NETWORK_Host_H__ |
---|
[1666] | 31 | |
---|
[1705] | 32 | #include "NetworkPrereqs.h" |
---|
[6412] | 33 | #include "core/CorePrereqs.h" |
---|
[1666] | 34 | |
---|
[2171] | 35 | namespace orxonox { |
---|
[1666] | 36 | |
---|
[3196] | 37 | const unsigned int CLIENTID_SERVER = 0; |
---|
[3084] | 38 | const unsigned int NETWORK_FREQUENCY = 30; |
---|
| 39 | const float NETWORK_PERIOD = 1.0f/NETWORK_FREQUENCY; |
---|
| 40 | |
---|
[1666] | 41 | /** |
---|
[1907] | 42 | * @brief Base class of Server and Client |
---|
| 43 | * This is the Base class of the Server and Client classes |
---|
| 44 | * - Makes server and client a singleton |
---|
| 45 | * - defines static functions available on both server and client |
---|
| 46 | * - is the interface to be used when communicating with the network |
---|
[6412] | 47 | * @author Oliver Scheuss |
---|
[1666] | 48 | */ |
---|
[2087] | 49 | class _NetworkExport Host{ |
---|
[1666] | 50 | private: |
---|
| 51 | //TODO add theese functions or adequate |
---|
[1711] | 52 | //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0; |
---|
| 53 | //virtual bool sendChat(packet::Chat *chat)=0; |
---|
[1666] | 54 | virtual bool queuePacket(ENetPacket *packet, int clientID)=0; |
---|
[2087] | 55 | virtual bool chat(const std::string& message)=0; |
---|
| 56 | virtual bool broadcast(const std::string& message)=0; |
---|
| 57 | virtual bool processChat(const std::string& message, unsigned int playerID)=0; |
---|
[1907] | 58 | virtual bool isServer_()=0; |
---|
[1740] | 59 | |
---|
| 60 | |
---|
| 61 | |
---|
[1666] | 62 | protected: |
---|
| 63 | Host(); |
---|
[1740] | 64 | virtual ~Host(); |
---|
[1705] | 65 | static Host *instance_; |
---|
[1907] | 66 | unsigned int clientID_; |
---|
| 67 | unsigned int shipID_; |
---|
[1740] | 68 | |
---|
[1666] | 69 | public: |
---|
| 70 | static bool running(){return instance_!=0;} |
---|
| 71 | static bool addPacket(ENetPacket *packet, int clientID=0); |
---|
[1711] | 72 | //static bool chat(std::string& message); |
---|
| 73 | // static bool receiveChat(packet::Chat *message, unsigned int clientID); |
---|
[1907] | 74 | static unsigned int getPlayerID(); |
---|
[1732] | 75 | static unsigned int getShipID(){return instance_->shipID_;} |
---|
[1711] | 76 | static void setClientID(unsigned int id){ instance_->clientID_ = id; } |
---|
| 77 | static void setShipID(unsigned int id){ instance_->shipID_ = id; } |
---|
[2087] | 78 | static bool isServer(){ return instance_->isServer_(); } |
---|
| 79 | static bool Chat(const std::string& message); |
---|
| 80 | static bool Broadcast(const std::string& message); |
---|
| 81 | static bool incomingChat(const std::string& message, unsigned int playerID); |
---|
[6412] | 82 | virtual void printRTT()=0; |
---|
[1711] | 83 | private: |
---|
[6412] | 84 | ConsoleCommand* printRTTCC_; |
---|
[1666] | 85 | }; |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | |
---|
[3214] | 89 | #endif /* _NETWORK_Host_H__ */ |
---|