Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7684


Ignore:
Timestamp:
Dec 1, 2010, 1:51:15 PM (13 years ago)
Author:
smerkli
Message:

further testing.

Location:
code/branches/masterserver/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/masterserver/src/libraries/network/MasterServerComm.cc

    r7672 r7684  
    4646      return 1;
    4747    }
     48
     49    /* initialize the event holder */
     50    this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );
    4851   
    4952    /* install atexit handler for enet */
     
    8992
    9093    /* Wait up to 2 seconds for the connection attempt to succeed. */
    91     if (enet_host_service (this->client, &this->event, 2000) > 0 &&
    92         this->event.type == ENET_EVENT_TYPE_CONNECT )
     94    if (enet_host_service (this->client, this->event, 2000) > 0 &&
     95        this->event->type == ENET_EVENT_TYPE_CONNECT )
    9396      fprintf( stdout, "Connection to server succeeded." );
    9497    else
     
    107110    /* see whether anything happened */
    108111    /* WORK MARK REMOVE THIS OUTPUT */
    109     COUT(2) << "MARK polling...\n";
     112    //COUT(2) << "MARK polling...\n";
    110113
    111114    /* enet_host_service returns 0 if no event occured */
    112115    /* just newly set below test to >0 from >= 0, to be tested */
    113     if( enet_host_service( this->client, &this->event, 1000 ) > 0 )
     116    if( enet_host_service( this->client, this->event, 1000 ) > 0 )
    114117    {
    115118      /* address buffer */
     
    118121
    119122      /* check what type of event it is and react accordingly */
    120       switch (this->event.type)
     123      switch (this->event->type)
    121124      { /* new connection, not supposed to happen. */
    122125        case ENET_EVENT_TYPE_CONNECT: break;
     
    128131        case ENET_EVENT_TYPE_RECEIVE:
    129132          addrconv = (char *) calloc( 50, 1 );
    130           enet_address_get_host_ip( &(this->event.peer->address), addrconv, 49 );
     133          enet_address_get_host_ip( &(this->event->peer->address),
     134            addrconv, 49 );
    131135
    132136          /* DEBUG */
    133137          printf( "A packet of length %u containing %s was "
    134138            "received from %s on channel %u.\n",
    135             this->event.packet->dataLength,
    136             this->event.packet->data,
     139            this->event->packet->dataLength,
     140            this->event->packet->data,
    137141            addrconv,
    138             this->event.channelID );
     142            this->event->channelID );
    139143          /* END DEBUG */
    140144
    141145          /* call the supplied callback, if any. */
    142146          if( (*callback) != NULL )
    143             retval = (*callback)( addrconv, &(this->event) );
    144 
    145           enet_packet_destroy( event.packet );
     147            retval = (*callback)( addrconv, (this->event) );
     148
     149          enet_packet_destroy( event->packet );
    146150          if( addrconv ) free( addrconv );
    147151          break;
  • code/branches/masterserver/src/libraries/network/MasterServerComm.h

    r7650 r7684  
    8585
    8686      /** event data holder */
    87       ENetEvent event;
     87      ENetEvent *event;
    8888
    8989      /** address holder */
  • code/branches/masterserver/src/modules/masterserver/MasterServer.cc

    r7666 r7684  
    3636  /* singleton stuff */
    3737  //ManageScopedSingleton( MasterServer, ScopeID::Root, false );
     38
     39  /* helpers */
     40  static void
     41  helper_output_debug( ENetEvent *event, char *addrconv )
     42  {
     43    COUT(4) << "A packet of length"
     44      << event->packet->dataLength
     45      << " containing "
     46      << (const char*)event->packet->data
     47      << " was received from "
     48      << addrconv
     49      << " on channel "
     50      << event->channelID << "\n";
     51  }
     52
     53  void
     54  MasterServer::helper_sendlist( ENetEvent *event )
     55  {
     56    /* get an iterator */
     57    std::list<packet::ServerInformation>::iterator i;
     58
     59    /* packet holder */
     60    ENetPacket *reply;
     61
     62    /* loop through list elements */
     63    for( i = mainlist.serverlist.begin(); i
     64        != mainlist.serverlist.end(); ++i )
     65    {
     66      /* WORK MARK */
     67      /* send this particular server */
     68      /* build reply string */
     69      char *tosend = (char *)calloc( (*i).getServerIP().length()
     70          + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
     71      if( !tosend )
     72      { COUT(2) << "Masterserver.cc: Memory allocation failed.\n";
     73        continue;
     74      }
     75      sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM,
     76          (*i).getServerIP().c_str() );
     77
     78      /* create packet from it */
     79      reply = enet_packet_create( tosend,
     80          strlen( tosend ) + 1,
     81          ENET_PACKET_FLAG_RELIABLE);
     82
     83      /* Send the reply to the peer over channel id 0. */
     84      enet_peer_send( event->peer, 0, reply );
     85
     86      /* One could just use enet_host_service() instead. */
     87      enet_host_flush( this->server );
     88
     89      /* free the tosend buffer */
     90      free( tosend );
     91    }
     92
     93    /* send end-of-list packet */
     94    reply = enet_packet_create( MSPROTO_SERVERLIST_END,
     95        MSPROTO_SERVERLIST_END_LEN + 1,
     96        ENET_PACKET_FLAG_RELIABLE );
     97
     98    enet_peer_send( event->peer, 0, reply );
     99
     100    /* One could just use enet_host_service() instead. */
     101    enet_host_flush( this->server );
     102  }
     103
     104
     105
    38106
    39107  /***** EVENTS *****/
     
    105173    /* DEBUG */
    106174    /* output debug info about the data that has come, to be removed */
    107     COUT(4) << "A packet of length"
    108       << event->packet->dataLength
    109       << " containing "
    110       << (const char*)event->packet->data
    111       << " was received from "
    112       << addrconv
    113       << " on channel "
    114       << event->channelID << "\n";
    115 
    116     /*
    117     //[> send some packet back for testing <]
    118     //[> TESTING <]
    119 
    120     //[> Create a reliable reply of size 7 containing "reply\0" <]
    121     //ENetPacket * reply = enet_packet_create ("reply",
    122         //strlen ("reply") + 1,
    123         //ENET_PACKET_FLAG_RELIABLE);
    124 
    125     //[> Send the reply to the peer over channel id 0. <]
    126     //enet_peer_send( event->peer, 0, reply );
    127 
    128     //[> One could just use enet_host_service() instead. <]
    129     //enet_host_flush( this->server );
    130 
    131     //[> /TESTING <]
    132     */
     175    helper_output_debug( event, addrconv );
    133176
    134177    /* GAME SERVER OR CLIENT CONNECTION? */
     
    151194      MSPROTO_CLIENT_LEN) )
    152195    { /* client */
    153      
    154196      if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
    155197        MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
    156       { /* send server list */
    157        
    158         /* get an iterator */
    159         std::list<packet::ServerInformation>::iterator i;
    160 
    161         /* packet holder */
    162         ENetPacket *reply;
    163 
    164         /* loop through list elements */
    165         for( i = mainlist.serverlist.begin(); i != mainlist.serverlist.end(); ++i )
    166         {
    167           /* WORK MARK */
    168           /* send this particular server */
    169           /* build reply string */
    170           char *tosend = (char *)calloc( (*i).getServerIP().length() + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
    171           sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM, (*i).getServerIP().c_str() );
    172 
    173           /* create packet from it */
    174            reply = enet_packet_create( tosend,
    175             strlen( tosend ) + 1,
    176             ENET_PACKET_FLAG_RELIABLE);
    177 
    178           /* Send the reply to the peer over channel id 0. */
    179           enet_peer_send( event->peer, 0, reply );
    180 
    181           /* One could just use enet_host_service() instead. */
    182           enet_host_flush( this->server );
    183         }
    184 
    185         /* send end-of-list packet */
    186         reply = enet_packet_create( MSPROTO_SERVERLIST_END,
    187           MSPROTO_SERVERLIST_END_LEN + 1,
    188           ENET_PACKET_FLAG_RELIABLE );
    189 
    190         enet_peer_send( event->peer, 0, reply );
    191 
    192         /* One could just use enet_host_service() instead. */
    193         enet_host_flush( this->server );
    194 
    195       }
     198        /* send server list */
     199        helper_sendlist( event );
    196200    }
    197201    else
  • code/branches/masterserver/src/modules/masterserver/MasterServer.h

    r7657 r7684  
    7070      int eventData( ENetEvent *event );
    7171
     72      /* helpers */
     73      void helper_sendlist( ENetEvent *event );
     74
    7275      /* members */
    7376      ENetAddress address;
Note: See TracChangeset for help on using the changeset viewer.