Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 951 was 790, checked in by nicolasc, 17 years ago

merged FICN back into trunk
awaiting release.

File size: 5.6 KB
RevLine 
[514]1/*
[777]2*   ORXONOX - the hottest 3D action shooter ever to exist
3*
4*
5*   License notice:
6*
7*   This program is free software; you can redistribute it and/or
8*   modify it under the terms of the GNU General Public License
9*   as published by the Free Software Foundation; either version 2
10*   of the License, or (at your option) any later version.
11*
12*   This program is distributed in the hope that it will be useful,
13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*   GNU General Public License for more details.
16*
17*   You should have received a copy of the GNU General Public License
18*   along with this program; if not, write to the Free Software
19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*
21*   Author:
22*      ...
23*   Co-authors:
24*      ...
25*
26*/
[514]27
[432]28//
29// C++ Implementation: ClientInformation
30//
[514]31// Description:
[432]32//
33//
34// Author:  <>, (C) 2007
35//
36// Copyright: See COPYING file that comes with this distribution
37//
38//
39
[777]40#include <iostream> //debug
[432]41
[777]42#include "ClientInformation.h"
[436]43
[777]44namespace network
[436]45{
[777]46  ClientInformation::ClientInformation() {
47    gamestateID_=GAMESTATEID_INITIAL;
48    preve=0;
49    nexte=0;
50    this->head=false;
51    synched_=false;
52  }
[432]53
[777]54  ClientInformation::ClientInformation(bool head) {
55    gamestateID_=GAMESTATEID_INITIAL;
56    preve=0;
57    nexte=0;
58    this->head=head;
59    synched_=false;
60  }
[432]61
[777]62  // ClientInformation::ClientInformation(ClientInformation *prev) {
63  //   if(prev->next()!=0){
64  //     this->nexte=prev->next();
65  //     this->nexte->setPrev(this);
66  //   }
67  //   else
68  //     this->nexte = 0;
69  //   prev->setNext(this);
70  //   this->preve = pref;
71  // }
72  //
73  // ClientInformation::ClientInformation(ClientInformation *prev, ClientInformation *next){
74  //   this->nexte = next;
75  //   this->preve = prev;
76  //   this->preve->setNext(this);
77  //   this->nexte->setPrev(this);
78  // }
[432]79
[777]80  ClientInformation::~ClientInformation() {
81    if(preve!=0)
82      preve->setNext(this->nexte);
83    if(nexte!=0)
84      nexte->setPrev(this->preve);
85  }
[432]86
[777]87  ClientInformation *ClientInformation::next() {
88    if(this!=0)
89      return this->nexte;
90    else
91      return 0;
92  }
93  ClientInformation *ClientInformation::prev() {
94    if(this!=0)
95      return this->preve;
96    else
97      return 0;
98  }
[432]99
[777]100  bool ClientInformation::setPrev(ClientInformation *prev) {
101    if(!head)
102      this->preve = prev;
103    else
104      return false;
105    return true;
106  }
[432]107
[777]108  bool ClientInformation::setNext(ClientInformation *next) {
109    this->nexte = next;
110    return true;
111  }
[432]112
[777]113  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
114    this->nexte->setPrev(ins);
115    ins->setNext(this->nexte);
116    ins->setPrev(this);
117    this->nexte = ins;
118    return ins;
119  }
[432]120
[777]121  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
122    this->prev()->setNext(ins);
123    ins->setPrev(this->preve);
124    this->preve=ins;
125    ins->setNext(this);
126    return ins;
127  }
[436]128
[777]129  void ClientInformation::setID(int clientID){
130    clientID_ = clientID;
131  }
[436]132
[777]133  void ClientInformation::setPeer(ENetPeer *peer){
134    peer_ = peer;
135  }
[436]136
[777]137  void ClientInformation::setGamestateID(int id){
138    gamestateID_=id;
139  }
[436]140
[777]141  int ClientInformation::getID() {
142    return clientID_;
[436]143  }
144
[777]145  ENetPeer *ClientInformation::getPeer() {
146    return peer_;
147  }
[436]148
[777]149  int ClientInformation::getGamestateID() {
150    return gamestateID_;
[446]151  }
[436]152
[777]153  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
154    ClientInformation *temp = this;
155    while(temp->next()!=0){
156      temp = temp->next();
157    }
158    temp->setNext(ins);
159    ins->setPrev(temp);
160    return ins;
[446]161  }
[436]162
[777]163  bool ClientInformation::removeClient(int clientID) {
164    ClientInformation *temp = this;
165    while(temp!=0 && temp->getID()!=clientID)
[444]166      temp = temp->next();
[777]167    if(temp==0)
168      return false;
169    delete temp;
170    return true;
171  }
172
173  bool ClientInformation::removeClient(ENetPeer *peer) {
174    ClientInformation *temp = this;
175    while(temp!=0){
176      if(!temp->head)
177        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
178          break;
179      temp = temp->next();
[444]180    }
[777]181    if(temp==0)
182      return false;
183    delete temp;
184    return true;
[444]185  }
[436]186
[777]187  /**
188  * This function goes forward through the list and looks for an element with clientID
189  * This function should only be applied to the head of the list
190  * @param clientID id to look for
191  * @return pointer to the element in the list or 0 if the search was unsuccessfull
192  */
193  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
194    ClientInformation *temp = this;
195    if (temp->head)
196      temp=temp->next();
197    while(temp!=0 && temp->getID()!=clientID){
198      temp = temp->next();
199    }
200    // returns 0 if nothing has been found
201    return temp;
202  }
[636]203
[777]204  /**
205  * This function goes forward through the list and looks for an element with clientID
206  * This function should only be applied to the head of the list
207  * @param peer peer to look for
208  * @return pointer to the element in the list
209  */
210  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
211    ClientInformation *temp = this;
212    while(temp!=0){
213      if(temp->head){
214        temp = temp->next();
215        continue;
216      }
217      if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
218        break;
219      temp = temp->next();
220    }
221    // returns 0 if nothing has been found
222    return temp;
223  }
224
225  void ClientInformation::setSynched(bool s) {
226    synched_=s;
227  }
228
229  bool ClientInformation::getSynched() {
230    return synched_;
231  }
232
[636]233}
Note: See TracBrowser for help on using the repository browser.