Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/merge/src/network/ClientInformation.cc @ 1299

Last change on this file since 1299 was 1299, checked in by scheusso, 17 years ago

a huge fix in packetbuffer

File size: 6.4 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 <iostream> //debug
44
45namespace network
46{
47  ClientInformation::ClientInformation() {
48    gamestateID_=GAMESTATEID_INITIAL;
49    preve=0;
50    nexte=0;
51    this->head=false;
52    synched_=false;
53  }
54
55  ClientInformation::ClientInformation(bool head) {
56    gamestateID_=GAMESTATEID_INITIAL;
57    preve=0;
58    nexte=0;
59    this->head=head;
60    synched_=false;
61  }
62
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  // }
80
81  ClientInformation::~ClientInformation() {
82    if(preve!=0)
83      preve->setNext(this->nexte);
84    if(nexte!=0)
85      nexte->setPrev(this->preve);
86  }
87
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  }
100
101  bool ClientInformation::setPrev(ClientInformation *prev) {
102    if(!head)
103      this->preve = prev;
104    else
105      return false;
106    return true;
107  }
108
109  bool ClientInformation::setNext(ClientInformation *next) {
110    this->nexte = next;
111    return true;
112  }
113
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  }
121
122  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
123    if(!this)
124      return NULL;
125    this->prev()->setNext(ins);
126    ins->setPrev(this->preve);
127    this->preve=ins;
128    ins->setNext(this);
129    return ins;
130  }
131
132  void ClientInformation::setID(int clientID){
133    clientID_ = clientID;
134  }
135
136  bool ClientInformation::setPeer(ENetPeer *peer){
137    if(!this)
138      return false;
139    peer_ = peer;
140    return true;
141  }
142
143  bool ClientInformation::setGamestateID(int id){
144    if(!this)
145      return false;
146    gamestateID_=id;
147    return true;
148  }
149
150  int ClientInformation::getID() {
151    if(!this)
152      return CLIENTID_UNKNOWN;
153    else
154      return clientID_;
155  }
156
157  ENetPeer *ClientInformation::getPeer() {
158    if(this)
159      return peer_;
160    else
161      return NULL;
162  }
163
164  int ClientInformation::getGamestateID() {
165    if(this)
166      return gamestateID_;
167    else
168      return -1;
169  }
170
171  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
172    if(!this)
173      return NULL;
174    ClientInformation *temp = this;
175    while(temp->next()!=0){
176      temp = temp->next();
177    }
178    temp->setNext(ins);
179    ins->setPrev(temp);
180    return ins;
181  }
182
183  bool ClientInformation::removeClient(int clientID) {
184    if(!this || clientID==CLIENTID_UNKNOWN)
185      return false;
186    ClientInformation *temp = this;
187    while(temp!=0 && temp->getID()!=clientID)
188      temp = temp->next();
189    if(temp==0)
190      return false;
191    delete temp;
192    return true;
193  }
194
195  bool ClientInformation::removeClient(ENetPeer *peer) {
196    if(!this || !peer)
197      return false;
198    ClientInformation *temp = this;
199    while(temp!=0){
200      if(!temp->head)
201        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
202          break;
203      temp = temp->next();
204    }
205    if(temp==0)
206      return false;
207    delete temp;
208    return true;
209  }
210
211  /**
212  * This function goes forward through the list and looks for an element with clientID
213  * This function should only be applied to the head of the list
214  * @param clientID id to look for
215  * @return pointer to the last element in the list or 0 if the search was unsuccessfull
216  */
217  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
218    ClientInformation *temp = this;
219    if (temp->head)
220      temp=temp->next();
221    while(temp!=0 && temp->getID()!=clientID){
222      temp = temp->next();
223    }
224    // returns 0 if nothing has been found
225    return temp;
226  }
227
228  /**
229  * This function goes forward through the list and looks for an element with clientID
230  * This function should only be applied to the head of the list
231  * @param peer peer to look for
232  * @return pointer to the element in the list
233  */
234  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
235    ClientInformation *temp = this;
236    while(temp!=0){
237      if(temp->head){
238        temp = temp->next();
239        continue;
240      }
241      if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
242        break;
243      temp = temp->next();
244    }
245    // returns 0 if nothing has been found
246    return temp;
247  }
248
249  bool ClientInformation::setSynched(bool s) {
250    if(!this)
251      return false;
252    synched_=s;
253    return true;
254  }
255
256  bool ClientInformation::getSynched() {
257    if(this)
258      return synched_;
259    else
260      return false;
261  }
262
263}
Note: See TracBrowser for help on using the repository browser.