Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

synchronising of classid↔classname works now

File size: 5.3 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  synched_=false;
50}
51
52ClientInformation::ClientInformation(bool head)
53{
54  gamestateID_=GAMESTATEID_INITIAL;
55  preve=0;
56  nexte=0;
57  this->head=head;
58  synched_=false;
59}
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
80ClientInformation::~ClientInformation()
81{
82  if(preve!=0)
83    preve->setNext(this->nexte);
84  if(nexte!=0)
85    nexte->setPrev(this->preve);
86}
87
88ClientInformation *ClientInformation::next(){
89  if(this!=0)
90    return this->nexte;
91  else
92    return 0;
93}
94ClientInformation *ClientInformation::prev(){
95  if(this!=0)
96    return this->preve;
97  else
98    return 0;
99}
100
101bool ClientInformation::setPrev(ClientInformation *prev){
102  if(!head)
103    this->preve = prev;
104  else
105    return false;
106  return true;
107}
108
109bool ClientInformation::setNext(ClientInformation *next){
110  this->nexte = next;
111  return true;
112}
113
114ClientInformation *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
122ClientInformation *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}
129
130void ClientInformation::setID(int clientID){
131  clientID_ = clientID;
132}
133void ClientInformation::setPeer(ENetPeer *peer){
134  peer_ = peer;
135}
136
137void ClientInformation::setGamestateID(int id){
138  gamestateID_=id;
139}
140
141int ClientInformation::getID(){
142  return clientID_;
143}
144ENetPeer *ClientInformation::getPeer(){
145  return peer_;
146}
147
148int ClientInformation::getGamestateID(){
149  return gamestateID_;
150}
151
152ClientInformation *ClientInformation::insertBack(ClientInformation *ins){
153  ClientInformation *temp = this;
154  while(temp->next()!=0){
155    temp = temp->next();
156  }
157  temp->setNext(ins);
158  ins->setPrev(temp);
159  return ins;
160}
161
162bool ClientInformation::removeClient(int clientID){
163  ClientInformation *temp = this;
164  while(temp!=0 && temp->getID()!=clientID)
165    temp = temp->next();
166  if(temp==0)
167    return false;
168  delete temp;
169  return true;
170}
171
172bool ClientInformation::removeClient(ENetPeer *peer){
173  ClientInformation *temp = this;
174  while(temp!=0){
175    if(!temp->head)
176      if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
177        break;
178    temp = temp->next();
179  }
180  if(temp==0)
181    return false;
182  delete temp;
183  return true;
184}
185
186/**
187 * This function goes forward through the list and looks for an element with clientID
188 * This function should only be applied to the head of the list
189 * @param clientID id to look for
190 * @return pointer to the element in the list or 0 if the search was unsuccessfull
191 */
192ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards){
193  ClientInformation *temp = this;
194  if (temp->head)
195    temp=temp->next();
196  while(temp!=0 && temp->getID()!=clientID){
197    temp = temp->next();
198  }
199  // returns 0 if nothing has been found
200  return temp;
201}
202
203/**
204 * This function goes forward through the list and looks for an element with clientID
205 * This function should only be applied to the head of the list
206 * @param peer peer to look for
207 * @return pointer to the element in the list
208 */
209ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards){
210  ClientInformation *temp = this;
211  while(temp!=0){
212    if(temp->head){
213      temp = temp->next();
214      continue;
215    }
216    if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
217      break;
218    temp = temp->next();
219  }
220  // returns 0 if nothing has been found
221  return temp;
222}
223
224void ClientInformation::setSynched(bool s){
225  synched_=s;
226}
227bool ClientInformation::getSynched(){
228  return synched_;
229}
230
231}
Note: See TracBrowser for help on using the repository browser.