- Timestamp:
- Oct 24, 2010, 8:33:58 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/masterserver/src/modules/masterserver/PeerList.cpp
r7574 r7580 28 28 29 29 #include "PeerList.h" 30 #include <cstdio> 30 31 31 32 namespace orxonox … … 36 37 int 37 38 PeerList::addPeer( ENetPeer *toadd ) 38 { 39 { /* error correction */ 40 if( toadd == NULL ) 41 { fprintf( stderr, "PeerList::addPeer: empty peer given.\n" ); 42 return -1; 43 } 39 44 40 45 /* if all went well, push to back of list */ 46 this->peerlist.push_back( toadd ); 41 47 return 0; 42 48 } 43 49 44 int 50 bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 ) 51 { return ( (addr1.host == addr2.host) && (addr1.port == addr2.port) ); } 52 53 bool 45 54 PeerList::remPeerByAddr( ENetAddress addr ) 46 { 55 { /* get an iterator */ 56 list<packet::ENetPeer *>::iterator i; 47 57 58 /* loop through list elements */ 59 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 60 if( sub_compAddr((*i)->address, addr ) ) 61 { /* found this name, remove and quit */ 62 this->peerlist.remove( i ); 63 return true; 64 } 48 65 49 50 return 0;66 /* not found */ 67 return false; 51 68 } 52 69 53 70 ENetPeer * 54 71 PeerList::findPeerByAddr( ENetAddress addr ) 55 { 72 { /* get an iterator */ 73 list<packet::ENetPeer *>::iterator i; 56 74 75 /* loop through list elements */ 76 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 77 if( sub_compAddr((*i)->address, addr ) ) 78 /* found this name, remove and quit */ 79 return i; 57 80 58 81 /* not found */ 59 82 return NULL; 60 83 }
Note: See TracChangeset
for help on using the changeset viewer.