Changeset 777 for code/branches/FICN/src/network/ClientInformation.cc
- Timestamp:
- Dec 31, 2007, 7:40:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/ClientInformation.cc
r636 r777 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 27 28 28 // … … 37 37 // 38 38 // 39 40 #include <iostream> //debug 41 39 42 #include "ClientInformation.h" 40 43 41 namespace network { 42 43 ClientInformation::ClientInformation() 44 namespace network 44 45 { 45 gamestateID_=GAMESTATEID_INITIAL; 46 preve=0; 47 nexte=0; 48 this->head=false; 49 synched_=false; 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 50 233 } 51 52 ClientInformation::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 // else68 // 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 {82 if(preve!=0)83 preve->setNext(this->nexte);84 if(nexte!=0)85 nexte->setPrev(this->preve);86 }87 88 ClientInformation *ClientInformation::next(){89 if(this!=0)90 return this->nexte;91 else92 return 0;93 }94 ClientInformation *ClientInformation::prev(){95 if(this!=0)96 return this->preve;97 else98 return 0;99 }100 101 bool ClientInformation::setPrev(ClientInformation *prev){102 if(!head)103 this->preve = prev;104 else105 return false;106 return true;107 }108 109 bool ClientInformation::setNext(ClientInformation *next){110 this->nexte = next;111 return true;112 }113 114 ClientInformation *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 122 ClientInformation *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 130 void ClientInformation::setID(int clientID){131 clientID_ = clientID;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 ENetPeer *ClientInformation::getPeer(){145 return peer_;146 }147 148 int ClientInformation::getGamestateID(){149 return gamestateID_;150 }151 152 ClientInformation *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 162 bool 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 172 bool 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 clientID188 * This function should only be applied to the head of the list189 * @param clientID id to look for190 * @return pointer to the element in the list or 0 if the search was unsuccessfull191 */192 ClientInformation *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 found200 return temp;201 }202 203 /**204 * This function goes forward through the list and looks for an element with clientID205 * This function should only be applied to the head of the list206 * @param peer peer to look for207 * @return pointer to the element in the list208 */209 ClientInformation *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 found221 return temp;222 }223 224 void ClientInformation::setSynched(bool s){225 synched_=s;226 }227 bool ClientInformation::getSynched(){228 return synched_;229 }230 231 }
Note: See TracChangeset
for help on using the changeset viewer.