Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lodfinal/src/network/Host.cc @ 2961

Last change on this file since 2961 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
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
29#include <assert.h>
30
31#include "Host.h"
32#include "core/ConsoleCommand.h"
33#include "packet/Packet.h"
34#include "ChatListener.h"
35
36namespace orxonox {
37
38SetConsoleCommandShortcut(Host, Chat);
39
40Host *Host::instance_=0;
41
42/**
43 * @brief Constructor: assures that only one reference will be created and sets the pointer
44 */
45Host::Host()
46{
47  clientID_=0;
48  assert(instance_==0);
49  instance_=this;
50}
51
52
53/**
54 * @brief Destructor: resets the instance pointer to 0
55 */
56Host::~Host()
57{
58  instance_=0;
59}
60
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 */
67bool Host::addPacket(ENetPacket *packet, int clientID){
68  if(instance_)
69    return instance_->queuePacket(packet, clientID);
70  else
71    return false;
72}
73
74
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// }
81
82// bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
83//   if(instance_)
84//     return instance_->processChat(message, clientID);
85//   else
86//     return false;
87// }
88
89/**
90 * This function returns the ID of the player
91 * @return playerID
92 */
93unsigned int Host::getPlayerID(){
94  if(!instance_)
95    return 0;
96  return instance_->clientID_;
97}
98
99bool Host::Chat(const std::string& message){
100  if(!instance_)
101    return false;
102  return instance_->chat(message);
103}
104
105bool Host::Broadcast(const std::string& message){
106  if(!instance_)
107    return false;
108  return instance_->broadcast(message);
109}
110
111bool Host::incomingChat(const std::string& message, unsigned int playerID){
112  for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
113    it->incomingChat(message, playerID);
114
115  return instance_->processChat(message, playerID);
116}
117
118}//namespace orxonox
Note: See TracBrowser for help on using the repository browser.