Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7650


Ignore:
Timestamp:
Nov 17, 2010, 4:05:13 PM (13 years ago)
Author:
smerkli
Message:

Minimum target achieved for today, servers can log on to master server, clients can get server list. To be debugged.

Location:
code/branches/masterserver/src/libraries/network
Files:
1 added
6 edited

Legend:

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

    r7632 r7650  
    111111      /* address buffer */
    112112      char *addrconv = NULL;
     113      int retval = 0;
    113114
    114115      /* check what type of event it is and react accordingly */
     
    136137          /* call the supplied callback, if any. */
    137138          if( (*callback) != NULL )
    138             (*callback)( addrconv, &(this->event) );
     139            retval = (*callback)( addrconv, &(this->event) );
    139140
    140141          enet_packet_destroy( event.packet );
     
    145146
    146147      /* event handled, return 0 */
    147       return 0;
     148      return retval;
    148149    }
    149150
     
    158159    ENetPacket * packet = enet_packet_create( data,
    159160        strlen( data ) + 1,
     161        ENET_PACKET_FLAG_RELIABLE);
     162
     163    /* Send the packet to the peer over channel id 0. */
     164    enet_peer_send (this->peer, 0, packet);
     165
     166    /* One could just use enet_host_service() instead. */
     167    enet_host_flush( this->client );
     168    if( packet ) free( packet );
     169
     170    /* all done. */
     171    return 0;
     172  }
     173
     174  int MasterServerComm::sendRequest( std::string data )
     175  {
     176    /* send the data to the friend */
     177    /* Create a reliable packet of size 7 containing "packet\0" */
     178    ENetPacket * packet = enet_packet_create( data.c_str(),
     179        data.length() + 1,
    160180        ENET_PACKET_FLAG_RELIABLE);
    161181
  • code/branches/masterserver/src/libraries/network/MasterServerComm.h

    r7631 r7650  
    2929#include <cstdlib>
    3030#include <cstdio>
     31#include <string>
    3132#include <cstring>
    3233#include <enet/enet.h>
     
    6566      int sendRequest( char *data );
    6667
     68      /** \param data The data to be sent.
     69       * \return 0 for success, other for error.
     70       *
     71       * Send a request to the master server containing data specified in data
     72       * (string version)
     73       */
     74      int sendRequest( std::string data );
     75
    6776      /** \param callback The callback function to call with data receivced.
    6877       * \return 0 for success, other for error
  • code/branches/masterserver/src/libraries/network/Server.cc

    r7634 r7650  
    105105    /* initialize it and see if it worked */
    106106    if( msc.initialize() )
    107       COUT(1) << "Error: could not initialize master server communications!\n";
     107    { COUT(1) << "Error: could not initialize master server communications!\n";
     108      return;
     109    }
    108110
    109111    /* connect and see if it worked */
    110112    if( msc.connect( MS_ADDRESS, 1234 ) )
    111       COUT(1) << "Error: could not connect to master server!\n";
    112 
    113     /* TODO */
     113    { COUT(1) << "Error: could not connect to master server!\n";
     114      return;
     115    }
     116
    114117    /* now send the master server some note we're here */
     118    msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
    115119  }
    116120
     
    164168
    165169  /* TODO */
    166   int replyhandler( char *addr, ENetEvent *ev )
     170  int rephandler( char *addr, ENetEvent *ev )
    167171  {
    168172    /* handle incoming data */
     
    174178  void Server::helper_HandleMasterServerRequests()
    175179  {
    176     this->msc.pollForReply( replyhandler );
     180    this->msc.pollForReply( rephandler );
    177181  }
    178182
  • code/branches/masterserver/src/libraries/network/Server.h

    r7634 r7650  
    3939#include "LANDiscoverable.h"
    4040#include "MasterServerComm.h"
     41#include "MasterServerProtocol.h"
    4142
    42 /* proto (move to central point soon) */
    43 #define MS_ADDRESS "localhost"
    4443
    4544namespace orxonox
     
    5756    ~Server();
    5857
     58    /* helpers */
    5959    void helper_ConnectToMasterserver();
     60    void helper_HandleMasterServerRequests();
     61    int replyhandler( char *addr, ENetEvent *ev );
     62
    6063    void open();
    6164    void close();
  • code/branches/masterserver/src/libraries/network/WANDiscovery.cc

    r7631 r7650  
    6363  /* callback for the network reply poller */
    6464  /* NOTE implement protocol-specific part here. */
    65   int replyhandler( char *addr, ENetEvent *ev )
     65  int rhandler( char *addr, ENetEvent *ev )
    6666  {
    67     /* handle incoming data
    68      * if a list entry arrives add to list
    69      * if a done entry arrives set done to true
    70      */
     67    /* handle incoming data */
     68    /* if a list entry arrives add to list */
     69    if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_ITEM,
     70      MSPROTO_SERVERLIST_ITEM_LEN ) )
     71    {
     72      /* create server structure from that item */
     73      ServerInformation toadd;
     74
     75      /* fill in data */
     76      toadd->setName( std::string(ev->packet->data +
     77        MSPROTO_SERVERLIST_ITEM_LEN) );
     78      toadd->setIP( std::string(ev->packet->data +
     79        MSPROTO_SERVERLIST_ITEM_LEN) );
     80
     81      /* add to list */
     82      this->servers_.add( toadd );
     83    }
     84    else if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_END,
     85      MSPROTO_SERVERLIST_END_LEN ) )
     86    { return 1; }
    7187
    7288    /* done handling, return all ok code 0 */
     
    8096
    8197    /* send request to server */
    82     msc.sendRequest( MSPROTO_CLIENT MSPROTO_REQ_LIST );
     98    msc.sendRequest( MSPROTO_CLIENT " " MSPROTO_REQ_LIST );
    8399
    84100    /* deal with replies */
    85     while( msc.pollForReply( replyhandler ) )
     101    while( !msc.pollForReply( rhandler ) )
    86102      /* nothing */;
    87103
  • code/branches/masterserver/src/libraries/network/WANDiscovery.h

    r7631 r7650  
    3434#include "util/Singleton.h"
    3535#include "MasterServerComm.h"
     36#include "MasterServerProtocol.h"
    3637
    3738#include <vector>
    3839
    39 /* master server address (to be moved elsewhere later) */
    40 #define MS_ADDRESS "localhost"
    41 
    42 /* protocol (to be moved elsewhere later) */
    43 #define MSPROTO_CLIENT "CL "
    44 #define MSPROTO_REQ_LIST "REQ:LIST"
    4540
    4641// tolua_begin
Note: See TracChangeset for help on using the changeset viewer.