[Orxonox-commit 2951] r7651 - in code/branches/masterserver/src: libraries/network libraries/network/packet modules/masterserver

smerkli at orxonox.net smerkli at orxonox.net
Wed Nov 17 16:18:14 CET 2010


Author: smerkli
Date: 2010-11-17 16:18:14 +0100 (Wed, 17 Nov 2010)
New Revision: 7651

Modified:
   code/branches/masterserver/src/libraries/network/WANDiscovery.cc
   code/branches/masterserver/src/libraries/network/WANDiscovery.h
   code/branches/masterserver/src/libraries/network/packet/ServerInformation.h
   code/branches/masterserver/src/modules/masterserver/MasterServer.cc
   code/branches/masterserver/src/modules/masterserver/MasterServer.h
   code/branches/masterserver/src/modules/masterserver/ServerList.h
Log:
done for today

Modified: code/branches/masterserver/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/masterserver/src/libraries/network/WANDiscovery.cc	2010-11-17 15:05:13 UTC (rev 7650)
+++ code/branches/masterserver/src/libraries/network/WANDiscovery.cc	2010-11-17 15:18:14 UTC (rev 7651)
@@ -61,27 +61,28 @@
   }
 
   /* callback for the network reply poller */
+  /* WORK MARK WORK WORK */
   /* NOTE implement protocol-specific part here. */
-  int rhandler( char *addr, ENetEvent *ev )
+  int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
   { 
     /* handle incoming data */
     /* if a list entry arrives add to list */
-    if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_ITEM,
+    if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
       MSPROTO_SERVERLIST_ITEM_LEN ) )
     { 
       /* create server structure from that item */
-      ServerInformation toadd;
+      packet::ServerInformation toadd;
 
       /* fill in data */
-      toadd->setName( std::string(ev->packet->data + 
+      toadd.setServerName( std::string((char*)ev->packet->data + 
         MSPROTO_SERVERLIST_ITEM_LEN) );
-      toadd->setIP( std::string(ev->packet->data + 
+      toadd.setServerIP( std::string((char*)ev->packet->data + 
         MSPROTO_SERVERLIST_ITEM_LEN) );
 
       /* add to list */
-      this->servers_.add( toadd );
+      this->servers_.push_back( toadd );
     }
-    else if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_END,
+    else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
       MSPROTO_SERVERLIST_END_LEN ) )
     { return 1; }
 
@@ -98,7 +99,7 @@
     msc.sendRequest( MSPROTO_CLIENT " " MSPROTO_REQ_LIST );
 
     /* deal with replies */
-    while( !msc.pollForReply( rhandler ) ) 
+    while( !msc.pollForReply( WANDiscovery::rhandler ) ) 
       /* nothing */;
 
     /* done receiving. */

Modified: code/branches/masterserver/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/masterserver/src/libraries/network/WANDiscovery.h	2010-11-17 15:05:13 UTC (rev 7650)
+++ code/branches/masterserver/src/libraries/network/WANDiscovery.h	2010-11-17 15:18:14 UTC (rev 7651)
@@ -76,6 +76,8 @@
        * Create and return an instance of WANDiscovery.
        */
       static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export
+    
+      int rhandler( char *addr, ENetEvent *ev );
       
     private:
       /** Singleton pointer */

Modified: code/branches/masterserver/src/libraries/network/packet/ServerInformation.h
===================================================================
--- code/branches/masterserver/src/libraries/network/packet/ServerInformation.h	2010-11-17 15:05:13 UTC (rev 7650)
+++ code/branches/masterserver/src/libraries/network/packet/ServerInformation.h	2010-11-17 15:18:14 UTC (rev 7651)
@@ -49,6 +49,7 @@
         std::string   getServerIP() { return this->serverIP_; }
         std::string   getServerName() { return this->serverName_; }
         void          setServerName(std::string name) { this->serverName_ = name; }
+        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
         uint32_t      getServerRTT() { return this->serverRTT_; }
         
       private:

Modified: code/branches/masterserver/src/modules/masterserver/MasterServer.cc
===================================================================
--- code/branches/masterserver/src/modules/masterserver/MasterServer.cc	2010-11-17 15:05:13 UTC (rev 7650)
+++ code/branches/masterserver/src/modules/masterserver/MasterServer.cc	2010-11-17 15:18:14 UTC (rev 7651)
@@ -56,15 +56,6 @@
       << " on port " 
       << event->peer->address.port << "\n";
 
-    /* game server or client connection? */
-    /* -> decide in protocol */
-    /* game server */
-    /* add to game server list */
-    /*  */
-
-    /* client */
-    /* add to client list */
-
     /* store string form of address here */
     event->peer->data = addrconv; 
 
@@ -81,21 +72,28 @@
       return -1;
     }
 
-    /* output that the disconnect happened, to be removed at a later time. */
+    /* output that the disconnect happened */
     COUT(4) << (char*)event->peer->data << " disconnected.\n";
 
+    /* create string from peer data */
+    std::string name = std::string( (char*)event->peer->data );
+
     /* remove the server from the list it belongs to */
+    this->mainlist->delServerByName( name );
 
     /* Reset the peer's client information. */
     if( event->peer->data ) free( event->peer->data );
+
+    /* done */
     return 0;
   }
 
   /* data event */
   int 
   MasterServer::eventData( ENetEvent *event )
-  { /* output what's in the packet (to be removed later) */
+  { /* validate packet */
     if( !event || !(event->packet) || !(event->peer) )
+      //|| !(event->packet->data) || !strlen(event->packet->data) )
     { COUT(2) << "No complete event given.\n";
       return -1;
     }
@@ -109,12 +107,13 @@
     COUT(4) << "A packet of length" 
       << event->packet->dataLength
       << " containing "
-      << event->packet->data
+      << (const char*)event->packet->data
       << " was received from "
       << addrconv 
       << " on channel "
       << event->channelID << "\n";
 
+    /*
     //[> send some packet back for testing <]
     //[> TESTING <]
 
@@ -130,19 +129,56 @@
     //enet_host_flush( this->server );
 
     //[> /TESTING <]
+    */
 
     /* GAME SERVER OR CLIENT CONNECTION? */
+    if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 
+      MSPROTO_GAME_SERVER_LEN ) )
+    { /* Game server */
 
-    /* Game server */
-    /* parse data */
-    /* start actions */
-    /* and send reply */
+      if( !strncmp( (char *)event->packet->data 
+        + MSPROTO_GAME_SERVER_LEN+1, 
+        MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
+      { /* register new server */
+        mainlist->addServer( packet::ServerInformation( event ) );
+      }
+    }
+    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 
+      MSPROTO_CLIENT_LEN) )
+    { /* client */
+      
+      if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
+        MSPROTO_REQ_LIST ) )
+      { /* send server list */
+        
+        /* get an iterator */
+        std::list<packet::ServerInformation *>::iterator i;
 
-    /* client */
-    /* parse data */
-    /* start actions */
-    /* and send reply */
+        /* loop through list elements */
+        for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+        {
+          /* WORK MARK */
+          /* send this particular server */
+          /* build reply string */
+          char *tosend = (char *)calloc( (*i)->getServerIP().length() + 1,1 );
+          snprintf( "%s %s", MSPROTO_SERVERLIST_ITEM, (*i)->getServerIP() );
 
+          /* create packet from it */
+          ENetPacket * reply = enet_packet_create( tosend,
+            strlen( tosend ) + 1, 
+            ENET_PACKET_FLAG_RELIABLE);
+
+          /* Send the reply to the peer over channel id 0. */
+          enet_peer_send( event->peer, 0, reply );
+
+          /* One could just use enet_host_service() instead. */
+          enet_host_flush( this->server );
+        } 
+      }
+    }
+    else
+    { /* bad message, don't do anything. */ } 
+
     /* delete addrconv */
     if( addrconv ) free( addrconv );
 

Modified: code/branches/masterserver/src/modules/masterserver/MasterServer.h
===================================================================
--- code/branches/masterserver/src/modules/masterserver/MasterServer.h	2010-11-17 15:05:13 UTC (rev 7650)
+++ code/branches/masterserver/src/modules/masterserver/MasterServer.h	2010-11-17 15:18:14 UTC (rev 7651)
@@ -38,6 +38,7 @@
 #include <network/packet/Gamestate.h>
 #include <network/packet/Welcome.h>
 #include <util/Singleton.h>
+#include <network/MasterServerProtocol.h>
 
 /* my includes */
 #include "ServerList.h"
@@ -46,10 +47,6 @@
 /* c compatibility */
 #include <cstdio>
 
-#define ORX_MSERVER_PORT 1234
-#define ORX_MSERVER_MAXCONNS 32
-#define ORX_MSERVER_MAXCHANS 2
-
 namespace orxonox 
 {
   /* singleton */

Modified: code/branches/masterserver/src/modules/masterserver/ServerList.h
===================================================================
--- code/branches/masterserver/src/modules/masterserver/ServerList.h	2010-11-17 15:05:13 UTC (rev 7650)
+++ code/branches/masterserver/src/modules/masterserver/ServerList.h	2010-11-17 15:18:14 UTC (rev 7651)
@@ -76,9 +76,9 @@
       /** sort by ping */
       void sortByPing();
 
-    private:
       /** the list of servers for internal storage */
       std::list<packet::ServerInformation *> serverlist;
+    private:
   };
 }
 




More information about the Orxonox-commit mailing list