Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/ClientInformation.cc @ 533

Last change on this file since 533 was 514, checked in by nicolasc, 17 years ago

added copyright notice

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