[Orxonox-commit 2454] r7161 - in code/branches/presentation3: data/gui/layouts data/gui/scripts src/libraries/network src/libraries/network/packet src/libraries/network/synchronisable src/libraries/util src/orxonox src/orxonox/gamestates

scheusso at orxonox.net scheusso at orxonox.net
Wed Jul 28 20:29:33 CEST 2010


Author: scheusso
Date: 2010-07-28 20:29:32 +0200 (Wed, 28 Jul 2010)
New Revision: 7161

Added:
   code/branches/presentation3/src/libraries/network/LANDiscoverable.cc
   code/branches/presentation3/src/libraries/network/LANDiscoverable.h
   code/branches/presentation3/src/libraries/network/LANDiscovery.cc
   code/branches/presentation3/src/libraries/network/LANDiscovery.h
   code/branches/presentation3/src/libraries/network/packet/ServerInformation.cc
   code/branches/presentation3/src/libraries/network/packet/ServerInformation.h
Modified:
   code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout
   code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua
   code/branches/presentation3/src/libraries/network/CMakeLists.txt
   code/branches/presentation3/src/libraries/network/Client.cc
   code/branches/presentation3/src/libraries/network/Client.h
   code/branches/presentation3/src/libraries/network/Connection.cc
   code/branches/presentation3/src/libraries/network/Connection.h
   code/branches/presentation3/src/libraries/network/Host.cc
   code/branches/presentation3/src/libraries/network/Host.h
   code/branches/presentation3/src/libraries/network/NetworkPrereqs.h
   code/branches/presentation3/src/libraries/network/Server.cc
   code/branches/presentation3/src/libraries/network/Server.h
   code/branches/presentation3/src/libraries/network/ServerConnection.cc
   code/branches/presentation3/src/libraries/network/ServerConnection.h
   code/branches/presentation3/src/libraries/network/packet/CMakeLists.txt
   code/branches/presentation3/src/libraries/network/packet/Packet.cc
   code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc
   code/branches/presentation3/src/libraries/util/Serialise.h
   code/branches/presentation3/src/orxonox/CameraManager.cc
   code/branches/presentation3/src/orxonox/Main.cc
   code/branches/presentation3/src/orxonox/gamestates/GSClient.cc
   code/branches/presentation3/src/orxonox/gamestates/GSClient.h
Log:
some new features:
-Orxonox servers announce themselves now inside a LAN (and can provide some information (e.g. server name, etc.) to the client )
-Orxonox clients discover the servers inside the LAN and list them in the menu


Modified: code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout
===================================================================
--- code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout	2010-07-28 18:29:32 UTC (rev 7161)
@@ -15,7 +15,7 @@
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
             <Property Name="VertFormatting" Value="TopAligned" />
             <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.6375,0}}" />
-            <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerLevelListbox" >
+            <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerListbox" >
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.8,0}}" />
             </Window>

Modified: code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua	2010-07-28 18:29:32 UTC (rev 7161)
@@ -3,8 +3,74 @@
 local P = createMenuSheet("MultiplayerMenu")
 
 function P.onLoad()
-    listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
-    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
+    P.multiplayerMode = "startClient"
+end
+
+function P.onShow()
+    if P.multiplayerMode == "startClient" then
+        local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+        P.showServerList()
+    end
+    if P.multiplayerMode == "startServer" then
+        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+        P.showLevelList()
+    end
+    if P.multiplayerMode == "startDedicated" then
+        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+        P.showLevelList()
+    end
+end
+
+function P.MultiplayerJoinButton_clicked(e)
+    P.multiplayerMode = "startClient"
+    P.showServerList()
+end
+
+function P.MultiplayerHostButton_clicked(e)
+    P.multiplayerMode = "startServer"
+    P.showLevelList()
+end
+
+function P.MultiplayerDedicatedButton_clicked(e)
+    P.multiplayerMode = "startDedicated"
+    P.showLevelList()
+end
+
+function P.MultiplayerStartButton_clicked(e)
+    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
+    if P.multiplayerMode == "startClient" then
+        if choice then
+            local client = orxonox.Client:getInstance()
+            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
+            client:setDestination( P.serverList[index][2], 55556 )
+        else
+            return
+        end
+    else
+        if choice then
+            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
+        else
+            return
+        end
+    end
+    orxonox.execute(P.multiplayerMode)
+    hideAllMenuSheets()
+end
+
+function P.MultiplayerBackButton_clicked(e)
+    hideMenuSheet(P.name)
+end
+
+function P.showLevelList()
+    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
+    CEGUI.toListbox(listbox):resetList()
+    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     orxonox.LevelManager:getInstance():compileAvailableLevelList()
     local levelList = {}
     local index = 0
@@ -18,56 +84,49 @@
         index = index + 1
     end
     table.sort(levelList)
+    index = 1
     for k,v in pairs(levelList) do
-        item = CEGUI.createListboxTextItem(v)
+        local item = CEGUI.createListboxTextItem(v)
         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+        item:setID(index)
+        index = index + 1
         CEGUI.toListbox(listbox):addItem(item)
         if v .. ".oxw" == preselect then
             listbox:setItemSelectState(item, true)
         end
     end
-    local multiplayerMode = "startClient"
-    if multiplayerMode == "startClient" then
-        window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
-        button:setSelected(true)
     end
-    if multiplayerMode == "startServer" then
-        window = winMgr:getWindow("orxonox/MultiplayerHostButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
-        button:setSelected(true)
+    
+function P.showServerList()
+    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
+    CEGUI.toListbox(listbox):resetList()
+    local discovery = orxonox.LANDiscovery:getInstance()
+    discovery:discover()
+    P.serverList = {}
+    local index = 0
+    local servername = ""
+    local serverip = ""
+    while true do
+        servername = discovery:getServerListItemName(index)
+        if servername == "" then
+            break
+        end
+        serverip = discovery:getServerListItemIP(index)
+        if serverip == "" then
+          break
+        end
+        table.insert(P.serverList, {servername, serverip})
+        index = index + 1
     end
-    if multiplayerMode == "startDedicated" then
-        window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
-        button:setSelected(true)
+    index = 1
+    for k,v in pairs(P.serverList) do
+        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
+        item:setID(index)
+        index = index + 1
+        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+        CEGUI.toListbox(listbox):addItem(item)
     end
 end
 
-function P.MultiplayerJoinButton_clicked(e)
-    multiplayerMode = "startClient"
-end
-
-function P.MultiplayerHostButton_clicked(e)
-    multiplayerMode = "startServer"
-end
-
-function P.MultiplayerDedicatedButton_clicked(e)
-    multiplayerMode = "startDedicated"
-end
-
-function P.MultiplayerStartButton_clicked(e)
-    local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem()
-    if choice then
-        orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
-        orxonox.execute(multiplayerMode)
-        hideAllMenuSheets()
-    end
-end
-
-function P.MultiplayerBackButton_clicked(e)
-    hideMenuSheet(P.name)
-end
-
 return P
 

Modified: code/branches/presentation3/src/libraries/network/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/libraries/network/CMakeLists.txt	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/CMakeLists.txt	2010-07-28 18:29:32 UTC (rev 7161)
@@ -28,6 +28,8 @@
   GamestateManager.cc
   GamestateClient.cc
   GamestateHandler.cc
+  LANDiscoverable.cc
+  LANDiscovery.cc
   NetworkFunction.cc
   Host.cc
   Server.cc
@@ -47,6 +49,8 @@
   GamestateHandler.h
   GamestateManager.h
   Host.h
+  LANDiscoverable.h
+  LANDiscovery.h
   NetworkFunction.h
   NetworkPrecompiledHeaders.h
   NetworkPrereqs.h
@@ -59,6 +63,9 @@
 ADD_SUBDIRECTORY(synchronisable)
 
 ORXONOX_ADD_LIBRARY(network
+  TOLUA_FILES
+    Client.h
+    LANDiscovery.h
   PCH_FILE
     NetworkPrecompiledHeaders.h
   LINK_LIBRARIES

Modified: code/branches/presentation3/src/libraries/network/Client.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/Client.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Client.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -49,38 +49,30 @@
 #include "packet/Gamestate.h"
 #include "FunctionCallManager.h"
 #include "core/CoreIncludes.h"
+#include "core/CommandLineParser.h"
 #include "core/Game.h"
+#include "core/ScopedSingletonManager.h"
 
 namespace orxonox
 {
 
+  ManageScopedSingleton( Client, ScopeID::Root, true );
 
   /**
   * Constructor for the Client class
   * initializes the address and the port to default localhost:NETWORK_PORT
   */
   Client::Client():
+      gamestate(0),
       isSynched_(false),
       gameStateFailure_(false),
       timeSinceLastUpdate_(0)
   {
+    this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
   }
 
-  /**
-  * Constructor for the Client class
-  * @param address the server address
-  * @param port port of the application on the server
-  */
-  Client::Client(const std::string& address, int port):
-      isSynched_(false),
-      gameStateFailure_(false),
-      timeSinceLastUpdate_(0)
+  Client::~Client()
   {
-      setPort( port );
-      setServerAddress( address );
-  }
-
-  Client::~Client(){
     if ( ClientConnection::isConnected() )
       closeConnection();
   }
@@ -89,31 +81,53 @@
   * Establish the Connection to the Server
   * @return true/false
   */
-  bool Client::establishConnection(){
+  bool Client::establishConnection()
+  {
     Synchronisable::setClient(true);
-    return ClientConnection::establishConnection();
+    this->gamestate = new GamestateClient();
+    if( ClientConnection::establishConnection() )
+    {
+      Host::setActive(true);
+      return true;
+    }
+    else
+      return false;
   }
 
   /**
   * closes the Connection to the Server
   * @return true/false
   */
-  bool Client::closeConnection(){
+  bool Client::closeConnection()
+  {
+    assert(this->gamestate);
+    delete this->gamestate;
+    this->gamestate = 0;
+    Host::setActive(false);
     return ClientConnection::closeConnection();
   }
+  
+  void Client::setDestination(const std::string& serverAddress, unsigned int port)
+  {
+    ClientConnection::setServerAddress(serverAddress);
+    ClientConnection::setPort(port);
+  }
 
-  bool Client::queuePacket(ENetPacket *packet, int clientID){
+  bool Client::queuePacket(ENetPacket *packet, int clientID)
+  {
     bool b = ClientConnection::addPacket(packet);
     assert(b);
     return b;
   }
 
-  bool Client::processChat(const std::string& message, unsigned int playerID){
+  bool Client::processChat(const std::string& message, unsigned int playerID)
+  {
 //    COUT(1) << "Player " << playerID << ": " << message << std::endl;
     return true;
   }
 
-  void Client::printRTT(){
+  void Client::printRTT()
+  {
     COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
   }
 
@@ -122,7 +136,8 @@
    * @param message message to be sent
    * @return result(true/false)
    */
-  bool Client::chat(const std::string& message){
+  bool Client::chat(const std::string& message)
+  {
     packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
     return m->send();
   }
@@ -132,7 +147,8 @@
    * Processes incoming packets, sends a gamestate to the server and does the cleanup
    * @param time
    */
-  void Client::update(const Clock& time){
+  void Client::update(const Clock& time)
+  {
     //this steers our network frequency
     timeSinceLastUpdate_+=time.getDeltaTime();
     if(timeSinceLastUpdate_>=NETWORK_PERIOD)
@@ -142,7 +158,7 @@
       if ( isConnected() && isSynched_ )
       {
         COUT(4) << "popping partial gamestate: " << std::endl;
-        packet::Gamestate *gs = gamestate.getGamestate();
+        packet::Gamestate *gs = gamestate->getGamestate();
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
         if(gs){
           COUT(4) << "client tick: sending gs " << gs << std::endl;
@@ -156,12 +172,12 @@
     sendPackets(); // flush the enet queue
 
     Connection::processQueue();
-    if(gamestate.processGamestates())
+    if(gamestate->processGamestates())
     {
       if(!isSynched_)
         isSynched_=true;
     }
-    gamestate.cleanup();
+    gamestate->cleanup();
     Connection::sendPackets();
 
     return;
@@ -183,4 +199,6 @@
     Game::getInstance().popState();
   }
 
+
+
 }

Modified: code/branches/presentation3/src/libraries/network/Client.h
===================================================================
--- code/branches/presentation3/src/libraries/network/Client.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Client.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -46,12 +46,17 @@
 #include <string>
 
 #include "util/UtilPrereqs.h"
+#include "util/Singleton.h"
 #include "ClientConnection.h"
 #include "GamestateClient.h"
 #include "Host.h"
+#include "LANDiscovery.h"
+#include "packet/ServerInformation.h"
 
+// tolua_begin
 namespace orxonox
 {
+// tolua_end
   /**
   Client *client;
   * The network/Client class
@@ -59,13 +64,18 @@
   * It is the root class of the network module
   *
   */
-  class _NetworkExport Client : public Host, public ClientConnection{
+  class _NetworkExport Client // tolua_export
+    : public Host, protected ClientConnection, public Singleton<Client>
+  { // tolua_export
+  friend class Singleton<Client>;
   public:
     Client();
-    Client(const std::string& address, int port);
     ~Client();
+    
+    static Client* getInstance(){ return singletonPtr_s; } // tolua_export
 
     bool establishConnection();
+    void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
     bool closeConnection();
     bool queuePacket(ENetPacket *packet, int clientID);
     bool processChat(const std::string& message, unsigned int playerID);
@@ -80,14 +90,15 @@
     Client(const Client& copy); // not used
     virtual bool isServer_(){return false;}
 
-    GamestateClient gamestate;
+    static Client* singletonPtr_s;
+    GamestateClient* gamestate;
     bool isSynched_;
 
     bool gameStateFailure_;
     float timeSinceLastUpdate_;
-  };
+  }; // tolua_export
 
 
-}
+} // tolua_export
 
 #endif /* _Client_H__ */

Modified: code/branches/presentation3/src/libraries/network/Connection.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/Connection.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Connection.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -35,19 +35,19 @@
 
 namespace orxonox
 {
-  Connection *Connection::instance_=0;
+//   Connection *Connection::instance_=0;
 
   Connection::Connection():
     host_(0)
   {
-    assert(instance_==0);
-    Connection::instance_=this;
+//     assert(instance_==0);
+//     Connection::instance_=this;
     enet_initialize();
     atexit(enet_deinitialize);
   }
 
   Connection::~Connection(){
-    Connection::instance_=0;
+//     Connection::instance_=0;
   }
 
   int Connection::service(ENetEvent* event) {
@@ -66,7 +66,7 @@
   }
 
   bool Connection::sendPackets() {
-    if ( !Connection::instance_ || this->host_==NULL )
+    if ( /*!Connection::instance_ || */this->host_==NULL )
       return false;
     enet_host_flush(this->host_);
     return true;

Modified: code/branches/presentation3/src/libraries/network/Connection.h
===================================================================
--- code/branches/presentation3/src/libraries/network/Connection.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Connection.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -60,7 +60,7 @@
 
   protected:
     Connection();
-    static Connection* getInstance(){ return Connection::instance_; }
+//     static Connection* getInstance(){ return Connection::instance_; }
 
     int service(ENetEvent* event);
     virtual void disconnectPeer(ENetPeer *peer);
@@ -74,7 +74,7 @@
   private:
     ENetAddress *bindAddress_;
 
-    static Connection *instance_;
+//     static Connection *instance_;
 
   };
 

Modified: code/branches/presentation3/src/libraries/network/Host.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/Host.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Host.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -37,82 +37,128 @@
 
 namespace orxonox {
 
-SetConsoleCommandShortcut(Host, Chat);
+  SetConsoleCommandShortcut(Host, Chat);
 
-Host *Host::instance_=0;
+  // Host*               Host::instance_=0;
+  uint32_t            Host::clientID_s=0;
+  uint32_t            Host::shipID_s=-1;
+  std::vector<Host*>  Host::instances_s;
 
-/**
- * @brief Constructor: assures that only one reference will be created and sets the pointer
- */
-Host::Host()
-{
-  clientID_=0;
-  assert(instance_==0);
-  instance_=this;
-  this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
-  CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
-}
+  /**
+  * @brief Constructor: assures that only one reference will be created and sets the pointer
+  */
+  Host::Host()
+  {
+  //   assert(instance_==0);
+    instances_s.push_back(this);
+    this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
+    CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
+    this->bIsActive_ = false;
+  }
 
 
-/**
- * @brief Destructor: resets the instance pointer to 0
- */
-Host::~Host()
-{
-  instance_=0;
-  if( this->printRTTCC_ )
-    delete this->printRTTCC_;
-}
+  /**
+  * @brief Destructor: resets the instance pointer to 0
+  */
+  Host::~Host()
+  {
+    assert( std::find( instances_s.begin(), instances_s.end(), this )!=instances_s.end() );
+    instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this ));
+    if( this->printRTTCC_ )
+      delete this->printRTTCC_;
+  }
 
-/**
- * This function is used to add an enetpacket to be sent to another peer
- * @param packet Packet to be added
- * @param clientID ID of the client the packet should be sent to
- * @return success?
- */
-bool Host::addPacket(ENetPacket *packet, int clientID){
-  if(instance_)
-    return instance_->queuePacket(packet, clientID);
-  else
-    return false;
-}
+  /**
+  * This function is used to add an enetpacket to be sent to another peer
+  * @param packet Packet to be added
+  * @param clientID ID of the client the packet should be sent to
+  * @return success?
+  */
+  bool Host::addPacket(ENetPacket *packet, int clientID)
+  {
+    bool result = true;
+    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
+    {
+      if( (*it)->isActive() )
+      {
+        if( !(*it)->queuePacket(packet, clientID) )
+          result = false;
+      }
+    }
+    return result;
+  }
 
-/**
- * This function returns the ID of the player
- * @return playerID
- */
-unsigned int Host::getPlayerID(){
-  if(!instance_)
-    return 0;
-  return instance_->clientID_;
-}
+  bool Host::Chat(const std::string& message)
+  {
+    if(instances_s.size()==0)
+    {
+      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
+        it->incomingChat(message, 0);
+      return true;
+    }
+    else
+    {
+      bool result = true;
+      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
+      {
+        if( (*it)->isActive() )
+        {
+          if( !(*it)->chat(message) )
+            result = false;
+        }
+      }
+      return result;
+    }
+  }
 
-bool Host::Chat(const std::string& message){
-  if(!instance_)
+  bool Host::Broadcast(const std::string& message)
   {
-    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, 0);
-    return true;
+    if(instances_s.size()==0)
+    {
+      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
+        it->incomingChat(message, CLIENTID_UNKNOWN);
+      return true;
+    }
+    else
+    {
+      bool result = true;
+      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
+      {
+        if( (*it)->isActive() )
+        {
+          if( !(*it)->broadcast(message) )
+            result = false;
+        }
+      }
+      return result;
+    }
   }
-  return instance_->chat(message);
-}
 
-bool Host::Broadcast(const std::string& message){
-  if(!instance_)
+  bool Host::incomingChat(const std::string& message, unsigned int playerID)
   {
     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, CLIENTID_UNKNOWN);
-    return true;
+      it->incomingChat(message, playerID);
+    
+    bool result = true;
+    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
+    {
+      if( (*it)->isActive() )
+      {
+        if( !(*it)->processChat(message, playerID) )
+          result = false;
+      }
+    }
+    return result;
   }
-  else
-    return instance_->broadcast(message);
-}
 
-bool Host::incomingChat(const std::string& message, unsigned int playerID){
-  for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-    it->incomingChat(message, playerID);
+  bool Host::isServer()
+  {
+    for (std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it )
+    {
+      if( (*it)->isServer_() )
+        return true;
+    }
+    return false;
+  }
 
-  return instance_->processChat(message, playerID);
-}
-
 }//namespace orxonox

Modified: code/branches/presentation3/src/libraries/network/Host.h
===================================================================
--- code/branches/presentation3/src/libraries/network/Host.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Host.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -32,6 +32,8 @@
 #include "NetworkPrereqs.h"
 #include "core/CorePrereqs.h"
 
+#include <vector>
+
 namespace orxonox {
 
   const unsigned int CLIENTID_SERVER = 0;
@@ -62,26 +64,31 @@
   protected:
     Host();
     virtual ~Host();
-    static Host *instance_;
-    unsigned int clientID_;
-    unsigned int shipID_;
+    void setActive( bool bActive ){ bIsActive_ = bActive; }
+//     static Host *instance_;
 
   public:
-    static bool running(){return instance_!=0;}
+//     static Host* getInstance(){ return instance_; }
+    static bool running(){ return instances_s.size(); }
     static bool addPacket(ENetPacket *packet, int clientID=0);
     //static bool chat(std::string& message);
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
-    static unsigned int getPlayerID();
-    static unsigned int getShipID(){return instance_->shipID_;}
-    static void setClientID(unsigned int id){ instance_->clientID_ = id; }
-    static void setShipID(unsigned int id){ instance_->shipID_ = id; }
-    static bool isServer(){ return instance_->isServer_(); }
+    static unsigned int getPlayerID(){ return clientID_s; }
+    static unsigned int getShipID(){return shipID_s;}
+    static void setClientID(unsigned int id){ clientID_s = id; }
+    static void setShipID(unsigned int id){ shipID_s = id; }
+    static bool isServer();
     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;
+    bool isActive(){ return bIsActive_; }
   private:
     ConsoleCommand* printRTTCC_;
+    static uint32_t clientID_s;
+    static uint32_t shipID_s;
+    static std::vector<Host*> instances_s;
+    bool bIsActive_;
 };
 
 }

Added: code/branches/presentation3/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/LANDiscoverable.cc	                        (rev 0)
+++ code/branches/presentation3/src/libraries/network/LANDiscoverable.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -0,0 +1,109 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "LANDiscoverable.h"
+
+#include "NetworkPrereqs.h"
+#include "packet/ServerInformation.h"
+
+#include <enet/enet.h>
+#include <cassert>
+#include <cstring>
+
+namespace orxonox
+{
+  const char* LAN_DISCOVERY_MESSAGE = "Orxonox Client";
+  const char* LAN_DISCOVERY_ACK     = "Orxonox Server Ack";
+
+  LANDiscoverable::LANDiscoverable()
+  {
+    this->host_ = 0;
+    this->bActive_ = false;
+    this->setActivity(true);
+  }
+
+  LANDiscoverable::~LANDiscoverable()
+  {
+    if( this->host_ )
+    {
+      enet_host_destroy( this->host_ );
+      assert( this->bActive_ );
+    }
+  }
+
+  void LANDiscoverable::setActivity(bool bActive)
+  {
+    if( bActive == this->bActive_ )        // no change
+      return;
+    
+    if( bActive )
+    {
+      ENetAddress bindAddress = { ENET_HOST_ANY, LAN_DISCOVERY_PORT };
+      assert( this->host_ == 0 );
+      this->host_ = enet_host_create( &bindAddress, 10, 0, 0 );
+    }
+    else
+    {
+      enet_host_destroy( this->host_ );
+      this->host_ = 0;
+    }
+      this->bActive_ = bActive;
+  }
+
+  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)
+      {
+        case ENET_EVENT_TYPE_CONNECT:
+        case ENET_EVENT_TYPE_DISCONNECT:
+        case ENET_EVENT_TYPE_NONE:
+          break;
+        case ENET_EVENT_TYPE_RECEIVE:
+          if( strcmp( LAN_DISCOVERY_MESSAGE, (char*)event.packet->data ) == 0 )      // check for a suitable orxonox client
+          {
+            packet::ServerInformation info;
+            info.setServerName("Orxonox Server");
+            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 );
+            enet_host_flush(this->host_);
+          }
+          break;
+      }
+    }
+  }
+
+}

Added: code/branches/presentation3/src/libraries/network/LANDiscoverable.h
===================================================================
--- code/branches/presentation3/src/libraries/network/LANDiscoverable.h	                        (rev 0)
+++ code/branches/presentation3/src/libraries/network/LANDiscoverable.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -0,0 +1,52 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _LANDISCOVERABLE_H__
+#define _LANDISCOVERABLE_H__
+
+#include "NetworkPrereqs.h"
+
+namespace orxonox
+{
+  
+  class LANDiscoverable
+  {
+    public:
+      LANDiscoverable();
+      ~LANDiscoverable();
+      void setActivity( bool bActive );
+      void update();
+      
+    private:
+      bool            bActive_;
+      ENetHost*       host_;
+  };
+
+}
+
+#endif // LANDISCOVERABLE_H

Added: code/branches/presentation3/src/libraries/network/LANDiscovery.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/LANDiscovery.cc	                        (rev 0)
+++ code/branches/presentation3/src/libraries/network/LANDiscovery.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -0,0 +1,113 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "LANDiscovery.h"
+
+#include <enet/enet.h>
+#include <cstring>
+
+#include "core/CoreIncludes.h"
+#include "core/ScopedSingletonManager.h"
+
+
+namespace orxonox
+{ 
+  ManageScopedSingleton(LANDiscovery, ScopeID::Root, true);
+  
+  LANDiscovery::LANDiscovery()
+  {
+    this->host_ = enet_host_create(NULL, 10, 0, 0 );
+  }
+
+  LANDiscovery::~LANDiscovery()
+  {
+    enet_host_destroy(this->host_);
+  }
+  
+  void LANDiscovery::discover()
+  {
+    this->servers_.clear();
+    ENetAddress address;
+    enet_address_set_host(&address, "255.255.255.255");
+    address.port = LAN_DISCOVERY_PORT;
+    
+    ENetPeer* peer;
+    peer = enet_host_connect(this->host_, &address, 0);
+    
+    ENetEvent event;
+    while( enet_host_service(this->host_, &event, 1000 ) )
+    {
+      switch( event.type )
+      {
+        case ENET_EVENT_TYPE_CONNECT:
+        {
+          COUT(0) << "connect from server: " << event.peer->address.host << endl;
+          ENetPacket* packet = enet_packet_create(LAN_DISCOVERY_MESSAGE, strlen(LAN_DISCOVERY_MESSAGE)+1, ENET_PACKET_FLAG_RELIABLE);
+          enet_peer_send(event.peer, 0, packet);
+          break;
+        }
+        case ENET_EVENT_TYPE_RECEIVE:
+          {
+            packet::ServerInformation info(&event);
+            COUT(0) << "received server information; name: " << info.getServerName() << ", IP: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
+            std::vector<packet::ServerInformation>::iterator it;
+            for( it=this->servers_.begin(); it!=this->servers_.end(); ++it )
+            {
+              if( (*it).getServerIP() == info.getServerIP() )
+                break;
+            }
+            if( it==this->servers_.end() )
+              this->servers_.push_back(info);
+          }
+//           enet_address_get_host_ip(&event.peer->address, buffer, buflen );
+//           serverIPs.push_back(std::string(buffer));
+          break;
+        default:
+          break;
+      }
+    }
+  }
+  
+  std::string LANDiscovery::getServerListItemName(unsigned int index)
+  {
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else
+      return this->servers_[index].getServerName();
+  }
+  
+  std::string LANDiscovery::getServerListItemIP(unsigned int index)
+  {
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else
+      return this->servers_[index].getServerIP();
+  }
+  
+  
+} // namespace orxonox

Added: code/branches/presentation3/src/libraries/network/LANDiscovery.h
===================================================================
--- code/branches/presentation3/src/libraries/network/LANDiscovery.h	                        (rev 0)
+++ code/branches/presentation3/src/libraries/network/LANDiscovery.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -0,0 +1,63 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef LANDISCOVERY_H
+#define LANDISCOVERY_H
+
+#include "NetworkPrereqs.h"
+#include "packet/ServerInformation.h"
+#include "util/Singleton.h"
+
+#include <vector>
+
+// tolua_begin
+namespace orxonox
+{
+
+  class _NetworkExport LANDiscovery
+// tolua_end
+    : public Singleton<LANDiscovery>
+  { // tolua_export
+    friend class Singleton<LANDiscovery>;
+    public:
+      LANDiscovery();
+      ~LANDiscovery();
+      void discover(); // tolua_export
+      std::string getServerListItemName( unsigned int index ); // tolua_export
+      std::string getServerListItemIP( unsigned int index ); // tolua_export
+      static LANDiscovery& getInstance(){ return Singleton<LANDiscovery>::getInstance(); } // tolua_export
+      
+    private:
+      static LANDiscovery* singletonPtr_s;
+      ENetHost* host_;
+      std::vector<packet::ServerInformation> servers_;
+  }; // tolua_export
+
+} // tolua_export
+
+#endif // LANDISCOVERY_H

Modified: code/branches/presentation3/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/branches/presentation3/src/libraries/network/NetworkPrereqs.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/NetworkPrereqs.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -63,8 +63,11 @@
 
 namespace orxonox
 {
-  static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
-  static const unsigned int CLIENTID_UNKNOWN    = static_cast<unsigned int>(-2);
+  static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
+  static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
+  extern const char* LAN_DISCOVERY_MESSAGE;
+  extern const char* LAN_DISCOVERY_ACK;
+  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
 }
 
 //-----------------------------------------------------------------------

Modified: code/branches/presentation3/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/Server.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Server.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -68,11 +68,13 @@
   * Constructor for default values (bindaddress is set to ENET_HOST_ANY
   *
   */
-  Server::Server() {
+  Server::Server()
+  {
     this->timeSinceLastUpdate_=0;
   }
 
-  Server::Server(int port){
+  Server::Server(int port)
+  {
     this->setPort( port );
     this->timeSinceLastUpdate_=0;
   }
@@ -82,7 +84,8 @@
   * @param port Port to listen on
   * @param bindAddress Address to listen on
   */
-  Server::Server(int port, const std::string& bindAddress) {
+  Server::Server(int port, const std::string& bindAddress)
+  {
     this->setPort( port );
     this->setBindAddress( bindAddress );
     this->timeSinceLastUpdate_=0;
@@ -91,29 +94,37 @@
   /**
   * @brief Destructor
   */
-  Server::~Server(){
+  Server::~Server()
+  {
   }
 
   /**
   * This function opens the server by creating the listener thread
   */
-  void Server::open() {
+  void Server::open()
+  {
+    Host::setActive(true);
     COUT(4) << "opening server" << endl;
     this->openListener();
+    LANDiscoverable::setActivity(true);
     return;
   }
 
   /**
   * This function closes the server
   */
-  void Server::close() {
+  void Server::close()
+  {
+    Host::setActive(false);
     COUT(4) << "closing server" << endl;
     this->disconnectClients();
     this->closeListener();
+    LANDiscoverable::setActivity(false);
     return;
   }
 
-  bool Server::processChat(const std::string& message, unsigned int playerID){
+  bool Server::processChat(const std::string& message, unsigned int playerID)
+  {
     ClientInformation *temp = ClientInformation::getBegin();
     packet::Chat *chat;
     while(temp){
@@ -133,9 +144,12 @@
   * calls processQueue and updateGamestate
   * @param time time since last tick
   */
-  void Server::update(const Clock& time) {
+  void Server::update(const Clock& time)
+  {
     // receive incoming packets
     Connection::processQueue();
+    // receive and process incoming discovery packets
+    LANDiscoverable::update();
 
     if ( ClientInformation::hasClients() )
     {
@@ -156,14 +170,16 @@
     }
   }
 
-  bool Server::queuePacket(ENetPacket *packet, int clientID){
+  bool Server::queuePacket(ENetPacket *packet, int clientID)
+  {
     return ServerConnection::addPacket(packet, clientID);
   }
 
   /**
    * @brief: returns ping time to client in milliseconds
    */
-  unsigned int Server::getRTT(unsigned int clientID){
+  unsigned int Server::getRTT(unsigned int clientID)
+  {
     assert(ClientInformation::findClient(clientID));
     return ClientInformation::findClient(clientID)->getRTT();
   }
@@ -177,7 +193,8 @@
   /**
    * @brief: return packet loss ratio to client (scales from 0 to 1)
    */
-  double Server::getPacketLoss(unsigned int clientID){
+  double Server::getPacketLoss(unsigned int clientID)
+  {
     assert(ClientInformation::findClient(clientID));
     return ClientInformation::findClient(clientID)->getPacketLoss();
   }
@@ -185,7 +202,8 @@
   /**
   * takes a new snapshot of the gamestate and sends it to the clients
   */
-  void Server::updateGamestate() {
+  void Server::updateGamestate()
+  {
     if( ClientInformation::getBegin()==NULL )
       //no client connected
       return;
@@ -207,7 +225,8 @@
   /**
   * sends the gamestate
   */
-  bool Server::sendGameState() {
+  bool Server::sendGameState()
+  {
 //     COUT(5) << "Server: starting function sendGameState" << std::endl;
 //     ClientInformation *temp = ClientInformation::getBegin();
 //     bool added=false;
@@ -243,7 +262,8 @@
     return true;
   }
 
-  bool Server::sendObjectDeletes(){
+  bool Server::sendObjectDeletes()
+  {
     ClientInformation *temp = ClientInformation::getBegin();
     if( temp == NULL )
       //no client connected
@@ -256,7 +276,8 @@
     }
 //     COUT(3) << "sending DeleteObjects" << std::endl;
     while(temp != NULL){
-      if( !(temp->getSynched()) ){
+      if( !(temp->getSynched()) )
+      {
         COUT(5) << "Server: not sending gamestate" << std::endl;
         temp=temp->next();
         continue;
@@ -275,12 +296,14 @@
   }
 
 
-  void Server::addPeer(ENetEvent *event){
+  void Server::addPeer(ENetEvent *event)
+  {
     static unsigned int newid=1;
 
     COUT(2) << "Server: adding client" << std::endl;
     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
-    if(!temp){
+    if(!temp)
+    {
       COUT(2) << "Server: could not add client" << std::endl;
     }
     temp->setID(newid);
@@ -309,9 +332,11 @@
     }
   }
 
-  bool Server::createClient(int clientID){
+  bool Server::createClient(int clientID)
+  {
     ClientInformation *temp = ClientInformation::findClient(clientID);
-    if(!temp){
+    if(!temp)
+    {
       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
       return false;
     }
@@ -344,25 +369,30 @@
     return true;
   }
 
-  void Server::disconnectClient( ClientInformation *client ){
+  void Server::disconnectClient( ClientInformation *client )
+  {
     ServerConnection::disconnectClient( client );
     GamestateManager::removeClient(client);
     // inform all the listeners
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
   }
 
-  bool Server::chat(const std::string& message){
+  bool Server::chat(const std::string& message)
+  {
       return this->sendChat(message, Host::getPlayerID());
   }
 
-  bool Server::broadcast(const std::string& message){
+  bool Server::broadcast(const std::string& message)
+  {
       return this->sendChat(message, CLIENTID_UNKNOWN);
   }
 
-  bool Server::sendChat(const std::string& message, unsigned int clientID){
+  bool Server::sendChat(const std::string& message, unsigned int clientID)
+  {
     ClientInformation *temp = ClientInformation::getBegin();
     packet::Chat *chat;
-    while(temp){
+    while(temp)
+    {
       chat = new packet::Chat(message, clientID);
       chat->setClientID(temp->getID());
       if(!chat->send())
@@ -376,7 +406,8 @@
     return true;
   }
 
-  void Server::syncClassid(unsigned int clientID) {
+  void Server::syncClassid(unsigned int clientID)
+  {
     int failures=0;
     packet::ClassID *classid = new packet::ClassID();
     classid->setClientID(clientID);

Modified: code/branches/presentation3/src/libraries/network/Server.h
===================================================================
--- code/branches/presentation3/src/libraries/network/Server.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/Server.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -36,6 +36,7 @@
 #include "Host.h"
 #include "GamestateManager.h"
 #include "ServerConnection.h"
+#include "LANDiscoverable.h"
 
 namespace orxonox
 {
@@ -44,7 +45,7 @@
   * This class is the root class of the network module for a server.
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
+  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
   public:
     Server();
     Server(int port);

Modified: code/branches/presentation3/src/libraries/network/ServerConnection.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/ServerConnection.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/ServerConnection.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -93,9 +93,9 @@
   }
 
   bool ServerConnection::addPacketAll(ENetPacket *packet) {
-    if ( !Connection::getInstance() )
-      return false;
-    enet_host_broadcast( Connection::getInstance()->getHost(), 0, packet);
+//     if ( !Connection::getInstance() )
+//       return false;
+    enet_host_broadcast( Connection::getHost(), 0, packet);
     return true;
   }
 

Modified: code/branches/presentation3/src/libraries/network/ServerConnection.h
===================================================================
--- code/branches/presentation3/src/libraries/network/ServerConnection.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/ServerConnection.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -55,8 +55,8 @@
 
     bool openListener();
     bool closeListener();
-    static bool addPacket(ENetPacket *packet, unsigned int ID);
-    static bool addPacketAll(ENetPacket *packet);
+    bool addPacket(ENetPacket *packet, unsigned int ID);
+    bool addPacketAll(ENetPacket *packet);
     virtual void disconnectClient(ClientInformation *client);
     void disconnectClient(int clientID);
   protected:

Modified: code/branches/presentation3/src/libraries/network/packet/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/libraries/network/packet/CMakeLists.txt	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/packet/CMakeLists.txt	2010-07-28 18:29:32 UTC (rev 7161)
@@ -10,6 +10,7 @@
   Packet.cc
   Welcome.cc
 COMPILATION_END
+  ServerInformation.cc
 )
 
 ADD_SOURCE_FILES(NETWORK_HDR_FILES
@@ -22,5 +23,6 @@
   FunctionIDs.h
   Gamestate.h
   Packet.h
+  ServerInformation.h
   Welcome.h
 )

Modified: code/branches/presentation3/src/libraries/network/packet/Packet.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/packet/Packet.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/packet/Packet.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -61,7 +61,8 @@
 
 std::map<size_t, Packet *> Packet::packetMap_;
 
-Packet::Packet(){
+Packet::Packet()
+{
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Outgoing;
   clientID_=0;
@@ -70,7 +71,8 @@
   bDataENetAllocated_ = false;
 }
 
-Packet::Packet(uint8_t *data, unsigned int clientID){
+Packet::Packet(uint8_t *data, unsigned int clientID)
+{
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Incoming;
   clientID_=clientID;

Added: code/branches/presentation3/src/libraries/network/packet/ServerInformation.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/packet/ServerInformation.cc	                        (rev 0)
+++ code/branches/presentation3/src/libraries/network/packet/ServerInformation.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -0,0 +1,84 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ServerInformation.h"
+
+#include <enet/enet.h>
+#include <cassert>
+#include <cstring>
+
+#include "util/Serialise.h"
+
+namespace orxonox
+{
+  namespace packet
+  {
+    
+    ServerInformation::ServerInformation()
+    {
+      
+    }
+    
+    ServerInformation::ServerInformation(ENetEvent* event)
+    {
+      // Save Server Round Trip Time
+      this->serverRTT_ = event->peer->roundTripTime;
+      // Save Server IP
+      char* serverIP = new char[16];
+      enet_address_get_host_ip(&event->peer->address, serverIP, 16);
+      this->serverIP_ = std::string(serverIP);
+      // Save ACK
+      uint8_t* temp = event->packet->data;
+      char* ack = new char[strlen(LAN_DISCOVERY_ACK)+1];
+      loadAndIncrease((char*&)ack, temp);
+      assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);
+      // Save Server Name
+      loadAndIncrease(this->serverName_, temp);
+    }
+
+    ServerInformation::~ServerInformation()
+    {
+      
+    }
+
+    void ServerInformation::send(ENetPeer* peer)
+    {
+      uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(this->serverName_);
+      uint8_t* temp = new uint8_t[size];
+      uint8_t* temp2 = temp;
+      saveAndIncrease((char*&)LAN_DISCOVERY_ACK, temp2);
+      saveAndIncrease(this->serverName_, temp2);
+      ENetPacket* packet = enet_packet_create( temp, size, 0 );
+      enet_peer_send(peer, 0, packet);
+      
+      delete[] temp;
+    }
+  
+  } // namespace packet
+} // namespace orxonox
+

Added: code/branches/presentation3/src/libraries/network/packet/ServerInformation.h
===================================================================
--- code/branches/presentation3/src/libraries/network/packet/ServerInformation.h	                        (rev 0)
+++ code/branches/presentation3/src/libraries/network/packet/ServerInformation.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -0,0 +1,63 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "../NetworkPrereqs.h"
+
+#include <string>
+
+#ifndef SERVERINFORMATION_H
+#define SERVERINFORMATION_H
+
+namespace orxonox
+{
+  namespace packet
+  {
+
+    class ServerInformation
+    {
+      public:
+        ServerInformation();
+        ServerInformation(ENetEvent* event);
+        ~ServerInformation();
+        
+        void          send( ENetPeer* peer );
+        std::string   getServerIP() { return this->serverIP_; }
+        std::string   getServerName() { return this->serverName_; }
+        void          setServerName(std::string name) { this->serverName_ = name; }
+        uint32_t      getServerRTT() { return this->serverRTT_; }
+        
+      private:
+        std::string   serverName_;
+        std::string   serverIP_;
+        uint32_t      serverRTT_;
+    };
+
+  }
+}
+
+#endif // SERVERINFORMATION_H

Modified: code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -53,7 +53,7 @@
     RegisterRootObject(Synchronisable);
     static uint32_t idCounter=0;
     objectMode_=0x1; // by default do not send data to server
-    if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) )
+    if ( GameMode::isMaster()/* || ( Host::running() && Host::isServer() )*/ )
     {
       this->setObjectID( idCounter++ );
     }

Modified: code/branches/presentation3/src/libraries/util/Serialise.h
===================================================================
--- code/branches/presentation3/src/libraries/util/Serialise.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/libraries/util/Serialise.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -52,6 +52,35 @@
     /** @brief checks whether the variable of type T is the same as in the bytestream */
     template <class T> inline bool checkEquality( const T& variable, uint8_t* mem );
 
+  
+  // =========== char*
+    
+  inline uint32_t returnSize( char*& variable )
+  {
+    return strlen(variable)+1;
+  }
+      
+  inline void saveAndIncrease( char*& variable, uint8_t*& mem )
+  {
+    strcpy((char*)mem, variable);
+    mem += returnSize(variable);
+  }
+        
+  inline void loadAndIncrease( char*& variable, uint8_t*& mem )
+  {
+    if( variable )
+      delete variable;
+    uint32_t len = strlen((char*)mem)+1;
+    variable = new char[len];
+    strcpy((char*)variable, (char*)mem);
+    mem += len;
+  }
+          
+  inline bool checkEquality( char*& variable, uint8_t* mem )
+  {
+    return strcmp(variable, (char*)mem)==0;
+  }
+    
 // =================== Template specialisation stuff =============
 
 // =========== bool
@@ -393,7 +422,7 @@
         double temp = static_cast<double>(variable);
         return memcmp(&temp, mem, sizeof(uint64_t))==0;
     }
-
+        
 // =========== string
 
     template <> inline uint32_t returnSize( const std::string& variable )

Modified: code/branches/presentation3/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/presentation3/src/orxonox/CameraManager.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/orxonox/CameraManager.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -67,6 +67,7 @@
 
     void CameraManager::requestFocus(Camera* camera)
     {
+      COUT(0) << "bliub" << endl;
         // notify old camera (if it exists)
         if (!this->cameraList_.empty())
             this->cameraList_.front()->removeFocus();

Modified: code/branches/presentation3/src/orxonox/Main.cc
===================================================================
--- code/branches/presentation3/src/orxonox/Main.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/orxonox/Main.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -39,6 +39,7 @@
 #include "core/Game.h"
 #include "core/LuaState.h"
 #include "ToluaBindOrxonox.h"
+#include "ToluaBindNetwork.h"
 #include "Main.h"
 
 SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
@@ -50,6 +51,7 @@
 SetCommandLineSwitch(dedicatedClient).information("Start in dedicated client mode");
 
 DeclareToluaInterface(Orxonox);
+DeclareToluaInterface(Network);
 
 namespace orxonox
 {

Modified: code/branches/presentation3/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/branches/presentation3/src/orxonox/gamestates/GSClient.cc	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/orxonox/gamestates/GSClient.cc	2010-07-28 18:29:32 UTC (rev 7161)
@@ -43,7 +43,6 @@
 
     GSClient::GSClient(const GameStateInfo& info)
         : GameState(info)
-        , client_(0)
     {
     }
 
@@ -55,29 +54,29 @@
     {
         GameMode::setIsClient(true);
 
-        this->client_ = new Client(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port"));
+//         this->client_ = new Client();
+//         this->client_->setDestination(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
 
-        if(!client_->establishConnection())
+        if( !Client::getInstance()->establishConnection() )
         {
-            delete this->client_;
             ThrowException(InitialisationFailed, "Could not establish connection with server.");
         }
 
-        client_->update(Game::getInstance().getGameClock());
+        Client::getInstance()->update(Game::getInstance().getGameClock());
     }
 
     void GSClient::deactivate()
     {
-        client_->closeConnection();
+        Client::getInstance()->closeConnection();
 
         // destroy client
-        delete this->client_;
+//         delete this->client_;
 
         GameMode::setIsClient(false);
     }
 
     void GSClient::update(const Clock& time)
     {
-        client_->update(time);
+        Client::getInstance()->update(time);
     }
 }

Modified: code/branches/presentation3/src/orxonox/gamestates/GSClient.h
===================================================================
--- code/branches/presentation3/src/orxonox/gamestates/GSClient.h	2010-07-26 12:56:06 UTC (rev 7160)
+++ code/branches/presentation3/src/orxonox/gamestates/GSClient.h	2010-07-28 18:29:32 UTC (rev 7161)
@@ -45,9 +45,6 @@
         void activate();
         void deactivate();
         void update(const Clock& time);
-
-    private:
-        Client* client_;
     };
 }
 




More information about the Orxonox-commit mailing list