[Orxonox-commit 3061] r7756 - code/branches/presentation/src/libraries/network
smerkli at orxonox.net
smerkli at orxonox.net
Sat Dec 11 21:07:55 CET 2010
Author: smerkli
Date: 2010-12-11 21:07:55 +0100 (Sat, 11 Dec 2010)
New Revision: 7756
Modified:
code/branches/presentation/src/libraries/network/MasterServer.cc
code/branches/presentation/src/libraries/network/MasterServerComm.cc
code/branches/presentation/src/libraries/network/MasterServerComm.h
code/branches/presentation/src/libraries/network/MasterServerProtocol.h
code/branches/presentation/src/libraries/network/Server.cc
code/branches/presentation/src/libraries/network/WANDiscovery.cc
Log:
started implementing server pings, but need a change to masterservercomm soon.
Modified: code/branches/presentation/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServer.cc 2010-12-11 15:12:21 UTC (rev 7755)
+++ code/branches/presentation/src/libraries/network/MasterServer.cc 2010-12-11 20:07:55 UTC (rev 7756)
@@ -184,6 +184,8 @@
COUT(2) << "Added new server to list: " <<
packet::ServerInformation( event ).getServerIP() << "\n";
}
+
+ /* TODO add hook for disconnect here */
}
else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
MSPROTO_CLIENT_LEN) )
@@ -217,6 +219,7 @@
exit( EXIT_FAILURE );
}
+ /* TODO schedule pings for servers somewhere here */
/* create an iterator for the loop */
enet_host_service( this->server, event, 100 );
Modified: code/branches/presentation/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerComm.cc 2010-12-11 15:12:21 UTC (rev 7755)
+++ code/branches/presentation/src/libraries/network/MasterServerComm.cc 2010-12-11 20:07:55 UTC (rev 7756)
@@ -37,7 +37,6 @@
*/
}
-
int MasterServerComm::initialize()
{
/* initialize Enet */
@@ -52,7 +51,6 @@
/* install atexit handler for enet */
atexit( enet_deinitialize );
-
/* initiate the client */
this->client = enet_host_create( NULL /* create a client host */,
1,
@@ -86,7 +84,7 @@
if (this->peer == NULL )
{ COUT(2) << "ERROR: No available peers for initiating an ENet connection.\n";
- return -1;
+ return -1;
}
/* Wait up to 2 seconds for the connection attempt to succeed. */
@@ -101,10 +99,18 @@
return -1;
}
+ /* all fine */
return 0;
}
- int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ) )
+ /* NOTE this is to be reimplemented soon to return
+ * a structure containing
+ * - addrconv
+ * - the event
+ * so we can also make callbacks from objects
+ */
+ int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ),
+ int delayms )
{
/* see whether anything happened */
/* WORK MARK REMOVE THIS OUTPUT */
@@ -116,7 +122,7 @@
/* enet_host_service returns 0 if no event occured */
/* just newly set below test to >0 from >= 0, to be tested */
- if( enet_host_service( this->client, this->event, 1000 ) > 0 )
+ if( enet_host_service( this->client, this->event, delayms ) > 0 )
{
/* check what type of event it is and react accordingly */
switch (this->event->type)
@@ -139,24 +145,22 @@
addrconv, 49 );
/* DEBUG */
- COUT(3) << "A packet of length " << this->event->packet->dataLength
+ COUT(3) << "MasterServer Debug: A packet of length "
+ << this->event->packet->dataLength
<< " containing " << this->event->packet->data
<< " was received from " << addrconv
<< " on channel " << this->event->channelID;
- //printf( "A packet of length %u containing %s was "
- //"received from %s on channel %u.\n",
- //this->event->packet->dataLength,
- //this->event->packet->data,
- //addrconv,
- //this->event->channelID );
/* END DEBUG */
/* call the supplied callback, if any. */
if( (*callback) != NULL )
retval = (*callback)( addrconv, (this->event) );
+ /* clean up */
enet_packet_destroy( event->packet );
- if( addrconv ) free( addrconv );
+ if( addrconv )
+ free( addrconv );
+
break;
default: break;
}
@@ -210,43 +214,3 @@
}
}
-
-
-/* DON'T DELETE THIS I MIGHT NEED IT AGAIN -smerkli */
-/* not needed anymore, only here for testing purposes */
-/*
-//[> sample callback to output debugging info. <]
-//int callb( char *addr, ENetEvent *ev )
-//{
- //printf( "A packet of length %u containing %s was "
- //"received from %s on channel %u.\n",
- //ev->packet->dataLength,
- //ev->packet->data,
- //addr,
- //ev->channelID );
- //return 0;
-//}
-
-//[> small testing implementation <]
-//int
-//main( int argc, char *argv[] )
-//{
- //[> setup object and connect <]
- //MasterServerComm msc = MasterServerComm();
- //if( msc.connect( argv[1], 1234 ) )
- //exit(EXIT_FAILURE);
-
- //[> send some data and poll for replies <]
- //char *theinput = (char *)calloc( 100,1 );
- //while( true )
- //{
- //fgets( theinput, 90, stdin );
- //if( !strncmp( theinput, "quit", 4 ) )
- //break;
-
- //msc.sendRequest( theinput );
- //msc.pollForReply( &callb );
- //}
-
-//}
-*/
Modified: code/branches/presentation/src/libraries/network/MasterServerComm.h
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerComm.h 2010-12-11 15:12:21 UTC (rev 7755)
+++ code/branches/presentation/src/libraries/network/MasterServerComm.h 2010-12-11 20:07:55 UTC (rev 7756)
@@ -80,7 +80,7 @@
* \return 0 for success, other for error
*
* Poll the master server for new data and act accordingly */
- int pollForReply( int (*callback)( char*, ENetEvent* ) );
+ int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms );
private:
/** client handle */
Modified: code/branches/presentation/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerProtocol.h 2010-12-11 15:12:21 UTC (rev 7755)
+++ code/branches/presentation/src/libraries/network/MasterServerProtocol.h 2010-12-11 20:07:55 UTC (rev 7756)
@@ -32,6 +32,8 @@
/* master server address (to be moved elsewhere later) */
#define MS_ADDRESS "129.132.3.8"
+
+/*** CLIENT COMMUNICATIONS ***/
/* Client token (shows that the party sending data is a client */
#define MSPROTO_CLIENT "CL"
#define MSPROTO_CLIENT_LEN 2
@@ -43,6 +45,7 @@
+/*** GAME SERVER COMMUNICATIONS ***/
/* Game server token (shows that the party sending data is a game server) */
#define MSPROTO_GAME_SERVER "GS"
#define MSPROTO_GAME_SERVER_LEN 2
@@ -61,8 +64,16 @@
#define MSPROTO_SERVERLIST_END "SL_END"
#define MSPROTO_SERVERLIST_END_LEN 6
+/* ping request from server */
+#define MSPROTO_PING_GAMESERVER "PING"
+#define MSPROTO_PING_GAMESERVER_LEN 4
+/* ping reply */
+#define MSPROTO_ACK "ACK"
+#define MSPROTO_ACK_LEN 3
+
+
/* default master server port */
#define ORX_MSERVER_PORT 55566
Modified: code/branches/presentation/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentation/src/libraries/network/Server.cc 2010-12-11 15:12:21 UTC (rev 7755)
+++ code/branches/presentation/src/libraries/network/Server.cc 2010-12-11 20:07:55 UTC (rev 7756)
@@ -133,6 +133,9 @@
LANDiscoverable::setActivity(true);
/* make discoverable on WAN */
+ /* TODO this needs to be optional, we need a switch from the UI to
+ * enable/disable this
+ */
helper_ConnectToMasterserver();
/* done */
@@ -168,11 +171,17 @@
}
- /* TODO */
+ /* handle incoming data */
int rephandler( char *addr, ENetEvent *ev )
{
- /* handle incoming data */
- /* TODO this is to be implemented. */
+ /* reply to pings */
+ if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER,
+ MSPROTO_PING_GAMESERVER_LEN ) )
+ //this->msc.sendRequest( MSPROTO_ACK );
+ /* NOTE implement this after pollForReply
+ * reimplementation
+ */
+ return 0;
/* done handling, return all ok code 0 */
return 0;
@@ -183,7 +192,7 @@
/* poll the master server for replies and see whether something
* has to be done or changed.
*/
- this->msc.pollForReply( rephandler );
+ this->msc.pollForReply( rephandler, 10 );
}
/**
Modified: code/branches/presentation/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/presentation/src/libraries/network/WANDiscovery.cc 2010-12-11 15:12:21 UTC (rev 7755)
+++ code/branches/presentation/src/libraries/network/WANDiscovery.cc 2010-12-11 20:07:55 UTC (rev 7756)
@@ -132,7 +132,7 @@
while( i > 0 )
{
/* poll for reply and act according to what was received */
- switch( this->msc.pollForReply( rhandler ) )
+ switch( this->msc.pollForReply( rhandler, 1000 ) )
{ case 0: /* no event occured, decrease timeout */
--i; break;
case 1: /* got a list element, continue */
More information about the Orxonox-commit
mailing list