Changeset 1360 for code/trunk/src/network/ClientInformation.cc
- Timestamp:
- May 22, 2008, 2:02:06 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/ClientInformation.cc
r1293 r1360 45 45 namespace network 46 46 { 47 boost::recursive_mutex ClientInformation::mutex_; 48 47 49 ClientInformation::ClientInformation() { 48 50 gamestateID_=GAMESTATEID_INITIAL; 49 51 preve=0; 50 52 nexte=0; 51 this->head=false; 53 partialGamestateID_=GAMESTATEID_INITIAL-1; 54 this->head_=false; 52 55 synched_=false; 53 56 } … … 57 60 preve=0; 58 61 nexte=0; 59 this->head=head; 62 partialGamestateID_=GAMESTATEID_INITIAL-1; 63 this->head_=head; 60 64 synched_=false; 61 65 } … … 80 84 81 85 ClientInformation::~ClientInformation() { 86 boost::recursive_mutex::scoped_lock lock(mutex_); 82 87 if(preve!=0) 83 88 preve->setNext(this->nexte); … … 87 92 88 93 ClientInformation *ClientInformation::next() { 94 boost::recursive_mutex::scoped_lock lock(mutex_); 89 95 if(this!=0) 90 96 return this->nexte; … … 93 99 } 94 100 ClientInformation *ClientInformation::prev() { 101 boost::recursive_mutex::scoped_lock lock(mutex_); 95 102 if(this!=0) 96 103 return this->preve; … … 100 107 101 108 bool ClientInformation::setPrev(ClientInformation *prev) { 102 if(!head) 109 boost::recursive_mutex::scoped_lock lock(mutex_); 110 if(!head_) 103 111 this->preve = prev; 104 112 else … … 108 116 109 117 bool ClientInformation::setNext(ClientInformation *next) { 118 boost::recursive_mutex::scoped_lock lock(mutex_); 110 119 this->nexte = next; 111 120 return true; … … 113 122 114 123 ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) { 124 boost::recursive_mutex::scoped_lock lock(mutex_); 115 125 this->nexte->setPrev(ins); 116 126 ins->setNext(this->nexte); … … 121 131 122 132 ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){ 133 boost::recursive_mutex::scoped_lock lock(mutex_); 134 if(!this) 135 return NULL; 123 136 this->prev()->setNext(ins); 124 137 ins->setPrev(this->preve); … … 129 142 130 143 void ClientInformation::setID(int clientID){ 144 boost::recursive_mutex::scoped_lock lock(mutex_); 131 145 clientID_ = clientID; 132 146 } 133 147 134 void ClientInformation::setPeer(ENetPeer *peer){ 148 bool ClientInformation::setPeer(ENetPeer *peer){ 149 boost::recursive_mutex::scoped_lock lock(mutex_); 150 if(!this) 151 return false; 135 152 peer_ = peer; 136 } 137 138 void ClientInformation::setGamestateID(int id){ 153 return true; 154 } 155 156 bool ClientInformation::setGamestateID(int id){ 157 boost::recursive_mutex::scoped_lock lock(mutex_); 158 if(!this) 159 return false; 139 160 gamestateID_=id; 161 return true; 162 } 163 164 bool ClientInformation::setPartialGamestateID(int id){ 165 boost::recursive_mutex::scoped_lock lock(mutex_); 166 if(!this) 167 return false; 168 partialGamestateID_=id; 169 return true; 140 170 } 141 171 142 172 int ClientInformation::getID() { 143 return clientID_; 173 boost::recursive_mutex::scoped_lock lock(mutex_); 174 if(!this) 175 return CLIENTID_UNKNOWN; 176 else 177 return clientID_; 144 178 } 145 179 146 180 ENetPeer *ClientInformation::getPeer() { 147 return peer_; 181 boost::recursive_mutex::scoped_lock lock(mutex_); 182 if(this) 183 return peer_; 184 else 185 return NULL; 186 } 187 188 bool ClientInformation::getHead(){ 189 boost::recursive_mutex::scoped_lock lock(mutex_); 190 return head_; 191 } 192 193 void ClientInformation::setHead(bool h){ 194 boost::recursive_mutex::scoped_lock lock(mutex_); 195 head_=h; 196 } 197 198 int ClientInformation::getFailures(){ 199 boost::recursive_mutex::scoped_lock lock(mutex_); 200 return failures_; 201 } 202 void ClientInformation::addFailure(){ 203 boost::recursive_mutex::scoped_lock lock(mutex_); 204 failures_++; 205 } 206 void ClientInformation::resetFailures(){ 207 boost::recursive_mutex::scoped_lock lock(mutex_); 208 failures_=0; 148 209 } 149 210 150 211 int ClientInformation::getGamestateID() { 151 return gamestateID_; 212 boost::recursive_mutex::scoped_lock lock(mutex_); 213 if(this) 214 return gamestateID_; 215 else 216 return -1; 217 } 218 219 int ClientInformation::getPartialGamestateID() { 220 boost::recursive_mutex::scoped_lock lock(mutex_); 221 if(this) 222 return partialGamestateID_; 223 else 224 return -1; 152 225 } 153 226 154 227 ClientInformation *ClientInformation::insertBack(ClientInformation *ins) { 228 boost::recursive_mutex::scoped_lock lock(mutex_); 229 if(!this) 230 return NULL; 155 231 ClientInformation *temp = this; 156 232 while(temp->next()!=0){ … … 163 239 164 240 bool ClientInformation::removeClient(int clientID) { 241 boost::recursive_mutex::scoped_lock lock(mutex_); 242 if(!this || clientID==CLIENTID_UNKNOWN) 243 return false; 165 244 ClientInformation *temp = this; 166 245 while(temp!=0 && temp->getID()!=clientID) … … 173 252 174 253 bool ClientInformation::removeClient(ENetPeer *peer) { 254 boost::recursive_mutex::scoped_lock lock(mutex_); 255 if(!this || !peer) 256 return false; 175 257 ClientInformation *temp = this; 176 258 while(temp!=0){ 177 if(!temp->head )259 if(!temp->head_) 178 260 if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port) 179 261 break; … … 193 275 */ 194 276 ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) { 195 ClientInformation *temp = this; 196 if (temp->head) 277 boost::recursive_mutex::scoped_lock lock(mutex_); 278 ClientInformation *temp = this; 279 if (temp->head_) 197 280 temp=temp->next(); 198 //bugfix: temp to temp->next(), get last elem if not found, not segflt 199 while(temp->next()!=0 && temp->getID()!=clientID){ 281 while(temp!=0 && temp->getID()!=clientID){ 200 282 temp = temp->next(); 201 283 } … … 211 293 */ 212 294 ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) { 213 ClientInformation *temp = this;214 //bugfix: temp to temp->next(), get last elem if not found, not segflt215 while(temp ->next()!=0){216 if(temp->head ){295 boost::recursive_mutex::scoped_lock lock(mutex_); 296 ClientInformation *temp = this; 297 while(temp!=0){ 298 if(temp->head_){ 217 299 temp = temp->next(); 218 300 continue; … … 226 308 } 227 309 228 void ClientInformation::setSynched(bool s) { 310 bool ClientInformation::setSynched(bool s) { 311 boost::recursive_mutex::scoped_lock lock(mutex_); 312 if(!this) 313 return false; 229 314 synched_=s; 315 return true; 230 316 } 231 317 232 318 bool ClientInformation::getSynched() { 233 return synched_; 319 boost::recursive_mutex::scoped_lock lock(mutex_); 320 if(this) 321 return synched_; 322 else 323 return false; 234 324 } 235 325
Note: See TracChangeset
for help on using the changeset viewer.