Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon/src/network/Host.cc @ 2112

Last change on this file since 2112 was 1907, checked in by scheusso, 16 years ago

merged network branch back to trunk

  • Property svn:eol-style set to native
File size: 2.6 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
35namespace network {
36
37SetConsoleCommandShortcut(Host, Chat);
38
39Host *Host::instance_=0;
40 
41/**
42 * @brief Constructor: assures that only one reference will be created and sets the pointer
43 */
44Host::Host()
45{
46  clientID_=0;
47  assert(instance_==0);
48  instance_=this;
49}
50
51
52/**
53 * @brief Destructor: resets the instance pointer to 0
54 */
55Host::~Host()
56{
57  instance_=0;
58}
59
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 */
66bool Host::addPacket(ENetPacket *packet, int clientID){
67  if(instance_)
68    return instance_->queuePacket(packet, clientID);
69  else
70    return false;
71}
72
73
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// }
80
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// }
87
88/**
89 * This function returns the ID of the player
90 * @return playerID
91 */
92unsigned int Host::getPlayerID(){ 
93  if(!instance_)
94    return 0;
95  return instance_->clientID_;
96}
97
98bool Host::Chat(std::string message){
99  if(!instance_)
100    return false;
101  return instance_->chat(message);
102}
103
104bool Host::incomingChat(std::string message, unsigned int playerID){
105  return instance_->processChat(message, playerID);
106}
107
108}//namespace network
Note: See TracBrowser for help on using the repository browser.