[Orxonox-commit 3516] r8202 - code/branches/masterserver2/src/libraries/network
smerkli at orxonox.net
smerkli at orxonox.net
Thu Apr 7 16:18:08 CEST 2011
Author: smerkli
Date: 2011-04-07 16:18:08 +0200 (Thu, 07 Apr 2011)
New Revision: 8202
Modified:
code/branches/masterserver2/src/libraries/network/MasterServer.cc
code/branches/masterserver2/src/libraries/network/ServerList.cc
code/branches/masterserver2/src/libraries/network/ServerList.h
Log:
done for today
Modified: code/branches/masterserver2/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/masterserver2/src/libraries/network/MasterServer.cc 2011-04-07 14:11:20 UTC (rev 8201)
+++ code/branches/masterserver2/src/libraries/network/MasterServer.cc 2011-04-07 14:18:08 UTC (rev 8202)
@@ -51,7 +51,7 @@
MasterServer::helper_sendlist( ENetEvent *event )
{
/* get an iterator */
- std::list<packet::ServerInformation>::iterator i;
+ std::list<ServerListElem>::iterator i;
/* packet holder */
ENetPacket *reply;
@@ -62,14 +62,14 @@
{
/* send this particular server */
/* build reply string */
- char *tosend = (char *)calloc( (*i).getServerIP().length()
+ char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()
+ MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
if( !tosend )
{ COUT(2) << "Masterserver.cc: Memory allocation failed.\n";
continue;
}
sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM,
- (*i).getServerIP().c_str() );
+ (*i).ServerInfo.getServerIP().c_str() );
/* create packet from it */
reply = enet_packet_create( tosend,
@@ -103,30 +103,28 @@
* servers.
*/
void
- MasterServer::helper_pingServers( void )
+ MasterServer::helper_cleanupServers()
{
/* get an iterator */
- std::list<packet::ServerInformation>::iterator i;
+ std::list<ServerListElem>::iterator i;
+
/* loop through list elements */
for( i = mainlist.serverlist.begin(); i
!= mainlist.serverlist.end(); ++i )
{
- /* to be implemented, waiting for Oli to reply to my email - sandro */
-
+ if( mainlist.serverlist.size() != 0 && (*i).peer &&
+ ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
+ (*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
+ { mainlist.delServerByName( (*i).ServerInfo.getServerName() );
+ COUT(2) << "someone timed out.\n";
+ }
}
}
- void
- MasterServer::helper_cleanupServers()
- {
- /* same as above. */
- }
-
-
/***** EVENTS *****/
/* connect event */
int
@@ -164,7 +162,7 @@
}
/* output that the disconnect happened */
- COUT(4) << (char*)event->peer->data << " disconnected.\n";
+ COUT(2) << (char*)event->peer->data << " disconnected.\n";
/* create string from peer data */
std::string name = std::string( (char*)event->peer->data );
@@ -204,7 +202,8 @@
+ MSPROTO_GAME_SERVER_LEN+1,
MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
{ /* register new server */
- mainlist.addServer( packet::ServerInformation( event ) );
+ mainlist.addServer( packet::ServerInformation( event ),
+ event->peer );
/* tell people we did so */
COUT(2) << "Added new server to list: " <<
@@ -259,10 +258,6 @@
exit( EXIT_FAILURE );
}
- /* TODO schedule pings for servers somewhere here */
- /* Iterate through servers and send pings */
- helper_pingServers();
-
/* check for timed out pings and remove those guys from
* the server list
*/
Modified: code/branches/masterserver2/src/libraries/network/ServerList.cc
===================================================================
--- code/branches/masterserver2/src/libraries/network/ServerList.cc 2011-04-07 14:11:20 UTC (rev 8201)
+++ code/branches/masterserver2/src/libraries/network/ServerList.cc 2011-04-07 14:18:08 UTC (rev 8202)
@@ -39,8 +39,14 @@
}
int
- ServerList::addServer( packet::ServerInformation toadd )
- { this->serverlist.push_back( toadd );
+ ServerList::addServer( packet::ServerInformation toadd,
+ ENetPeer *peer )
+ {
+ ServerListElem toAdd;
+ toAdd.ServerInfo = toadd;
+ toAdd.peer = peer;
+
+ this->serverlist.push_back( toAdd );
return 0;
}
@@ -48,11 +54,11 @@
ServerList::delServerByName( std::string name )
{
/* get an iterator */
- std::list<packet::ServerInformation>::iterator i;
+ std::list<ServerListElem>::iterator i;
/* loop through list elements */
for( i = serverlist.begin(); i != serverlist.end(); ++i )
- if( (*i).getServerName() == name )
+ if( (*i).ServerInfo.getServerName() == name )
{ /* found this name, remove and quit */
this->serverlist.erase( i );
return true;
@@ -63,11 +69,11 @@
bool ServerList::delServerByAddress( std::string address )
{
/* get an iterator */
- std::list<packet::ServerInformation>::iterator i;
+ std::list<ServerListElem>::iterator i;
/* loop through list elements */
- for( i=serverlist.begin(); i != serverlist.end(); ++i )
- if( (*i).getServerIP() == address )
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ if( (*i).ServerInfo.getServerIP() == address )
{ /* found this name, remove and quit */
this->serverlist.erase( i );
return true;
@@ -77,9 +83,9 @@
/* sort by name */
- bool sub_compare_names( packet::ServerInformation no1,
- packet::ServerInformation no2 )
- { return no1.getServerName() > no2.getServerName(); }
+ bool sub_compare_names( ServerListElem no1,
+ ServerListElem no2 )
+ { return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); }
void ServerList::sortByName()
{
@@ -87,11 +93,10 @@
}
/* sort by ping */
- bool sub_compare_pings( packet::ServerInformation no1,
- packet::ServerInformation no2 )
+ bool sub_compare_pings( ServerListElem no1,
+ ServerListElem no2 )
{
- /* TODO */
- return no1.getServerName() > no2.getServerName();
+ return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName();
}
void ServerList::sortByPing()
Modified: code/branches/masterserver2/src/libraries/network/ServerList.h
===================================================================
--- code/branches/masterserver2/src/libraries/network/ServerList.h 2011-04-07 14:11:20 UTC (rev 8201)
+++ code/branches/masterserver2/src/libraries/network/ServerList.h 2011-04-07 14:18:08 UTC (rev 8202)
@@ -36,6 +36,15 @@
/* methods necessary */
namespace orxonox
{
+ struct ServerListElem
+ {
+ /* server information (name, IP, etc) */
+ packet::ServerInformation ServerInfo;
+
+ /* peer pointer */
+ ENetPeer* peer;
+ };
+
/** This class is keeps a list of game servers
* and some info about them.
*/
@@ -53,7 +62,8 @@
*
* Add server to the game server list
*/
- int addServer( packet::ServerInformation toadd );
+ int addServer( packet::ServerInformation toadd,
+ ENetPeer *peer );
/** \param name Name of the server to remove
*
@@ -77,7 +87,7 @@
void sortByPing();
/** the list of servers for internal storage */
- std::list<packet::ServerInformation> serverlist;
+ std::list<ServerListElem> serverlist;
private:
};
}
More information about the Orxonox-commit
mailing list