[Orxonox-commit 1243] r5961 - code/trunk/src/libraries/network

scheusso at orxonox.net scheusso at orxonox.net
Fri Oct 16 15:38:49 CEST 2009


Author: scheusso
Date: 2009-10-16 15:38:48 +0200 (Fri, 16 Oct 2009)
New Revision: 5961

Modified:
   code/trunk/src/libraries/network/Client.cc
   code/trunk/src/libraries/network/Client.h
   code/trunk/src/libraries/network/ClientConnection.cc
   code/trunk/src/libraries/network/ClientConnection.h
   code/trunk/src/libraries/network/ClientInformation.cc
   code/trunk/src/libraries/network/Host.cc
   code/trunk/src/libraries/network/Host.h
   code/trunk/src/libraries/network/Server.cc
   code/trunk/src/libraries/network/Server.h
Log:
new ConsoleCommand: printRTT: prints the round trip time to (the server / all clients)
small change in ClientDisconnection handling (only internal)


Modified: code/trunk/src/libraries/network/Client.cc
===================================================================
--- code/trunk/src/libraries/network/Client.cc	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/Client.cc	2009-10-16 13:38:48 UTC (rev 5961)
@@ -110,6 +110,10 @@
 //    COUT(1) << "Player " << playerID << ": " << message << std::endl;
     return true;
   }
+  
+  void Client::printRTT(){
+    COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
+  }
 
   /**
    * This function implements the method of sending a chat message to the server

Modified: code/trunk/src/libraries/network/Client.h
===================================================================
--- code/trunk/src/libraries/network/Client.h	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/Client.h	2009-10-16 13:38:48 UTC (rev 5961)
@@ -71,6 +71,7 @@
     bool processChat(const std::string& message, unsigned int playerID);
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message) { return false; }
+    virtual void printRTT();
 
     void update(const Clock& time);
   protected:

Modified: code/trunk/src/libraries/network/ClientConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.cc	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/ClientConnection.cc	2009-10-16 13:38:48 UTC (rev 5961)
@@ -145,5 +145,11 @@
         // server closed the connection
     this->connectionClosed();
   }
+  
+  uint32_t ClientConnection::getRTT()
+  { 
+    assert(server_);
+    return server_->roundTripTime;
+  }
 
 }

Modified: code/trunk/src/libraries/network/ClientConnection.h
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.h	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/ClientConnection.h	2009-10-16 13:38:48 UTC (rev 5961)
@@ -54,6 +54,7 @@
     inline bool isConnected(){ return this->established_; }
   protected:
     virtual void connectionClosed()=0;
+    uint32_t getRTT();
   private:
     virtual void addPeer(ENetEvent* event);
     virtual void removePeer(ENetEvent* event);

Modified: code/trunk/src/libraries/network/ClientInformation.cc
===================================================================
--- code/trunk/src/libraries/network/ClientInformation.cc	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/ClientInformation.cc	2009-10-16 13:38:48 UTC (rev 5961)
@@ -41,6 +41,7 @@
 #include "ClientInformation.h"
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
+#include "ClientConnectionListener.h"
 
 namespace orxonox
 {
@@ -65,6 +66,7 @@
       next()->setPrev(this->prev());
     if(this==head_)
       head_=next();
+    ClientConnectionListener::broadcastClientDisconnected( this->getID() );
   }
 
   ClientInformation *ClientInformation::next() {

Modified: code/trunk/src/libraries/network/Host.cc
===================================================================
--- code/trunk/src/libraries/network/Host.cc	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/Host.cc	2009-10-16 13:38:48 UTC (rev 5961)
@@ -49,6 +49,8 @@
   clientID_=0;
   assert(instance_==0);
   instance_=this;
+  this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
+  CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
 }
 
 
@@ -58,6 +60,8 @@
 Host::~Host()
 {
   instance_=0;
+  if( this->printRTTCC_ )
+    delete this->printRTTCC_;
 }
 
 /**

Modified: code/trunk/src/libraries/network/Host.h
===================================================================
--- code/trunk/src/libraries/network/Host.h	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/Host.h	2009-10-16 13:38:48 UTC (rev 5961)
@@ -30,6 +30,7 @@
 #define _NETWORK_Host_H__
 
 #include "NetworkPrereqs.h"
+#include "core/CorePrereqs.h"
 
 namespace orxonox {
 
@@ -78,7 +79,9 @@
     static bool Chat(const std::string& message);
     static bool Broadcast(const std::string& message);
     static bool incomingChat(const std::string& message, unsigned int playerID);
+    virtual void printRTT()=0;
   private:
+    ConsoleCommand* printRTTCC_;
 };
 
 }

Modified: code/trunk/src/libraries/network/Server.cc
===================================================================
--- code/trunk/src/libraries/network/Server.cc	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/Server.cc	2009-10-16 13:38:48 UTC (rev 5961)
@@ -163,10 +163,16 @@
   /**
    * @brief: returns ping time to client in milliseconds 
    */
-  unsigned int Server::getPing(unsigned int clientID){
+  unsigned int Server::getRTT(unsigned int clientID){
     assert(ClientInformation::findClient(clientID));
     return ClientInformation::findClient(clientID)->getRTT();
   }
+  
+  void Server::printRTT()
+  {
+    for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
+      COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
+  }
 
   /**
    * @brief: return packet loss ratio to client (scales from 0 to 1)
@@ -298,7 +304,7 @@
     else
     {
       //ServerConnection::disconnectClient( client );
-      ClientConnectionListener::broadcastClientDisconnected( client->getID() );
+      //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
       delete client;
     }
   }
@@ -342,7 +348,7 @@
     ServerConnection::disconnectClient( client );
     GamestateManager::removeClient(client);
     // inform all the listeners
-    ClientConnectionListener::broadcastClientDisconnected(client->getID());
+    // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
   }
 
   bool Server::chat(const std::string& message){

Modified: code/trunk/src/libraries/network/Server.h
===================================================================
--- code/trunk/src/libraries/network/Server.h	2009-10-16 09:26:52 UTC (rev 5960)
+++ code/trunk/src/libraries/network/Server.h	2009-10-16 13:38:48 UTC (rev 5961)
@@ -56,7 +56,8 @@
     bool processChat(const std::string& message, unsigned int playerID);
     bool queuePacket(ENetPacket *packet, int clientID);
     void update(const Clock& time);
-    unsigned int getPing(unsigned int clientID);
+    unsigned int getRTT(unsigned int clientID);
+    virtual void printRTT();
     double getPacketLoss(unsigned int clientID);
   protected:
     void updateGamestate();




More information about the Orxonox-commit mailing list