Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7756


Ignore:
Timestamp:
Dec 11, 2010, 9:07:55 PM (13 years ago)
Author:
smerkli
Message:

started implementing server pings, but need a change to masterservercomm soon.

Location:
code/branches/presentation/src/libraries/network
Files:
6 edited

Legend:

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

    r7750 r7756  
    185185          packet::ServerInformation( event ).getServerIP() << "\n";
    186186      }
     187
     188      /* TODO add hook for disconnect here */
    187189    }
    188190    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
     
    218220    }
    219221
     222    /* TODO schedule pings for servers somewhere here */
    220223   
    221224    /* create an iterator for the loop */
  • code/branches/presentation/src/libraries/network/MasterServerComm.cc

    r7745 r7756  
    3838  }
    3939
    40 
    4140  int MasterServerComm::initialize()
    4241  {
     
    5251    /* install atexit handler for enet */
    5352    atexit( enet_deinitialize );
    54 
    5553
    5654    /* initiate the client */
     
    8785    if (this->peer == NULL )
    8886    { COUT(2) << "ERROR: No available peers for initiating an ENet connection.\n";
    89     return -1;
     87      return -1;
    9088    }
    9189
     
    102100    }
    103101
    104     return 0;
    105   }
    106 
    107   int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ) )
     102    /* all fine */
     103    return 0;
     104  }
     105
     106  /* NOTE this is to be reimplemented soon to return
     107   * a structure containing
     108   * - addrconv
     109   * - the event
     110   * so we can also make callbacks from objects
     111   */
     112  int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ),
     113    int delayms )
    108114  {
    109115    /* see whether anything happened */
     
    117123    /* enet_host_service returns 0 if no event occured */
    118124    /* just newly set below test to >0 from >= 0, to be tested */
    119     if( enet_host_service( this->client, this->event, 1000 ) > 0 )
     125    if( enet_host_service( this->client, this->event, delayms ) > 0 )
    120126    {
    121127      /* check what type of event it is and react accordingly */
     
    140146
    141147          /* DEBUG */
    142           COUT(3) << "A packet of length " << this->event->packet->dataLength
     148          COUT(3) << "MasterServer Debug: A packet of length "
     149            << this->event->packet->dataLength
    143150            << " containing " << this->event->packet->data
    144151            << " was received from " << addrconv
    145152            << " on channel " << this->event->channelID;
    146           //printf( "A packet of length %u containing %s was "
    147             //"received from %s on channel %u.\n",
    148             //this->event->packet->dataLength,
    149             //this->event->packet->data,
    150             //addrconv,
    151             //this->event->channelID );
    152153          /* END DEBUG */
    153154
     
    156157            retval = (*callback)( addrconv, (this->event) );
    157158
     159          /* clean up */
    158160          enet_packet_destroy( event->packet );
    159           if( addrconv ) free( addrconv );
     161          if( addrconv )
     162            free( addrconv );
     163
    160164          break;
    161165        default: break;
     
    211215
    212216}
    213 
    214 
    215 /* DON'T DELETE THIS I MIGHT NEED IT AGAIN -smerkli */
    216 /* not needed anymore, only here for testing purposes */
    217 /*
    218 //[> sample callback to output debugging info. <]
    219 //int callb( char *addr, ENetEvent *ev )
    220 //{
    221   //printf( "A packet of length %u containing %s was "
    222       //"received from %s on channel %u.\n",
    223       //ev->packet->dataLength,
    224       //ev->packet->data,
    225       //addr,
    226       //ev->channelID );
    227   //return 0;
    228 //}
    229 
    230 //[> small testing implementation <]
    231 //int
    232 //main( int argc, char *argv[] )
    233 //{
    234   //[> setup object and connect <]
    235   //MasterServerComm msc = MasterServerComm();
    236   //if( msc.connect( argv[1], 1234 ) )
    237     //exit(EXIT_FAILURE);
    238  
    239   //[> send some data and poll for replies <]
    240   //char *theinput = (char *)calloc( 100,1 );
    241   //while( true )
    242   //{
    243     //fgets( theinput, 90, stdin );
    244     //if( !strncmp( theinput, "quit", 4 ) )
    245       //break;
    246 
    247     //msc.sendRequest( theinput );
    248     //msc.pollForReply( &callb );
    249   //}
    250 
    251 //}
    252 */
  • code/branches/presentation/src/libraries/network/MasterServerComm.h

    r7745 r7756  
    8181       *
    8282       * Poll the master server for new data and act accordingly */
    83       int pollForReply( int (*callback)( char*, ENetEvent* ) );
     83      int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms );
    8484
    8585    private:
  • code/branches/presentation/src/libraries/network/MasterServerProtocol.h

    r7750 r7756  
    3333#define MS_ADDRESS "129.132.3.8"
    3434
     35
     36/*** CLIENT COMMUNICATIONS ***/
    3537/* Client token (shows that the party sending data is a client */
    3638#define MSPROTO_CLIENT "CL"
     
    4446
    4547
     48/*** GAME SERVER COMMUNICATIONS ***/
    4649/* Game server token (shows that the party sending data is a game server) */
    4750#define MSPROTO_GAME_SERVER "GS"
     
    6265#define MSPROTO_SERVERLIST_END_LEN 6
    6366
     67/* ping request from server */
     68#define MSPROTO_PING_GAMESERVER "PING"
     69#define MSPROTO_PING_GAMESERVER_LEN 4
     70
     71/* ping reply */
     72#define MSPROTO_ACK "ACK"
     73#define MSPROTO_ACK_LEN 3
     74
    6475
    6576
  • code/branches/presentation/src/libraries/network/Server.cc

    r7750 r7756  
    134134
    135135    /* make discoverable on WAN */
     136    /* TODO this needs to be optional, we need a switch from the UI to
     137     * enable/disable this
     138     */
    136139    helper_ConnectToMasterserver();
    137140
     
    169172
    170173
    171   /* TODO */
     174  /* handle incoming data */
    172175  int rephandler( char *addr, ENetEvent *ev )
    173176  {
    174     /* handle incoming data */
    175     /* TODO this is to be implemented. */
     177    /* reply to pings */
     178    if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER,
     179      MSPROTO_PING_GAMESERVER_LEN ) )
     180      //this->msc.sendRequest( MSPROTO_ACK );
     181      /* NOTE implement this after pollForReply
     182       * reimplementation
     183       */
     184      return 0;
    176185
    177186    /* done handling, return all ok code 0 */
     
    184193     * has to be done or changed.
    185194     */
    186     this->msc.pollForReply( rephandler );
     195    this->msc.pollForReply( rephandler, 10 );
    187196  }
    188197
  • code/branches/presentation/src/libraries/network/WANDiscovery.cc

    r7750 r7756  
    133133    {
    134134      /* poll for reply and act according to what was received */
    135       switch( this->msc.pollForReply( rhandler ) )
     135      switch( this->msc.pollForReply( rhandler, 1000 ) )
    136136      { case 0: /* no event occured, decrease timeout */
    137137          --i; break;
Note: See TracChangeset for help on using the changeset viewer.