Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged FICN back into trunk
awaiting release.

File size: 5.6 KB
Line 
1/*
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*/
27
28//
29// C++ Implementation: ClientInformation
30//
31// Description:
32//
33//
34// Author:  <>, (C) 2007
35//
36// Copyright: See COPYING file that comes with this distribution
37//
38//
39
40#include <iostream> //debug
41
42#include "ClientInformation.h"
43
44namespace network
45{
46  ClientInformation::ClientInformation() {
47    gamestateID_=GAMESTATEID_INITIAL;
48    preve=0;
49    nexte=0;
50    this->head=false;
51    synched_=false;
52  }
53
54  ClientInformation::ClientInformation(bool head) {
55    gamestateID_=GAMESTATEID_INITIAL;
56    preve=0;
57    nexte=0;
58    this->head=head;
59    synched_=false;
60  }
61
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  // }
79
80  ClientInformation::~ClientInformation() {
81    if(preve!=0)
82      preve->setNext(this->nexte);
83    if(nexte!=0)
84      nexte->setPrev(this->preve);
85  }
86
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  }
99
100  bool ClientInformation::setPrev(ClientInformation *prev) {
101    if(!head)
102      this->preve = prev;
103    else
104      return false;
105    return true;
106  }
107
108  bool ClientInformation::setNext(ClientInformation *next) {
109    this->nexte = next;
110    return true;
111  }
112
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  }
120
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  }
128
129  void ClientInformation::setID(int clientID){
130    clientID_ = clientID;
131  }
132
133  void ClientInformation::setPeer(ENetPeer *peer){
134    peer_ = peer;
135  }
136
137  void ClientInformation::setGamestateID(int id){
138    gamestateID_=id;
139  }
140
141  int ClientInformation::getID() {
142    return clientID_;
143  }
144
145  ENetPeer *ClientInformation::getPeer() {
146    return peer_;
147  }
148
149  int ClientInformation::getGamestateID() {
150    return gamestateID_;
151  }
152
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;
161  }
162
163  bool ClientInformation::removeClient(int clientID) {
164    ClientInformation *temp = this;
165    while(temp!=0 && temp->getID()!=clientID)
166      temp = temp->next();
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();
180    }
181    if(temp==0)
182      return false;
183    delete temp;
184    return true;
185  }
186
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  }
203
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
233}
Note: See TracBrowser for help on using the repository browser.