[Orxonox-commit 5767] r10427 - in code/branches/multiplayerFS15/src/libraries/network: . packet
frovelli at orxonox.net
frovelli at orxonox.net
Thu May 7 14:22:43 CEST 2015
Author: frovelli
Date: 2015-05-07 14:22:43 +0200 (Thu, 07 May 2015)
New Revision: 10427
Modified:
code/branches/multiplayerFS15/src/libraries/network/GamestateManager.h
code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc
code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h
code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc
code/branches/multiplayerFS15/src/libraries/network/MasterServerProtocol.h
code/branches/multiplayerFS15/src/libraries/network/PeerList.cc
code/branches/multiplayerFS15/src/libraries/network/PeerList.h
code/branches/multiplayerFS15/src/libraries/network/Server.cc
code/branches/multiplayerFS15/src/libraries/network/Server.h
code/branches/multiplayerFS15/src/libraries/network/ServerList.cc
code/branches/multiplayerFS15/src/libraries/network/ServerList.h
code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc
code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h
code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc
code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h
code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h
Log:
Implemented custom servernames
Modified: code/branches/multiplayerFS15/src/libraries/network/GamestateManager.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/GamestateManager.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/GamestateManager.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -1,4 +1,4 @@
-/*
+ /*
* ORXONOX - the hottest 3D action shooter ever to exist
* > www.orxonox.net <
*
@@ -77,9 +77,9 @@
bool isSynched;
std::map< uint32_t, packet::Gamestate* > gamestates;
};
-
+
public:
-
+
GamestateManager();
~GamestateManager();
@@ -87,7 +87,7 @@
virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID);
virtual uint32_t getLastReceivedGamestateID( unsigned int peerID );
virtual uint32_t getCurrentGamestateID(){ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }
-
+
bool processGamestates();
bool sendAck(unsigned int gamestateID, uint32_t peerID);
bool update();
Modified: code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -34,7 +34,10 @@
#include "util/Output.h"
#include "packet/ServerInformation.h"
+#include "core/config/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+
namespace orxonox
{
const char* LAN_DISCOVERY_MESSAGE = "Orxonox Client";
@@ -42,11 +45,23 @@
LANDiscoverable::LANDiscoverable()
{
+ /* register object in orxonox */
+ RegisterObject(LANDiscoverable);
+
+ this->setConfigValues();
+ // this->setActivity(true);
this->host_ = 0;
this->bActive_ = false;
-// this->setActivity(true);
}
+ void LANDiscoverable::setConfigValues()
+ {
+ /* update msaddress string from orxonox.ini config file, if it
+ * has changed.
+ */
+ SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213");
+ }
+
LANDiscoverable::~LANDiscoverable()
{
if( this->host_ )
@@ -60,7 +75,7 @@
{
if( bActive == this->bActive_ ) // no change
return;
-
+
if( bActive )
{
ENetAddress bindAddress;
@@ -83,11 +98,11 @@
void LANDiscoverable::update()
{
ENetEvent event;
-
+
if( this->bActive_==false )
return;
assert(this->host_);
-
+
while( enet_host_service( this->host_, &event, 0 ) > 0 )
{
switch(event.type)
@@ -103,7 +118,7 @@
{
orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl;
packet::ServerInformation info;
- info.setServerName("Orxonox Server");
+ info.setServerName(this->ownName);
info.send(event.peer);
// ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE );
// enet_peer_send(event.peer, 0, packet );
Modified: code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -30,21 +30,25 @@
#define _LANDISCOVERABLE_H__
#include "NetworkPrereqs.h"
+#include "core/config/Configurable.h"
namespace orxonox
{
- class LANDiscoverable
+ class LANDiscoverable: public Configurable
{
public:
LANDiscoverable();
virtual ~LANDiscoverable();
void setActivity( bool bActive );
void update();
+ /** Function used for the configuration file parameter update */
+ void setConfigValues();
private:
bool bActive_;
ENetHost* host_;
+ std::string ownName;
};
}
Modified: code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -33,7 +33,7 @@
#include "core/CorePrereqs.h"
#include "util/Output.h"
-namespace orxonox
+namespace orxonox
{
/*** MACROS ***/
/* commands for the terminal interface */
@@ -48,7 +48,7 @@
/* command: list servers */
- void
+ void
MasterServer::listServers( void )
{
/* get an iterator */
@@ -58,8 +58,8 @@
orxout(user_info) << "List of connected servers" << std::endl;
/* loop through list elements */
- for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
- i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
+ for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
+ i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
{
orxout(user_info) << " " << (*i).ServerInfo.getServerIP() << std::endl;
}
@@ -69,15 +69,15 @@
" servers connected." << std::endl;
}
- void
+ void
MasterServer::delServer( std::string todeladdr )
{
/* tell the user we're now removing the entry from the server list */
- orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..."
+ orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..."
<< std::endl;
/* see if we actually have that server on our list */
- ServerListSearchResult shandle =
+ ServerListSearchResult shandle =
MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr);
if( !shandle.success )
@@ -85,7 +85,7 @@
return;
}
- /* force-disconnect the server */
+ /* force-disconnect the server */
enet_peer_disconnect( shandle.result.peer, 0 );
/* actually remove the entry from the server list by address */
@@ -97,16 +97,16 @@
/* helpers */
- static void
+ static void
helper_output_debug( ENetEvent *event, char *addrconv )
{
orxout(verbose, context::master_server)
- << "A packet of length"
+ << "A packet of length"
<< event->packet->dataLength
<< " containing "
<< (const char*)event->packet->data
<< " was received from "
- << addrconv
+ << addrconv
<< " on channel "
<< event->channelID << endl;
}
@@ -121,23 +121,23 @@
ENetPacket *reply;
/* loop through list elements */
- for( i = mainlist.serverlist.begin(); i
- != mainlist.serverlist.end(); ++i )
+ for( i = mainlist.serverlist.begin(); i
+ != mainlist.serverlist.end(); ++i )
{
/* send this particular server */
/* build reply string */
- char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()
- + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
- if( !tosend )
+ int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1;
+ char *tosend = (char *)calloc(packetlen ,1 );
+ if( !tosend )
{ orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl;
continue;
- }
- sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM,
- (*i).ServerInfo.getServerIP().c_str() );
+ }
+ sprintf( tosend, "%s %s %s", MSPROTO_SERVERLIST_ITEM,
+ (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str());
/* create packet from it */
reply = enet_packet_create( tosend,
- strlen( tosend ) + 1,
+ strlen( tosend ) + 1,
ENET_PACKET_FLAG_RELIABLE);
/* Send the reply to the peer over channel id 0. */
@@ -148,7 +148,7 @@
/* free the tosend buffer */
free( tosend );
- }
+ }
/* create end-of-list packet */
reply = enet_packet_create( MSPROTO_SERVERLIST_END,
@@ -162,40 +162,40 @@
enet_host_flush( this->server );
}
- /* maybe the two methods below can be merged into one and
- * made to use ENet's RTT functionality to check for disconnected
+ /* maybe the two methods below can be merged into one and
+ * made to use ENet's RTT functionality to check for disconnected
* servers.
*/
- void
+ void
MasterServer::helper_cleanupServers( void )
{
/* get an iterator */
std::list<ServerListElem>::iterator i;
-
+
if( mainlist.serverlist.size() == 0 )
return;
/* loop through list elements */
- for( i = mainlist.serverlist.begin(); i
- != mainlist.serverlist.end(); ++i )
+ for( i = mainlist.serverlist.begin(); i
+ != mainlist.serverlist.end(); ++i )
{ /* see if we have a disconnected peer */
- if( (*i).peer &&
+ if( (*i).peer &&
((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
(*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
- {
+ {
/* Remove it from the list */
orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n";
mainlist.delServerByName( (*i).ServerInfo.getServerName() );
/* stop iterating, we manipulated the list */
/* TODO note: this only removes one dead server per loop
- * iteration. not beautiful, but one iteration is ~100ms,
+ * iteration. not beautiful, but one iteration is ~100ms,
* so not really relevant for the moment.
*/
break;
}
}
-
+
}
@@ -203,7 +203,7 @@
/***** EVENTS *****/
/* connect event */
- int
+ int
MasterServer::eventConnect( ENetEvent *event )
{ /* check for bad parameters */
if( !event )
@@ -216,20 +216,20 @@
enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
/* output debug info */
- orxout(verbose, context::master_server) << "A new client connected from "
- << addrconv
- << " on port "
+ orxout(verbose, context::master_server) << "A new client connected from "
+ << addrconv
+ << " on port "
<< event->peer->address.port << endl;
/* store string form of address here */
- event->peer->data = addrconv;
+ event->peer->data = addrconv;
/* all fine. */
return 0;
}
/* disconnect event */
- int
+ int
MasterServer::eventDisconnect( ENetEvent *event )
{ /* check for bad parameters */
if( !event )
@@ -254,14 +254,14 @@
}
/* data event */
- int
+ int
MasterServer::eventData( ENetEvent *event )
{ /* validate packet */
if( !event || !(event->packet) || !(event->peer) )
{ orxout(internal_warning, context::master_server) << "No complete event given." << endl;
return -1;
}
-
+
/* generate address in readable form */
char *addrconv = (char *) calloc( 50, 1 );
enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
@@ -270,19 +270,19 @@
helper_output_debug( event, addrconv );
/* GAME SERVER OR CLIENT CONNECTION? */
- if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER,
+ if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER,
MSPROTO_GAME_SERVER_LEN ) )
{ /* Game server */
- if( !strncmp( (char *)event->packet->data
- + MSPROTO_GAME_SERVER_LEN+1,
+ 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 ),
event->peer );
-
+
/* tell people we did so */
- orxout(internal_info, context::master_server) << "Added new server to list: " <<
+ orxout(internal_info, context::master_server) << "Added new server to list: " <<
packet::ServerInformation( event ).getServerIP() << endl;
}
@@ -291,18 +291,34 @@
MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
{
/* create string from peer data */
- std::string name = std::string( addrconv );
+ std::string ip = std::string( addrconv );
/* remove the server from the list it belongs to */
- this->mainlist.delServerByAddress( name );
+ this->mainlist.delServerByAddress( ip );
/* tell the user */
- orxout(internal_info, context::master_server) << "Removed server " << name << " from list." << endl;
+ orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl;
}
+ else if( !strncmp( (char *)event->packet->data
+ + MSPROTO_GAME_SERVER_LEN+1,
+ MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) )
+ {
+ /* create string from peer data */
+ std::string ip = std::string( addrconv );
+ std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
+ std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1);
+
+ /* remove the server from the list it belongs to */
+ this->mainlist.setNameByAddress( ip, name );
+
+ /* tell the user */
+ orxout(internal_info, context::master_server) << "Updated server " << ip << " with new name " << name << endl;
+ }
+
/* TODO add hook for disconnect here */
}
- else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
+ else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
MSPROTO_CLIENT_LEN) )
{ /* client */
if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
@@ -311,7 +327,7 @@
helper_sendlist( event );
}
else
- { /* bad message, don't do anything. */ }
+ { /* bad message, don't do anything. */ }
/* delete addrconv */
if( addrconv ) free( addrconv );
@@ -323,13 +339,13 @@
/**** MAIN ROUTINE *****/
- int
+ int
MasterServer::run()
{
/***** ENTER MAIN LOOP *****/
ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
if( event == NULL )
- {
+ {
orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl;
exit( EXIT_FAILURE );
}
@@ -344,11 +360,11 @@
/* check what type of event it is and react accordingly */
switch (event->type)
{ /* new connection */
- case ENET_EVENT_TYPE_CONNECT:
+ case ENET_EVENT_TYPE_CONNECT:
eventConnect( event ); break;
/* disconnect */
- case ENET_EVENT_TYPE_DISCONNECT:
+ case ENET_EVENT_TYPE_DISCONNECT:
eventDisconnect( event ); break;
/* incoming data */
@@ -357,8 +373,9 @@
}
/* done */
+ free(event);
return 0;
- }
+ }
/* constructor */
MasterServer::MasterServer()
@@ -379,15 +396,15 @@
this->address.host = ENET_HOST_ANY;
this->address.port = ORX_MSERVER_PORT;
- /* create a host with the above settings (the last two 0 mean: accept
+ /* create a host with the above settings (the last two 0 mean: accept
* any input/output bandwidth */
- this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS,
+ this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS,
ORX_MSERVER_MAXCHANS, 0, 0 );
assert(this->server);
/* see if creation worked */
if( !this->server )
- { orxout(user_error, context::master_server) <<
+ { orxout(user_error, context::master_server) <<
"An error occurred while trying to create an ENet server host." << endl;
exit( EXIT_FAILURE );
}
Modified: code/branches/multiplayerFS15/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/MasterServerProtocol.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/MasterServerProtocol.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -36,7 +36,7 @@
/*** CLIENT COMMUNICATIONS ***/
/* Client token (shows that the party sending data is a client */
#define MSPROTO_CLIENT "CL"
-#define MSPROTO_CLIENT_LEN 2
+#define MSPROTO_CLIENT_LEN 2
/* Request: Serverlist (requiest made from client to master server */
#define MSPROTO_REQ_LIST "REQ:LIST"
@@ -66,7 +66,7 @@
/* ping request from server */
#define MSPROTO_PING_GAMESERVER "PING"
-#define MSPROTO_PING_GAMESERVER_LEN 4
+#define MSPROTO_PING_GAMESERVER_LEN 4
/* server disconnect */
#define MSPROTO_SERVERDC "DC"
@@ -74,10 +74,16 @@
/* ping reply */
#define MSPROTO_ACK "ACK"
-#define MSPROTO_ACK_LEN 3
+#define MSPROTO_ACK_LEN 3
+#define MSPROTO_SET_NAME "NAM"
+#define MSPROTO_SET_NAME_LEN 3
+#define MSPROTO_SET_CLIENTS "CLI"
+#define MSPROTO_SET_CLIENTS_LEN 3
+#define SERVER_NAME_MAXLEN 7
+
/* default master server port */
#define ORX_MSERVER_PORT 55557
Modified: code/branches/multiplayerFS15/src/libraries/network/PeerList.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/PeerList.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/PeerList.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -37,10 +37,10 @@
PeerList::PeerList() { }
PeerList::~PeerList() { }
- int
+ int
PeerList::addPeer( ENetPeer *toadd )
{ /* error correction */
- if( toadd == NULL )
+ if( toadd == NULL )
{ orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl;
return -1;
}
@@ -51,7 +51,7 @@
}
bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
- {
+ {
for( int i = 0; i < 16; ++i )
if( addr1.host.addr[i] < addr2.host.addr[i] )
return -i;
@@ -60,15 +60,15 @@
return 0;
}
-
+
bool
PeerList::remPeerByAddr( ENetAddress addr )
{ /* get an iterator */
std::list<ENetPeer *>::iterator i;
/* loop through list elements */
- for( i = peerlist.begin(); i != peerlist.end(); ++i )
+ for( i = peerlist.begin(); i != peerlist.end(); ++i )
if( !sub_compAddr((*i)->address, addr ) )
{ /* found this name, remove and quit */
this->peerlist.remove( *i );
@@ -85,7 +85,7 @@
std::list<ENetPeer *>::iterator i;
/* loop through list elements */
- for( i = peerlist.begin(); i != peerlist.end(); ++i )
+ for( i = peerlist.begin(); i != peerlist.end(); ++i )
if( !sub_compAddr((*i)->address, addr ) )
/* found this name, remove and quit */
return *i;
@@ -94,5 +94,9 @@
return NULL;
}
+ int
+ PeerList::count(){
+ return this->peerlist.size();
+ }
+
}
-
Modified: code/branches/multiplayerFS15/src/libraries/network/PeerList.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/PeerList.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/PeerList.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -34,12 +34,12 @@
#include <enet/enet.h>
/* peer list */
-namespace orxonox
+namespace orxonox
{
- /** This class keeps a list of open connections
+ /** This class keeps a list of open connections
* and some info about them.
*/
- class PeerList
+ class PeerList
{ public:
/** constructor */
PeerList();
@@ -49,24 +49,30 @@
/** \param toadd The peer to add
* \return 0 for success, -1 for error.
- *
- * Add new peer to list
+ *
+ * Add new peer to list
*/
int addPeer( ENetPeer *toadd );
/** \param addr Address to look for
* \return if the peer was found or not
- *
- * Remove peer from list by address
+ *
+ * Remove peer from list by address
*/
bool remPeerByAddr( ENetAddress addr );
/** \param addr The address to find by
- *
- * Find a connection by address */
+ *
+ * Find a connection by address
+ */
ENetPeer *findPeerByAddr( ENetAddress addr );
- /* NOTE: making this list public so it can easily
+ /**
+ * Count current peers
+ */
+ int count();
+
+ /* NOTE: making this list public so it can easily
* be iterated. This makes sense since iterating it
* will happen all the time, and using getter methods
* for the next in list would slow things down unnecessarily.
Modified: code/branches/multiplayerFS15/src/libraries/network/Server.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/Server.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/Server.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -76,7 +76,13 @@
this->setPort( port );
this->timeSinceLastUpdate_=0;
}
-
+/*
+ Server::Server(int port, const std::string name)
+ {
+ this->setPort( port );
+ this->timeSinceLastUpdate_=0;
+ this->serverName_=name;
+ }*/
/**
* Constructor
* @param port Port to listen on
Modified: code/branches/multiplayerFS15/src/libraries/network/Server.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/Server.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/Server.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -66,6 +66,9 @@
unsigned int getRTT(unsigned int clientID);
virtual void printRTT();
float getPacketLoss(unsigned int clientID);
+ int getClientCount() { return this->clientIDs_.size();}
+ std::string getServerName() { return this->serverName_;}
+
protected:
void updateGamestate();
private:
@@ -88,6 +91,7 @@
float timeSinceLastUpdate_;
std::deque<packet::Packet*> packetQueue_;
std::vector<uint32_t> clientIDs_;
+ std::string serverName_;
};
Modified: code/branches/multiplayerFS15/src/libraries/network/ServerList.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/ServerList.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/ServerList.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -144,4 +144,18 @@
this->serverlist.sort( sub_compare_pings );
}
+ bool ServerList::setNameByAddress( std::string address, std::string name ){
+ /* get an iterator */
+ std::list<ServerListElem>::iterator i;
+
+ /* loop through list elements */
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ if( (*i).ServerInfo.getServerIP() == address )
+ { /* found this adress, rename and quit */
+ (*i).ServerInfo.setServerName( name );
+ return true;
+ }
+ return false;
+ };
+
}
Modified: code/branches/multiplayerFS15/src/libraries/network/ServerList.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/ServerList.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/ServerList.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -34,10 +34,10 @@
#include <network/packet/ServerInformation.h>
/* methods necessary */
-namespace orxonox
-{
+namespace orxonox
+{
/* HELPER STRUCTURES */
- struct ServerListElem
+ struct ServerListElem
{
/* server information (name, IP, etc) */
packet::ServerInformation ServerInfo;
@@ -62,7 +62,7 @@
/** This class is keeps a list of game servers
* and some info about them.
*/
- class ServerList
+ class ServerList
{ public:
/** constructor */
ServerList();
@@ -73,43 +73,42 @@
/* BASIC MANIPULATION */
/** \param toadd the server to add.
- *
+ *
* Add server to the game server list
*/
int addServer( packet::ServerInformation toadd,
ENetPeer *peer );
/** \param name Name of the server to remove
- *
- * Remove server by name
+ *
+ * Remove server by name
*/
bool delServerByName( std::string name );
/** \param address IP address of the server to remove
- *
+ *
* Remove server by address
*/
bool delServerByAddress( std::string address );
+ bool setNameByAddress( std::string address, std::string name );
-
-
/* SEARCHING */
- /* \param address The address of the server that is to be
+ /* \param address The address of the server that is to be
* found
* \return A struct containing a result of the search and a boolean
* that is only true if the search was successful
- *
+ *
* Find and return the list handle of a given address.
*/
ServerListSearchResult
findServerByAddress( std::string address );
- /* \param name The name of the server that is to be
+ /* \param name The name of the server that is to be
* found
* \return The struct containing the list entry of the server
- *
+ *
* Find and return the list handle of a given name.
*/
ServerListSearchResult
@@ -119,7 +118,7 @@
/* SORTING */
/** sort by name */
void sortByName();
-
+
/** sort by ping */
void sortByPing();
Modified: code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -43,35 +43,36 @@
{
/* debugging output */
orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl;
-
+
/* register object in orxonox */
RegisterObject(WANDiscoverable);
/* check for the masterserver address option in orxonox.ini */
this->setConfigValues();
-
+
}
void WANDiscoverable::setConfigValues()
{
- /* update msaddress string from orxonox.ini config file, if it
- * has changed.
+ /* update msaddress string from orxonox.ini config file, if it
+ * has changed.
*/
SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
+ SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213");
// SetConfigValue( msaddress, "orxonox.net");
- }
+ }
WANDiscoverable::~WANDiscoverable()
{
if( this->bActive_ )
this->disconnect();
}
-
+
void WANDiscoverable::setActivity(bool bActive)
{
if( bActive==this->bActive_ )
return;
-
+
if( bActive )
{
if( this->connect() )
@@ -83,7 +84,7 @@
this->bActive_ = false;
}
}
-
+
bool WANDiscoverable::connect()
{
/* initialize it and see if it worked */
@@ -92,22 +93,26 @@
orxout(internal_error, context::master_server) << "Could not initialize master server communications!" << endl;
return false;
}
-
+
/* connect and see if it worked */
if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
{
- orxout(internal_error, context::master_server) << "Could not connect to master server at "
+ orxout(internal_error, context::master_server) << "Could not connect to master server at "
<< this->msaddress << endl;
return false;
}
-
+
/* debugging output */
orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl;
-
-
+
+ std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " ";
+ request += this->ownName;
+
// Now register the server at the master server
this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
-
+ this->msc.sendRequest( request );
+
+
return true;
}
@@ -119,5 +124,5 @@
-
+
} // namespace orxonox
Modified: code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -45,30 +45,31 @@
~WANDiscoverable();
/** \return Address of the master server
- *
- * Get the master server address
+ *
+ * Get the master server address
*/
std::string getMSAddress()
{ return this->msaddress; }
/** Function used for the configuration file parameter update */
void setConfigValues();
-
+
/** Function used to set the activity/discoverability */
void setActivity( bool bActive );
/** Master server communications object */
MasterServerComm msc;
-
+
private:
/** Function used to connect to the master server */
bool connect();
-
+
/** Function used to disconnect from the master server */
void disconnect();
-
+
/** master server address */
std::string msaddress;
+ std::string ownName;
bool bActive_;
};
Modified: code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc 2015-05-07 12:22:43 UTC (rev 10427)
@@ -40,7 +40,7 @@
{
/* debugging output */
orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl;
-
+
/* register object in orxonox */
RegisterObject(WANDiscovery);
@@ -53,7 +53,7 @@
/* connect and see if it worked */
if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
- orxout(internal_error, context::master_server) << "Could not connect to master server at "
+ orxout(internal_error, context::master_server) << "Could not connect to master server at "
<< this->msaddress << endl;
/* debugging output */
@@ -62,21 +62,21 @@
void WANDiscovery::setConfigValues()
{
- /* update msaddress string from orxonox.ini config file, if it
- * has changed.
+ /* update msaddress string from orxonox.ini config file, if it
+ * has changed.
*/
SetConfigValue( msaddress, "master.orxonox.net");
- }
+ }
WANDiscovery::~WANDiscovery()
- {
+ {
/* clear server list */
- this->servers_.clear();
+ this->servers_.clear();
}
/* callback for the network reply poller */
int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
- {
+ {
/* error recognition */
if( !ev || !ev->packet || !ev->packet->data )
{ orxout(internal_warning, context::master_server) << "Bad arguments received in WANDiscovery's reply handler." << endl;
@@ -87,33 +87,33 @@
/* if a list entry arrives add to list */
if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
MSPROTO_SERVERLIST_ITEM_LEN ) )
- {
+ {
/* create server structure from that item */
packet::ServerInformation toadd;
/* fill in data, -1 for the index: index should be length -1 */
- toadd.setServerName( std::string((char*)ev->packet->data +
- MSPROTO_SERVERLIST_ITEM_LEN+1) );
- toadd.setServerIP( std::string((char*)ev->packet->data +
- MSPROTO_SERVERLIST_ITEM_LEN+1) );
+ std::string datastr = std::string((char*)ev->packet->data + MSPROTO_SERVERLIST_ITEM_LEN+1);
+ int separator = datastr.find(" ");
+ toadd.setServerIP(datastr.substr(0,separator));
+ toadd.setServerName(datastr.substr(separator+1));
/* add to list */
this->servers_.push_back( toadd );
}
else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
MSPROTO_SERVERLIST_END_LEN ) )
- {
+ {
/* this is the only case where 2 should be returned,
* as 1 is used to signal that we're done receiving
* the list
*/
- return 2;
+ return 2;
}
/* done handling, return all ok code 0 */
return 1;
}
-
+
void WANDiscovery::discover()
{
/* clear list */
@@ -130,7 +130,7 @@
switch( this->msc.pollForReply( this, 500 ) )
{ case 0: /* no event occured, decrease timeout */
--i; break;
- case 1: /* got a list element, continue */
+ case 1: /* got a list element, continue */
break;
case 2: /* done. */
i = 0; break;
@@ -158,5 +158,15 @@
return this->servers_[index].getServerIP();
}
+ std::string WANDiscovery::getServerListItemRTT(unsigned int index)
+ {
+ if( index >= this->servers_.size() )
+ return BLANKSTRING;
+ else{
+ uint32_t serverrtt = this->servers_[index].getServerRTT();
+ return Ogre::StringConverter::toString(serverrtt);
+ }
+ }
+
} // namespace orxonox
Modified: code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -34,6 +34,7 @@
#include "core/config/ConfigValueIncludes.h"
#include "MasterServerComm.h"
#include "MasterServerProtocol.h"
+#include <OgreStringConverter.h>
#include <vector>
@@ -55,8 +56,8 @@
~WANDiscovery();
/** \return Address of the master server
- *
- * Get the master server address
+ *
+ * Get the master server address
*/
std::string getMSAddress()
{ return this->msaddress; }
@@ -64,22 +65,29 @@
/** ask server for server list */
void discover(); // tolua_export
- /** \param index Index to get the name of
+ /** \param index Index to get the name of
* \return The name of the server
- *
- * Get the name of the server at index index.
+ *
+ * Get the name of the server at index index.
*/
std::string getServerListItemName( unsigned int index ); // tolua_export
- /** \param index Index to get the IP of
+ /** \param index Index to get the IP of
* \return The IP of the server
- *
- * Get the IP of the server at index index.
+ *
+ * Get the IP of the server at index index.
*/
std::string getServerListItemIP( unsigned int index ); // tolua_export
+ /** \param index Index to get the RTT of
+ * \return The RTT of the server
+ *
+ * Get the RTT of the server at index index.
+ */
+ std::string getServerListItemRTT( unsigned int index ); // tolua_export
+
/* todo: might make this private and use getter/setter methods
- * at some later time.
+ * at some later time.
*/
/** game server list */
std::vector<packet::ServerInformation> servers_;
@@ -91,7 +99,7 @@
MasterServerComm msc;
int rhandler( char *addr, ENetEvent *ev );
-
+
private:
/** master server address */
std::string msaddress;
Modified: code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h
===================================================================
--- code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h 2015-05-06 18:53:13 UTC (rev 10426)
+++ code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h 2015-05-07 12:22:43 UTC (rev 10427)
@@ -46,10 +46,10 @@
~ServerInformation();
void send( ENetPeer* peer );
- std::string getServerIP() { return this->serverIP_; }
+ void setServerName(std::string name) { this->serverName_ = name; }
std::string getServerName() { return this->serverName_; }
- void setServerName(std::string name) { this->serverName_ = name; }
void setServerIP( std::string IP ) { this->serverIP_ = IP; }
+ std::string getServerIP() { return this->serverIP_; }
uint32_t getServerRTT() { return this->serverRTT_; }
private:
More information about the Orxonox-commit
mailing list