[1751] | 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 | |
---|
[1666] | 29 | #include <assert.h> |
---|
| 30 | |
---|
| 31 | #include "Host.h" |
---|
[1907] | 32 | #include "core/ConsoleCommand.h" |
---|
[1666] | 33 | #include "packet/Packet.h" |
---|
| 34 | |
---|
| 35 | namespace network { |
---|
| 36 | |
---|
[1907] | 37 | SetConsoleCommandShortcut(Host, Chat); |
---|
| 38 | |
---|
[1666] | 39 | Host *Host::instance_=0; |
---|
| 40 | |
---|
[1907] | 41 | /** |
---|
| 42 | * @brief Constructor: assures that only one reference will be created and sets the pointer |
---|
| 43 | */ |
---|
[1666] | 44 | Host::Host() |
---|
| 45 | { |
---|
[1907] | 46 | clientID_=0; |
---|
[1666] | 47 | assert(instance_==0); |
---|
| 48 | instance_=this; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
[1907] | 52 | /** |
---|
| 53 | * @brief Destructor: resets the instance pointer to 0 |
---|
| 54 | */ |
---|
[1666] | 55 | Host::~Host() |
---|
| 56 | { |
---|
| 57 | instance_=0; |
---|
| 58 | } |
---|
| 59 | |
---|
[1907] | 60 | /** |
---|
| 61 | * This function is used to add an enetpacket to be sent to another peer |
---|
| 62 | * @param packet Packet to be added |
---|
| 63 | * @param clientID ID of the client the packet should be sent to |
---|
| 64 | * @return success? |
---|
| 65 | */ |
---|
[1666] | 66 | bool Host::addPacket(ENetPacket *packet, int clientID){ |
---|
| 67 | if(instance_) |
---|
| 68 | return instance_->queuePacket(packet, clientID); |
---|
| 69 | else |
---|
| 70 | return false; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
[1711] | 74 | // bool Host::chat(std::string& message){ |
---|
| 75 | // if(!instance_) |
---|
| 76 | // return false; |
---|
| 77 | // packet::Chat *c = new packet::Chat(message, getPlayerID()); |
---|
| 78 | // return instance_->sendChat(c); |
---|
| 79 | // } |
---|
[1666] | 80 | |
---|
[1711] | 81 | // bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){ |
---|
| 82 | // if(instance_) |
---|
| 83 | // return instance_->processChat(message, clientID); |
---|
| 84 | // else |
---|
| 85 | // return false; |
---|
| 86 | // } |
---|
[1666] | 87 | |
---|
[1907] | 88 | /** |
---|
| 89 | * This function returns the ID of the player |
---|
| 90 | * @return playerID |
---|
| 91 | */ |
---|
| 92 | unsigned int Host::getPlayerID(){ |
---|
[1666] | 93 | if(!instance_) |
---|
| 94 | return 0; |
---|
[1907] | 95 | return instance_->clientID_; |
---|
[1666] | 96 | } |
---|
| 97 | |
---|
[1907] | 98 | bool Host::Chat(std::string message){ |
---|
| 99 | if(!instance_) |
---|
| 100 | return false; |
---|
| 101 | return instance_->chat(message); |
---|
| 102 | } |
---|
[1666] | 103 | |
---|
[1907] | 104 | bool Host::incomingChat(std::string message, unsigned int playerID){ |
---|
| 105 | return instance_->processChat(message, playerID); |
---|
| 106 | } |
---|
| 107 | |
---|
[1666] | 108 | }//namespace network |
---|