Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

done for today

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

Legend:

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

    r7650 r7651  
    6262
    6363  /* callback for the network reply poller */
     64  /* WORK MARK WORK WORK */
    6465  /* NOTE implement protocol-specific part here. */
    65   int rhandler( char *addr, ENetEvent *ev )
     66  int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
    6667  {
    6768    /* handle incoming data */
    6869    /* if a list entry arrives add to list */
    69     if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_ITEM,
     70    if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
    7071      MSPROTO_SERVERLIST_ITEM_LEN ) )
    7172    {
    7273      /* create server structure from that item */
    73       ServerInformation toadd;
     74      packet::ServerInformation toadd;
    7475
    7576      /* fill in data */
    76       toadd->setName( std::string(ev->packet->data +
     77      toadd.setServerName( std::string((char*)ev->packet->data +
    7778        MSPROTO_SERVERLIST_ITEM_LEN) );
    78       toadd->setIP( std::string(ev->packet->data +
     79      toadd.setServerIP( std::string((char*)ev->packet->data +
    7980        MSPROTO_SERVERLIST_ITEM_LEN) );
    8081
    8182      /* add to list */
    82       this->servers_.add( toadd );
     83      this->servers_.push_back( toadd );
    8384    }
    84     else if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_END,
     85    else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
    8586      MSPROTO_SERVERLIST_END_LEN ) )
    8687    { return 1; }
     
    99100
    100101    /* deal with replies */
    101     while( !msc.pollForReply( rhandler ) )
     102    while( !msc.pollForReply( WANDiscovery::rhandler ) )
    102103      /* nothing */;
    103104
  • code/branches/masterserver/src/libraries/network/WANDiscovery.h

    r7650 r7651  
    7777       */
    7878      static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export
     79   
     80      int rhandler( char *addr, ENetEvent *ev );
    7981     
    8082    private:
  • code/branches/masterserver/src/libraries/network/packet/ServerInformation.h

    r7459 r7651  
    5050        std::string   getServerName() { return this->serverName_; }
    5151        void          setServerName(std::string name) { this->serverName_ = name; }
     52        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
    5253        uint32_t      getServerRTT() { return this->serverRTT_; }
    5354       
  • code/branches/masterserver/src/modules/masterserver/MasterServer.cc

    r7630 r7651  
    5757      << event->peer->address.port << "\n";
    5858
    59     /* game server or client connection? */
    60     /* -> decide in protocol */
    61     /* game server */
    62     /* add to game server list */
    63     /*  */
    64 
    65     /* client */
    66     /* add to client list */
    67 
    6859    /* store string form of address here */
    6960    event->peer->data = addrconv;
     
    8273    }
    8374
    84     /* output that the disconnect happened, to be removed at a later time. */
     75    /* output that the disconnect happened */
    8576    COUT(4) << (char*)event->peer->data << " disconnected.\n";
    8677
     78    /* create string from peer data */
     79    std::string name = std::string( (char*)event->peer->data );
     80
    8781    /* remove the server from the list it belongs to */
     82    this->mainlist->delServerByName( name );
    8883
    8984    /* Reset the peer's client information. */
    9085    if( event->peer->data ) free( event->peer->data );
     86
     87    /* done */
    9188    return 0;
    9289  }
     
    9592  int
    9693  MasterServer::eventData( ENetEvent *event )
    97   { /* output what's in the packet (to be removed later) */
     94  { /* validate packet */
    9895    if( !event || !(event->packet) || !(event->peer) )
     96      //|| !(event->packet->data) || !strlen(event->packet->data) )
    9997    { COUT(2) << "No complete event given.\n";
    10098      return -1;
     
    110108      << event->packet->dataLength
    111109      << " containing "
    112       << event->packet->data
     110      << (const char*)event->packet->data
    113111      << " was received from "
    114112      << addrconv
     
    116114      << event->channelID << "\n";
    117115
     116    /*
    118117    //[> send some packet back for testing <]
    119118    //[> TESTING <]
     
    131130
    132131    //[> /TESTING <]
     132    */
    133133
    134134    /* GAME SERVER OR CLIENT CONNECTION? */
    135 
    136     /* Game server */
    137     /* parse data */
    138     /* start actions */
    139     /* and send reply */
    140 
    141     /* client */
    142     /* parse data */
    143     /* start actions */
    144     /* and send reply */
     135    if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER,
     136      MSPROTO_GAME_SERVER_LEN ) )
     137    { /* Game server */
     138
     139      if( !strncmp( (char *)event->packet->data
     140        + MSPROTO_GAME_SERVER_LEN+1,
     141        MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
     142      { /* register new server */
     143        mainlist->addServer( packet::ServerInformation( event ) );
     144      }
     145    }
     146    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
     147      MSPROTO_CLIENT_LEN) )
     148    { /* client */
     149     
     150      if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
     151        MSPROTO_REQ_LIST ) )
     152      { /* send server list */
     153       
     154        /* get an iterator */
     155        std::list<packet::ServerInformation *>::iterator i;
     156
     157        /* loop through list elements */
     158        for( i = serverlist.begin(); i != serverlist.end(); ++i )
     159        {
     160          /* WORK MARK */
     161          /* send this particular server */
     162          /* build reply string */
     163          char *tosend = (char *)calloc( (*i)->getServerIP().length() + 1,1 );
     164          snprintf( "%s %s", MSPROTO_SERVERLIST_ITEM, (*i)->getServerIP() );
     165
     166          /* create packet from it */
     167          ENetPacket * reply = enet_packet_create( tosend,
     168            strlen( tosend ) + 1,
     169            ENET_PACKET_FLAG_RELIABLE);
     170
     171          /* Send the reply to the peer over channel id 0. */
     172          enet_peer_send( event->peer, 0, reply );
     173
     174          /* One could just use enet_host_service() instead. */
     175          enet_host_flush( this->server );
     176        }
     177      }
     178    }
     179    else
     180    { /* bad message, don't do anything. */ }
    145181
    146182    /* delete addrconv */
  • code/branches/masterserver/src/modules/masterserver/MasterServer.h

    r7611 r7651  
    3939#include <network/packet/Welcome.h>
    4040#include <util/Singleton.h>
     41#include <network/MasterServerProtocol.h>
    4142
    4243/* my includes */
     
    4647/* c compatibility */
    4748#include <cstdio>
    48 
    49 #define ORX_MSERVER_PORT 1234
    50 #define ORX_MSERVER_MAXCONNS 32
    51 #define ORX_MSERVER_MAXCHANS 2
    5249
    5350namespace orxonox
  • code/branches/masterserver/src/modules/masterserver/ServerList.h

    r7631 r7651  
    7777      void sortByPing();
    7878
    79     private:
    8079      /** the list of servers for internal storage */
    8180      std::list<packet::ServerInformation *> serverlist;
     81    private:
    8282  };
    8383}
Note: See TracChangeset for help on using the changeset viewer.