Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/Host.cc @ 3011

Last change on this file since 3011 was 2773, checked in by rgrieder, 16 years ago

Removed all enet and boost includes from header files in the network library.

  • Reduces dependencies
  • Minimises problems with windows.h
  • Speeds up the compiling process a little bit (probably negligible)
  • Also removes ugly WIN32_LEAN_AND_MEAN declarations before every enet.h include in the network library.

Removed windows.h header from util/Sleep.h by adding Sleep.cc

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[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
[2773]29#include <cassert>
[1666]30
31#include "Host.h"
[1907]32#include "core/ConsoleCommand.h"
[1666]33#include "packet/Packet.h"
[2087]34#include "ChatListener.h"
[1666]35
[2171]36namespace orxonox {
[1666]37
[1907]38SetConsoleCommandShortcut(Host, Chat);
39
[1666]40Host *Host::instance_=0;
[2087]41
[1907]42/**
43 * @brief Constructor: assures that only one reference will be created and sets the pointer
44 */
[1666]45Host::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]56Host::~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]67bool 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
[2171]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 */
[2087]93unsigned int Host::getPlayerID(){
[1666]94  if(!instance_)
95    return 0;
[1907]96  return instance_->clientID_;
[1666]97}
98
[2087]99bool Host::Chat(const std::string& message){
[1907]100  if(!instance_)
101    return false;
102  return instance_->chat(message);
103}
[1666]104
[2087]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){
[2171]112  for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
[2087]113    it->incomingChat(message, playerID);
114
[1907]115  return instance_->processChat(message, playerID);
116}
117
[2171]118}//namespace orxonox
Note: See TracBrowser for help on using the repository browser.