Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/ClientInformation.cc @ 1194

Last change on this file since 1194 was 1062, checked in by rgrieder, 17 years ago
  • changed header file inclusion order
File size: 5.7 KB
RevLine 
[1056]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 */
[514]28
[432]29//
30// C++ Implementation: ClientInformation
31//
[514]32// Description:
[432]33//
34//
35// Author:  <>, (C) 2007
36//
37// Copyright: See COPYING file that comes with this distribution
38//
39//
40
[1062]41#include "ClientInformation.h"
42
[777]43#include <iostream> //debug
[432]44
[777]45namespace network
[436]46{
[777]47  ClientInformation::ClientInformation() {
48    gamestateID_=GAMESTATEID_INITIAL;
49    preve=0;
50    nexte=0;
51    this->head=false;
52    synched_=false;
53  }
[432]54
[777]55  ClientInformation::ClientInformation(bool head) {
56    gamestateID_=GAMESTATEID_INITIAL;
57    preve=0;
58    nexte=0;
59    this->head=head;
60    synched_=false;
61  }
[432]62
[777]63  // ClientInformation::ClientInformation(ClientInformation *prev) {
64  //   if(prev->next()!=0){
65  //     this->nexte=prev->next();
66  //     this->nexte->setPrev(this);
67  //   }
68  //   else
69  //     this->nexte = 0;
70  //   prev->setNext(this);
71  //   this->preve = pref;
72  // }
73  //
74  // ClientInformation::ClientInformation(ClientInformation *prev, ClientInformation *next){
75  //   this->nexte = next;
76  //   this->preve = prev;
77  //   this->preve->setNext(this);
78  //   this->nexte->setPrev(this);
79  // }
[432]80
[777]81  ClientInformation::~ClientInformation() {
82    if(preve!=0)
83      preve->setNext(this->nexte);
84    if(nexte!=0)
85      nexte->setPrev(this->preve);
86  }
[432]87
[777]88  ClientInformation *ClientInformation::next() {
89    if(this!=0)
90      return this->nexte;
91    else
92      return 0;
93  }
94  ClientInformation *ClientInformation::prev() {
95    if(this!=0)
96      return this->preve;
97    else
98      return 0;
99  }
[432]100
[777]101  bool ClientInformation::setPrev(ClientInformation *prev) {
102    if(!head)
103      this->preve = prev;
104    else
105      return false;
106    return true;
107  }
[432]108
[777]109  bool ClientInformation::setNext(ClientInformation *next) {
110    this->nexte = next;
111    return true;
112  }
[432]113
[777]114  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
115    this->nexte->setPrev(ins);
116    ins->setNext(this->nexte);
117    ins->setPrev(this);
118    this->nexte = ins;
119    return ins;
120  }
[432]121
[777]122  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
123    this->prev()->setNext(ins);
124    ins->setPrev(this->preve);
125    this->preve=ins;
126    ins->setNext(this);
127    return ins;
128  }
[436]129
[777]130  void ClientInformation::setID(int clientID){
131    clientID_ = clientID;
132  }
[436]133
[777]134  void ClientInformation::setPeer(ENetPeer *peer){
135    peer_ = peer;
136  }
[436]137
[777]138  void ClientInformation::setGamestateID(int id){
139    gamestateID_=id;
140  }
[436]141
[777]142  int ClientInformation::getID() {
143    return clientID_;
[436]144  }
145
[777]146  ENetPeer *ClientInformation::getPeer() {
147    return peer_;
148  }
[436]149
[777]150  int ClientInformation::getGamestateID() {
151    return gamestateID_;
[446]152  }
[436]153
[777]154  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
155    ClientInformation *temp = this;
156    while(temp->next()!=0){
157      temp = temp->next();
158    }
159    temp->setNext(ins);
160    ins->setPrev(temp);
161    return ins;
[446]162  }
[436]163
[777]164  bool ClientInformation::removeClient(int clientID) {
165    ClientInformation *temp = this;
166    while(temp!=0 && temp->getID()!=clientID)
[444]167      temp = temp->next();
[777]168    if(temp==0)
169      return false;
170    delete temp;
171    return true;
172  }
173
174  bool ClientInformation::removeClient(ENetPeer *peer) {
175    ClientInformation *temp = this;
176    while(temp!=0){
177      if(!temp->head)
178        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
179          break;
180      temp = temp->next();
[444]181    }
[777]182    if(temp==0)
183      return false;
184    delete temp;
185    return true;
[444]186  }
[436]187
[777]188  /**
189  * This function goes forward through the list and looks for an element with clientID
190  * This function should only be applied to the head of the list
191  * @param clientID id to look for
192  * @return pointer to the element in the list or 0 if the search was unsuccessfull
193  */
194  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
195    ClientInformation *temp = this;
196    if (temp->head)
197      temp=temp->next();
198    while(temp!=0 && temp->getID()!=clientID){
199      temp = temp->next();
200    }
201    // returns 0 if nothing has been found
202    return temp;
203  }
[636]204
[777]205  /**
206  * This function goes forward through the list and looks for an element with clientID
207  * This function should only be applied to the head of the list
208  * @param peer peer to look for
209  * @return pointer to the element in the list
210  */
211  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
212    ClientInformation *temp = this;
213    while(temp!=0){
214      if(temp->head){
215        temp = temp->next();
216        continue;
217      }
218      if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
219        break;
220      temp = temp->next();
221    }
222    // returns 0 if nothing has been found
223    return temp;
224  }
225
226  void ClientInformation::setSynched(bool s) {
227    synched_=s;
228  }
229
230  bool ClientInformation::getSynched() {
231    return synched_;
232  }
233
[636]234}
Note: See TracBrowser for help on using the repository browser.