Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 24, 2010, 8:33:58 PM (14 years ago)
Author:
smerkli
Message:

Further implementation, constructing a testing environment soon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/masterserver/src/modules/masterserver/PeerList.cpp

    r7574 r7580  
    2828
    2929#include "PeerList.h"
     30#include <cstdio>
    3031
    3132namespace orxonox
     
    3637  int
    3738  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    }
    3944
    40 
     45    /* if all went well, push to back of list */
     46    this->peerlist.push_back( toadd );
    4147    return 0;
    4248  }
    4349
    44   int
     50  bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
     51  { return ( (addr1.host == addr2.host) && (addr1.port == addr2.port) ); }
     52
     53  bool
    4554  PeerList::remPeerByAddr( ENetAddress addr )
    46   {
     55  { /* get an iterator */
     56    list<packet::ENetPeer *>::iterator i;
    4757
     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      }
    4865
    49 
    50     return 0;
     66    /* not found */
     67    return false;
    5168  }
    5269
    5370  ENetPeer *
    5471  PeerList::findPeerByAddr( ENetAddress addr )
    55   {
     72  { /* get an iterator */
     73    list<packet::ENetPeer *>::iterator i;
    5674
     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;
    5780
    58 
     81    /* not found */
    5982    return NULL;
    6083  }
Note: See TracChangeset for help on using the changeset viewer.