Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/network/Host.cc @ 6698

Last change on this file since 6698 was 5961, checked in by scheusso, 15 years ago

new ConsoleCommand: printRTT: prints the round trip time to (the server / all clients)
small change in ClientDisconnection handling (only internal)

  • Property svn:eol-style set to native
File size: 3.1 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
[3214]29#include "Host.h"
30
[2773]31#include <cassert>
[3214]32#include <string>
[1666]33
[1907]34#include "core/ConsoleCommand.h"
[3214]35#include "core/ObjectList.h"
[2087]36#include "ChatListener.h"
[1666]37
[2171]38namespace orxonox {
[1666]39
[1907]40SetConsoleCommandShortcut(Host, Chat);
41
[1666]42Host *Host::instance_=0;
[2087]43
[1907]44/**
45 * @brief Constructor: assures that only one reference will be created and sets the pointer
46 */
[1666]47Host::Host()
48{
[1907]49  clientID_=0;
[1666]50  assert(instance_==0);
51  instance_=this;
[5961]52  this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
53  CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
[1666]54}
55
56
[1907]57/**
58 * @brief Destructor: resets the instance pointer to 0
59 */
[1666]60Host::~Host()
61{
62  instance_=0;
[5961]63  if( this->printRTTCC_ )
64    delete this->printRTTCC_;
[1666]65}
66
[1907]67/**
68 * This function is used to add an enetpacket to be sent to another peer
69 * @param packet Packet to be added
70 * @param clientID ID of the client the packet should be sent to
71 * @return success?
72 */
[1666]73bool Host::addPacket(ENetPacket *packet, int clientID){
74  if(instance_)
75    return instance_->queuePacket(packet, clientID);
76  else
77    return false;
78}
79
[1907]80/**
81 * This function returns the ID of the player
82 * @return playerID
83 */
[2087]84unsigned int Host::getPlayerID(){
[1666]85  if(!instance_)
86    return 0;
[1907]87  return instance_->clientID_;
[1666]88}
89
[2087]90bool Host::Chat(const std::string& message){
[1907]91  if(!instance_)
[3095]92  {
93    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
94      it->incomingChat(message, 0);
95    return true;
96  }
[1907]97  return instance_->chat(message);
98}
[1666]99
[2087]100bool Host::Broadcast(const std::string& message){
101  if(!instance_)
[3058]102  {
103    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
[3095]104      it->incomingChat(message, CLIENTID_UNKNOWN);
[3074]105    return true;
[3058]106  }
[3059]107  else
108    return instance_->broadcast(message);
[2087]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.