Changeset 9656 in orxonox.OLD for trunk/src/lib/network/monitor/network_node.cc
- Timestamp:
- Aug 4, 2006, 11:01:28 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/monitor/network_node.cc
r9494 r9656 18 18 #include "debug.h" 19 19 20 21 20 /** 22 21 * constructor … … 39 38 * adds a client 40 39 */ 41 void NetworkNode::addClient( PeerInfo* node)40 void NetworkNode::addClient(NetworkNode* node) 42 41 { 43 42 this->clientList.push_back(node); … … 49 48 * adds a proxy server 50 49 */ 51 void NetworkNode::addActiveProxyServer( PeerInfo* node)50 void NetworkNode::addActiveProxyServer(NetworkNode* node) 52 51 { 53 52 this->activeProxyServerList.push_back(node); … … 58 57 * adds a proxy server 59 58 */ 60 void NetworkNode::addPassiveProxyServer( PeerInfo* node)59 void NetworkNode::addPassiveProxyServer(NetworkNode* node) 61 60 { 62 61 this->passiveProxyServerList.push_back(node); … … 66 65 * adds a master server 67 66 */ 68 void NetworkNode::addMasterServer( PeerInfo* node)67 void NetworkNode::addMasterServer(NetworkNode* node) 69 68 { 70 69 this->masterServerList.push_back(node); … … 75 74 * removes a client 76 75 */ 77 void NetworkNode::removeClient( PeerInfo* node)78 { 79 std::list< PeerInfo*>::iterator it = this->clientList.begin();76 void NetworkNode::removeClient(NetworkNode* node) 77 { 78 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 80 79 for(; it != this->clientList.end(); it++) 81 80 { … … 94 93 * removes a proxy server 95 94 */ 96 void NetworkNode::removeActiveProxyServer( PeerInfo* node)97 { 98 std::list< PeerInfo*>::iterator it = this->activeProxyServerList.begin();95 void NetworkNode::removeActiveProxyServer(NetworkNode* node) 96 { 97 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 99 98 for(; it != this->activeProxyServerList.end(); it++) 100 99 { … … 113 112 * removes a proxy server 114 113 */ 115 void NetworkNode::removePassiveProxyServer( PeerInfo* node)116 { 117 std::list< PeerInfo*>::iterator it = this->passiveProxyServerList.begin();114 void NetworkNode::removePassiveProxyServer(NetworkNode* node) 115 { 116 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 118 117 for(; it != this->passiveProxyServerList.end(); it++) 119 118 { … … 131 130 * removes a master server 132 131 */ 133 void NetworkNode::removeMasterServer( PeerInfo* node)134 { 135 std::list< PeerInfo*>::iterator it = this->masterServerList.begin();132 void NetworkNode::removeMasterServer(NetworkNode* node) 133 { 134 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 136 135 for(; it != this->masterServerList.end(); it++) 137 136 { … … 145 144 146 145 PRINTF(2)("Could not remove client from the list, very strange..."); 146 } 147 148 149 150 151 /** 152 * removes a client 153 */ 154 void NetworkNode::removeClient(int userId) 155 { 156 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 157 for(; it != this->clientList.end(); it++) 158 { 159 if( (*it)->getPeerInfo()->userId == userId) 160 { 161 this->clientList.erase(it); 162 this->playerNumber--; 163 return; 164 } 165 } 166 167 PRINTF(2)("Could not remove client from the list, very strange..."); 168 } 169 170 /** 171 * removes a proxy server 172 */ 173 void NetworkNode::removeActiveProxyServer(int userId) 174 { 175 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 176 for(; it != this->activeProxyServerList.end(); it++) 177 { 178 if( (*it)->getPeerInfo()->userId == userId) 179 { 180 this->activeProxyServerList.erase(it); 181 this->playerNumber--; 182 return; 183 } 184 } 185 186 PRINTF(2)("Could not remove proxy server from the list, very strange..."); 187 } 188 189 /** 190 * removes a proxy server 191 */ 192 void NetworkNode::removePassiveProxyServer(int userId) 193 { 194 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 195 for(; it != this->passiveProxyServerList.end(); it++) 196 { 197 if( (*it)->getPeerInfo()->userId == userId) 198 { 199 this->passiveProxyServerList.erase(it); 200 return; 201 } 202 } 203 204 PRINTF(2)("Could not remove proxy server from the list, very strange..."); 205 } 206 207 /** 208 * removes a master server 209 */ 210 void NetworkNode::removeMasterServer(int userId) 211 { 212 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 213 for(; it != this->masterServerList.end(); it++) 214 { 215 if( (*it)->getPeerInfo()->userId == userId) 216 { 217 this->masterServerList.erase(it); 218 this->playerNumber--; 219 return; 220 } 221 } 222 223 PRINTF(2)("Could not remove client from the list, very strange..."); 224 } 225 226 227 228 229 230 /** 231 * gets the peer info by user id 232 * @param userId the user id of the node to look up 233 * @return the peer info of this node NULL if nothing found 234 */ 235 PeerInfo* NetworkNode::getPeerByUserId( int userId) 236 { 237 // look through the master server lists 238 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 239 for( ;it != this->masterServerList.end(); it++) 240 { 241 if( (*it)->getPeerInfo()->userId == userId) 242 return (*it)->getPeerInfo(); 243 } 244 245 // look through the active proxy server list 246 it = this->activeProxyServerList.begin(); 247 for( ; it != this->activeProxyServerList.end(); it++) 248 { 249 if( (*it)->getPeerInfo()->userId == userId) 250 return (*it)->getPeerInfo(); 251 } 252 253 // look through the passive server list 254 it = this->passiveProxyServerList.begin(); 255 for( ; it != this->passiveProxyServerList.end(); it++) 256 { 257 if( (*it)->getPeerInfo()->userId == userId) 258 return (*it)->getPeerInfo(); 259 } 260 261 // look through the client list 262 it = this->clientList.begin(); 263 for( ; it != this->clientList.end(); it++) 264 { 265 if( (*it)->getPeerInfo()->userId == userId) 266 return (*it)->getPeerInfo(); 267 } 268 269 return NULL; 147 270 } 148 271 … … 154 277 PeerInfo* NetworkNode::getClient(int index) const 155 278 { 156 if( this->clientList.size() < index)279 if( (int)this->clientList.size() < index) 157 280 return NULL; 158 281 159 std::list< PeerInfo*>::const_iterator it = this->clientList.begin();282 std::list<NetworkNode*>::const_iterator it = this->clientList.begin(); 160 283 for(int i = 0; it != this->clientList.end(); it++, i++) 161 284 { 162 285 if( i == index) 163 return (*it) ;286 return (*it)->getPeerInfo(); 164 287 } 165 288 … … 174 297 PeerInfo* NetworkNode::getActiveProxyServer(int index) const 175 298 { 176 if( this->activeProxyServerList.size() < index)299 if( (int)this->activeProxyServerList.size() < index) 177 300 return NULL; 178 301 179 std::list< PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();302 std::list<NetworkNode*>::const_iterator it = this->activeProxyServerList.begin(); 180 303 for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) 181 304 { 182 305 if( i == index) 183 return (*it) ;306 return (*it)->getPeerInfo(); 184 307 } 185 308 … … 194 317 PeerInfo* NetworkNode::getPassiveProxyServer(int index) const 195 318 { 196 if( this->passiveProxyServerList.size() < index)319 if( (int)this->passiveProxyServerList.size() < index) 197 320 return NULL; 198 321 199 std::list< PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();322 std::list<NetworkNode*>::const_iterator it = this->passiveProxyServerList.begin(); 200 323 for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) 201 324 { 202 325 if( i == index) 203 return (*it) ;326 return (*it)->getPeerInfo(); 204 327 } 205 328 … … 214 337 PeerInfo* NetworkNode::getMasterServer(int index) const 215 338 { 216 if( this->masterServerList.size() < index)339 if( (int)this->masterServerList.size() < index) 217 340 return NULL; 218 341 219 std::list< PeerInfo*>::const_iterator it = this->masterServerList.begin();342 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 220 343 for(int i = 0; it != this->masterServerList.end(); it++, i++) 221 344 { 222 345 if( i == index) 223 return (*it); 346 return (*it)->getPeerInfo(); 347 } 348 349 return NULL; 350 } 351 352 353 354 /** 355 * searches for a given NetworkNode 356 * @param userId of the searched node 357 * @returns the PeerInfo of the userId peer 358 */ 359 NetworkNode* NetworkNode::getNodeByUserId( int userId) 360 { 361 if( this->peerInfo->userId == userId) 362 return this; 363 364 365 NetworkNode* node = NULL; 366 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 367 368 for(; it != this->masterServerList.end(); it++) 369 { 370 node = (*it)->getNodeByUserId(userId); 371 if( node != NULL) 372 return node; 373 } 374 375 it = this->activeProxyServerList.begin(); 376 for(; it != this->activeProxyServerList.end(); it++) 377 { 378 node = (*it)->getNodeByUserId(userId); 379 if( node != NULL) 380 return node; 381 } 382 383 it = this->passiveProxyServerList.begin(); 384 for(; it != this->passiveProxyServerList.end(); it++) 385 { 386 node = (*it)->getNodeByUserId(userId); 387 if( node != NULL) 388 return node; 389 } 390 391 it = this->clientList.begin(); 392 for(; it != this->clientList.end(); it++) 393 { 394 node = (*it)->getNodeByUserId(userId); 395 if( node != NULL) 396 return node; 224 397 } 225 398 … … 234 407 void NetworkNode::debug(int depth) const 235 408 { 236 PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); 237 238 PRINT(0)(" master servers: %i\n", this->masterServerList.size()); 239 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 240 for(; it != this->masterServerList.end(); it++) 241 { 242 IP* ip = &(*it)->ip; 243 PRINT(0)(" - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 244 } 245 246 PRINT(0)(" proxy servers active: %i\n", this->activeProxyServerList.size()); 247 it = this->activeProxyServerList.begin(); 248 for(; it != this->activeProxyServerList.end(); it++) 249 { 250 IP* ip = &(*it)->ip; 251 PRINT(0)(" - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 252 } 253 254 PRINT(0)(" proxy servers passive: %i\n", this->passiveProxyServerList.size()); 255 it = this->passiveProxyServerList.begin(); 256 for(; it != this->passiveProxyServerList.end(); it++) 257 { 258 IP* ip = &(*it)->ip; 259 PRINT(0)(" - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 260 } 261 262 PRINT(0)(" clients: %i\n", this->clientList.size()); 263 it = this->clientList.begin(); 264 for(; it != this->clientList.end(); it++) 265 { 266 IP* ip = &(*it)->ip; 267 PRINT(0)(" - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 268 } 269 } 270 409 char indent[depth +1]; 410 for( int i = 0; i < depth; i++) { indent[i] = ' '; } 411 indent[depth] = '\0'; 412 413 PRINT(0)("%s + %s, with id %i and ip: %s\n", indent, this->peerInfo->getNodeTypeString().c_str(), this->peerInfo->userId, this->peerInfo->ip.ipString().c_str()); 414 415 416 417 std::list<NetworkNode*>::const_iterator it; 418 if( !this->masterServerList.empty()) 419 { 420 it = this->masterServerList.begin(); 421 422 for(; it != this->masterServerList.end(); it++) 423 { 424 (*it)->debug(depth+1); 425 } 426 } 427 428 if( !this->activeProxyServerList.empty()) 429 { 430 it = this->activeProxyServerList.begin(); 431 432 for(; it != this->activeProxyServerList.end(); it++) 433 { 434 (*it)->debug(depth+1); 435 } 436 } 437 438 439 if( !this->passiveProxyServerList.empty()) 440 { 441 it = this->passiveProxyServerList.begin(); 442 443 for(; it != this->passiveProxyServerList.end(); it++) 444 { 445 (*it)->debug(depth+1); 446 } 447 } 448 449 if( !this->clientList.empty()) 450 { 451 it = this->clientList.begin(); 452 453 for(; it != this->clientList.end(); it++) 454 { 455 (*it)->debug(depth+1); 456 } 457 } 458 } 459
Note: See TracChangeset
for help on using the changeset viewer.