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