Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2010, 3:24:56 PM (14 years ago)
Author:
smerkli
Message:

wrote some test client and further implemented the master server itself. now we need to make the module actually work for debugging.

Location:
code/branches/masterserver/src/modules/masterserver
Files:
1 added
4 edited

Legend:

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

    r7580 r7589  
    3333/***** EVENTS *****/
    3434/* connect event */
    35 int eventConnect( ENetEvent *event )
     35int eventConnect( ENetEvent *event,
     36  orxonox::ServerList *serverlist,
     37  orxonox::PeerList *peers )
    3638{ /* check for bad parameters */
    3739  if( !event )
     
    4143
    4244  /* output debug info */
    43   //printf( "A new client connected from %x:%u.\n",
    44       //event->peer->address.host,
    45       //event->peer->address.port);
     45  printf( "A new client connected from %x:%u.\n",
     46      event->peer->address.host,
     47      event->peer->address.port);
    4648
    4749  /* game server or client connection? */
     50  /* -> decide in protocol */
    4851    /* game server */
    4952      /* add to game server list */
     53      /*  */
     54
    5055    /* client */
    5156      /* add to client list */
     
    6166
    6267/* disconnect event */
    63 int eventDisconnect( ENetEvent *event )
     68int eventDisconnect( ENetEvent *event,
     69  orxonox::ServerList *serverlist,
     70  orxonox::PeerList *peers )
    6471{ /* check for bad parameters */
    6572  if( !event )
     
    6976
    7077  /* output that the disconnect happened, to be removed at a later time. */
    71   //printf ("%s disconnected.\n", event->peer -> data);
     78  printf( "%s disconnected.\n", event->peer->data );
    7279
    7380  /* remove the server from the list it belongs to */
     
    126133  ENetHost *server;
    127134
    128   /* Bind the server to the default localhost.     */
    129   /* A specific host address can be specified by   */
    130   /* enet_address_set_host (& address, "x.x.x.x"); */
     135  /* Bind the server to the default localhost and port ORX_MSERVER_PORT */
    131136  address.host = ENET_HOST_ANY;
    132 
    133   /* Bind the server to port 1234. */
    134137  address.port = ORX_MSERVER_PORT;
    135138
    136   server = enet_host_create( & address /* the address to bind the server host to */,
    137       ORX_MSERVER_MAXCONNS      /* allow up to 32 clients and/or outgoing connections */,
    138       ORX_MSERVER_MAXCHANS      /* allow up to 2 channels to be used, 0 and 1 */,
    139       0      /* assume any amount of incoming bandwidth */,
    140       0      /* assume any amount of outgoing bandwidth */);
     139  /* create a host with the above settings (the last two 0 mean: accept
     140   * any input/output bandwidth */
     141  server = enet_host_create( &address, ORX_MSERVER_MAXCONNS,
     142    ORX_MSERVER_MAXCHANS, 0, 0 );     
    141143
    142144  /* see if creation worked */
     
    149151  /***** INITIALIZE GAME SERVER LIST *****/
    150152  orxonox::ServerList *mainlist = new orxonox::ServerList();
    151   //if( mainlist == NULL )
    152   //{ fprintf( stderr, "Error creating server list.\n" );
    153     //exit( EXIT_FAILURE );
    154   //}
     153  if( mainlist == NULL )
     154  { fprintf( stderr, "Error creating server list.\n" );
     155    exit( EXIT_FAILURE );
     156  }
     157
     158  /***** INITIALIZE PEER LIST *****/
     159  orxonox::PeerList *peers = new orxonox::PeerList();
    155160
    156161  /***** ENTER MAIN LOOP *****/
     
    161166  }
    162167
    163   /* NOTE this only waits on one client, we need to find some way to
    164    * actually listen on all active connections. This will be implemented
    165    * together with the list of active connections.
    166    */
    167   /* Wait up to 1000 milliseconds for an event. */
    168   while (enet_host_service (client, event, 1000) > 0)
     168  /* create an iterator for the loop */
     169  while( enet_host_service( server, event, 1000 ) > 0 )
    169170  { /* check what type of event it is and react accordingly */
    170     switch (event.type)
     171    switch (event->type)
    171172    { /* new connection */
    172       case ENET_EVENT_TYPE_CONNECT: eventConnect( event ); break;
     173      case ENET_EVENT_TYPE_CONNECT:
     174        eventConnect( event, mainlist, peers ); break;
    173175
    174176      /* disconnect */
    175       case ENET_EVENT_TYPE_DISCONNECT: eventDisconnect( event ); break;
     177      case ENET_EVENT_TYPE_DISCONNECT:
     178        eventDisconnect( event, mainlist, peers ); break;
    176179
    177180      /* incoming data */
    178181      case ENET_EVENT_TYPE_RECEIVE: eventData( event ); break;
     182      default: break;
    179183    }
    180184  }
  • code/branches/masterserver/src/modules/masterserver/MasterServer.h

    r7569 r7589  
    4141/* my includes */
    4242#include "ServerList.h"
     43#include "PeerList.h"
    4344
    4445/* c compatibility */
  • code/branches/masterserver/src/modules/masterserver/PeerList.h

    r7580 r7589  
    6767      ENetPeer *findPeerByAddr( ENetAddress addr );
    6868
     69      /* NOTE: making this list public so it can easily
     70       * be iterated. This makes sense since iterating it
     71       * will happen all the time, and using getter methods
     72       * for the next in list would slow things down unnecessarily.
     73       */
     74      /** the list of servers for internal storage */
     75      std::list<ENetPeer *> peerlist;
    6976    private:
    70       /** the list of servers for internal storage */
    71       std::list<packet::ENetPeer *> peerlist;
     77      /* nothing so far. */
    7278  };
    7379}
  • code/branches/masterserver/src/modules/masterserver/ServerList.cpp

    r7565 r7589  
    2727 */
    2828
    29  #include "ServerList.h"
     29#include "ServerList.h"
    3030
    3131namespace orxonox
     
    3636  ServerList::~ServerList()
    3737  { /* delete the list */
    38     serverlist.clear();}
     38    serverlist.clear();
    3939  }
    4040
    41   int ServerList::addServer( ServerInformation *toadd )
     41  int
     42  ServerList::addServer( packet::ServerInformation *toadd )
    4243  { this->serverlist.push_back( toadd );
    4344    return 0;
    4445  }
    4546
    46   bool ServerList::delServerByName( std::string name )
     47  bool
     48  ServerList::delServerByName( std::string name )
    4749  {
    4850    /* get an iterator */
    49     list<ServerInformation *>::iterator i;
     51    std::list<packet::ServerInformation *>::iterator i;
    5052
    5153    /* loop through list elements */
    5254    for( i = serverlist.begin(); i != serverlist.end(); ++i )
    53       if( (*i)->serverName_ == name )
     55      if( (*i)->getServerName() == name )
    5456      { /* found this name, remove and quit */
    55         this->serverlist.remove( i );
     57        this->serverlist.remove( *i );
    5658        return true;
    5759      }
     
    6264  {
    6365    /* get an iterator */
    64     list<ServerInformation *>::iterator i;
     66    std::list<packet::ServerInformation *>::iterator i;
    6567
    6668    /* loop through list elements */
    6769    for( i=serverlist.begin(); i != serverlist.end(); ++i )
    68       if( (*i)->serverIP_ == address )
     70      if( (*i)->getServerIP() == address )
    6971      { /* found this name, remove and quit */
    70         this->serverlist.remove( i );
     72        this->serverlist.remove( *i );
    7173        return true;
    7274      }
     
    7678
    7779  /* sort by name */
    78   bool sub_compare_names( ServerInformation *no1, ServerInformation *no2 )
    79   { return no1->serverName_ > no2->serverName_; }
     80  bool sub_compare_names( packet::ServerInformation *no1,
     81    packet::ServerInformation *no2 )
     82  { return no1->getServerName() > no2->getServerName(); }
    8083
    8184  void ServerList::sortByName()
     
    8588 
    8689  /* sort by ping */
    87   bool sub_compare_pings( ServerInformation *no1, ServerInformation *no2 )
    88   { TODO return no1->serverName_ > no2->serverName_; }
     90  bool sub_compare_pings( packet::ServerInformation *no1,
     91    packet::ServerInformation *no2 )
     92  {
     93    /* TODO */
     94    return no1->getServerName() > no2->getServerName();
     95  }
    8996
    9097  void ServerList::sortByPing()
Note: See TracChangeset for help on using the changeset viewer.