Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

further testing.

Location:
code/branches/masterserver/src/modules/masterserver
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.