Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/toonshader/src/network/ClientInformation.cc @ 5656

Last change on this file since 5656 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: 6.3 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 *      ...
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29//
30// C++ Implementation: ClientInformation
31//
32// Description:
33//
34//
35// Author:  <>, (C) 2007
36//
37// Copyright: See COPYING file that comes with this distribution
38//
39//
40
41#include "ClientInformation.h"
42
43#include <enet/enet.h>
44#include <iostream> //debug
45
46namespace orxonox
47{
48 
49
50  ClientInformation *ClientInformation::head_=0;
51
52  ClientInformation::ClientInformation() {
53    if(!head_)
54      head_=this;
55    gamestateID_=GAMESTATEID_INITIAL;
56    preve=0;
57    nexte=0;
58    partialGamestateID_=GAMESTATEID_INITIAL-1;
59    synched_=false;
60  }
61
62  ClientInformation::~ClientInformation() {
63    if(prev()!=0)
64      prev()->setNext(this->next());
65    if(next()!=0)
66      next()->setPrev(this->prev());
67    if(this==head_)
68      head_=next();
69  }
70
71  ClientInformation *ClientInformation::next() {
72    if(this!=0)
73      return this->nexte;
74    else
75      return 0;
76  }
77  ClientInformation *ClientInformation::prev() {
78    if(this!=0)
79      return this->preve;
80    else
81      return 0;
82  }
83
84  bool ClientInformation::setPrev(ClientInformation *prev) {
85    if(this==head_)
86      head_=prev;
87    this->preve = prev;
88    return true;
89  }
90
91  bool ClientInformation::setNext(ClientInformation *next) {
92    this->nexte = next;
93    return true;
94  }
95
96  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
97    this->next()->setPrev(ins);
98    ins->setNext(this->next());
99    ins->setPrev(this);
100    this->nexte = ins;
101    return ins;
102  }
103
104  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
105    if(!this)
106      return NULL;
107    this->prev()->setNext(ins);
108    ins->setPrev(this->prev());
109    this->preve=ins;
110    ins->setNext(this);
111    return ins;
112  }
113
114  void ClientInformation::setID(int clientID){
115    if(!this)
116      return;
117    clientID_ = clientID;
118  }
119
120  bool ClientInformation::setPeer(ENetPeer *peer){
121    if(!this)
122      return false;
123    peer_ = peer;
124    return true;
125  }
126
127  bool ClientInformation::setGamestateID(int id){
128    if(!this)
129      return false;
130    gamestateID_=id;
131    return true;
132  }
133
134  bool ClientInformation::setPartialGamestateID(int id){
135    if(!this)
136      return false;
137    partialGamestateID_=id;
138    return true;
139  }
140
141  unsigned int ClientInformation::getID() {
142    if(!this)
143      return CLIENTID_UNKNOWN;
144    else
145      return clientID_;
146  }
147
148  ENetPeer *ClientInformation::getPeer() {
149    if(this)
150      return peer_;
151    else
152      return NULL;
153  }
154
155  int ClientInformation::getFailures(){
156    return failures_;
157  }
158  void ClientInformation::addFailure(){
159    failures_++;
160  }
161  void ClientInformation::resetFailures(){
162    failures_=0;
163  }
164
165  uint32_t ClientInformation::getRTT(){
166    return this->peer_->roundTripTime;
167  }
168
169  double ClientInformation::getPacketLoss(){
170    return ((double)this->peer_->packetLoss)/ENET_PEER_PACKET_LOSS_SCALE;
171  }
172
173  unsigned int ClientInformation::getGamestateID() {
174    if(this)
175      return gamestateID_;
176    else
177      return (unsigned int)-1;
178  }
179
180  unsigned int ClientInformation::getPartialGamestateID() {
181    if(this)
182      return partialGamestateID_;
183    else
184      return (unsigned int)-1;
185  }
186
187  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
188    ClientInformation *temp = head_;
189    if(temp==ins){
190      return head_;
191    }
192    while(temp->next()!=0){
193      temp = temp->next();
194    }
195    temp->setNext(ins);
196    ins->setPrev(temp);
197    return ins;
198  }
199
200  bool ClientInformation::removeClient(unsigned int clientID) {
201    if((unsigned int)clientID==CLIENTID_UNKNOWN)
202      return false;
203    ClientInformation *temp = head_;
204    while(temp!=0 && temp->getID()!=clientID)
205      temp = temp->next();
206    if(temp==0)
207      return false;
208    delete temp;
209    return true;
210  }
211
212  bool ClientInformation::removeClient(ENetPeer *peer) {
213    if(!peer)
214      return false;
215    ClientInformation *temp = head_;
216    while(temp!=0){
217      if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
218        break;
219      temp = temp->next();
220    }
221    if(temp==0)
222      return false;
223    delete temp;
224    return true;
225  }
226
227  /**
228  * This function goes forward through the list and looks for an element with clientID
229  * This function should only be applied to the head of the list
230  * @param clientID id to look for
231  * @return pointer to the last element in the list or 0 if the search was unsuccessfull
232  */
233  ClientInformation *ClientInformation::findClient(unsigned int clientID, bool look_backwards) {
234    ClientInformation *temp = head_;
235    while(temp!=0 && temp->getID()!=clientID){
236      temp = temp->next();
237    }
238    // returns 0 if nothing has been found
239    return temp;
240  }
241
242  /**
243  * This function goes forward through the list and looks for an element with clientID
244  * This function should only be applied to the head of the list
245  * @param peer peer to look for
246  * @return pointer to the element in the list
247  */
248  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
249    ClientInformation *temp = head_;
250    while(temp!=0){
251      if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
252        break;
253      temp = temp->next();
254    }
255    // returns 0 if nothing has been found
256    return temp;
257  }
258
259  bool ClientInformation::setSynched(bool s) {
260    if(!this)
261      return false;
262    synched_=s;
263    return true;
264  }
265
266  bool ClientInformation::getSynched() {
267    if(this)
268      return synched_;
269    else
270      return false;
271  }
272
273}
Note: See TracBrowser for help on using the repository browser.