Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

still problems with chatserver/client

File size: 4.1 KB
Line 
1//
2// C++ Implementation: ClientInformation
3//
4// Description:
5//
6//
7// Author:  <>, (C) 2007
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include "ClientInformation.h"
13
14namespace network {
15
16ClientInformation::ClientInformation()
17{
18  gamestateID_=GAMESTATEID_INITIAL;
19  preve=0;
20  nexte=0;
21  this->head=false;
22}
23
24ClientInformation::ClientInformation(bool head)
25{
26  gamestateID_=GAMESTATEID_INITIAL;
27  preve=0;
28  nexte=0;
29  this->head=head;
30}
31//
32
33// ClientInformation::ClientInformation(ClientInformation *prev){
34//   if(prev->next()!=0){
35//     this->nexte=prev->next();
36//     this->nexte->setPrev(this);
37//   }
38//   else
39//     this->nexte = 0;
40//   prev->setNext(this);
41//   this->preve = pref;
42// }
43//
44// ClientInformation::ClientInformation(ClientInformation *prev, ClientInformation *next){
45//   this->nexte = next;
46//   this->preve = prev;
47//   this->preve->setNext(this);
48//   this->nexte->setPrev(this);
49// }
50
51ClientInformation::~ClientInformation()
52{
53  if(preve!=0)
54    preve->setNext(this->nexte);
55  if(nexte!=0)
56    nexte->setPrev(this->preve);
57}
58
59ClientInformation *ClientInformation::next(){
60  if(this!=0)
61    return this->nexte;
62  else
63    return 0;
64}
65ClientInformation *ClientInformation::prev(){
66  if(this!=0)
67    return this->preve;
68  else
69    return 0;
70}
71
72bool ClientInformation::setPrev(ClientInformation *prev){
73  if(!head)
74    this->preve = prev;
75  else
76    return false;
77  return true;
78}
79
80bool ClientInformation::setNext(ClientInformation *next){
81  this->nexte = next;
82  return true;
83}
84
85ClientInformation *ClientInformation::insertAfter(ClientInformation *ins){
86  this->nexte->setPrev(ins);
87  ins->setNext(this->nexte);
88  ins->setPrev(this);
89  this->nexte = ins;
90  return ins;
91}
92
93ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
94  this->prev()->setNext(ins);
95  ins->setPrev(this->preve);
96  this->preve=ins;
97  ins->setNext(this);
98  return ins;
99}
100
101void ClientInformation::setID(int clientID){
102  clientID_ = clientID;
103}
104void ClientInformation::setPeer(ENetPeer *peer){
105  peer_ = peer;
106}
107
108void ClientInformation::setGamestateID(int id){
109  gamestateID_=id;
110}
111
112int ClientInformation::getID(){
113  return clientID_;
114}
115ENetPeer *ClientInformation::getPeer(){
116  return peer_;
117}
118
119int ClientInformation::getGamestateID(){
120  return gamestateID_;
121}
122
123ClientInformation *ClientInformation::insertBack(ClientInformation *ins){
124  ClientInformation *temp = this;
125  while(temp->next()!=0){
126    temp = temp->next();
127  }
128  temp->setNext(ins);
129  ins->setPrev(temp);
130  return ins;
131}
132
133bool ClientInformation::removeClient(int clientID){
134  ClientInformation *temp = this;
135  while(temp!=0 && temp->getID()!=clientID)
136    temp = temp->next();
137  if(temp==0)
138    return false;
139  delete temp;
140  return true;
141}
142
143bool ClientInformation::removeClient(ENetPeer *peer){
144  ClientInformation *temp = this;
145  while(temp!=0 && (temp->getPeer()->address.host!=peer->address.host || temp->getPeer()->address.port!=peer->address.port))
146    temp = temp->next();
147  if(temp==0)
148    return false;
149  delete temp;
150  return true;
151}
152
153/**
154 * This function goes forward through the list and looks for an element with clientID
155 * This function should only be applied to the head of the list
156 * @param clientID id to look for
157 * @return pointer to the element in the list or 0 if the search was unsuccessfull
158 */
159ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards){
160  ClientInformation *temp = this;
161  while(temp!=0 && temp->getID()!=clientID)
162    temp = temp->next();
163  // returns 0 if nothing has been found
164  return temp;
165}
166
167/**
168 * This function goes forward through the list and looks for an element with clientID
169 * This function should only be applied to the head of the list
170 * @param peer peer to look for
171 * @return pointer to the element in the list
172 */
173ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards){
174  ClientInformation *temp = this;
175  while(temp!=0 && (temp->getPeer()->address.host!=address->host || temp->getPeer()->address.port != address->port))
176    temp = temp->next();
177  // returns 0 if nothing has been found
178  return temp;
179}
180
181}
Note: See TracBrowser for help on using the repository browser.