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/modules/masterserver
Files:
3 edited

Legend:

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