Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 21, 2011, 4:01:44 PM (14 years ago)
Author:
smerkli
Message:

ms-delserver command implemented to kick servers from the master server list

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

Legend:

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

    r8242 r8280  
    3838  /* commands for the terminal interface */
    3939  SetConsoleCommand( "ms-listservers", &MasterServer::listServers );
    40   //SetConsoleCommand( "ms-delserver", &MasterServer::delServer );
     40  SetConsoleCommand( "ms-delserver", &MasterServer::delServer );
    4141  //SetConsoleCommand( "ms-serverinfo", &MasterServer::serverInfo );
    4242
     
    6767    COUT(0) << MasterServer::getInstance()->mainlist.serverlist.size() <<
    6868      " servers connected." << std::endl;
     69  }
     70
     71  void
     72  MasterServer::delServer( std::string todeladdr )
     73  {
     74    /* tell the user we're now removing the entry from the server list */
     75    COUT(0) << "MS: Deleting server \"" << todeladdr << "\"..."
     76      << std::endl;
     77
     78    /* see if we actually have that server on our list */
     79    ServerListSearchResult shandle =
     80      MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr);
     81
     82    if( !shandle.success )
     83    { COUT(0) << "MS: Server not found, not removing." << std::endl;
     84      return;
     85    }
     86
     87    /* force-disconnect the server */ 
     88    enet_peer_disconnect( shandle.result.peer, NULL );
     89
     90    /* actually remove the entry from the server list by address */
     91    MasterServer::getInstance()->mainlist.delServerByAddress( todeladdr);
     92
     93    /* tell the user about our success */
     94    COUT(0) << "MS: Server deletion successful." << std::endl;
    6995  }
    7096
     
    365391    }
    366392
    367     /***** INITIALIZE GAME SERVER AND PEER LISTS *****/
    368     this->peers = new PeerList();
    369 
    370393    /* set pointer to this instance */
    371394    MasterServer::setInstance( this );
  • code/branches/masterserver2/src/libraries/network/MasterServer.h

    r8241 r8280  
    7070      /* functions for commands */
    7171      static void listServers( void );
     72      static void delServer( std::string todeladdr );
    7273
    7374    private:
     
    8586      ENetHost *server;
    8687      ServerList mainlist;
    87       PeerList *peers;
    8888
    8989      unsigned int port;
  • code/branches/masterserver2/src/libraries/network/MasterServerComm.cc

    r7801 r8280  
    168168        case ENET_EVENT_TYPE_CONNECT: break;
    169169
    170         /* disconnect */
    171         case ENET_EVENT_TYPE_DISCONNECT: /* ?? */ break;
     170        /* disconnection event - probably kick from masterserver or crash. */
     171        case ENET_EVENT_TYPE_DISCONNECT:
     172          COUT(0) << "ERROR: Master server connection was dropped." << std::endl;
     173          break;
    172174
    173175        /* incoming data */
  • code/branches/masterserver2/src/libraries/network/ServerList.cc

    r8203 r8280  
    8282  }
    8383
     84  /* SEARCHING */
     85  ServerListSearchResult
     86  ServerList::findServerByAddress( std::string address )
     87  {
     88    /* get an iterator */
     89    std::list<ServerListElem>::iterator i;
    8490
     91    /* loop through list elements */
     92    for( i = serverlist.begin(); i != serverlist.end(); ++i )
     93      if( (*i).ServerInfo.getServerIP() == address )
     94      { /* found the target, return it */
     95        ServerListSearchResult res = { (*i), true };
     96        return res;
     97      }
     98
     99    /* no success */
     100    ServerListSearchResult res = { (*i), false };
     101    return res;
     102  }
     103
     104  ServerListSearchResult
     105  ServerList::findServerByName( std::string name )
     106  {
     107    /* get an iterator */
     108    std::list<ServerListElem>::iterator i;
     109
     110    /* iterate, return when name found */
     111    /* loop through list elements */
     112    for( i = serverlist.begin(); i != serverlist.end(); ++i )
     113      if( (*i).ServerInfo.getServerName() == name )
     114      {
     115        ServerListSearchResult res = { (*i), true };
     116        return res;
     117      }
     118
     119    /* no luck, return a struct that tells the caller so */
     120    ServerListSearchResult res = { (*i), false };
     121    return res;
     122  }
     123
     124  /* SORTING */
    85125  /* sort by name */
    86126  bool sub_compare_names( ServerListElem no1,
  • code/branches/masterserver2/src/libraries/network/ServerList.h

    r8202 r8280  
    3737namespace orxonox
    3838{
     39  /* HELPER STRUCTURES */
    3940  struct ServerListElem
    4041  {
     
    4546    ENetPeer* peer;
    4647  };
     48
     49  struct ServerListSearchResult
     50  {
     51    /* list element found */
     52    ServerListElem result;
     53
     54    /* successful search */
     55    bool success;
     56  };
     57
     58
     59
     60
    4761
    4862  /** This class is keeps a list of game servers
     
    7993
    8094
    81       /* SORTING (to be implemented) */
    8295
     96
     97      /* SEARCHING */
     98      /* \param address The address of the server that is to be
     99       *  found
     100       * \return A struct containing a result of the search and a boolean
     101       *  that is only true if the search was successful
     102       *
     103       * Find and return the list handle of a given address.
     104       */
     105      ServerListSearchResult
     106      findServerByAddress( std::string address );
     107
     108
     109      /* \param name The name of the server that is to be
     110       *  found
     111       * \return The struct containing the list entry of the server
     112       *
     113       * Find and return the list handle of a given name.
     114       */
     115      ServerListSearchResult
     116      findServerByName( std::string name );
     117
     118
     119      /* SORTING */
    83120      /** sort by name  */
    84121      void sortByName();
Note: See TracChangeset for help on using the changeset viewer.