Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2011, 4:18:08 PM (14 years ago)
Author:
smerkli
Message:

done for today

Location:
code/branches/masterserver2/src/libraries/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/masterserver2/src/libraries/network/MasterServer.cc

    r8163 r8202  
    5252  {
    5353    /* get an iterator */
    54     std::list<packet::ServerInformation>::iterator i;
     54    std::list<ServerListElem>::iterator i;
    5555
    5656    /* packet holder */
     
    6363      /* send this particular server */
    6464      /* build reply string */
    65       char *tosend = (char *)calloc( (*i).getServerIP().length()
     65      char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()
    6666          + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
    6767      if( !tosend )
     
    7070      }
    7171      sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM,
    72           (*i).getServerIP().c_str() );
     72          (*i).ServerInfo.getServerIP().c_str() );
    7373
    7474      /* create packet from it */
     
    104104   */
    105105  void
    106   MasterServer::helper_pingServers( void )
     106  MasterServer::helper_cleanupServers()
    107107  {
    108108    /* get an iterator */
    109     std::list<packet::ServerInformation>::iterator i;
     109    std::list<ServerListElem>::iterator i;
     110
    110111    /* loop through list elements */
    111112    for( i = mainlist.serverlist.begin(); i
    112113        != mainlist.serverlist.end(); ++i )
    113114    {
    114       /* to be implemented, waiting for Oli to reply to my email - sandro */
    115    
     115      if( mainlist.serverlist.size() != 0 && (*i).peer &&
     116         ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
     117          (*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
     118      { mainlist.delServerByName( (*i).ServerInfo.getServerName() );
     119        COUT(2) << "someone timed out.\n";
     120      }
    116121    }
    117122 
    118   }
    119 
    120   void
    121   MasterServer::helper_cleanupServers()
    122   {
    123     /* same as above. */
    124 
    125123  }
    126124
     
    165163
    166164    /* output that the disconnect happened */
    167     COUT(4) << (char*)event->peer->data << " disconnected.\n";
     165    COUT(2) << (char*)event->peer->data << " disconnected.\n";
    168166
    169167    /* create string from peer data */
     
    205203        MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
    206204      { /* register new server */
    207         mainlist.addServer( packet::ServerInformation( event ) );
     205        mainlist.addServer( packet::ServerInformation( event ),
     206          event->peer );
    208207       
    209208        /* tell people we did so */
     
    260259    }
    261260
    262     /* TODO schedule pings for servers somewhere here */
    263     /* Iterate through servers and send pings */
    264     helper_pingServers();
    265    
    266261    /* check for timed out pings and remove those guys from
    267262     * the server list
  • code/branches/masterserver2/src/libraries/network/ServerList.cc

    r7801 r8202  
    4040
    4141  int
    42   ServerList::addServer( packet::ServerInformation toadd )
    43   { this->serverlist.push_back( toadd );
     42  ServerList::addServer( packet::ServerInformation toadd,
     43    ENetPeer *peer )
     44  {
     45    ServerListElem toAdd;
     46    toAdd.ServerInfo = toadd;
     47    toAdd.peer = peer;
     48
     49    this->serverlist.push_back( toAdd );
    4450    return 0;
    4551  }
     
    4955  {
    5056    /* get an iterator */
    51     std::list<packet::ServerInformation>::iterator i;
     57    std::list<ServerListElem>::iterator i;
    5258
    5359    /* loop through list elements */
    5460    for( i = serverlist.begin(); i != serverlist.end(); ++i )
    55       if( (*i).getServerName() == name )
     61      if( (*i).ServerInfo.getServerName() == name )
    5662      { /* found this name, remove and quit */
    5763        this->serverlist.erase( i );
     
    6470  {
    6571    /* get an iterator */
    66     std::list<packet::ServerInformation>::iterator i;
     72    std::list<ServerListElem>::iterator i;
    6773
    6874    /* loop through list elements */
    69     for( i=serverlist.begin(); i != serverlist.end(); ++i )
    70       if( (*i).getServerIP() == address )
     75    for( i = serverlist.begin(); i != serverlist.end(); ++i )
     76      if( (*i).ServerInfo.getServerIP() == address )
    7177      { /* found this name, remove and quit */
    7278        this->serverlist.erase( i );
     
    7884
    7985  /* sort by name */
    80   bool sub_compare_names( packet::ServerInformation no1,
    81     packet::ServerInformation no2 )
    82   { return no1.getServerName() > no2.getServerName(); }
     86  bool sub_compare_names( ServerListElem no1,
     87    ServerListElem no2 )
     88  { return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); }
    8389
    8490  void ServerList::sortByName()
     
    8894 
    8995  /* sort by ping */
    90   bool sub_compare_pings( packet::ServerInformation no1,
    91     packet::ServerInformation no2 )
     96  bool sub_compare_pings( ServerListElem no1,
     97    ServerListElem no2 )
    9298  {
    93     /* TODO */
    94     return no1.getServerName() > no2.getServerName();
     99    return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName();
    95100  }
    96101
  • code/branches/masterserver2/src/libraries/network/ServerList.h

    r7801 r8202  
    3737namespace orxonox
    3838{
     39  struct ServerListElem
     40  {
     41    /* server information (name, IP, etc) */
     42    packet::ServerInformation ServerInfo;
     43
     44    /* peer pointer */
     45    ENetPeer* peer;
     46  };
     47
    3948  /** This class is keeps a list of game servers
    4049   * and some info about them.
     
    5463       * Add server to the game server list
    5564       */
    56       int addServer( packet::ServerInformation toadd );
     65      int addServer( packet::ServerInformation toadd,
     66        ENetPeer *peer );
    5767
    5868      /** \param name Name of the server to remove
     
    7888
    7989      /** the list of servers for internal storage */
    80       std::list<packet::ServerInformation> serverlist;
     90      std::list<ServerListElem> serverlist;
    8191    private:
    8292  };
Note: See TracChangeset for help on using the changeset viewer.