Index: /code/branches/libraries2/src/libraries/network/CMakeLists.txt
===================================================================
--- /code/branches/libraries2/src/libraries/network/CMakeLists.txt	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/CMakeLists.txt	(revision 5713)
@@ -0,0 +1,74 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        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.
+ #
+
+SET_SOURCE_FILES(NETWORK_SRC_FILES
+  ChatListener.cc
+  Client.cc
+  ClientConnection.cc
+  ClientInformation.cc
+  ClientConnectionListener.cc
+  Connection.cc
+  FunctionCallManager.cc
+  GamestateManager.cc
+  GamestateClient.cc
+  GamestateHandler.cc
+  NetworkFunction.cc
+  Host.cc
+  Server.cc
+  ServerConnection.cc
+  TrafficControl.cc
+)
+
+SET_SOURCE_FILES(NETWORK_HDR_FILES
+  ChatListener.h
+  Client.h
+  ClientConnection.h
+  ClientConnectionListener.h
+  ClientInformation.h
+  Connection.h
+  FunctionCallManager.h
+  GamestateClient.h
+  GamestateHandler.h
+  GamestateManager.h
+  Host.h
+  NetworkFunction.h
+  NetworkPrecompiledHeaders.h
+  NetworkPrereqs.h
+  Server.h
+  ServerConnection.h
+  TrafficControl.h
+)
+
+ADD_SUBDIRECTORY(packet)
+ADD_SUBDIRECTORY(synchronisable)
+
+ORXONOX_ADD_LIBRARY(network
+  DEFINE_SYMBOL
+    "NETWORK_SHARED_BUILD"
+  PCH_FILE
+    NetworkPrecompiledHeaders.h
+  LINK_LIBRARIES
+    ${ZLIB_LIBRARY}
+    ${ENET_LIBRARY}
+    ${Boost_THREAD_LIBRARY}
+    util
+    core
+  SOURCE_FILES
+    ${NETWORK_SRC_FILES} ${NETWORK_HDR_FILES}
+)
Index: /code/branches/libraries2/src/libraries/network/ChatListener.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/ChatListener.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ChatListener.cc	(revision 5713)
@@ -0,0 +1,40 @@
+/*
+ *   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 "ChatListener.h"
+#include "core/CoreIncludes.h"
+
+namespace orxonox
+{
+    ChatListener::ChatListener()
+    {
+        RegisterRootObject(ChatListener);
+    }
+}
+
+
Index: /code/branches/libraries2/src/libraries/network/ChatListener.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/ChatListener.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ChatListener.h	(revision 5713)
@@ -0,0 +1,47 @@
+/*
+ *   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 _NETWORK_ChatListener__
+#define _NETWORK_ChatListener__
+
+#include "NetworkPrereqs.h"
+#include "core/OrxonoxClass.h"
+
+namespace orxonox
+{
+    class _NetworkExport ChatListener : virtual public OrxonoxClass
+    {
+        public:
+            ChatListener();
+            virtual ~ChatListener() {}
+
+            virtual void incomingChat(const std::string& message, unsigned int senderID) = 0;
+    };
+}
+
+#endif /* _NETWORK_ChatListener__ */
Index: /code/branches/libraries2/src/libraries/network/Client.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/Client.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Client.cc	(revision 5713)
@@ -0,0 +1,161 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Implementation: Client
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "Client.h"
+
+#include <cassert>
+
+#include "util/Debug.h"
+#include "core/Clock.h"
+#include "synchronisable/Synchronisable.h"
+#include "packet/Chat.h"
+#include "packet/Gamestate.h"
+#include "FunctionCallManager.h"
+
+namespace orxonox
+{
+
+
+  /**
+  * Constructor for the Client class
+  * initializes the address and the port to default localhost:NETWORK_PORT
+  */
+  Client::Client():
+      isSynched_(false),
+      gameStateFailure_(false)
+  {
+  }
+
+  /**
+  * 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)
+  {
+      setPort( port );
+      setServerAddress( address );
+  }
+
+  Client::~Client(){
+    if ( ClientConnection::isConnected() )
+      closeConnection();
+  }
+
+  /**
+  * Establish the Connection to the Server
+  * @return true/false
+  */
+  bool Client::establishConnection(){
+    Synchronisable::setClient(true);
+    return ClientConnection::establishConnection();
+  }
+
+  /**
+  * closes the Connection to the Server
+  * @return true/false
+  */
+  bool Client::closeConnection(){
+    return ClientConnection::closeConnection();
+  }
+
+  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){
+//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
+    return true;
+  }
+
+  /**
+   * This function implements the method of sending a chat message to the server
+   * @param message message to be sent
+   * @return result(true/false)
+   */
+  bool Client::chat(const std::string& message){
+    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
+    return m->send();
+  }
+
+
+  /**
+   * Processes incoming packets, sends a gamestate to the server and does the cleanup
+   * @param time
+   */
+  void Client::update(const Clock& time){
+    //this steers our network frequency
+    timeSinceLastUpdate_+=time.getDeltaTime();
+    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    {
+      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
+      //     COUT(3) << ".";
+      if ( isConnected() && isSynched_ )
+      {
+        COUT(4) << "popping partial gamestate: " << std::endl;
+        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;
+          if( !gs->send() )
+            COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
+        // gs gets automatically deleted by enet callback
+        }
+        FunctionCallManager::sendCalls();
+      }
+    }
+    sendPackets(); // flush the enet queue
+    
+    Connection::processQueue();
+    if(gamestate.processGamestates())
+    {
+      if(!isSynched_)
+        isSynched_=true;
+    }
+    gamestate.cleanup();
+
+    return;
+  }
+
+}
Index: /code/branches/libraries2/src/libraries/network/Client.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/Client.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Client.h	(revision 5713)
@@ -0,0 +1,89 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Interface: Client
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef _Client_H__
+#define _Client_H__
+
+#include "NetworkPrereqs.h"
+
+#include <string>
+#include "ClientConnection.h"
+#include "GamestateClient.h"
+#include "Host.h"
+
+namespace orxonox
+{
+  /**
+  Client *client;
+  * The network/Client class
+  * This class implements all necessary function for the network communication
+  * It is the root class of the network module
+  *
+  */
+  class _NetworkExport Client : public Host, public ClientConnection{
+  public:
+    Client();
+    Client(const std::string& address, int port);
+    ~Client();
+
+    bool establishConnection();
+    bool closeConnection();
+    bool queuePacket(ENetPacket *packet, int clientID);
+    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; }
+
+    void update(const Clock& time);
+
+  private:
+    Client(const Client& copy); // not used
+    virtual bool isServer_(){return false;}
+
+    GamestateClient gamestate;
+    bool isSynched_;
+
+    bool gameStateFailure_;
+    float timeSinceLastUpdate_;
+  };
+
+
+}
+
+#endif /* _Client_H__ */
Index: /code/branches/libraries2/src/libraries/network/ClientConnection.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/ClientConnection.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ClientConnection.cc	(revision 5713)
@@ -0,0 +1,145 @@
+/*
+ *   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 "ClientConnection.h"
+
+#include <cassert>
+#include <enet/enet.h>
+#include "util/Debug.h"
+
+namespace orxonox
+{
+  const unsigned int NETWORK_CLIENT_WAIT_TIME = 1;
+  const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs
+  const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
+  const unsigned int NETWORK_CLIENT_CHANNELS = 2;
+
+
+  ClientConnection::ClientConnection():
+    established_(false),
+    server_(NULL)
+  {
+    this->serverAddress_ = new ENetAddress();
+    //set standard address and port
+    enet_address_set_host(this->serverAddress_, "127.0.0.1");
+    serverAddress_->port = NETWORK_PORT;
+  }
+
+  ClientConnection::~ClientConnection(){
+    if(this->established_)
+      closeConnection();
+    delete this->serverAddress_; // surely was created
+  }
+
+  void ClientConnection::setServerAddress( const std::string& serverAddress ) {
+    enet_address_set_host (this->serverAddress_, serverAddress.c_str());
+  }
+
+  void ClientConnection::setPort( unsigned int port ) {
+    this->serverAddress_->port = port;
+  }
+
+  bool ClientConnection::establishConnection()
+  {
+    ENetEvent event;
+    
+    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
+    if ( this->host_ == NULL )
+    {
+      COUT(2) << "ClientConnection: host_ == NULL" << std::endl;
+      // error handling
+      return false;
+    }
+    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS);
+    if ( this->server_==NULL )
+    {
+      COUT(2) << "ClientConnection: server == NULL" << std::endl;
+      // error handling
+      return false;
+    }
+    // handshake
+    for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++ )
+    {
+      if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
+      {
+        this->established_=true;
+        return true;
+      }
+    }
+    COUT(1) << "Could not connect to server" << endl;
+    return false;
+  }
+
+  bool ClientConnection::closeConnection() {
+    ENetEvent event;
+    
+    if ( !this->established_ )
+      return true;
+    this->established_ = false;
+    enet_peer_disconnect(this->server_, 0);
+    for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
+    {
+      if ( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME) >= 0 )
+      {
+        switch (event.type)
+        {
+          case ENET_EVENT_TYPE_NONE:
+          case ENET_EVENT_TYPE_CONNECT:
+            break;
+          case ENET_EVENT_TYPE_RECEIVE:
+            enet_packet_destroy(event.packet);
+            break;
+          case ENET_EVENT_TYPE_DISCONNECT:
+            COUT(4) << "received disconnect confirmation from server" << endl;
+            return true;
+        }
+      }
+    }
+    enet_peer_reset( this->server_ );
+    return false;
+  }
+
+
+  bool ClientConnection::addPacket(ENetPacket *packet) {
+    assert( this->server_ );
+    assert( packet );
+    return Connection::addPacket( packet, this->server_ );
+  }
+
+  void ClientConnection::addClient(ENetEvent* event)
+  {
+    assert(0);
+  }
+  void ClientConnection::disconnectPeer(ENetEvent* event)
+  {
+    this->established_=false;
+    COUT(1) << "Received disconnect Packet from Server!" << endl;
+        // server closed the connection
+  }
+
+}
Index: /code/branches/libraries2/src/libraries/network/ClientConnection.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/ClientConnection.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ClientConnection.h	(revision 5713)
@@ -0,0 +1,70 @@
+/*
+ *   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 _ClientConnection_H__
+#define _ClientConnection_H__
+
+#include "NetworkPrereqs.h"
+#include "Connection.h"
+
+namespace orxonox
+{
+
+  class _NetworkExport ClientConnection: public Connection{
+  public:
+    ClientConnection();
+    virtual ~ClientConnection();
+    
+    void setServerAddress( const std::string& serverAddress );
+    void setPort( unsigned int port );
+    
+    ENetEvent *getEvent();
+    // check wheter the packet queue is empty
+    bool queueEmpty();
+    // create a new listener thread
+    virtual bool establishConnection();
+    virtual bool closeConnection();
+    // add a packet to queue for the server
+    bool addPacket(ENetPacket *packet);
+    inline bool isConnected(){ return this->established_; }
+  private:
+    virtual void addClient(ENetEvent* event);
+    virtual void disconnectPeer(ENetEvent* event);
+    
+    bool disconnectConnection();
+    // enet stuff
+    ENetAddress *serverAddress_;
+    bool established_;
+    // clientlist
+    ENetPeer *server_;
+};
+
+
+}
+
+#endif /* _ClientConnection_H__ */
Index: /code/branches/libraries2/src/libraries/network/ClientConnectionListener.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/ClientConnectionListener.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ClientConnectionListener.cc	(revision 5713)
@@ -0,0 +1,54 @@
+/*
+ *   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 "ClientConnectionListener.h"
+
+#include "core/CoreIncludes.h"
+#include "core/GameMode.h"
+#include "ClientInformation.h"
+
+namespace orxonox{
+
+  ClientConnectionListener::ClientConnectionListener()
+  { 
+    RegisterRootObject(ClientConnectionListener); 
+  }
+
+  void ClientConnectionListener::getConnectedClients(){
+    if(GameMode::showsGraphics())
+      this->clientConnected(0); //server client id
+    ClientInformation *client = ClientInformation::getBegin();
+    while(client){
+      this->clientConnected(client->getID());
+      client=client->next();
+    }
+  }
+
+}
+
+
Index: /code/branches/libraries2/src/libraries/network/ClientConnectionListener.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/ClientConnectionListener.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ClientConnectionListener.h	(revision 5713)
@@ -0,0 +1,55 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ClientConnectionListener_H__
+#define _ClientConnectionListener_H__
+
+#include "NetworkPrereqs.h"
+#include "core/OrxonoxClass.h"
+
+namespace orxonox{
+
+  class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
+  {
+    friend class Server;
+
+  public:
+    ClientConnectionListener();
+    virtual ~ClientConnectionListener() {}
+
+    void getConnectedClients();
+
+  protected:
+    virtual void clientConnected(unsigned int clientID) = 0;
+    virtual void clientDisconnected(unsigned int clientID) = 0;
+  };
+
+}
+
+
+#endif /* _ClientConnectionListener_H__ */
Index: /code/branches/libraries2/src/libraries/network/ClientInformation.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/ClientInformation.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ClientInformation.cc	(revision 5713)
@@ -0,0 +1,271 @@
+/*
+ *   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:
+ *      ...
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+//
+// C++ Implementation: ClientInformation
+//
+// Description:
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "ClientInformation.h"
+#include <enet/enet.h>
+
+namespace orxonox
+{
+  
+
+  ClientInformation *ClientInformation::head_=0;
+
+  ClientInformation::ClientInformation() {
+    if(!head_)
+      head_=this;
+    gamestateID_=GAMESTATEID_INITIAL;
+    preve=0;
+    nexte=0;
+    partialGamestateID_=GAMESTATEID_INITIAL-1;
+    synched_=false;
+  }
+
+  ClientInformation::~ClientInformation() {
+    if(prev()!=0)
+      prev()->setNext(this->next());
+    if(next()!=0)
+      next()->setPrev(this->prev());
+    if(this==head_)
+      head_=next();
+  }
+
+  ClientInformation *ClientInformation::next() {
+    if(this!=0)
+      return this->nexte;
+    else
+      return 0;
+  }
+  ClientInformation *ClientInformation::prev() {
+    if(this!=0)
+      return this->preve;
+    else
+      return 0;
+  }
+
+  bool ClientInformation::setPrev(ClientInformation *prev) {
+    if(this==head_)
+      head_=prev;
+    this->preve = prev;
+    return true;
+  }
+
+  bool ClientInformation::setNext(ClientInformation *next) {
+    this->nexte = next;
+    return true;
+  }
+
+  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
+    this->next()->setPrev(ins);
+    ins->setNext(this->next());
+    ins->setPrev(this);
+    this->nexte = ins;
+    return ins;
+  }
+
+  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
+    if(!this)
+      return NULL;
+    this->prev()->setNext(ins);
+    ins->setPrev(this->prev());
+    this->preve=ins;
+    ins->setNext(this);
+    return ins;
+  }
+
+  void ClientInformation::setID(int clientID){
+    if(!this)
+      return;
+    clientID_ = clientID;
+  }
+
+  bool ClientInformation::setPeer(ENetPeer *peer){
+    if(!this)
+      return false;
+    peer_ = peer;
+    return true;
+  }
+
+  bool ClientInformation::setGamestateID(int id){
+    if(!this)
+      return false;
+    gamestateID_=id;
+    return true;
+  }
+
+  bool ClientInformation::setPartialGamestateID(int id){
+    if(!this)
+      return false;
+    partialGamestateID_=id;
+    return true;
+  }
+
+  unsigned int ClientInformation::getID() {
+    if(!this)
+      return CLIENTID_UNKNOWN;
+    else
+      return clientID_;
+  }
+
+  ENetPeer *ClientInformation::getPeer() {
+    if(this)
+      return peer_;
+    else
+      return NULL;
+  }
+
+  int ClientInformation::getFailures(){
+    return failures_;
+  }
+  void ClientInformation::addFailure(){
+    failures_++;
+  }
+  void ClientInformation::resetFailures(){
+    failures_=0;
+  }
+
+  uint32_t ClientInformation::getRTT(){
+    return this->peer_->roundTripTime;
+  }
+
+  double ClientInformation::getPacketLoss(){
+    return static_cast<double>(this->peer_->packetLoss)/ENET_PEER_PACKET_LOSS_SCALE;
+  }
+
+  unsigned int ClientInformation::getGamestateID() {
+    if(this)
+      return gamestateID_;
+    else
+      return static_cast<unsigned int>(-1);
+  }
+
+  unsigned int ClientInformation::getPartialGamestateID() {
+    if(this)
+      return partialGamestateID_;
+    else
+      return static_cast<unsigned int>(-1);
+  }
+
+  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
+    ClientInformation *temp = head_;
+    if(temp==ins){
+      return head_;
+    }
+    while(temp->next()!=0){
+      temp = temp->next();
+    }
+    temp->setNext(ins);
+    ins->setPrev(temp);
+    return ins;
+  }
+
+  bool ClientInformation::removeClient(unsigned int clientID) {
+    if(clientID==CLIENTID_UNKNOWN)
+      return false;
+    ClientInformation *temp = head_;
+    while(temp!=0 && temp->getID()!=clientID)
+      temp = temp->next();
+    if(temp==0)
+      return false;
+    delete temp;
+    return true;
+  }
+
+  bool ClientInformation::removeClient(ENetPeer *peer) {
+    if(!peer)
+      return false;
+    ClientInformation *temp = head_;
+    while(temp!=0){
+      if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
+        break;
+      temp = temp->next();
+    }
+    if(temp==0)
+      return false;
+    delete temp;
+    return true;
+  }
+
+  /**
+  * This function goes forward through the list and looks for an element with clientID
+  * This function should only be applied to the head of the list
+  * @param clientID id to look for
+  * @return pointer to the last element in the list or 0 if the search was unsuccessfull
+  */
+  ClientInformation *ClientInformation::findClient(unsigned int clientID, bool look_backwards) {
+    ClientInformation *temp = head_;
+    while(temp!=0 && temp->getID()!=clientID){
+      temp = temp->next();
+    }
+    // returns 0 if nothing has been found
+    return temp;
+  }
+
+  /**
+  * This function goes forward through the list and looks for an element with clientID
+  * This function should only be applied to the head of the list
+  * @param peer peer to look for
+  * @return pointer to the element in the list
+  */
+  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
+    ClientInformation *temp = head_;
+    while(temp!=0){
+      if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
+        break;
+      temp = temp->next();
+    }
+    // returns 0 if nothing has been found
+    return temp;
+  }
+
+  bool ClientInformation::setSynched(bool s) {
+    if(!this)
+      return false;
+    synched_=s;
+    return true;
+  }
+
+  bool ClientInformation::getSynched() {
+    if(this)
+      return synched_;
+    else
+      return false;
+  }
+
+}
Index: /code/branches/libraries2/src/libraries/network/ClientInformation.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/ClientInformation.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ClientInformation.h	(revision 5713)
@@ -0,0 +1,117 @@
+/*
+ *   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:
+ *      ...
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+//
+// C++ Interface: ClientInformation
+//
+// Description:
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _ClientInformation_H__
+#define _ClientInformation_H__
+
+#include "NetworkPrereqs.h"
+
+// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
+
+namespace orxonox
+{
+
+  /**
+  * This class implements a list for client information
+  * @author Oliver Scheuss
+  */
+  class _NetworkExport ClientInformation{
+  public:
+    ClientInformation();
+    //   ClientInformation(ClientInformation *prev, ClientInformation *next);
+    //   ClientInformation(ClientInformation *prev);
+    ~ClientInformation();
+    ClientInformation *next();
+    ClientInformation *prev();
+    static ClientInformation *insertBack(ClientInformation *ins);
+
+    // set functions
+    void setID(int clientID);
+    bool setPeer(ENetPeer *peer);
+    bool setGamestateID(int id);
+    bool setPartialGamestateID(int id);
+    inline void setShipID(unsigned int id){ShipID_=id;}
+
+    // get functions
+    inline unsigned int getShipID(){return ShipID_;}
+    unsigned int getID();
+    unsigned int getGamestateID();
+    unsigned int getPartialGamestateID();
+    ENetPeer *getPeer();
+
+    int getFailures();
+    void addFailure();
+    void resetFailures();
+    uint32_t getRTT();
+    double getPacketLoss();
+
+    static bool removeClient(unsigned int clientID);
+    static bool removeClient(ENetPeer *peer);
+    static ClientInformation *findClient(unsigned int clientID, bool look_backwards=false);
+    static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
+    static ClientInformation *getBegin(){return head_;}
+    static bool hasClients(){ return ClientInformation::head_!=0; }
+
+    bool setSynched(bool s);
+    bool getSynched();
+
+  private:
+    static ClientInformation *head_;
+
+    bool setNext(ClientInformation *next);
+    bool setPrev(ClientInformation *prev);
+    ClientInformation *insertAfter(ClientInformation *ins);
+    ClientInformation *insertBefore(ClientInformation *ins);
+
+    ClientInformation *preve;
+    ClientInformation *nexte;
+    //actual information:
+    ENetPeer *peer_;
+    unsigned int clientID_;
+    unsigned int gamestateID_;
+    unsigned int partialGamestateID_;
+    unsigned int ShipID_;   // this is the unique objectID
+    bool synched_;
+    unsigned short failures_;
+
+  };
+
+}
+
+#endif /* _ClientInformation_H__ */
Index: /code/branches/libraries2/src/libraries/network/Connection.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/Connection.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Connection.cc	(revision 5713)
@@ -0,0 +1,103 @@
+/*
+ *   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 "Connection.h"
+
+#include <cassert>
+#include <enet/enet.h>
+#include "packet/Packet.h"
+
+namespace orxonox
+{
+  Connection *Connection::instance_=0;
+
+  Connection::Connection():
+    host_(0)
+  {
+    assert(instance_==0);
+    Connection::instance_=this;
+    enet_initialize();
+    atexit(enet_deinitialize);
+  }
+
+  Connection::~Connection(){
+    Connection::instance_=0;
+  }
+
+  int Connection::service(ENetEvent* event) {
+    return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+  }
+
+  void Connection::disconnectPeer(ENetPeer *peer) {
+    enet_peer_disconnect(peer, 0);
+  }
+
+  bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
+    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
+      return false;
+    else
+      return true;
+  }
+
+  bool Connection::sendPackets() {
+    if ( !Connection::instance_ || this->host_==NULL )
+      return false;
+    enet_host_flush(this->host_);
+    return true;
+  }
+
+  void Connection::processQueue() {
+    ENetEvent event;
+    
+    assert(this->host_);
+
+    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    {
+      switch(event.type){
+        // log handling ================
+        case ENET_EVENT_TYPE_CONNECT:
+          addClient( &event );
+          break;
+        case ENET_EVENT_TYPE_DISCONNECT:
+          disconnectPeer( &event );
+          break;
+        case ENET_EVENT_TYPE_RECEIVE:
+          processPacket( &event );
+          break;
+        case ENET_EVENT_TYPE_NONE:
+          break;
+      }
+    }
+  }
+
+  bool Connection::processPacket(ENetEvent* event) {
+    packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
+    return p->process();
+  }
+
+}
Index: /code/branches/libraries2/src/libraries/network/Connection.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/Connection.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Connection.h	(revision 5713)
@@ -0,0 +1,83 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Interface: Connection
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _Connection_H__
+#define _Connection_H__
+
+#include "NetworkPrereqs.h"
+
+namespace orxonox
+{
+    const unsigned int NETWORK_PORT = 55556;
+    const unsigned int NETWORK_MAX_CONNECTIONS = 50;
+    const unsigned int NETWORK_WAIT_TIMEOUT = 0;
+    const unsigned int NETWORK_DEFAULT_CHANNEL = 0;
+    const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
+
+  class _NetworkExport Connection{
+  public:
+    virtual ~Connection();
+    
+    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
+    bool sendPackets();
+    ENetHost* getHost(){ return this->host_; }
+
+  protected:
+    Connection();
+    static Connection* getInstance(){ return Connection::instance_; }
+    
+    int service(ENetEvent* event);
+    void disconnectPeer(ENetPeer *peer);
+    
+    void processQueue();
+    virtual void addClient(ENetEvent* event)=0;
+    virtual void disconnectPeer(ENetEvent* event)=0;
+    virtual bool processPacket(ENetEvent* event);
+    
+    ENetHost *host_;
+  private:
+    ENetAddress *bindAddress_;
+
+    static Connection *instance_;
+
+  };
+
+}
+
+#endif /* _Connection_H__ */
Index: /code/branches/libraries2/src/libraries/network/FunctionCallManager.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/FunctionCallManager.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/FunctionCallManager.cc	(revision 5713)
@@ -0,0 +1,165 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "FunctionCallManager.h"
+#include "packet/FunctionCalls.h"
+
+namespace orxonox {
+    
+std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::clientMap_;
+
+// Static calls
+
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
+{  
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::	clientMap_[clientID]->addCallStatic(functionID);
+}
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
+{  
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1);
+}
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+{  
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
+}
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+{  
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
+}
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+{  
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
+}
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+{  
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
+}
+
+
+// MemberCalls
+
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
+{ 
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID);
+}
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)
+{ 
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
+}
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+{ 
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
+}
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+{ 
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
+}
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+{ 
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
+}
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+{ 
+  if(clientMap_.find(clientID)==clientMap_.end()) 
+  {
+    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
+    FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
+  } 
+  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
+}
+
+// Send calls
+
+void FunctionCallManager::sendCalls()
+{
+  std::map<uint32_t, packet::FunctionCalls*>::iterator it;
+  for (it = FunctionCallManager::clientMap_.begin(); it != FunctionCallManager::clientMap_.end(); it++ )
+  {
+    assert(!FunctionCallManager::clientMap_.empty());
+    it->second->send();
+  }
+  FunctionCallManager::clientMap_.clear();
+}
+
+
+} //namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/FunctionCallManager.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/FunctionCallManager.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/FunctionCallManager.h	(revision 5713)
@@ -0,0 +1,69 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _FunctionCallManager_H__
+#define _FunctionCallManager_H__
+
+#include "NetworkPrereqs.h"
+
+#include <map>
+#include "util/UtilPrereqs.h"
+
+namespace orxonox {
+/**
+	@author
+*/
+
+class _NetworkExport FunctionCallManager
+{
+public:
+  static void addCallStatic(uint32_t functionID, uint32_t clientID);
+  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);
+  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  
+  static void sendCalls();
+  
+  static std::map<uint32_t, packet::FunctionCalls*> clientMap_;
+protected:
+  FunctionCallManager();
+  ~FunctionCallManager();
+};
+
+} //namespace orxonox
+
+#endif /* _FunctionCallManager_H__ */
Index: /code/branches/libraries2/src/libraries/network/GamestateClient.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/GamestateClient.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/GamestateClient.cc	(revision 5713)
@@ -0,0 +1,186 @@
+/*
+ *   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:
+ *      Dumeni Manatschal
+ *
+ */
+
+#include "GamestateClient.h"
+
+#include "util/Debug.h"
+#include "core/ObjectList.h"
+#include "synchronisable/Synchronisable.h"
+#include "synchronisable/NetworkCallbackManager.h"
+#include "packet/Acknowledgement.h"
+#include "packet/Gamestate.h"
+
+
+namespace orxonox
+{
+  struct _NetworkExport GameStateItem{
+    packet::Gamestate *state;
+    unsigned int id;
+  };
+
+  GamestateClient::GamestateClient() {
+    COUT(5) << "this: " << this << std::endl;
+    last_diff_=0;
+    last_gamestate_=GAMESTATEID_INITIAL-1;
+    tempGamestate_=NULL;
+  }
+
+  GamestateClient::~GamestateClient() {
+      std::map<unsigned int, packet::Gamestate *>::iterator it;
+      for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
+          delete (*it).second;
+      if( this->tempGamestate_ )
+          delete this->tempGamestate_;
+  }
+
+  bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){
+    return true;
+  }
+
+  bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){
+    if(tempGamestate_!=NULL){
+      //delete the obsolete gamestate
+      if(tempGamestate_->getID()>gs->getID())
+        return false;
+      delete tempGamestate_;
+    }
+    tempGamestate_=gs;
+    return true;
+  }
+
+  bool GamestateClient::processGamestates(){
+    if(tempGamestate_==NULL)
+      return false;
+    bool isDiffed = tempGamestate_->isDiffed();
+    int id = GAMESTATEID_INITIAL;
+    packet::Gamestate *processed = processGamestate(tempGamestate_);
+    assert(processed);
+    
+    //now call the queued callbacks
+    NetworkCallbackManager::callCallbacks();
+    
+    if (!processed){
+      sendAck(0);
+      return false;
+    }
+    //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
+    tempGamestate_=NULL;
+    gamestateMap_[processed->getID()]=processed;
+    if(isDiffed)
+      last_diff_ = processed->getBaseID();
+    id = processed->getID();
+    sendAck(id);
+    return true;
+  }
+
+
+  /**
+  * This function removes a Synchronisable out of the universe
+  * @param it iterator of the list pointing to the object
+  * @return iterator pointing to the next object in the list
+  */
+  void GamestateClient::removeObject(ObjectList<Synchronisable>::iterator &it) {
+    ObjectList<Synchronisable>::iterator temp=it;
+    ++it;
+    delete  *temp;
+  }
+
+  packet::Gamestate *GamestateClient::getGamestate(){
+    packet::Gamestate *gs = new packet::Gamestate();
+    if(!gs->collectData(0,0x2)){
+      delete gs;
+      return 0;
+    }
+    return gs;
+  }
+
+  void GamestateClient::cleanup(){
+    std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();
+    while(it!=gamestateMap_.end()){
+      if(it->first>=last_diff_)
+        break;
+      // otherwise delete that stuff
+      delete (*it).second;
+      temp=it++;
+      gamestateMap_.erase(temp);
+    }
+    tempGamestate_=NULL;
+  }
+
+  void GamestateClient::printGamestateMap(){
+    std::map<unsigned int, packet::Gamestate*>::iterator it;
+    COUT(4) << "gamestates: ";
+    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){
+      COUT(4) << it->first << ":" << it->second << "|";
+    }
+    COUT(4) << std::endl;
+
+  }
+
+  bool GamestateClient::sendAck(unsigned int gamestateID){
+    packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0);
+    if(!ack->send()){
+      COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
+      return false;
+    }
+    else{
+      COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
+      return true;
+    }
+  }
+
+  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
+    if(gs->isCompressed())
+    {
+      bool b = gs->decompressData();
+      assert(b);
+    }
+    if(gs->isDiffed()){
+      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
+      if(!base){
+        COUT(3) << "could not find base gamestate id: " << gs->getBaseID() << endl;
+        delete gs;
+        return 0;
+      }
+//       assert(base); //TODO: fix this
+      packet::Gamestate *undiffed = gs->undiff(base);
+      delete gs;
+      gs=undiffed;
+      COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
+    }
+    if(gs->spreadData(0x2))
+      return gs;
+    else
+    {
+      COUT(3) << "could not spread gamestate" << endl;
+      return NULL;
+    }
+  }
+
+}
+
Index: /code/branches/libraries2/src/libraries/network/GamestateClient.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/GamestateClient.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/GamestateClient.h	(revision 5713)
@@ -0,0 +1,80 @@
+/*
+ *   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:
+ *      Dumeni Manatschal
+ *
+ */
+
+//
+// C++ Interface: GameStateClient
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _GamestateClient_H__
+#define _GamestateClient_H__
+
+#include "NetworkPrereqs.h"
+
+#include <map>
+#include "core/CorePrereqs.h"
+#include "GamestateHandler.h"
+
+const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
+
+namespace orxonox
+{
+  class _NetworkExport GamestateClient: public GamestateHandler
+  {
+  public:
+    GamestateClient();
+    ~GamestateClient();
+
+    bool add(packet::Gamestate *gs, unsigned int clientID);
+    bool ack(unsigned int gamestateID, unsigned int clientID);
+
+    bool processGamestates();
+    packet::Gamestate *getGamestate();
+    void cleanup();
+  private:
+    packet::Gamestate *processGamestate(packet::Gamestate *gs);
+    void removeObject(ObjectListIterator<Synchronisable> &it);
+    void printGamestateMap();
+    bool sendAck(unsigned int gamestateID);
+
+    unsigned int           last_diff_;
+    unsigned int           last_gamestate_;
+    std::map<unsigned int, packet::Gamestate *> gamestateMap_;
+    packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
+
+  };
+
+}
+
+#endif /* _GamestateClient_H__ */
Index: /code/branches/libraries2/src/libraries/network/GamestateHandler.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/GamestateHandler.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/GamestateHandler.cc	(revision 5713)
@@ -0,0 +1,50 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "GamestateHandler.h"
+#include <cassert>
+
+namespace orxonox {
+
+GamestateHandler *GamestateHandler::instance_=0;
+  
+GamestateHandler::GamestateHandler()
+{
+  assert(instance_==0);
+  instance_=this;
+}
+
+
+GamestateHandler::~GamestateHandler()
+{
+  instance_=0;
+}
+
+
+
+}//namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/GamestateHandler.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/GamestateHandler.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/GamestateHandler.h	(revision 5713)
@@ -0,0 +1,58 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GamestateHandler_H__
+#define _GamestateHandler_H__
+
+#include "NetworkPrereqs.h"
+
+namespace orxonox {
+
+/**
+	@author Oliver Scheuss
+*/
+class _NetworkExport GamestateHandler{
+  private:
+    virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;
+    virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;
+
+    static GamestateHandler *instance_;
+
+
+  protected:
+    GamestateHandler();
+    virtual ~GamestateHandler();
+
+  public:
+    static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
+    static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
+};
+
+}
+
+#endif /* _GamestateHandler_H__ */
Index: /code/branches/libraries2/src/libraries/network/GamestateManager.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/GamestateManager.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/GamestateManager.cc	(revision 5713)
@@ -0,0 +1,277 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Implementation: GameStateManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "GamestateManager.h"
+
+#include <cassert>
+#include <queue>
+// #include <boost/thread/mutex.hpp>
+
+#include "util/Debug.h"
+#include "core/Executor.h"
+#include "core/ThreadPool.h"
+#include "ClientInformation.h"
+#include "packet/Acknowledgement.h"
+#include "packet/Gamestate.h"
+#include "synchronisable/NetworkCallbackManager.h"
+#include "TrafficControl.h"
+
+namespace orxonox
+{
+  GamestateManager::GamestateManager() :
+  reference(0), id_(0)
+  {
+    trafficControl_ = new TrafficControl();
+//     threadMutex_ = new boost::mutex();
+//     threadPool_ = new ThreadPool();
+  }
+
+  GamestateManager::~GamestateManager()
+  {
+    if( this->reference )
+        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
+    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
+      delete (*it).second;
+    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
+    std::map<unsigned int, packet::Gamestate*>::iterator it2;
+    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
+    {
+      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
+        delete (*it2).second;
+    }
+    delete this->trafficControl_;
+//     delete this->threadMutex_;
+//     delete this->threadPool_;
+  }
+
+  bool GamestateManager::update(){
+//     cleanup();
+    return getSnapshot();
+  }
+
+  bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){
+    assert(gs);
+    std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
+    if(it!=gamestateQueue.end()){
+      // delete obsolete gamestate
+      delete it->second;
+    }
+    gamestateQueue[clientID] = gs;
+    return true;
+  }
+
+  bool GamestateManager::processGamestates(){
+    if( this->gamestateQueue.empty() )
+        return true;
+    std::map<unsigned int, packet::Gamestate*>::iterator it;
+    // now push only the most recent gamestates we received (ignore obsolete ones)
+    for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){
+      bool b = processGamestate(it->second);
+      assert(b);
+      delete it->second;
+    }
+    // now clear the queue
+    gamestateQueue.clear();
+    //and call all queued callbacks
+    NetworkCallbackManager::callCallbacks();
+    return true;
+  }
+
+
+  bool GamestateManager::getSnapshot(){
+    if ( reference != 0 )
+      delete reference;
+    reference = new packet::Gamestate();
+    if(!reference->collectData(++id_, 0x1)){ //we have no data to send
+      delete reference;
+      reference=0;
+    }
+    return true;
+  }
+  
+  void GamestateManager::sendGamestates()
+  {
+    ClientInformation *temp = ClientInformation::getBegin();
+    std::queue<packet::Gamestate*> clientGamestates;
+    while(temp != NULL){
+      if( !(temp->getSynched()) ){
+        COUT(5) << "Server: not sending gamestate" << std::endl;
+        temp=temp->next();
+        if(!temp)
+          break;
+        continue;
+      }
+      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+      int cid = temp->getID(); //get client id
+      
+      unsigned int gID = temp->getGamestateID();
+      if(!reference)
+        return;
+      
+      packet::Gamestate *client=0;
+      if(gID != GAMESTATEID_INITIAL){
+        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
+        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
+        if(it!=gamestateMap_[cid].end())
+        {
+          client = it->second;
+        }
+      }
+      
+      clientGamestates.push(0);
+      finishGamestate( cid, &clientGamestates.back(), client, reference );
+      //FunctorMember<GamestateManager>* functor = 
+//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
+//       executor->setObject(this);
+//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+//       (*static_cast<Executor*>(executor))();
+//       this->threadPool_->passFunction( executor, true );
+//       (*functor)( cid, &(clientGamestates.back()), client, reference );
+      
+      temp = temp->next();
+    }
+    
+//     threadPool_->synchronise();
+    
+    while( !clientGamestates.empty() )
+    {
+      if(clientGamestates.front())
+        clientGamestates.front()->send();
+      clientGamestates.pop();
+    }
+  }
+
+
+  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
+    //why are we searching the same client's gamestate id as we searched in
+    //Server::sendGameState?
+    // save the (undiffed) gamestate in the clients gamestate map
+    //chose wheather the next gamestate is the first or not
+    
+    packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
+//     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
+//     packet::Gamestate *gs = new packet::Gamestate();
+//     gs->collectData( id_, 0x1 );
+//     this->threadMutex_->lock();
+    gamestateMap_[clientID][gamestate->getID()]=gs;
+//     this->threadMutex_->unlock();
+    
+    if(base)
+    {
+        
+//       COUT(3) << "diffing" << std::endl;
+//       packet::Gamestate* gs1  = gs;
+      packet::Gamestate *diffed = gs->diff(base);
+      //packet::Gamestate *gs2 = diffed->undiff(gs);
+//       assert(*gs == *gs2);
+      gs = diffed;
+//       packet::Gamestate* gs2 = gs->undiff(client);
+//       gs = new packet::Gamestate(*gs);
+//       assert(*gs1==*gs2);
+    }
+    else{
+      gs = new packet::Gamestate(*gs);
+    }
+    
+    
+    bool b = gs->compressData();
+    assert(b);
+//     COUT(4) << "sending gamestate with id " << gs->getID();
+//     if(gamestate->isDiffed())
+//     COUT(4) << " and baseid " << gs->getBaseID() << endl;
+//     else
+//     COUT(4) << endl;
+    gs->setClientID(clientID);
+    *destgamestate = gs;
+  }
+
+
+  bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) {
+    ClientInformation *temp = ClientInformation::findClient(clientID);
+    assert(temp);
+    unsigned int curid = temp->getGamestateID();
+
+    if(gamestateID == ACKID_NACK){
+      temp->setGamestateID(GAMESTATEID_INITIAL);
+      // now delete all saved gamestates for this client
+      std::map<unsigned int, packet::Gamestate*>::iterator it;
+      for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
+        delete it->second;
+
+        gamestateMap_[clientID].erase(it++);
+      }
+      return true;
+    }
+
+    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
+    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
+    std::map<unsigned int, packet::Gamestate*>::iterator it;
+    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
+      delete it->second;
+      gamestateMap_[clientID].erase(it++);
+    }
+    temp->setGamestateID(gamestateID);
+    TrafficControl::processAck(clientID, gamestateID);
+    return true;
+  }
+
+  void GamestateManager::removeClient(ClientInformation* client){
+    assert(client);
+    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
+    // first delete all remained gamestates
+    std::map<unsigned int, packet::Gamestate*>::iterator it;
+    for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
+      delete it->second;
+    // now delete the clients gamestatemap
+    gamestateMap_.erase(clientMap);
+  }
+
+  bool GamestateManager::processGamestate(packet::Gamestate *gs){
+    if(gs->isCompressed())
+    {
+       bool b = gs->decompressData();
+       assert(b);
+    }
+    assert(!gs->isDiffed());
+    return gs->spreadData(0x1);
+  }
+
+}
Index: /code/branches/libraries2/src/libraries/network/GamestateManager.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/GamestateManager.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/GamestateManager.h	(revision 5713)
@@ -0,0 +1,98 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Interface: GamestateManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _GamestateManager_H__
+#define _GamestateManager_H__
+
+#include "NetworkPrereqs.h"
+
+#include <map>
+#include "GamestateHandler.h"
+#include "core/CorePrereqs.h"
+
+namespace orxonox
+{
+
+  const int KEEP_GAMESTATES = 10;
+
+  /**
+  * This Class implements a manager for gamestates:
+  * - creating snapshots of gamestates
+  * - writing gamestates to universe
+  * - diffing gamestates
+  * EN/DECODATION:
+  * a: last Gamestate a client has received
+  * b: new Gamestate
+  * x: diffed and compressed gamestate
+  * x=(a^b)
+  * b=(a^x)
+  * diff(a,diff(a,x))=x (hope this is correct)
+  * @author Oliver Scheuss
+  */
+  class _NetworkExport GamestateManager: public GamestateHandler{
+  public:
+    GamestateManager();
+    ~GamestateManager();
+
+    bool add(packet::Gamestate *gs, unsigned int clientID);
+    bool processGamestates();
+    bool update();
+    void sendGamestates();
+//     packet::Gamestate *popGameState(unsigned int clientID);
+    void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
+
+    bool getSnapshot();
+
+    bool ack(unsigned int gamestateID, unsigned int clientID);
+    void removeClient(ClientInformation *client);
+  private:
+    bool processGamestate(packet::Gamestate *gs);
+
+    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
+    std::map<unsigned int, packet::Gamestate*> gamestateQueue;
+    packet::Gamestate *reference;
+    TrafficControl *trafficControl_;
+    unsigned int id_;
+//     boost::mutex* threadMutex_;
+    ThreadPool*   /*thread*/Pool_;
+  };
+
+}
+
+#endif /* _GameStateManager_H__ */
Index: /code/branches/libraries2/src/libraries/network/Host.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/Host.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Host.cc	(revision 5713)
@@ -0,0 +1,114 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Host.h"
+
+#include <cassert>
+#include <string>
+
+#include "core/ConsoleCommand.h"
+#include "core/ObjectList.h"
+#include "ChatListener.h"
+
+namespace orxonox {
+
+SetConsoleCommandShortcut(Host, Chat);
+
+Host *Host::instance_=0;
+
+/**
+ * @brief Constructor: assures that only one reference will be created and sets the pointer
+ */
+Host::Host()
+{
+  clientID_=0;
+  assert(instance_==0);
+  instance_=this;
+}
+
+
+/**
+ * @brief Destructor: resets the instance pointer to 0
+ */
+Host::~Host()
+{
+  instance_=0;
+}
+
+/**
+ * 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 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(!instance_)
+  {
+    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
+      it->incomingChat(message, 0);
+    return true;
+  }
+  return instance_->chat(message);
+}
+
+bool Host::Broadcast(const std::string& message){
+  if(!instance_)
+  {
+    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
+      it->incomingChat(message, CLIENTID_UNKNOWN);
+    return true;
+  }
+  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);
+
+  return instance_->processChat(message, playerID);
+}
+
+}//namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/Host.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/Host.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Host.h	(revision 5713)
@@ -0,0 +1,86 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _NETWORK_Host_H__
+#define _NETWORK_Host_H__
+
+#include "NetworkPrereqs.h"
+
+namespace orxonox {
+
+  const unsigned int CLIENTID_SERVER = 0;
+  const unsigned int NETWORK_FREQUENCY = 30;
+  const float NETWORK_PERIOD = 1.0f/NETWORK_FREQUENCY;
+
+/**
+*       @brief Base class of Server and Client
+*       This is the Base class of the Server and Client classes
+*       - Makes server and client a singleton
+*       - defines static functions available on both server and client
+*       - is the interface to be used when communicating with the network
+*	@author Oliver Scheuss
+*/
+class _NetworkExport Host{
+  private:
+    //TODO add theese functions or adequate
+    //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
+    //virtual bool sendChat(packet::Chat *chat)=0;
+    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
+    virtual bool chat(const std::string& message)=0;
+    virtual bool broadcast(const std::string& message)=0;
+    virtual bool processChat(const std::string& message, unsigned int playerID)=0;
+    virtual bool isServer_()=0;
+
+
+
+  protected:
+    Host();
+    virtual ~Host();
+    static Host *instance_;
+    unsigned int clientID_;
+    unsigned int shipID_;
+
+  public:
+    static bool running(){return instance_!=0;}
+    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 bool Chat(const std::string& message);
+    static bool Broadcast(const std::string& message);
+    static bool incomingChat(const std::string& message, unsigned int playerID);
+  private:
+};
+
+}
+
+#endif /* _NETWORK_Host_H__ */
Index: /code/branches/libraries2/src/libraries/network/NetworkFunction.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/NetworkFunction.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/NetworkFunction.cc	(revision 5713)
@@ -0,0 +1,97 @@
+/*
+ *   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 "NetworkFunction.h"
+#include "core/CoreIncludes.h"
+
+namespace orxonox
+{
+  std::map<std::string, NetworkFunctionBase*> NetworkFunctionBase::nameMap_;
+  std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_;
+  
+  std::map<NetworkFunctionPointer, NetworkFunctionStatic*> NetworkFunctionStatic::functorMap_;
+  std::map<uint32_t, NetworkFunctionStatic*> NetworkFunctionStatic::idMap_;
+      
+  std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
+  std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
+
+  NetworkFunctionBase::NetworkFunctionBase(const std::string& name)
+  {
+    RegisterRootObject(NetworkFunctionBase);
+    
+    static uint32_t networkID = 0;
+    this->networkID_ = networkID++;
+    
+    this->name_ = name;
+    nameMap_[name] = this;
+  }
+  NetworkFunctionBase::~NetworkFunctionBase()
+  {
+  }
+  
+  
+  void NetworkFunctionBase::destroyAllNetworkFunctions()
+  {
+    std::map<std::string, NetworkFunctionBase*>::iterator it;
+    for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
+      delete it->second;
+  }
+  
+  
+  NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
+    NetworkFunctionBase(name)
+  {
+    RegisterObject(NetworkFunctionStatic);
+    
+    this->functor_ = functor;
+    functorMap_[p] = this;
+    idMap_[ this->getNetworkID() ] = this;
+  }
+  
+  NetworkFunctionStatic::~NetworkFunctionStatic()
+  {
+    delete this->functor_;
+  }
+  
+  
+  
+  NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p):
+    NetworkFunctionBase(name)
+  {
+    RegisterObject(NetworkMemberFunctionBase);
+    
+    functorMap_[p] = this;
+    idMap_[ this->getNetworkID() ] = this;
+  }
+  
+  NetworkMemberFunctionBase::~NetworkMemberFunctionBase()
+  {
+  }
+  
+
+}
Index: /code/branches/libraries2/src/libraries/network/NetworkFunction.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/NetworkFunction.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/NetworkFunction.h	(revision 5713)
@@ -0,0 +1,246 @@
+/*
+ *   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 _NetworkFunction_H__
+#define _NetworkFunction_H__
+
+#include "NetworkPrereqs.h"
+
+#include <cassert>
+#include <cstring>
+#include <map>
+#include <string>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/static_assert.hpp>
+
+#include "core/Functor.h"
+#include "core/Identifier.h"
+#include "FunctionCallManager.h"
+#include "synchronisable/Synchronisable.h"
+
+namespace orxonox
+{
+
+#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
+static const unsigned int MAX_FUNCTION_POINTER_SIZE = 8;
+#else
+static const unsigned int MAX_FUNCTION_POINTER_SIZE = 16;
+#endif //ORXONOX_COMPILER_GCC
+static const unsigned int MAX_FUNCTION_POINTER_INTS = (MAX_FUNCTION_POINTER_SIZE-1)/4+1;
+
+struct _NetworkExport NetworkFunctionPointer {
+  uint32_t pointer[MAX_FUNCTION_POINTER_INTS];
+  bool operator<(const NetworkFunctionPointer& b) const
+  {
+#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
+    return pointer[0]<b.pointer[0] ? true : pointer[1]<b.pointer[1];
+#else //ORXONOX_COMPILER_GCC
+    return pointer[0]<b.pointer[0] ? true : ( pointer[1]<b.pointer[1] ? true : ( pointer[2]<b.pointer[2] ? true : pointer[3]<b.pointer[3] ) );
+#endif //ORXONOX_COMPILER_GCC
+  }
+};
+
+
+
+
+
+class _NetworkExport NetworkFunctionBase: virtual public OrxonoxClass {
+  public:
+    NetworkFunctionBase(const std::string& name);
+    ~NetworkFunctionBase();
+    
+    virtual void        setNetworkID(uint32_t id)       { this->networkID_ = id; }
+    inline uint32_t     getNetworkID() const            { return this->networkID_; }
+    inline const std::string& getName() const           { return name_; }
+    static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
+    
+    static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
+    
+    static void destroyAllNetworkFunctions();
+    
+  protected:
+    static std::map<uint32_t, bool> isStaticMap_;
+    
+  private:
+    static std::map<std::string, NetworkFunctionBase*> nameMap_;
+    uint32_t networkID_;
+    std::string name_;
+      
+};
+
+
+class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
+  public:
+    NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p);
+    ~NetworkFunctionStatic();
+    
+    inline void call(){ (*this->functor_)(); }
+    inline void call(const MultiType& mt1){ (*this->functor_)(mt1); }
+    inline void call(const MultiType& mt1, const MultiType& mt2){ (*this->functor_)(mt1, mt2); }
+    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3){ (*this->functor_)(mt1, mt2, mt3); }
+    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); }
+    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
+    
+    virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
+    static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
+    static NetworkFunctionStatic* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
+    static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
+    
+  private:
+    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
+    static std::map<uint32_t, NetworkFunctionStatic*> idMap_;
+    
+    FunctorStatic* functor_;
+    
+};
+
+
+class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase {
+  public:
+    NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p);
+    ~NetworkMemberFunctionBase();
+    
+    virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
+    static inline NetworkMemberFunctionBase* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
+    static NetworkMemberFunctionBase* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
+    static NetworkMemberFunctionBase* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
+    
+    // 
+    virtual void call(uint32_t objectID)=0;
+    virtual void call(uint32_t objectID, const MultiType& mt1)=0;
+    virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)=0;
+    virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)=0;
+    virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
+    virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
+    
+  private:
+    static std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> functorMap_;
+    static std::map<uint32_t, NetworkMemberFunctionBase*> idMap_;
+};
+
+
+template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
+  public:
+    NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p);
+    ~NetworkMemberFunction();
+    
+    inline void call(uint32_t objectID)
+    { 
+      if ( Synchronisable::getSynchronisable(objectID)!=0 )
+        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)));
+    }
+    inline void call(uint32_t objectID, const MultiType& mt1)
+    { 
+      if ( Synchronisable::getSynchronisable(objectID)!=0 )
+        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1);
+    }
+    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)
+    { 
+      if ( Synchronisable::getSynchronisable(objectID)!=0 )
+        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2);
+    }
+    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+    { 
+      if ( Synchronisable::getSynchronisable(objectID)!=0 )
+        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3);
+    }
+    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+    { 
+      if ( Synchronisable::getSynchronisable(objectID)!=0 )
+        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4);
+    }
+    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+    { 
+      if ( Synchronisable::getSynchronisable(objectID)!=0 )
+        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5);
+    }
+    
+  private:
+    FunctorMember<T>* functor_;
+};
+
+template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p):
+    NetworkMemberFunctionBase(name, p), functor_(functor)
+{
+}
+template <class T> NetworkMemberFunction<T>::~NetworkMemberFunction()
+{
+  delete this->functor_;
+}
+
+template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
+{
+  if( sizeof(NetworkFunctionPointer)-sizeof(T) > 0)
+    memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
+  T p2 = ptr;
+  memcpy( &destptr, &p2, sizeof(T) );
+//   for(unsigned int i=0; i<(sizeof(T)-1/4)+1; i++)
+//     *((uint32_t*)destptr+i) = p2>>32*i;
+}
+
+template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
+{
+  BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
+  NetworkFunctionPointer destptr;
+  copyPtr( ptr, destptr );
+  new NetworkFunctionStatic( createFunctor(ptr), name, destptr );
+  return 0;
+}
+
+template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
+{
+  BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above
+  NetworkFunctionPointer destptr;
+  copyPtr( ptr, destptr );
+  new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr );
+  return 0;
+}
+
+#define registerStaticNetworkFunction( functionPointer ) \
+  static void* BOOST_PP_CAT( NETWORK_FUNCTION_, __LINE__ ) = registerStaticNetworkFunctionFct( functionPointer, #functionPointer );
+#define registerMemberNetworkFunction( class, function ) \
+  static void* BOOST_PP_CAT( NETWORK_FUNCTION_##class, __LINE__ ) = registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function);
+  // call it with functionPointer, clientID, args
+#define callStaticNetworkFunction( functionPointer, ...) \
+  { \
+    NetworkFunctionPointer p1; \
+    copyPtr( functionPointer, p1 ); \
+    FunctionCallManager::addCallStatic(NetworkFunctionStatic::getFunction(p1)->getNetworkID(), __VA_ARGS__); \
+  }
+  // call it with class, function, objectID, clientID, args
+#define callMemberNetworkFunction( class, function, objectID, ...) \
+  { \
+    NetworkFunctionPointer p1; \
+    copyPtr( &class::function, p1 ); \
+    FunctionCallManager::addCallMember(NetworkMemberFunctionBase::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
+  }
+
+
+}
+
+#endif /* _NetworkFunction_H__ */
Index: /code/branches/libraries2/src/libraries/network/NetworkPrecompiledHeaders.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/NetworkPrecompiledHeaders.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/NetworkPrecompiledHeaders.h	(revision 5713)
@@ -0,0 +1,66 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+@file
+@brief
+    Compilation of the most often used header files in the network library
+*/
+
+#include "OrxonoxConfig.h"
+
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <list>
+#include <map>
+#include <queue>
+#include <set>
+#include <sstream>
+#include <string>
+#include <vector>
+
+
+#ifdef ORXONOX_COMPILER_MSVC
+
+#include <OgreMath.h>
+#include <OgreVector2.h>
+#include <OgreVector3.h>
+#include <OgreVector4.h>
+#include <OgreQuaternion.h>
+#include <OgreColourValue.h>
+
+#define WIN32_LEAN_AND_MEAN
+#include <enet/enet.h>
+#undef max
+#undef min
+
+#include "util/Debug.h"
+#include "core/Identifier.h"
+
+#endif /* ORXONOX_COMPILER_MSVC */
Index: /code/branches/libraries2/src/libraries/network/NetworkPrereqs.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/NetworkPrereqs.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/NetworkPrereqs.h	(revision 5713)
@@ -0,0 +1,143 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+  @file
+  @brief Contains all the necessary forward declarations for all classes and structs.
+*/
+
+#ifndef _NetworkPrereqs_H__
+#define _NetworkPrereqs_H__
+
+#include "OrxonoxConfig.h"
+
+//-----------------------------------------------------------------------
+// Shared library settings
+//-----------------------------------------------------------------------
+#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( NETWORK_STATIC_BUILD )
+#  ifdef NETWORK_SHARED_BUILD
+#    define _NetworkExport __declspec(dllexport)
+#  else
+#    if defined( __MINGW32__ )
+#      define _NetworkExport
+#    else
+#      define _NetworkExport __declspec(dllimport)
+#    endif
+#  endif
+#elif defined ( ORXONOX_GCC_VISIBILITY )
+#  define _NetworkExport  __attribute__ ((visibility("default")))
+#else
+#  define _NetworkExport
+#endif
+
+//-----------------------------------------------------------------------
+// Library global contants
+//-----------------------------------------------------------------------
+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 uint32_t     OBJECTID_UNKNOWN    = static_cast<uint32_t>(-1);
+}
+
+//-----------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------
+
+// from ENet
+struct _ENetPeer;
+typedef _ENetPeer ENetPeer;
+struct _ENetPacket;
+typedef _ENetPacket ENetPacket;
+struct _ENetEvent;
+typedef _ENetEvent ENetEvent;
+struct _ENetHost;
+typedef _ENetHost ENetHost;
+struct _ENetAddress;
+typedef _ENetAddress ENetAddress;
+
+namespace orxonox
+{
+  class Client;
+  class ClientConnection;
+  class ClientConnectionListener;
+  class ClientFrameListener;
+  class ClientInformation;
+  class Connection;
+  class FunctionCallManager;
+  class GamestateClient;
+  class GamestateManager;
+  class GamestateHandler;
+  class NetworkCallbackBase;
+  template <class T> class NetworkCallback;
+  class NetworkCallbackManager;
+  class NetworkFunctionBase;
+  class NetworkFunctionStatic;
+  class NetworkMemberFunctionBase;
+  template <class T> class NetworkMemeberFunction;
+  struct NetworkFunctionPointer;
+  class Server;
+  class ServerConnection;
+  class ServerFrameListener;
+  class Synchronisable;
+  class SynchronisableVariableBase;
+  template <class T> class SynchronisableVariable;
+  template <class T> class SynchronisableVariableBidirectional;
+  struct ClientList;
+  struct PacketEnvelope;
+  struct QueueItem;
+  struct syncData;
+  class TrafficControl;
+  class obj;
+  class objInfo;
+
+  namespace packet
+  {
+    class Acknowledgement;
+    class Chat;
+    class ClassID;
+    class FunctionCalls;
+    class FunctionIDs;
+    class Gamestate;
+    class NetworkIDs;
+    class Packet;
+    class Welcome;
+
+    namespace PacketFlag
+    {
+      enum Value
+      {
+        Reliable   = 1,
+        Unsequence = 2,
+        NoAllocate = 4
+      };
+    }
+  }
+}
+
+#endif /* _NetworkPrereqs_H__ */
Index: /code/branches/libraries2/src/libraries/network/Server.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/Server.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Server.cc	(revision 5713)
@@ -0,0 +1,375 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Implementation: Server
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "Server.h"
+
+#include <enet/enet.h>
+#include <cassert>
+#include <string>
+
+#include "util/Debug.h"
+#include "core/Clock.h"
+#include "core/ObjectList.h"
+#include "core/Executor.h"
+#include "packet/Chat.h"
+#include "packet/ClassID.h"
+#include "packet/DeleteObjects.h"
+#include "packet/FunctionIDs.h"
+#include "packet/Gamestate.h"
+#include "packet/Welcome.h"
+#include "ChatListener.h"
+#include "ClientInformation.h"
+#include "FunctionCallManager.h"
+#include "GamestateManager.h"
+
+namespace orxonox
+{
+  const unsigned int MAX_FAILURES = 20;
+
+  /**
+  * Constructor for default values (bindaddress is set to ENET_HOST_ANY
+  *
+  */
+  Server::Server() {
+    this->timeSinceLastUpdate_=0;
+  }
+
+  Server::Server(int port){
+    this->setPort( port );
+    this->timeSinceLastUpdate_=0;
+  }
+
+  /**
+  * Constructor
+  * @param port Port to listen on
+  * @param bindAddress Address to listen on
+  */
+  Server::Server(int port, const std::string& bindAddress) {
+    this->setPort( port );
+    this->setBindAddress( bindAddress );
+    this->timeSinceLastUpdate_=0;
+  }
+
+  /**
+  * @brief Destructor
+  */
+  Server::~Server(){
+  }
+
+  /**
+  * This function opens the server by creating the listener thread
+  */
+  void Server::open() {
+    COUT(4) << "opening server" << endl;
+    this->openListener();
+    return;
+  }
+
+  /**
+  * This function closes the server
+  */
+  void Server::close() {
+    COUT(4) << "closing server" << endl;
+    this->disconnectClients();
+    this->closeListener();
+    return;
+  }
+
+  bool Server::processChat(const std::string& message, unsigned int playerID){
+    ClientInformation *temp = ClientInformation::getBegin();
+    packet::Chat *chat;
+    while(temp){
+      chat = new packet::Chat(message, playerID);
+      chat->setClientID(temp->getID());
+      if(!chat->send())
+        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+      temp = temp->next();
+    }
+//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
+    return true;
+  }
+
+
+  /**
+  * Run this function once every tick
+  * calls processQueue and updateGamestate
+  * @param time time since last tick
+  */
+  void Server::update(const Clock& time) {
+    // receive incoming packets
+    Connection::processQueue();
+    
+    if ( ClientInformation::hasClients() )
+    {
+      // process incoming gamestates
+      GamestateManager::processGamestates();
+      
+      // send function calls to clients
+      FunctionCallManager::sendCalls();
+      
+      //this steers our network frequency
+      timeSinceLastUpdate_+=time.getDeltaTime();
+      if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+      {
+        timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
+        updateGamestate();
+      }
+      sendPackets(); // flush the enet queue
+    }
+  }
+
+  bool Server::queuePacket(ENetPacket *packet, int clientID){
+    return ServerConnection::addPacket(packet, clientID);
+  }
+  
+  /**
+   * @brief: returns ping time to client in milliseconds 
+   */
+  unsigned int Server::getPing(unsigned int clientID){
+    assert(ClientInformation::findClient(clientID));
+    return ClientInformation::findClient(clientID)->getRTT();
+  }
+
+  /**
+   * @brief: return packet loss ratio to client (scales from 0 to 1)
+   */
+  double Server::getPacketLoss(unsigned int clientID){
+    assert(ClientInformation::findClient(clientID));
+    return ClientInformation::findClient(clientID)->getPacketLoss();
+  }
+
+  /**
+  * takes a new snapshot of the gamestate and sends it to the clients
+  */
+  void Server::updateGamestate() {
+    if( ClientInformation::getBegin()==NULL )
+      //no client connected
+      return;
+    GamestateManager::update();
+    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
+    //std::cout << "updated gamestate, sending it" << std::endl;
+    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
+    sendGameState();
+    sendObjectDeletes();
+    COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
+    //std::cout << "sent gamestate" << std::endl;
+  }
+
+  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
+    packet::Packet *p = packet::Packet::createPacket(packet, peer);
+    return p->process();
+  }
+
+  /**
+  * sends the gamestate
+  */
+  bool Server::sendGameState() {
+//     COUT(5) << "Server: starting function sendGameState" << std::endl;
+//     ClientInformation *temp = ClientInformation::getBegin();
+//     bool added=false;
+//     while(temp != NULL){
+//       if( !(temp->getSynched()) ){
+//         COUT(5) << "Server: not sending gamestate" << std::endl;
+//         temp=temp->next();
+//         if(!temp)
+//           break;
+//         continue;
+//       }
+//       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+//       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+//       int cid = temp->getID(); //get client id
+//       packet::Gamestate *gs = GamestateManager::popGameState(cid);
+//       if(gs==NULL){
+//         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
+//         temp = temp->next();
+//         continue;
+//       }
+//       //std::cout << "adding gamestate" << std::endl;
+//       gs->setClientID(cid);
+//       if ( !gs->send() ){
+//         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+//         temp->addFailure();
+//       }else
+//         temp->resetFailures();
+//       added=true;
+//       temp=temp->next();
+//       // gs gets automatically deleted by enet callback
+//     }
+    GamestateManager::sendGamestates();
+    return true;
+  }
+
+  bool Server::sendObjectDeletes(){
+    ClientInformation *temp = ClientInformation::getBegin();
+    if( temp == NULL )
+      //no client connected
+      return true;
+    packet::DeleteObjects *del = new packet::DeleteObjects();
+    if(!del->fetchIDs())
+      return true;  //everything ok (no deletes this tick)
+//     COUT(3) << "sending DeleteObjects" << std::endl;
+    while(temp != NULL){
+      if( !(temp->getSynched()) ){
+        COUT(5) << "Server: not sending gamestate" << std::endl;
+        temp=temp->next();
+        continue;
+      }
+      int cid = temp->getID(); //get client id
+      packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
+      assert(cd);
+      cd->setClientID(cid);
+      if ( !cd->send() )
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+      temp=temp->next();
+      // gs gets automatically deleted by enet callback
+    }
+    delete del;
+    return true;
+  }
+
+
+  void Server::addClient(ENetEvent *event){
+    static unsigned int newid=1;
+
+    COUT(2) << "Server: adding client" << std::endl;
+    ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
+    if(!temp){
+      COUT(2) << "Server: could not add client" << std::endl;
+    }
+    temp->setID(newid);
+    temp->setPeer(event->peer);
+
+    // inform all the listeners
+    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
+    while(listener){
+      listener->clientConnected(newid);
+      listener++;
+    }
+
+    ++newid;
+
+    COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
+    createClient(temp->getID());
+}
+
+  bool Server::createClient(int clientID){
+    ClientInformation *temp = ClientInformation::findClient(clientID);
+    if(!temp){
+      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
+      return false;
+    }
+    COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+    
+    // synchronise class ids
+    syncClassid(temp->getID());
+    
+    // now synchronise functionIDs
+    packet::FunctionIDs *fIDs = new packet::FunctionIDs();
+    fIDs->setClientID(clientID);
+    bool b = fIDs->send();
+    assert(b);
+    
+    temp->setSynched(true);
+    COUT(4) << "sending welcome" << std::endl;
+    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
+    w->setClientID(temp->getID());
+    b = w->send();
+    assert(b);
+    packet::Gamestate *g = new packet::Gamestate();
+    g->setClientID(temp->getID());
+    b = g->collectData(0,0x1);
+    if(!b)
+      return false; //no data for the client
+    b = g->compressData();
+    assert(b);
+    b = g->send();
+    assert(b);
+    return true;
+  }
+  
+  void Server::disconnectClient( ClientInformation *client ){
+    ServerConnection::disconnectClient( client );
+    GamestateManager::removeClient(client);
+// inform all the listeners
+    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
+    while(listener){
+      listener->clientDisconnected(client->getID());
+      ++listener;
+    }
+    delete client; //remove client from list
+  }
+
+  bool Server::chat(const std::string& message){
+      return this->sendChat(message, Host::getPlayerID());
+  }
+
+  bool Server::broadcast(const std::string& message){
+      return this->sendChat(message, CLIENTID_UNKNOWN);
+  }
+
+  bool Server::sendChat(const std::string& message, unsigned int clientID){
+    ClientInformation *temp = ClientInformation::getBegin();
+    packet::Chat *chat;
+    while(temp){
+      chat = new packet::Chat(message, clientID);
+      chat->setClientID(temp->getID());
+      if(!chat->send())
+        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+      temp = temp->next();
+    }
+//    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
+    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
+      it->incomingChat(message, clientID);
+
+    return true;
+  }
+
+  void Server::syncClassid(unsigned int clientID) {
+    int failures=0;
+    packet::ClassID *classid = new packet::ClassID();
+    classid->setClientID(clientID);
+    while(!classid->send() && failures < 10){
+      failures++;
+    }
+    assert(failures<10);
+    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
+  }
+
+}
Index: /code/branches/libraries2/src/libraries/network/Server.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/Server.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/Server.h	(revision 5713)
@@ -0,0 +1,86 @@
+/*
+ *   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 _Server_H__
+#define _Server_H__
+
+#include "NetworkPrereqs.h"
+
+#include "core/CorePrereqs.h"
+#include "Host.h"
+#include "GamestateManager.h"
+#include "ServerConnection.h"
+
+namespace orxonox
+{
+
+  /**
+  * 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{
+  public:
+    Server();
+    Server(int port);
+    Server(int port, const std::string& bindAddress);
+    ~Server();
+
+    void open();
+    void close();
+    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);
+    double getPacketLoss(unsigned int clientID);
+  protected:
+    void updateGamestate();
+  private:
+    virtual bool isServer_(){return true;}
+    unsigned int shipID(){return 0;}
+    unsigned int playerID(){return 0;}
+    
+    void addClient(ENetEvent *event);
+    bool createClient(int clientID);
+    void disconnectClient( ClientInformation *client);
+    bool processPacket( ENetPacket *packet, ENetPeer *peer );
+    bool sendGameState();
+    bool sendObjectDeletes();
+    virtual bool chat(const std::string& message);
+    virtual bool broadcast(const std::string& message);
+    bool sendChat(const std::string& message, unsigned int clientID);
+    void syncClassid(unsigned int clientID);
+
+    float timeSinceLastUpdate_;
+  };
+
+
+
+
+}
+
+#endif /* _Server_H__ */
Index: /code/branches/libraries2/src/libraries/network/ServerConnection.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/ServerConnection.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ServerConnection.cc	(revision 5713)
@@ -0,0 +1,166 @@
+/*
+ *   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 "ServerConnection.h"
+
+#include <cassert>
+#include <string>
+#include <enet/enet.h>
+
+#include "util/Debug.h"
+#include "ClientInformation.h"
+
+namespace orxonox
+{
+
+  ServerConnection::ServerConnection():
+    bListening_(false)
+  {
+    this->bindAddress_ = new ENetAddress();
+    this->bindAddress_->host = ENET_HOST_ANY;
+    this->bindAddress_->port = NETWORK_PORT;
+  }
+
+  ServerConnection::~ServerConnection(){
+    if ( this->bListening_ )
+      closeListener();
+    delete this->bindAddress_;
+  }
+
+  void ServerConnection::setBindAddress( const std::string& bindAddress ) {
+    enet_address_set_host (this->bindAddress_, bindAddress.c_str());
+  }
+
+  void ServerConnection::setPort( unsigned int port ) {
+      this->bindAddress_->port = port;
+  }
+
+  bool ServerConnection::openListener() {
+    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0);
+    if ( this->host_ == NULL )
+      return false;
+    else
+      return true;
+  }
+
+  bool ServerConnection::closeListener() {
+    this->bListening_=false;
+    disconnectClients();
+    enet_host_destroy(this->host_);
+    return true;
+  }
+
+  bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
+    if ( clientID == CLIENTID_UNKNOWN )
+    {
+      return addPacketAll(packet);
+    }
+    else
+    {
+      ClientInformation *temp = ClientInformation::findClient(clientID);
+      if(!temp){
+        COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
+        return false;
+      }
+      return Connection::addPacket(packet, temp->getPeer());
+    }
+  }
+
+  bool ServerConnection::addPacketAll(ENetPacket *packet) {
+    if ( !Connection::getInstance() )
+      return false;
+    enet_host_broadcast( Connection::getInstance()->getHost(), 0, packet);
+    return true;
+  }
+  
+  void ServerConnection::disconnectClient(ClientInformation *client)
+  {
+    Connection::disconnectPeer( client->getPeer() );
+    delete client;
+  }
+  
+  void ServerConnection::disconnectPeer( ENetEvent* event )
+  {
+    COUT(4) << "removing client from list" << std::endl;
+    ClientInformation *client = ClientInformation::findClient(&event->peer->address);
+    if(!client)
+      return;
+    else
+      ServerConnection::disconnectClient( client );
+  }
+  
+  void ServerConnection::disconnectClient(int clientID){
+    ClientInformation *client = ClientInformation::findClient(clientID);
+    if(client)
+      disconnectClient(client);
+  }
+
+  void ServerConnection::disconnectClients() {
+    ENetEvent event;
+    ClientInformation *temp = ClientInformation::getBegin();
+    while(temp!=0){
+      disconnectClient( temp );
+      temp = temp->next();
+    }
+    temp = ClientInformation::getBegin();
+    while( temp!=0 ){
+      if( service( &event ) )
+      {
+        switch (event.type)
+        {
+        case ENET_EVENT_TYPE_NONE: break;
+        case ENET_EVENT_TYPE_CONNECT: break;
+        case ENET_EVENT_TYPE_RECEIVE:
+          enet_packet_destroy(event.packet);
+          break;
+        case ENET_EVENT_TYPE_DISCONNECT:
+          if(ClientInformation::findClient(&(event.peer->address)))
+            delete ClientInformation::findClient(&(event.peer->address));
+          temp = ClientInformation::getBegin();
+          break;
+        }
+      }
+    }
+    return;
+  }
+
+
+  int ServerConnection::getClientID(ENetPeer* peer) {
+    return getClientID(&(peer->address));
+  }
+
+  int ServerConnection::getClientID(ENetAddress* address) {
+    return ClientInformation::findClient(address)->getID();
+  }
+
+  ENetPeer *ServerConnection::getClientPeer(int clientID) {
+    return ClientInformation::findClient(clientID)->getPeer();
+  }
+
+
+}
Index: /code/branches/libraries2/src/libraries/network/ServerConnection.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/ServerConnection.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/ServerConnection.h	(revision 5713)
@@ -0,0 +1,80 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+//
+// C++ Interface: ServerConnection
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _ServerConnection_H__
+#define _ServerConnection_H__
+
+#include "NetworkPrereqs.h"
+#include "Connection.h"
+
+namespace orxonox
+{
+
+  class _NetworkExport ServerConnection : public Connection{
+  public:
+    ~ServerConnection();
+    
+    void setBindAddress( const std::string& bindAddress );
+    void setPort( unsigned int port );
+    
+    bool openListener();
+    bool closeListener();
+    static bool addPacket(ENetPacket *packet, unsigned int ID);
+    static bool addPacketAll(ENetPacket *packet);
+    virtual void disconnectClient(ClientInformation *client);
+    void disconnectPeer( ENetEvent* event );
+    void disconnectClient(int clientID);
+  protected:
+    ServerConnection();
+    void disconnectClients();
+
+  private:
+    int getClientID(ENetPeer* peer);
+    int getClientID(ENetAddress* address);
+    ENetPeer* getClientPeer(int clientID);
+
+    ENetAddress* bindAddress_;
+
+    bool bListening_;
+
+  };
+
+}
+
+#endif /* _ServerConnection_H__ */
Index: /code/branches/libraries2/src/libraries/network/TODO
===================================================================
--- /code/branches/libraries2/src/libraries/network/TODO	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/TODO	(revision 5713)
@@ -0,0 +1,11 @@
+todo: 
+	test network functionality with paketloss/delay: http://www.linuxfoundation.org/en/Net:Netem#Packet_loss
+
+	minimize synchronisableHeader
+
+	!!! ensure that objects get synched, when newly created, even if not their tick
+
+	setvariable mode
+	objectmode
+	priorities (put into gamestatehandler)
+		manage delete object handling (only send deletes of acked objects)
Index: /code/branches/libraries2/src/libraries/network/TrafficControl.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/TrafficControl.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/TrafficControl.cc	(revision 5713)
@@ -0,0 +1,327 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "TrafficControl.h"
+
+#include <cassert>
+#include <boost/bind.hpp>
+
+#include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
+#include "synchronisable/Synchronisable.h"
+
+namespace orxonox {
+
+  static const unsigned int SCHED_PRIORITY_OFFSET = static_cast<unsigned int>(-1);
+
+  objInfo::objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched)
+  {
+    objID = ID; objCreatorID = creatorID; objCurGS = curGsID; objDiffGS = diffGsID; objSize = size; objValuePerm = prioperm; objValueSched = priosched;
+  }
+
+  objInfo::objInfo()
+  {
+    objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objCurGS = GAMESTATEID_INITIAL; objDiffGS = objCurGS; objSize = 0; objValuePerm = 0; objValueSched = 0;
+  }
+
+
+
+  obj::obj()
+  {
+    objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objSize = 0; objDataOffset = 0;
+  }
+  obj::obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset )
+  {
+    objID = ID; objCreatorID = creatorID; objSize = size; objDataOffset = offset;
+  }
+
+/**
+*Initializing protected members
+*/
+	TrafficControl *TrafficControl::instance_=0;
+
+	/**
+	* @brief Constructor: assures that only one reference will be created and sets the pointer
+	*/
+	TrafficControl::TrafficControl()
+	{
+    RegisterObject(TrafficControl);
+	  assert(instance_==0);
+	  instance_=this;
+    this->setConfigValues();
+	}
+
+	/**
+	* @brief Destructor: resets the instance pointer to 0
+	*/
+	TrafficControl::~TrafficControl()
+	{
+	  instance_=0;
+	}
+
+/**
+*Definition of public members
+*/
+
+  void TrafficControl::setConfigValues()
+  {
+    SetConfigValue ( bActive_, false );
+    SetConfigValue ( targetSize, 10000 );
+  }
+
+  /**
+  * sort-algorithm for sorting the objectlist after priorities
+  */
+  bool TrafficControl::prioritySort(uint32_t clientID, obj i, obj j)
+  {
+    assert(clientListPerm_.find(clientID) != clientListPerm_.end());  //make sure the client exists in our list
+    assert(clientListPerm_[clientID].find(i.objID) != clientListPerm_[clientID].end()); // make sure the object i is in the client list
+    assert(clientListPerm_[clientID].find(j.objID) != clientListPerm_[clientID].end()); // make sure the object j is in the client list
+
+    int prio1 = clientListPerm_[clientID][i.objID].objValuePerm + clientListPerm_[clientID][i.objID].objValueSched;
+    int prio2 = clientListPerm_[clientID][j.objID].objValuePerm + clientListPerm_[clientID][j.objID].objValueSched;
+    return prio1 < prio2;
+  }
+
+  /**
+  * sort-algorithm for sorting the objectList after position in original data stream
+  */
+  bool TrafficControl::dataSort(obj i, obj j)
+  {
+    int pos1 = i.objDataOffset;
+    int pos2 = j.objDataOffset;
+    return pos1 < pos2;
+  }
+
+
+
+	void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list)
+	{
+	  currentClientID=clientID;
+	  currentGamestateID=gamestateID;
+	  evaluateList(clientID, list);
+	  return;
+	}
+
+  TrafficControl *TrafficControl::getInstance()
+  {
+    assert(instance_);
+    return instance_;
+  }
+
+	void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
+	{
+    if ( !this->bActive_ )
+      return;
+	  std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
+
+    //assertions to make sure the maps already exist
+    assert(clientListTemp_.find(clientID) != clientListTemp_.end() );
+    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
+    assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
+    
+    // shortcut for maps
+    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
+    std::map<unsigned int, std::list<obj> >& objectListTemp = clientListTemp_[clientID];
+
+    for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++)
+	  {
+      if(objectListPerm.find((*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists
+      {
+        objectListPerm[(*itvec).objID].objCurGS = gamestateID;
+        objectListPerm[(*itvec).objID].objValueSched = 0; //set scheduling value back
+      }
+      else
+      {
+        assert(0);
+        objectListPerm[(*itvec).objID].objCurGS = gamestateID;
+        objectListPerm[(*itvec).objID].objID = (*itvec).objID;
+        objectListPerm[(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
+        objectListPerm[(*itvec).objID].objSize = (*itvec).objSize;
+      }
+	  }
+	   // remove temporary list (with acked objects) from the map
+    objectListTemp.erase( objectListTemp.find(gamestateID) );
+	}
+
+/**
+*Definition of private members
+*/
+
+	/**
+	*updateClientListPerm
+	*returns void
+	*/
+	void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf)
+	{
+	  std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
+    unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0;
+    clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom);
+	}
+
+  /**
+  * updateClientListTemp
+  * takes the shortened list which will be sent to the gsmanager and puts the *info into clientListTemp
+  */
+  void TrafficControl::updateClientListTemp(std::list<obj>& list)
+  {
+    clientListTemp_[currentClientID][currentGamestateID] = list;
+  }
+
+  /**
+  *cut
+  *takes the current list that has to be returned to the gsmanager and shortens it in criteria of bandwidth of clientID(XY)
+  */
+  void TrafficControl::cut(std::list<obj>& list, unsigned int targetsize)
+  {
+    unsigned int size=0;
+    std::list<obj>::iterator itvec, ittemp;
+    assert(!list.empty());
+    for(itvec = list.begin(); itvec != list.end();)
+    {
+      assert( (*itvec).objSize < 1000);
+      if ( ( size + (*itvec).objSize ) < targetsize )
+      {
+        size += (*itvec).objSize;//objSize is given in bytes
+        ++itvec;
+      }
+      else
+      {
+        clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
+        list.erase(itvec, list.end());
+        break;
+      }
+//       printList(list, currentClientID);
+    }
+    assert(!list.empty());
+  }
+
+
+	/**
+	*evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
+	*/
+	void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list)
+	{
+
+    if( bActive_ )
+    {
+      //now the sorting
+
+      //compare listToProcess vs clientListPerm
+      //if listToProcess contains new Objects, add them to clientListPerm
+      std::list<obj>::iterator itvec;
+    
+      std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
+    
+      for( itvec=list.begin(); itvec != list.end(); itvec++)
+      {
+        if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
+        {
+        // we already have the object in our map
+        //obj bleibt in liste und permanente prio wird berechnet
+          objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
+          continue;//check next objId
+        }
+        else
+        {
+        // insert the object into clientListPerm
+          insertinClientListPerm(clientID,*itvec);
+          continue;//check next objId
+        }
+      }
+    //end compare listToProcess vs clientListPerm
+      
+      //sort copied list according to priorities
+      // use boost bind here because we need to pass a memberfunction to stl sort
+//       sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
+      list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
+      
+//       list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
+
+      //now we check, that the creator of an object always exists on a client
+      std::list<obj>::iterator itcreator;
+      for(itvec = list.begin(); itvec != list.end(); itvec++)
+      {
+        fixCreatorDependencies(itvec, list, clientID);
+      }
+      //end of sorting
+      //now the cutting, work the same obj out in processobjectlist and copiedlist, compression rate muss noch festgelegt werden.
+//       printList(list, clientID);
+      cut(list, targetSize);
+      //now sort again after objDataOffset
+//       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
+      list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
+      
+      //diese Funktion updateClientList muss noch gemacht werden
+      updateClientListTemp(list);
+      //end of sorting
+    }
+  }
+
+  void TrafficControl::printList(std::list<obj>& list, unsigned int clientID)
+  {
+    std::list<obj>::iterator it;
+    COUT(0) << "=========== Objectlist ===========" << endl;
+    for( it=list.begin(); it!=list.end(); it++)
+      COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;
+  }
+
+  void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID)
+  {
+    if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
+      return;
+    if( clientListPerm_[clientID][(*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
+      return;
+    std::list<obj>::iterator it2, it3=it1;
+    for( it2 = ++it3; it2 != list.end(); it2++ )
+    {
+      if( (*it2).objID == (*it1).objCreatorID )
+      {
+        it3 = list.insert(it1, *it2); //insert creator before it1
+        list.erase(it2);
+//         printList(list, clientID);
+        fixCreatorDependencies( it3, list, clientID );
+        break;
+      }
+    }
+  }
+
+  void TrafficControl::clientDisconnected(unsigned int clientID)
+  {
+    if( clientListPerm_.find(clientID) == clientListPerm_.end() )
+    {
+      assert(!this->bActive_);
+      return;
+    }
+    clientListTemp_.erase(clientListTemp_.find(clientID));
+    if( clientListTemp_.find(clientID) != clientListTemp_.end() )
+      clientListPerm_.erase(clientListPerm_.find(clientID));
+  }
+
+
+}//namespace network
Index: /code/branches/libraries2/src/libraries/network/TrafficControl.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/TrafficControl.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/TrafficControl.h	(revision 5713)
@@ -0,0 +1,142 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>
+ *   Co-authors:
+ *      ...
+ *
+
+ */
+#ifndef _TrafficControl_H__
+#define _TrafficControl_H__
+
+#include "NetworkPrereqs.h"
+
+#include <list>
+#include <map>
+#include "network/ClientConnectionListener.h"
+
+namespace orxonox {
+
+
+  /**
+   *a list of objects of this type will be given by the Server's Gamestate Manager
+   */
+  class objInfo
+  {
+    public:
+      uint32_t objID;
+      uint32_t objCreatorID;
+      uint32_t objCurGS;//current GameState ID
+      uint32_t objDiffGS;//difference between current and latest GameState
+      uint32_t objSize;
+      int objValuePerm;
+      int objValueSched;
+      objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched);
+      objInfo();
+  };
+
+/**
+   *a list of objects of this type will be given by the Server's Gamestate Manager
+ */
+  class obj
+  {
+    public:
+      uint32_t objID;
+      uint32_t objCreatorID;
+      uint32_t objSize;
+      uint32_t objDataOffset;
+      obj();
+      obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset );
+  };
+  
+
+
+
+/**
+*
+*/
+class TrafficControl : public ClientConnectionListener {
+  private:
+
+    /**
+    *permanent client list: contains client ids, object ids and objectInfos (in this order)
+    */
+    std::map<unsigned int, std::map<unsigned int, objInfo > > clientListPerm_;
+    //has to be created with constructor and then needs to be updated by evaluateList().
+
+    /**
+    *temporary client list: contains client ids, gamestate ids and object ids (in this order)
+    */
+    std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_;
+
+    /**updateReferenceList
+    *currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server
+    */
+    unsigned int currentGamestateID;
+    unsigned int currentClientID;
+    unsigned int targetSize;
+    bool         bActive_;
+    
+    void insertinClientListPerm(unsigned int clientID, obj objinf);
+    
+    void cut(std::list<obj>& list, unsigned int targetsize);
+    void updateClientListTemp(std::list<obj>& list);//done
+    /**
+    *evaluates Data given (list) and produces result(->Data to be updated)
+    */
+    void evaluateList(unsigned int clientID, std::list<obj>& list);//done    
+    void ack(unsigned int clientID, unsigned int gamestateID);  // this function gets called when the server receives an ack from the client
+    
+    //ClientConnectionListener functions
+    virtual void clientConnected(unsigned int clientID){};
+    virtual void clientDisconnected(unsigned int clientID);
+
+ 
+  protected:
+    static TrafficControl *instance_;
+
+  public:
+    TrafficControl();
+    virtual ~TrafficControl();
+    /**
+    *is being used by GSManager from Server:
+    *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY 
+    *Elements of list are accessed by *list[i]
+    *Elements of struct i are therefore: *list[i].objID
+    */
+    void setConfigValues();
+    static TrafficControl *getInstance();
+    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list); //gets a pointer to the list (containing objectIDs) and sorts it
+    static void processAck(unsigned int clientID, unsigned int gamestateID)
+    { return instance_->ack(clientID, gamestateID); }
+    void deleteObject(unsigned int objectID);				// this function gets called when an object has been deleted (in order to clean up lists and maps)
+    
+    bool prioritySort(uint32_t clientID, obj i, obj j);
+    bool dataSort(obj i, obj j);
+    void printList(std::list<obj>& list, unsigned int clientID);
+    void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj>& list, unsigned int clientID);
+};
+
+}
+
+#endif /* _TrafficControl_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/Acknowledgement.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Acknowledgement.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Acknowledgement.cc	(revision 5713)
@@ -0,0 +1,76 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Acknowledgement.h"
+
+#include "util/Debug.h"
+#include "network/GamestateHandler.h"
+
+namespace orxonox {
+namespace packet {
+
+#define PACKET_FLAGS_ACK    0
+#define _PACKETID           0
+#define _ACKID              _PACKETID + sizeof(packet::Type::Value)
+  
+Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_ACK;
+  data_=new uint8_t[ getSize() ];
+  *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
+  *(uint32_t *)(data_ + _ACKID ) = id;
+  clientID_=clientID;
+}
+
+Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+}
+
+Acknowledgement::~Acknowledgement()
+{
+}
+
+unsigned int Acknowledgement::getSize() const{
+  return _ACKID + sizeof(uint32_t);
+}
+
+bool Acknowledgement::process(){
+  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
+  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
+  delete this;
+  return b;
+}
+
+unsigned int Acknowledgement::getAckID(){
+  return *(uint32_t *)(data_ + _ACKID);
+}
+
+} //namespace packet
+} //namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/Acknowledgement.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Acknowledgement.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Acknowledgement.h	(revision 5713)
@@ -0,0 +1,58 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Acknowledgement_H__
+#define _Acknowledgement_H__
+
+#include "network/NetworkPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+const unsigned int ACKID_NACK = 0;
+namespace packet {
+/**
+	@author
+*/
+class _NetworkExport Acknowledgement : public Packet
+{
+public:
+  Acknowledgement( unsigned int id, unsigned int clientID );
+  Acknowledgement( uint8_t* data, unsigned int clientID );
+  ~Acknowledgement();
+
+  inline unsigned int getSize() const;
+  bool process();
+
+  unsigned int getAckID();
+private:
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _Acknowledgement_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/CMakeLists.txt
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/CMakeLists.txt	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/CMakeLists.txt	(revision 5713)
@@ -0,0 +1,24 @@
+ADD_SOURCE_FILES(NETWORK_SRC_FILES
+  Acknowledgement.cc
+  Chat.cc
+  ClassID.cc
+  DeleteObjects.cc
+  FunctionIDs.cc
+  FunctionCalls.cc
+  Gamestate.cc
+  Packet.cc
+  Welcome.cc
+)
+
+ADD_SOURCE_FILES(NETWORK_HDR_FILES
+  Acknowledgement.h
+  Chat.cc
+  Chat.h
+  ClassID.h
+  DeleteObjects.h
+  FunctionCalls.h
+  FunctionIDs.h
+  Gamestate.h
+  Packet.h
+  Welcome.h
+)
Index: /code/branches/libraries2/src/libraries/network/packet/Chat.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Chat.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Chat.cc	(revision 5713)
@@ -0,0 +1,81 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Chat.h"
+
+#include <cstring>
+#include <string>
+#include "network/Host.h"
+
+namespace orxonox {
+namespace packet {
+  
+#define   PACKET_FLAGS_CHAT PacketFlag::Reliable
+#define   _PACKETID         0
+const int _PLAYERID     =   _PACKETID + sizeof(Type::Value);
+#define   _MESSAGELENGTH    _PLAYERID + sizeof(uint32_t)
+#define   _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
+
+Chat::Chat( const std::string& message, unsigned int playerID )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_CHAT;
+  messageLength_ = message.length()+1;
+  data_=new unsigned char[ getSize() ];
+  *(Type::Value *)(data_ + _PACKETID ) = Type::Chat;
+  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
+  *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
+  memcpy( data_+_MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())), messageLength_ );
+}
+
+Chat::Chat( uint8_t* data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+  messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );
+}
+
+Chat::~Chat()
+{
+}
+
+unsigned int Chat::getSize() const{
+  return _MESSAGE + messageLength_;
+}
+
+bool Chat::process(){
+  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
+  delete this;
+  return b;
+}
+
+unsigned char *Chat::getMessage(){
+  return data_ + _MESSAGE;
+}
+
+} //namespace packet
+} //namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/Chat.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Chat.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Chat.h	(revision 5713)
@@ -0,0 +1,60 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _NETWORK_Chat_H__
+#define _NETWORK_Chat_H__
+
+#include "network/NetworkPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+namespace packet {
+/**
+	@author
+*/
+class _NetworkExport Chat : public Packet
+{
+public:
+  Chat( const std::string& message, unsigned int playerID );
+  Chat( uint8_t* data, unsigned int clientID );
+  ~Chat();
+
+  inline unsigned int getSize() const;
+  bool process();
+
+  unsigned int getMessageLength(){ return messageLength_; };
+  unsigned char *getMessage();
+private:
+  uint32_t messageLength_;
+  unsigned int clientID_;
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _NETWORK_Chat_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/ClassID.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/ClassID.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/ClassID.cc	(revision 5713)
@@ -0,0 +1,158 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ClassID.h"
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+#include <map>
+#include <queue>
+#include <string>
+
+#include "core/CoreIncludes.h"
+
+namespace orxonox {
+namespace packet {
+
+
+#define PACKET_FLAGS_CLASSID  PacketFlag::Reliable
+#define _PACKETID             0
+
+
+ClassID::ClassID( ) : Packet(){
+  Identifier *id;
+  std::string classname;
+  unsigned int nrOfClasses=0; 
+  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
+  uint32_t network_id;
+  flags_ = flags_ | PACKET_FLAGS_CLASSID;
+  std::queue<std::pair<uint32_t, std::string> > tempQueue;
+  
+  //calculate total needed size (for all strings and integers)
+  std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
+  for(;it != Factory::getFactoryMapEnd();++it){
+    id = (*it).second;
+    if(id == NULL)
+      continue;
+    classname = id->getName();
+    network_id = id->getNetworkID();
+    if(network_id==0)
+      COUT(3) << "we got a null class id: " << id->getName() << std::endl;
+    // now push the network id and the classname to the stack
+    tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) );
+    ++nrOfClasses;
+    packetSize += (classname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t);
+  }
+  
+  this->data_=new uint8_t[ packetSize ];
+  //set the appropriate packet id
+  assert(this->data_);
+  *(Type::Value *)(this->data_ + _PACKETID ) = Type::ClassID;
+  
+  uint8_t *temp=data_+sizeof(uint32_t);
+  // save the number of all classes
+  *(uint32_t*)temp = nrOfClasses;
+  temp += sizeof(uint32_t);
+  
+  // now save all classids and classnames
+  std::pair<uint32_t, std::string> tempPair;
+  while( !tempQueue.empty() ){
+    tempPair = tempQueue.front();
+    tempQueue.pop();
+    *(uint32_t*)temp = tempPair.first;
+    *(uint32_t*)(temp+sizeof(uint32_t)) = tempPair.second.size()+1;
+    memcpy(temp+2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);
+    temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
+  }
+  
+  COUT(5) << "classid packetSize is " << packetSize << endl;
+  
+}
+
+ClassID::ClassID( uint8_t* data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+}
+
+ClassID::~ClassID()
+{
+}
+
+uint32_t ClassID::getSize() const{
+  uint8_t *temp = data_+sizeof(uint32_t); // packet identification
+  uint32_t totalsize = sizeof(uint32_t); // packet identification
+  uint32_t nrOfClasses = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
+  totalsize += sizeof(uint32_t); // storage size for nr of all classes
+  
+  for(unsigned int i=0; i<nrOfClasses; i++){
+    totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
+  }
+  return totalsize;
+}
+
+
+bool ClassID::process(){
+  int nrOfClasses;
+  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
+  uint32_t networkID;
+  uint32_t stringsize;
+  unsigned char *classname;
+  
+  
+  //clean the map of network ids
+  Factory::cleanNetworkIDs();
+  
+  COUT(4) << "=== processing classids: " << endl;
+  std::pair<uint32_t, std::string> tempPair;
+  Identifier *id;
+  // read the total number of classes
+  nrOfClasses = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
+  
+  for( int i=0; i<nrOfClasses; i++){
+    networkID = *(uint32_t*)temp;
+    stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
+    classname = temp+2*sizeof(uint32_t);
+    id=ClassByString( std::string((const char*)classname) );
+    COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
+    if(id==NULL){
+      COUT(0) << "Recieved a bad classname" << endl;
+      abort();
+    }
+    id->setNetworkID( networkID );
+    temp += 2*sizeof(uint32_t) + stringsize;
+  }
+  delete this;
+  return true;
+}
+
+
+} //namespace packet
+}//namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/ClassID.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/ClassID.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/ClassID.h	(revision 5713)
@@ -0,0 +1,58 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _NETWORK_ClassID_H__
+#define _NETWORK_ClassID_H__
+
+#include "network/NetworkPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+namespace packet {
+
+  
+/**
+	@author
+*/
+class _NetworkExport ClassID : public Packet
+{
+public:
+  ClassID( );
+  ClassID( uint8_t* data, unsigned int clientID );
+  ~ClassID();
+
+  uint32_t getSize() const;
+  bool process();
+
+private:
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _NETWORK_ClassID_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/DeleteObjects.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/DeleteObjects.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/DeleteObjects.cc	(revision 5713)
@@ -0,0 +1,98 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include "DeleteObjects.h"
+
+#include <cassert>
+#include "util/Debug.h"
+#include "network/synchronisable/Synchronisable.h"
+
+namespace orxonox {
+namespace packet {
+
+#define PACKET_FLAG_DELETE  PacketFlag::Reliable
+#define _PACKETID           0
+#define _QUANTITY           _PACKETID + sizeof(Type::Value)
+#define _OBJECTIDS          _QUANTITY + sizeof(uint32_t)
+  
+DeleteObjects::DeleteObjects()
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAG_DELETE;
+}
+
+DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+}
+
+DeleteObjects::~DeleteObjects()
+{
+}
+
+bool DeleteObjects::fetchIDs(){
+  unsigned int number = Synchronisable::getNumberOfDeletedObject();
+  if(number==0)
+    return false;
+  COUT(4) << "sending DeleteObjects: ";
+  unsigned int size = sizeof(Type::Value) + sizeof(uint32_t)*(number+1);
+  data_ = new uint8_t[size];
+  uint8_t *tdata = data_;
+  *reinterpret_cast<Type::Value*>(tdata) = Type::DeleteObjects;
+  tdata += sizeof(Type::Value);
+  *(uint32_t *)tdata = number;
+  tdata += sizeof(uint32_t);
+  for(unsigned int i=0; i<number; i++){
+    unsigned int temp = Synchronisable::popDeletedObject();
+//     assert(temp<10000); //ugly hack
+    *reinterpret_cast<uint32_t*>(tdata) = temp;
+    COUT(4) << temp << " ";
+    tdata += sizeof(uint32_t);
+  }
+  COUT(4) << std::endl;
+  return true;
+}
+
+unsigned int DeleteObjects::getSize() const{
+  assert(data_);
+  return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
+}
+
+bool DeleteObjects::process(){
+  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
+    COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
+    Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
+  }
+  delete this;
+  return true;
+}
+
+
+} //namespace packet
+} //namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/DeleteObjects.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/DeleteObjects.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/DeleteObjects.h	(revision 5713)
@@ -0,0 +1,57 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef _DeleteObjects_H__
+#define _DeleteObjects_H__
+
+#include "network/NetworkPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+namespace packet {
+/**
+	@author
+*/
+class _NetworkExport DeleteObjects : public Packet
+{
+public:
+  DeleteObjects( );
+  DeleteObjects( uint8_t* data, unsigned int clientID );
+  ~DeleteObjects();
+
+  bool fetchIDs();
+
+  inline unsigned int getSize() const;
+  bool process();
+
+private:
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _DeleteObjects_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/FunctionCalls.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/FunctionCalls.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/FunctionCalls.cc	(revision 5713)
@@ -0,0 +1,321 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "FunctionCalls.h"
+
+#include <cassert>
+#include <cstring>
+#include "util/MultiType.h"
+#include "network/NetworkFunction.h"
+
+namespace orxonox {
+namespace packet {
+  
+#define   PACKET_FLAGS_FUNCTIONCALLS PacketFlag::Reliable
+#define   _PACKETID         0
+const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
+    
+FunctionCalls::FunctionCalls()
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS;
+  currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls
+  nrOfCalls_ = 0;
+  currentMemBlocks_ = 1;
+  data_=new uint8_t[ FUNCTIONCALLS_MEM_ALLOCATION ];
+  *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls;
+  *(uint32_t*)(data_+sizeof(uint32_t)) = 0; // set nrOfCalls to 0
+}
+
+FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+}
+
+FunctionCalls::~FunctionCalls()
+{
+}
+
+
+bool FunctionCalls::process(){
+  assert(isDataENetAllocated());
+  uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
+  this->nrOfCalls_ = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
+  for( unsigned int i = 0; i<this->nrOfCalls_; i++ )
+  {
+    uint32_t functionID = *(uint32_t*)temp;
+    bool isStatic = *(uint8_t*)(temp+sizeof(uint32_t));
+    if( isStatic )
+    {
+      MultiType mt1, mt2, mt3, mt4, mt5;
+      NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( functionID );
+      uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
+      temp+=2*sizeof(uint32_t)+sizeof(uint8_t);
+      switch(nrOfArguments)
+      {
+        case 0:
+          fct->call();
+          break;
+        case 1:
+          mt1.importData(temp);
+          fct->call(mt1);
+          break;
+        case 2:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          fct->call(mt1, mt2);
+          break;
+        case 3:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          mt3.importData(temp);
+          fct->call(mt1, mt2, mt3);
+          break;
+        case 4:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          mt3.importData(temp);
+          mt4.importData(temp);
+          fct->call(mt1, mt2, mt3, mt4);
+          break;
+        case 5:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          mt3.importData(temp);
+          mt4.importData(temp);
+          mt5.importData(temp);
+          fct->call(mt1, mt2, mt3, mt4, mt5);
+          break;
+        default:
+          assert(0);
+      }
+    }
+    else // not a static function, so also handle the objectID
+    {
+      MultiType mt1, mt2, mt3, mt4, mt5;
+      NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( functionID );
+      uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
+      uint32_t objectID = *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t));
+      temp+=3*sizeof(uint32_t)+sizeof(uint8_t);
+      switch(nrOfArguments)
+      {
+        case 0:
+          fct->call(objectID);
+          break;
+        case 1:
+          mt1.importData(temp);
+          fct->call(objectID, mt1);
+          break;
+        case 2:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          fct->call(objectID, mt1, mt2);
+          break;
+        case 3:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          mt3.importData(temp);
+          fct->call(objectID, mt1, mt2, mt3);
+          break;
+        case 4:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          mt3.importData(temp);
+          mt4.importData(temp);
+          fct->call(objectID, mt1, mt2, mt3, mt4);
+          break;
+        case 5:
+          mt1.importData(temp);
+          mt2.importData(temp);
+          mt3.importData(temp);
+          mt4.importData(temp);
+          mt5.importData(temp);
+          fct->call(objectID, mt1, mt2, mt3, mt4, mt5);
+          break;
+        default:
+          assert(0);
+          break;
+      }
+    }
+  }
+  delete this;
+  return true;
+}
+
+void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+  assert(!isDataENetAllocated());
+  
+  // first determine the size that has to be reserved for this call
+  uint32_t callsize = 2*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and for bool isStatic
+  uint32_t nrOfArguments = 0;
+  if(mt1)
+  {
+    nrOfArguments++;
+    callsize += mt1->getNetworkSize();
+    if(mt2)
+    {
+      nrOfArguments++;
+      callsize += mt2->getNetworkSize();
+      if(mt3)
+      {
+        nrOfArguments++;
+        callsize += mt3->getNetworkSize();
+        if(mt4)
+        {
+          nrOfArguments++;
+          callsize += mt4->getNetworkSize();
+          if(mt5)
+          {
+            nrOfArguments++;
+            callsize += mt5->getNetworkSize();
+          }
+        }
+      }
+    }
+  }
+  
+  // now allocated mem if neccessary
+  if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
+  {
+    currentMemBlocks_ = (currentSize_ + callsize)%FUNCTIONCALLS_MEM_ALLOCATION+1;
+    uint8_t *temp = new uint8_t[currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION];
+    memcpy( temp, data_, currentSize_ );
+    delete[] data_;
+    data_ = temp;
+  }
+  
+  // now serialise the mt values and copy the function id and isStatic
+  uint8_t* temp = data_+currentSize_;
+  *(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
+  *(uint32_t*)temp = networkID;
+  *(uint8_t*)(temp+sizeof(uint32_t)) = true;
+  *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
+  temp += 2*sizeof(uint32_t)+sizeof(uint8_t);
+  if(mt1)
+  {
+    mt1->exportData( temp ); //temp gets automatically increased
+    if(mt2)
+    {
+      mt2->exportData( temp ); //temp gets automatically increased
+      if(mt3)
+      {
+        mt3->exportData( temp ); //temp gets automatically increased
+        if(mt4)
+        {
+          mt4->exportData( temp ); //temp gets automatically increased
+          if(mt5)
+          {
+            mt5->exportData( temp ); //temp gets automatically increased
+          }
+        }
+      }
+    }
+  }
+  //currentSize_ += callsize;
+  currentSize_ = temp-data_;
+  
+}
+
+void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+  assert(!isDataENetAllocated());
+  
+  // first determine the size that has to be reserved for this call
+  uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID
+  uint32_t nrOfArguments = 0;
+  if(mt1)
+  {
+    nrOfArguments++;
+    callsize += mt1->getNetworkSize();
+    if(mt2)
+    {
+      nrOfArguments++;
+      callsize += mt2->getNetworkSize();
+      if(mt3)
+      {
+        nrOfArguments++;
+        callsize += mt3->getNetworkSize();
+        if(mt4)
+        {
+          nrOfArguments++;
+          callsize += mt4->getNetworkSize();
+          if(mt5)
+          {
+            nrOfArguments++;
+            callsize += mt5->getNetworkSize();
+          }
+        }
+      }
+    }
+  }
+  
+  // now allocated mem if neccessary
+  if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
+  {
+    currentMemBlocks_ = (currentSize_ + callsize)%FUNCTIONCALLS_MEM_ALLOCATION+1;
+    uint8_t *temp = new uint8_t[currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION];
+    memcpy( temp, data_, currentSize_ );
+    delete[] data_;
+    data_ = temp;
+  }
+  
+  // now serialise the mt values and copy the function id
+  uint8_t* temp = data_+currentSize_;
+  *(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
+  *(uint32_t*)temp = networkID;
+  *(uint8_t*)(temp+sizeof(uint32_t)) = false;
+  *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
+  *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t)) = objectID;
+  temp += 3*sizeof(uint32_t)+sizeof(uint8_t);
+  if(mt1)
+  {
+    mt1->exportData( temp ); //temp gets automatically increased
+    if(mt2)
+    {
+      mt2->exportData( temp ); //temp gets automatically increased
+      if(mt3)
+      {
+        mt3->exportData( temp ); //temp gets automatically increased
+        if(mt4)
+        {
+          mt4->exportData( temp ); //temp gets automatically increased
+          if(mt5)
+          {
+            mt5->exportData( temp ); //temp gets automatically increased
+          }
+        }
+      }
+    }
+  }
+  currentSize_ += callsize;
+  
+}
+
+
+} //namespace packet
+} //namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/FunctionCalls.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/FunctionCalls.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/FunctionCalls.h	(revision 5713)
@@ -0,0 +1,69 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _FunctionCalls_H__
+#define _FunctionCalls_H__
+
+#include "network/NetworkPrereqs.h"
+
+#include <cassert>
+#include "util/UtilPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+
+namespace packet {
+/**
+	@author
+*/
+
+
+class _NetworkExport FunctionCalls : public Packet
+{
+public:
+  FunctionCalls();
+  FunctionCalls( uint8_t* data, unsigned int clientID );
+  ~FunctionCalls();
+
+  inline unsigned int getSize() const
+    { assert(!this->isDataENetAllocated()); return currentSize_; }
+  bool process();
+
+  void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
+  void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
+private:
+  uint32_t nrOfCalls_;
+  unsigned int clientID_;
+  uint32_t currentSize_;
+  uint32_t currentMemBlocks_; // this saves the number of memory blocks (of size FUNCTIONCALLS_MEM_ALLOCATION) allocated
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _FunctionCalls_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/FunctionIDs.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/FunctionIDs.cc	(revision 5713)
@@ -0,0 +1,144 @@
+/*
+ *   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 "FunctionIDs.h"
+
+#include <cassert>
+#include <cstring>
+#include <queue>
+#include <string>
+
+#include "util/Debug.h"
+#include "core/ObjectList.h"
+#include "network/NetworkFunction.h"
+
+namespace orxonox {
+namespace packet {
+
+
+#define PACKET_FLAGS_FUNCTIONIDS  PacketFlag::Reliable
+#define _PACKETID                 0
+
+
+FunctionIDs::FunctionIDs( ) : Packet(){
+  std::string functionname;
+  unsigned int nrOfFunctions=0; 
+  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
+  uint32_t networkID;
+  flags_ = flags_ | PACKET_FLAGS_FUNCTIONIDS;
+  std::queue<std::pair<uint32_t, std::string> > tempQueue;
+  
+  //calculate total needed size (for all strings and integers)
+  ObjectList<NetworkFunctionBase>::iterator it;
+  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
+    functionname = it->getName();
+    networkID = it->getNetworkID();
+    // now push the network id and the classname to the stack
+    tempQueue.push( std::pair<unsigned int, std::string>(networkID, functionname) );
+    ++nrOfFunctions;
+    packetSize += (functionname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t); // reserver size for the functionname string, the functionname length and the networkID
+  }
+  
+  this->data_=new uint8_t[ packetSize ];
+  //set the appropriate packet id
+  assert(this->data_);
+  *(Type::Value *)(this->data_ + _PACKETID ) = Type::FunctionIDs;
+  
+  uint8_t *temp=data_+sizeof(uint32_t);
+  // save the number of all classes
+  *(uint32_t*)temp = nrOfFunctions;
+  temp += sizeof(uint32_t);
+  
+  // now save all classids and classnames
+  std::pair<uint32_t, std::string> tempPair;
+  while( !tempQueue.empty() ){
+    tempPair = tempQueue.front();
+    tempQueue.pop();
+    *(uint32_t*)temp = tempPair.first;
+    *(uint32_t*)(temp+sizeof(uint32_t)) = tempPair.second.size()+1;
+    memcpy(temp+2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);
+    temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
+  }
+  
+  COUT(5) << "FunctionIDs packetSize is " << packetSize << endl;
+  
+}
+
+FunctionIDs::FunctionIDs( uint8_t* data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+}
+
+FunctionIDs::~FunctionIDs()
+{
+}
+
+uint32_t FunctionIDs::getSize() const{
+  assert(this->data_);
+  uint8_t *temp = data_+sizeof(uint32_t); // packet identification
+  uint32_t totalsize = sizeof(uint32_t); // data size
+  uint32_t nrOfFunctions = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
+  totalsize += sizeof(uint32_t); // storage size for nr of all classes
+  
+  for(unsigned int i=0; i<nrOfFunctions; i++){
+    totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); // for each network function add size for id, sizeof(string) and length of string itself to totalsize
+    temp += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
+  }
+  return totalsize;
+}
+
+
+bool FunctionIDs::process(){
+  int nrOfFunctions;
+  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
+  uint32_t networkID;
+  uint32_t stringsize;
+  unsigned char *functionname;
+  
+  COUT(4) << "=== processing functionids: " << endl;
+  std::pair<uint32_t, std::string> tempPair;
+  // read the total number of classes
+  nrOfFunctions = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
+  
+  for( int i=0; i<nrOfFunctions; i++){
+    networkID = *(uint32_t*)temp;
+    stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
+    functionname = temp+2*sizeof(uint32_t);
+    COUT(3) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
+    NetworkFunctionBase::setNetworkID((const char*)functionname, networkID);
+    temp += 2*sizeof(uint32_t) + stringsize;
+  }
+  delete this;
+  return true;
+}
+
+
+} //namespace packet
+}//namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/FunctionIDs.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/FunctionIDs.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/FunctionIDs.h	(revision 5713)
@@ -0,0 +1,58 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _FunctionIDs_H__
+#define _FunctionIDs_H__
+
+#include "network/NetworkPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+namespace packet {
+
+  
+/**
+	@author
+*/
+class _NetworkExport FunctionIDs : public Packet
+{
+public:
+  FunctionIDs( );
+  FunctionIDs( uint8_t* data, unsigned int clientID );
+  ~FunctionIDs();
+
+  uint32_t getSize() const;
+  bool process();
+
+private:
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _FunctionIDs_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/Gamestate.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Gamestate.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Gamestate.cc	(revision 5713)
@@ -0,0 +1,622 @@
+/*
+ *   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 "Gamestate.h"
+
+#include <zlib.h>
+
+#include "util/Debug.h"
+#include "core/GameMode.h"
+#include "core/ObjectList.h"
+#include "network/synchronisable/Synchronisable.h"
+#include "network/GamestateHandler.h"
+
+namespace orxonox {
+
+namespace packet {
+
+#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
+
+#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
+
+
+Gamestate::Gamestate()
+{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+  header_ = 0;
+}
+
+Gamestate::Gamestate(uint8_t *data, unsigned int clientID):
+    Packet(data, clientID)
+{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+  header_ = new GamestateHeader(data_);
+}
+
+Gamestate::Gamestate(uint8_t *data)
+{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+  data_=data;
+  header_ = new GamestateHeader(data_);
+}
+
+Gamestate::Gamestate(const Gamestate& g) :
+    Packet( *(Packet*)&g )
+{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+  header_ = new GamestateHeader(data_);
+}
+
+
+Gamestate::~Gamestate()
+{
+  if( header_ )
+    delete header_;
+}
+
+bool Gamestate::collectData(int id, uint8_t mode)
+{
+  assert(this->header_==0); // make sure the header didn't exist before
+  uint32_t tempsize=0, currentsize=0;
+  assert(data_==0);
+  uint32_t size = calcGamestateSize(id, mode);
+
+  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
+  if(size==0)
+    return false;
+  data_ = new uint8_t[size + GamestateHeader::getSize()];
+  if(!data_){
+    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
+    return false;
+  }
+  
+  // create the header object
+  assert( header_ == 0 );
+  header_ = new GamestateHeader(data_);
+
+  //start collect data synchronisable by synchronisable
+  uint8_t *mem=data_;
+  mem += GamestateHeader::getSize();
+  ObjectList<Synchronisable>::iterator it;
+  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
+    
+//     tempsize=it->getSize(id, mode);
+
+    tempsize = it->getData(mem, id, mode);
+    if ( tempsize != 0 )
+      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
+    
+#ifndef NDEBUG
+    if(currentsize+tempsize > size){
+      assert(0); // if we don't use multithreading this part shouldn't be neccessary
+      // start allocate additional memory
+      COUT(3) << "G.St.Man: need additional memory" << std::endl;
+      ObjectList<Synchronisable>::iterator temp = it;
+      uint32_t addsize=tempsize;
+      while(++temp)
+        addsize+=temp->getSize(id, mode);
+      data_ = (uint8_t *)realloc(data_, GamestateHeader::getSize() + currentsize + addsize);
+      if(!data_)
+        return false;
+      size = currentsize+addsize;
+    }// stop allocate additional memory
+#endif
+//     if(!it->getData(mem, id, mode))
+//       return false; // mem pointer gets automatically increased because of call by reference
+    // increase size counter by size of current synchronisable
+    currentsize+=tempsize;
+  }
+
+
+  //start write gamestate header
+  header_->setDataSize( currentsize );
+  header_->setID( id );
+  header_->setBaseID( GAMESTATEID_INITIAL );
+  header_->setDiffed( false );
+  header_->setComplete( true );
+  header_->setCompressed( false );
+  //stop write gamestate header
+
+  COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
+  COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
+  return true;
+}
+
+bool Gamestate::spreadData(uint8_t mode)
+{
+  COUT(4) << "processing gamestate with id " << header_->getID() << endl;
+  assert(data_);
+  assert(!header_->isCompressed());
+  assert(!header_->isDiffed());
+  uint8_t *mem=data_+GamestateHeader::getSize();
+  Synchronisable *s;
+
+  // update the data of the objects we received
+  while(mem < data_+GamestateHeader::getSize()+header_->getDataSize()){
+    SynchronisableHeader objectheader(mem);
+
+    s = Synchronisable::getSynchronisable( objectheader.getObjectID() );
+    if(!s)
+    {
+      if (!GameMode::isMaster())
+      {
+        Synchronisable::fabricate(mem, mode);
+      }
+      else
+      {
+        mem += objectheader.getDataSize();
+      }
+    }
+    else
+    {
+      bool b = s->updateData(mem, mode);
+      assert(b);
+    }
+  }
+   // In debug mode, check first, whether there are no duplicate objectIDs
+#ifndef NDEBUG
+  if(this->getID()%1000==0){
+    std::list<uint32_t> v1;
+    ObjectList<Synchronisable>::iterator it;
+    for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) {
+      if (it->getObjectID() == OBJECTID_UNKNOWN) {
+        if (it->objectMode_ != 0x0) {
+          COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl;
+          COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
+          COUT(0) << "Objects class: " << it->getIdentifier()->getName() << std::endl;
+          assert(false);
+        }
+      }
+      else {
+        std::list<uint32_t>::iterator it2;
+        for (it2 = v1.begin(); it2 != v1.end(); ++it2) {
+          if (it->getObjectID() == *it2) {
+            COUT(0) << "Found duplicate objectIDs on the client!" << std::endl
+                    << "Are you sure you don't create a Sychnronisable objcect with 'new' \
+                        that doesn't have objectMode = 0x0?" << std::endl;
+            assert(false);
+          }
+        }
+        v1.push_back(it->getObjectID());
+      }
+    }
+  }
+#endif
+  return true;
+}
+
+uint32_t Gamestate::getSize() const
+{
+  assert(data_);
+  if(header_->isCompressed())
+    return header_->getCompSize()+GamestateHeader::getSize();
+  else
+  {
+    return header_->getDataSize()+GamestateHeader::getSize();
+  }
+}
+
+bool Gamestate::operator==(packet::Gamestate gs){
+  uint8_t *d1 = data_+GamestateHeader::getSize();
+  uint8_t *d2 = gs.data_+GamestateHeader::getSize();
+  GamestateHeader* h1 = new GamestateHeader(data_);
+  GamestateHeader* h2 = new GamestateHeader(gs.data_);
+  assert(h1->getDataSize() == h2->getDataSize());
+  assert(!isCompressed());
+  assert(!gs.isCompressed());
+  return memcmp(d1, d2, h1->getDataSize())==0;
+}
+
+bool Gamestate::process()
+{
+  return GamestateHandler::addGamestate(this, getClientID());
+}
+
+
+
+bool Gamestate::compressData()
+{
+  assert(data_);
+  assert(!header_->isCompressed());
+  uLongf buffer = (uLongf)(((header_->getDataSize() + 12)*1.01)+1);
+  if(buffer==0)
+    return false;
+
+  uint8_t *ndata = new uint8_t[buffer+GamestateHeader::getSize()];
+  uint8_t *dest = ndata + GamestateHeader::getSize();
+  uint8_t *source = data_ + GamestateHeader::getSize();
+  int retval;
+  retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) );
+  switch ( retval ) {
+    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
+    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false;
+    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; return false;
+    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; return false;
+  }
+
+  //copy and modify header
+  GamestateHeader *temp = header_;
+  header_ = new GamestateHeader(ndata, temp);
+  delete temp;
+  //delete old data
+  delete[] data_;
+  //save new data
+  data_ = ndata;
+  header_->setCompSize( buffer );
+  header_->setCompressed( true );
+  COUT(5) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;
+  return true;
+}
+bool Gamestate::decompressData()
+{
+  assert(data_);
+  assert(header_->isCompressed());
+  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_->getID() << ", baseid: " << header_->getBaseID() << ", datasize: " << header_->getDataSize() << ", compsize: " << header_->getCompSize() << std::endl;
+  uint32_t datasize = header_->getDataSize();
+  uint32_t compsize = header_->getCompSize();
+  uint32_t bufsize;
+  bufsize = datasize;
+  assert(bufsize!=0);
+  uint8_t *ndata = new uint8_t[bufsize + GamestateHeader::getSize()];
+  uint8_t *dest = ndata + GamestateHeader::getSize();
+  uint8_t *source = data_ + GamestateHeader::getSize();
+  int retval;
+  uLongf length=bufsize;
+  retval = uncompress( dest, &length, source, (uLong)compsize );
+  switch ( retval ) {
+    case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
+    case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return false;
+    case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return false;
+    case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false;
+  }
+
+  //copy over the header
+  GamestateHeader *temp = header_;
+  header_ = new GamestateHeader( data_, header_ );
+  delete temp;
+
+  if (this->bDataENetAllocated_){
+    // Memory was allocated by ENet. --> We let it be since enet_packet_destroy will
+    // deallocated it anyway. So data and packet stay together.
+    this->bDataENetAllocated_ = false;
+  }
+  else{
+    // We allocated the memory in the first place (unlikely). So we destroy the old data
+    // and overwrite it with the new decompressed data.
+    delete[] this->data_;
+  }
+
+  //set new pointers
+  data_ = ndata;
+  header_->setCompressed( false );
+  assert(header_->getDataSize()==datasize);
+  assert(header_->getCompSize()==compsize);
+  return true;
+}
+
+/*Gamestate *Gamestate::diff(Gamestate *base)
+{
+  assert(data_);
+  assert(!header_->isCompressed());
+  assert(!header_->isDiffed());
+  GamestateHeader diffHeader(base->data_);
+  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
+  uint32_t of=0; // pointers offset
+  uint32_t dest_length=0;
+  dest_length=header_->getDataSize();
+  if(dest_length==0)
+    return NULL;
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+  uint8_t *dest = ndata + GamestateHeader::getSize();
+  while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
+    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
+    ++of;
+  }
+  if(diffHeader.getDataSize()!=header_->getDataSize()){
+    uint8_t n=0;
+    if(diffHeader.getDataSize() < header_->getDataSize()){
+      while(of<dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
+    }
+  }
+
+  Gamestate *g = new Gamestate(ndata, getClientID());
+  *(g->header_) = *header_;
+  g->header_->setDiffed( true );
+  g->header_->setBaseID( base->getID() );
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  return g;
+}*/
+
+Gamestate *Gamestate::diff(Gamestate *base)
+{
+  assert(this && base); assert(data_ && base->data_);
+  assert(!header_->isCompressed() && !base->header_->isCompressed());
+  assert(!header_->isDiffed());
+  
+  uint8_t *basep = GAMESTATE_START(base->data_);
+  uint8_t *gs = GAMESTATE_START(this->data_);
+  uint32_t dest_length = header_->getDataSize();
+  
+  if(dest_length==0)
+    return NULL;
+  
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+  uint8_t *dest = GAMESTATE_START(ndata);
+  
+  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+#ifndef NDEBUG
+  uint8_t *dest2 = new uint8_t[dest_length];
+  rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() );
+  assert( memcmp( dest2, gs, dest_length) == 0 );
+#endif
+
+  Gamestate *g = new Gamestate(ndata, getClientID());
+  assert(g->header_);
+  *(g->header_) = *header_;
+  g->header_->setDiffed( true );
+  g->header_->setBaseID( base->getID() );
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  assert(g->isDiffed());
+  assert(!g->isCompressed());
+  return g;
+}
+
+Gamestate *Gamestate::undiff(Gamestate *base)
+{
+  assert(this && base); assert(data_ && base->data_);
+  assert(!header_->isCompressed() && !base->header_->isCompressed());
+  assert(header_->isDiffed());
+  
+  uint8_t *basep = GAMESTATE_START(base->data_);
+  uint8_t *gs = GAMESTATE_START(this->data_);
+  uint32_t dest_length = header_->getDataSize();
+  
+  if(dest_length==0)
+    return NULL;
+  
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+  uint8_t *dest = ndata + GamestateHeader::getSize();
+  
+  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+  
+  Gamestate *g = new Gamestate(ndata, getClientID());
+  assert(g->header_);
+  *(g->header_) = *header_;
+  g->header_->setDiffed( false );
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  assert(!g->isDiffed());
+  assert(!g->isCompressed());
+  return g;
+}
+
+
+// Gamestate *Gamestate::diff(Gamestate *base)
+// {
+//   assert(data_);
+//   assert(!header_->isCompressed());
+//   assert(!header_->isDiffed());
+//   GamestateHeader diffHeader(base->data_);
+//   uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
+//   uint32_t of=0; // pointers offset
+//   uint32_t dest_length=0;
+//   dest_length=header_->getDataSize();
+//   if(dest_length==0)
+//     return NULL;
+//   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+//   uint8_t *dest = ndata + GamestateHeader::getSize();
+//   
+//   
+//   // LOOP-UNROLLED DIFFING
+//   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
+//   // diff in 4-byte steps
+//   while( of < (uint32_t)(header_->getDataSize())/4 ){
+//     if( of < (uint32_t)(diffHeader.getDataSize())/4 )
+//     {
+//       *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
+//       ++of;
+//     }
+//     else
+//     {
+//       *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
+//       ++of;
+//     }
+//   }
+//   for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 )
+//   {
+//     if( of*4+of2 < diffHeader.getDataSize() )
+//     {
+//       *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor
+//     }
+//     else
+//     {
+//       *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of)
+//     }
+//   }
+// 
+//   Gamestate *g = new Gamestate(ndata, getClientID());
+//   *(g->header_) = *header_;
+//   g->header_->setDiffed( true );
+//   g->header_->setBaseID( base->getID() );
+//   g->flags_=flags_;
+//   g->packetDirection_ = packetDirection_;
+//   return g;
+// }
+
+
+void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)
+{
+  uint64_t* gd = (uint64_t*)data;
+  uint64_t* bd = (uint64_t*)basedata;
+  uint64_t* nd = (uint64_t*)newdata;
+  
+  unsigned int i;
+  for( i=0; i<datalength/8; i++ )
+  {
+    if( i<baselength/8 )
+      *(nd+i) = *(gd+i) ^ *(bd+i);  // xor the data
+    else
+      *(nd+i) = *(gd+i); // just copy over the data
+  }
+  unsigned int j;
+  // now process the rest (when datalength isn't a multiple of 4)
+  for( j = 8*(datalength/8); j<datalength; j++ )
+  {
+    if( j<baselength )
+      *(newdata+j) = *(data+j) ^ *(basedata+j); // xor
+    else
+      *(newdata+j) = *(data+j); // just copy
+  }
+  assert(j==datalength);
+}
+
+Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
+  assert(data_);
+  std::list<obj>::iterator it;
+
+  // allocate memory for new data
+  uint8_t *gdata = new uint8_t[header_->getDataSize()+GamestateHeader::getSize()];
+  // create a gamestate out of it
+  Gamestate *gs = new Gamestate(gdata);
+  uint8_t *newdata = gdata + GamestateHeader::getSize();
+  uint8_t *origdata = GAMESTATE_START(data_);
+
+  //copy the GamestateHeader
+  assert(gs->header_);
+  *(gs->header_) = *header_;
+
+  uint32_t objectOffset;
+  unsigned int objectsize, destsize=0;
+  // TODO: Why is this variable not used?
+  //Synchronisable *object;
+
+  //call TrafficControl
+  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
+
+  //copy in the zeros
+//   std::list<obj>::iterator itt;
+//   COUT(0) << "myvector contains:";
+//   for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )
+//     COUT(0) << " " << (*itt).objID;
+//   COUT(0) << endl;
+  for(it=dataVector_.begin(); it!=dataVector_.end();){
+    SynchronisableHeader oldobjectheader(origdata);
+    SynchronisableHeader newobjectheader(newdata);
+    if ( (*it).objSize == 0 )
+    {
+      ++it;
+      continue;
+    }
+    objectsize = oldobjectheader.getDataSize();
+    objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader
+    if ( (*it).objID == oldobjectheader.getObjectID() ){
+      memcpy(newdata, origdata, objectsize);
+      assert(newobjectheader.isDataAvailable()==true);
+      ++it;
+    }else{
+      newobjectheader = oldobjectheader;
+      newobjectheader.setDataAvailable(false);
+      memset(newdata+objectOffset, 0, objectsize-objectOffset);
+    }
+    newdata += objectsize;
+    origdata += objectsize;
+    destsize += objectsize;
+  }
+#ifndef NDEBUG
+  uint32_t origsize = destsize;
+  while ( origsize < header_->getDataSize() )
+  {
+    SynchronisableHeader oldobjectheader(origdata);
+    objectsize = oldobjectheader.getDataSize();
+    origdata += objectsize;
+    origsize += objectsize;
+  }
+  assert(origsize==header_->getDataSize());
+  assert(destsize!=0);
+#endif
+  gs->header_->setDataSize( destsize );
+  return gs;
+}
+
+
+/*Gamestate *Gamestate::undiff(Gamestate *base)
+{
+  assert(this && base);assert(data_);
+  assert(header_->isDiffed());
+  assert(!header_->isCompressed() && !base->header_->isCompressed());
+  uint8_t *basep = GAMESTATE_START(base->data_);
+  uint8_t *gs = GAMESTATE_START(this->data_);
+  uint32_t of=0; // pointers offset
+  uint32_t dest_length=0;
+  dest_length=header_->getDataSize();
+  if(dest_length==0)
+    return NULL;
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+  uint8_t *dest = ndata + GamestateHeader::getSize();
+  while(of < base->header_->getDataSize() && of < header_->getDataSize()){
+    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
+    ++of;
+  }
+  if(base->header_->getDataSize()!=header_->getDataSize()){
+    uint8_t n=0;
+    if(base->header_->getDataSize() < header_->getDataSize()){
+      while(of < dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
+    }
+  }
+  Gamestate *g = new Gamestate(ndata, getClientID());
+  assert(g->header_);
+  *(g->header_) = *header_;
+  g->header_->setDiffed( false );
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  assert(!g->isDiffed());
+  assert(!g->isCompressed());
+  return g;
+}*/
+
+uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
+{
+  uint32_t size=0;
+    // get the start of the Synchronisable list
+  ObjectList<Synchronisable>::iterator it;
+    // get total size of gamestate
+  for(it = ObjectList<Synchronisable>::begin(); it; ++it)
+    size+=it->getSize(id, mode); // size of the actual data of the synchronisable
+  return size;
+}
+
+} //namespace packet
+} //namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/Gamestate.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Gamestate.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Gamestate.h	(revision 5713)
@@ -0,0 +1,138 @@
+/*
+ *   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 _Gamestate_H__
+#define _Gamestate_H__
+
+#include "network/NetworkPrereqs.h"
+
+#include <cassert>
+#include <cstring>
+#include <list>
+
+#include "util/CRC32.h"
+#include "network/TrafficControl.h"
+#include "Packet.h"
+
+namespace orxonox {
+
+namespace packet {
+
+class _NetworkExport GamestateHeader{
+  public:
+    GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
+    GamestateHeader(uint8_t *data, GamestateHeader* h)
+    { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }
+    static inline uint32_t getSize()
+    { return 21; }
+
+    inline int32_t getID() const
+    { assert(data_); return *(int32_t*)(data_+4); }
+    inline void setID(int32_t id)
+    { assert(data_); *(int32_t*)(data_+4) = id; }
+
+    inline int32_t getBaseID() const
+    { assert(data_); return *(int32_t*)(data_+8); }
+    inline void setBaseID(int32_t id)
+    { assert(data_); *(int32_t*)(data_+8) = id; }
+
+    inline uint32_t getDataSize() const
+    { assert(data_); return *(uint32_t*)(data_+12); }
+    inline void setDataSize(uint32_t size)
+    { assert(data_); *(uint32_t*)(data_+12) = size; }
+
+    inline uint32_t getCompSize() const
+    { assert(data_); return *(uint32_t*)(data_+16); }
+    inline void setCompSize(uint32_t size)
+    { assert(data_); *(uint32_t*)(data_+16) = size; }
+
+    inline bool isDiffed() const
+    { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
+    inline void setDiffed(bool b)
+    { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
+
+    inline bool isComplete() const
+    { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
+    inline void setComplete(bool b)
+    { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
+
+    inline bool isCompressed() const
+    { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
+    inline void setCompressed(bool b)
+    { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
+
+    inline void operator=(GamestateHeader& h)
+    { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
+  private:
+    uint8_t *data_;
+
+};
+
+/**
+	@author Oliver Scheuss
+*/
+class _NetworkExport Gamestate: public Packet{
+  public:
+    Gamestate();
+    Gamestate(uint8_t *data, unsigned int clientID);
+    Gamestate(uint8_t *data);
+    Gamestate(const Gamestate& g);
+
+    ~Gamestate();
+
+    bool collectData(int id, uint8_t mode=0x0);
+    bool spreadData( uint8_t mode=0x0);
+    inline int32_t getID() const { return header_->getID(); }
+    inline bool isDiffed() const { return header_->isDiffed(); }
+    inline bool isCompressed() const { return header_->isCompressed(); }
+    inline int32_t getBaseID() const { return header_->getBaseID(); }
+    Gamestate *diff(Gamestate *base);
+    Gamestate *undiff(Gamestate *base);
+    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
+    bool compressData();
+    bool decompressData();
+    bool operator ==(packet::Gamestate gs);
+
+    // Packet functions
+  private:
+    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
+    virtual uint32_t getSize() const;
+    virtual inline bool process();
+
+  private:
+    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
+    std::list<obj> dataVector_;
+    GamestateHeader* header_;
+};
+
+}
+
+}
+
+#endif /* _Gamestate_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/Packet.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Packet.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Packet.cc	(revision 5713)
@@ -0,0 +1,244 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include "Packet.h"
+
+#include <cassert>
+#include <cstring>
+#include <enet/enet.h>
+#include <boost/static_assert.hpp>
+
+#include "util/Debug.h"
+#include "Acknowledgement.h"
+#include "Chat.h"
+#include "ClassID.h"
+#include "DeleteObjects.h"
+#include "FunctionCalls.h"
+#include "FunctionIDs.h"
+#include "Gamestate.h"
+#include "Welcome.h"
+#include "network/Host.h"
+#include "network/ClientInformation.h"
+
+namespace orxonox{
+
+namespace packet{
+
+// Make sure we assume the right values
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)   == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
+
+#define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate
+#define _PACKETID           0
+
+std::map<size_t, Packet *> Packet::packetMap_;
+
+Packet::Packet(){
+  flags_ = PACKET_FLAG_DEFAULT;
+  packetDirection_ = Direction::Outgoing;
+  clientID_=0;
+  data_=0;
+  enetPacket_=0;
+  bDataENetAllocated_ = false;
+}
+
+void blub(ENetPacket *packet){
+  COUT(4) << "blubb" << std::endl;
+}
+
+Packet::Packet(uint8_t *data, unsigned int clientID){
+  flags_ = PACKET_FLAG_DEFAULT;
+  packetDirection_ = Direction::Incoming;
+  clientID_=clientID;
+  data_=data;
+  enetPacket_=0;
+  bDataENetAllocated_ = false;
+}
+
+
+Packet::Packet(const Packet &p){
+  enetPacket_=p.enetPacket_;
+  flags_=p.flags_;
+  packetDirection_ = p.packetDirection_;
+  clientID_ = p.clientID_;
+  if(p.data_){
+    data_ = new uint8_t[p.getSize()];
+    memcpy(data_, p.data_, p.getSize());
+  }else
+    data_=0;
+  bDataENetAllocated_ = p.bDataENetAllocated_;
+}
+
+/**
+@brief
+    Destroys a packet completely.
+    
+    That also means destroying the ENetPacket if one exists. There 
+*/
+Packet::~Packet(){
+  // Deallocate data_ memory if necessary.
+  if (this->bDataENetAllocated_){
+    // In this case ENet allocated data_ and will destroy it.
+  }
+  else if (this->data_) {
+    // This destructor was probably called as a consequence of ENet executing our callback.
+    // It simply serves us to be able to deallocate the packet content (data_) ourselves since
+    // we have created it in the first place.
+    delete[] this->data_;
+  }
+
+  // Destroy the ENetPacket if necessary.
+  // Note: For the case ENet used the callback to destroy the packet, we have already set
+  // enetPacket_ to NULL to avoid destroying it again.
+  if (this->enetPacket_){
+    // enetPacket_->data gets destroyed too by ENet if it was allocated by it.
+    enet_packet_destroy(enetPacket_);
+  }
+}
+
+bool Packet::send(){
+  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
+    assert(0);
+    return false;
+  }
+  if(!enetPacket_){
+    if(!data_){
+      assert(0);
+      return false;
+    }
+    // We deliver ENet the data address so that it doesn't memcpy everything again.
+    // --> We have to delete data_ ourselves!
+    enetPacket_ = enet_packet_create(getData(), getSize(), getFlags());
+    enetPacket_->freeCallback = &Packet::deletePacket;
+    // Add the packet to a global list so we can access it again once enet calls our
+    // deletePacket method. We can of course only give a one argument function to the ENet C library.
+    {
+      // Assures we don't create a packet and destroy it right after in another thread
+      // without having a reference in the packetMap_
+      packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
+    }
+  }
+#ifndef NDEBUG
+  switch( *(Type::Value *)(data_ + _PACKETID) )
+  {
+    case Type::Acknowledgement:
+    case Type::Chat:
+    case Type::ClassID:
+    case Type::Gamestate:
+    case Type::Welcome:
+    case Type::DeleteObjects:
+    case Type::FunctionIDs:
+    case Type::FunctionCalls:
+      break;
+    default:
+      assert(0); //there was some error, if this is the case
+      break;
+  }
+#endif
+//  ENetPacket *temp = enetPacket_;
+//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
+  if(!Host::addPacket( enetPacket_, clientID_))
+    enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually
+  return true;
+}
+
+Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
+  uint8_t *data = packet->data;
+  assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
+  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
+  Packet *p = 0;
+  COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
+  switch( *(Type::Value *)(data + _PACKETID) )
+  {
+    case Type::Acknowledgement:
+      COUT(5) << "ack" << std::endl;
+      p = new Acknowledgement( data, clientID );
+      break;
+    case Type::Chat:
+      COUT(5) << "chat" << std::endl;
+      p = new Chat( data, clientID );
+      break;
+    case Type::ClassID:
+      COUT(5) << "classid" << std::endl;
+      p = new ClassID( data, clientID );
+      break;
+    case Type::Gamestate:
+      COUT(5) << "gamestate" << std::endl;
+      // TODO: remove brackets
+      p = new Gamestate( data, clientID );
+      break;
+    case Type::Welcome:
+      COUT(5) << "welcome" << std::endl;
+      p = new Welcome( data, clientID );
+      break;
+    case Type::DeleteObjects:
+      COUT(5) << "deleteobjects" << std::endl;
+      p = new DeleteObjects( data, clientID );
+      break;
+    case Type::FunctionCalls:
+      COUT(5) << "functionCalls" << std::endl;
+      p = new FunctionCalls( data, clientID );
+      break;
+    case Type::FunctionIDs:
+      COUT(5) << "functionIDs" << std::endl;
+      p = new FunctionIDs( data, clientID );
+      break;
+    default:
+      assert(0); //TODO: repair this
+      break;
+  }
+
+  // Data was created by ENet
+  p->bDataENetAllocated_ = true;
+  p->enetPacket_ = packet;
+
+  return p;
+}
+
+/**
+@brief
+    ENet calls this method whenever it wants to destroy a packet that contains
+    data we allocated ourselves.
+*/
+void Packet::deletePacket(ENetPacket *enetPacket){
+  // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
+  std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
+  assert(it != packetMap_.end());
+  // Make sure we don't delete it again in the destructor
+  it->second->enetPacket_ = 0;
+  delete it->second;
+  packetMap_.erase(it);
+  COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
+}
+
+} // namespace packet
+
+} // namespace orxonox
+
Index: /code/branches/libraries2/src/libraries/network/packet/Packet.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Packet.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Packet.h	(revision 5713)
@@ -0,0 +1,105 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef _NETWORK_Packet_H__
+#define _NETWORK_Packet_H__
+
+#include "network/NetworkPrereqs.h"
+#include <map>
+
+namespace orxonox {
+
+namespace packet{
+
+namespace Direction{
+  enum Value{
+    Incoming,
+    Outgoing,
+    Bidirectional
+  };
+}
+namespace Type{
+  enum Value{
+    Acknowledgement,
+    Chat,
+    ClassID,
+    DeleteObjects,
+    FunctionIDs,
+    FunctionCalls,
+    Gamestate,
+    Welcome
+  };
+}
+
+/**
+	@author Oliver Scheuss <scheusso [at] ee.ethz.ch>
+*/
+class _NetworkExport Packet{
+  public:
+    Packet(const Packet &p);
+    virtual ~Packet();
+    static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
+    static void deletePacket(ENetPacket *packet);
+
+    virtual unsigned char *getData(){ return data_; };
+    virtual unsigned int getSize() const =0;
+    virtual bool process()=0;
+    inline uint32_t getFlags()
+      { return flags_; }
+    inline int getClientID()
+      { return clientID_; }
+    inline void setClientID( int id )
+      { clientID_ = id; }
+
+    bool send();
+  protected:
+    Packet();
+    Packet(uint8_t *data, unsigned int clientID);
+//    Packet(ENetPacket *packet, ENetPeer *peer);
+    inline bool isDataENetAllocated() const
+      { return bDataENetAllocated_; }
+
+    uint32_t flags_;
+    unsigned int clientID_;
+    Direction::Value packetDirection_;
+    /** Pointer to the data. Be careful when deleting it because it might
+        point to a location that was allocated by ENet.
+        See bDataENetAllocated_ */
+    uint8_t *data_;
+    /** Tells whether data_ was allocated by ENet or ourselves.
+        data_ might no correlate with enetPacket_->data. */
+    bool bDataENetAllocated_;
+  private:
+    static std::map<size_t, Packet *> packetMap_;
+    ENetPacket *enetPacket_;
+};
+
+} //namespace packet
+
+} //namespace orxonox
+
+#endif /* _NETWORK_Packet_H__ */
Index: /code/branches/libraries2/src/libraries/network/packet/Welcome.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Welcome.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Welcome.cc	(revision 5713)
@@ -0,0 +1,88 @@
+
+
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Welcome.h"
+
+#include <cassert>
+#include "util/Debug.h"
+#include "network/Host.h"
+#include "network/synchronisable/Synchronisable.h"
+
+namespace orxonox {
+namespace packet {
+
+#define PACKET_FLAGS_CLASSID  PacketFlag::Reliable
+#define _PACKETID             0
+#define _CLIENTID             _PACKETID + sizeof(Type::Value)
+#define _ENDIANTEST           _CLIENTID + sizeof(uint32_t)
+
+  Welcome::Welcome( uint32_t clientID, uint32_t shipID )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_CLASSID;
+  assert(getSize());
+  data_=new uint8_t[ getSize() ];
+  assert(data_);
+  *(packet::Type::Value *)(data_ + _PACKETID ) = packet::Type::Welcome;
+  *(uint32_t *)(data_ + _CLIENTID ) = static_cast<uint32_t>(clientID);
+  *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321;
+}
+
+Welcome::Welcome( uint8_t* data, uint32_t clientID )
+  : Packet(data, clientID)
+{
+}
+
+Welcome::~Welcome()
+{
+}
+
+uint8_t *Welcome::getData(){
+  return data_;
+}
+
+unsigned int Welcome::getSize() const{
+  return sizeof(packet::Type::Value) + 2*sizeof(uint32_t);
+}
+
+bool Welcome::process(){
+  uint32_t clientID;
+  clientID = *(uint32_t *)(data_ + _CLIENTID );
+  assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
+  Host::setClientID(clientID);
+  COUT(3) << "Welcome set clientId: " << clientID << endl;
+  Synchronisable::setClient(true);
+  delete this;
+  return true;
+}
+
+
+} //namespace packet
+}//namespace orxonox
Index: /code/branches/libraries2/src/libraries/network/packet/Welcome.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/packet/Welcome.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/packet/Welcome.h	(revision 5713)
@@ -0,0 +1,57 @@
+/*
+ *   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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef _NETWORK_Welcome_H__
+#define _NETWORK_Welcome_H__
+
+#include "network/NetworkPrereqs.h"
+#include "Packet.h"
+
+namespace orxonox {
+namespace packet {
+
+/**
+	@author
+*/
+class _NetworkExport Welcome : public Packet
+{
+public:
+  Welcome( uint32_t clientID, uint32_t shipID );
+  Welcome( uint8_t* data, uint32_t clientID );
+  virtual ~Welcome();
+
+  uint8_t *getData();
+  inline unsigned int getSize() const;
+  bool process();
+
+private:
+};
+
+} //namespace packet
+} //namespace orxonox
+
+#endif /* _NETWORK_Welcome_H__ */
Index: /code/branches/libraries2/src/libraries/network/synchronisable/CMakeLists.txt
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/CMakeLists.txt	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/CMakeLists.txt	(revision 5713)
@@ -0,0 +1,13 @@
+ADD_SOURCE_FILES(NETWORK_SRC_FILES
+  NetworkCallbackManager.cc
+  Synchronisable.cc
+  SynchronisableSpecialisations.cc
+  SynchronisableVariable.cc
+)
+
+ADD_SOURCE_FILES(NETWORK_HDR_FILES
+  NetworkCallback.h
+  NetworkCallbackManager.h
+  Synchronisable.h
+  SynchronisableVariable.h
+)
Index: /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallback.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallback.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallback.h	(revision 5713)
@@ -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:
+ *      Oliver Scheuss, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#ifndef _NetworkCallback_H__
+#define _NetworkCallback_H__
+
+#include "network/NetworkPrereqs.h"
+#include "NetworkCallbackManager.h"
+
+namespace orxonox{
+  
+  class _NetworkExport NetworkCallbackBase
+  {
+    public:
+      virtual void call() = 0;
+      NetworkCallbackBase(){ NetworkCallbackManager::registerCallback( this ); }
+      virtual ~NetworkCallbackBase() {}
+  };
+
+  template <class T>
+  class NetworkCallback: public NetworkCallbackBase
+  {
+    public:
+      NetworkCallback(T* object, void (T::*function) (void)) : object_(object), function_(function) {}
+	  virtual ~NetworkCallback() {}
+      virtual void call()
+        { (this->object_->*function_)(); }
+
+    private:
+      T* object_;
+      void (T::*function_) (void);
+  };
+
+}
+
+
+#endif /* _NetworkCallback_H__ */
Index: /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallbackManager.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallbackManager.cc	(revision 5713)
@@ -0,0 +1,67 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+ 
+#include "NetworkCallbackManager.h"
+#include "NetworkCallback.h"
+
+namespace orxonox{
+  
+  std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_;
+  std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_;
+  
+  void NetworkCallbackManager::registerCallback(NetworkCallbackBase *cb)
+  { 
+    callbackSet_.insert(cb); 
+  }
+  void NetworkCallbackManager::deleteCallback(NetworkCallbackBase *cb)
+  {
+    std::set<NetworkCallbackBase*>::iterator it = callbackSet_.find(cb);
+    if (it != callbackSet_.end())
+    {
+      callbackSet_.erase(it);
+      delete cb;
+    }
+  }
+  
+  void NetworkCallbackManager::triggerCallback(NetworkCallbackBase *cb)
+  {
+    if (triggeredCallbacks_.empty() || triggeredCallbacks_.front() != cb)
+      triggeredCallbacks_.push(cb);
+  }
+
+  void NetworkCallbackManager::callCallbacks()
+  {
+    while( triggeredCallbacks_.empty()==false )
+    {
+      //make sure callback hasn't been deleted before
+      if ( callbackSet_.find(triggeredCallbacks_.front()) != callbackSet_.end() )
+        triggeredCallbacks_.front()->call();
+      triggeredCallbacks_.pop();
+    }
+  }
+}
Index: /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallbackManager.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallbackManager.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/NetworkCallbackManager.h	(revision 5713)
@@ -0,0 +1,55 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#ifndef _NetworkCallbackManager_H__
+#define _NetworkCallbackManager_H__
+
+#include "network/NetworkPrereqs.h"
+
+#include <set>
+#include <queue>
+
+namespace orxonox{
+  
+  class _NetworkExport NetworkCallbackManager{
+    public:
+      static void registerCallback(NetworkCallbackBase *cb);
+      static void deleteCallback(NetworkCallbackBase *cb);
+      static void triggerCallback(NetworkCallbackBase *cb);
+      static void callCallbacks();
+    private:
+      static std::set<NetworkCallbackBase*> callbackSet_;
+      static std::queue<NetworkCallbackBase*> triggeredCallbacks_;
+  };
+  
+
+}
+
+
+#endif /* _NetworkCallbackManager_H__ */
Index: /code/branches/libraries2/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/Synchronisable.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/Synchronisable.cc	(revision 5713)
@@ -0,0 +1,387 @@
+/*
+ *   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:
+ *      Dumeni Manatschal, (C) 2007
+ *      Oliver Scheuss, (C) 2007
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include "Synchronisable.h"
+
+#include <cstdlib>
+#include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
+#include "network/Host.h"
+
+namespace orxonox
+{
+
+  std::map<uint32_t, Synchronisable *> Synchronisable::objectMap_;
+  std::queue<uint32_t> Synchronisable::deletedObjects_;
+
+  uint8_t Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
+
+  /**
+  * Constructor:
+  * Initializes all Variables and sets the right objectID
+  */
+  Synchronisable::Synchronisable(BaseObject* creator){
+    RegisterRootObject(Synchronisable);
+    static uint32_t idCounter=0;
+    objectMode_=0x1; // by default do not send data to server
+    if ( !Host::running() || ( Host::running() && Host::isServer() ) )
+    {
+      this->objectID = idCounter++; //this is only needed when running a server
+    //add synchronisable to the objectMap
+      objectMap_[this->objectID] = this;
+    }
+    else
+      objectID=OBJECTID_UNKNOWN;
+    classID = static_cast<uint32_t>(-1);
+    
+    // set dataSize to 0
+    this->dataSize_ = 0;
+    // set standard priority
+    this->setPriority( Priority::Normal );
+
+    // get creator id
+    this->creatorID = OBJECTID_UNKNOWN;
+
+    searchcreatorID:
+    if (creator)
+    {
+        Synchronisable* synchronisable_creator = orxonox_cast<Synchronisable*>(creator);
+        if (synchronisable_creator && synchronisable_creator->objectMode_)
+        {
+            this->creatorID = synchronisable_creator->getObjectID();
+        }
+        else if (creator != creator->getCreator())
+        {
+            creator = creator->getCreator();
+            goto searchcreatorID;
+        }
+    }
+  }
+
+  /**
+   * Destructor:
+   * Delete all callback objects and remove objectID from the objectMap_
+   */
+  Synchronisable::~Synchronisable(){
+    // delete callback function objects
+    if(!Identifier::isCreatingHierarchy()){
+      // remove object from the static objectMap
+      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
+        deletedObjects_.push(objectID);
+    }
+    // delete all Synchronisable Variables from syncList ( which are also in stringList )
+    for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
+      delete (*it);
+    syncList.clear();
+    stringList.clear();
+    std::map<uint32_t, Synchronisable*>::iterator it;
+    it = objectMap_.find(objectID);
+    if (it != objectMap_.end())
+      objectMap_.erase(it);
+
+  }
+
+
+  /**
+   * This function sets the internal mode for synchronisation
+   * @param b true if this object is located on a client or on a server
+   */
+  void Synchronisable::setClient(bool b){
+    if(b) // client
+      state_=0x2;
+    else  // server
+      state_=0x1;
+  }
+
+  /**
+   * This function fabricated a new synchrnisable (and children of it), sets calls updateData and create
+   * After calling this function the mem pointer will be increased by the size of the needed data
+   * @param mem pointer to where the appropriate data is located
+   * @param mode defines the mode, how the data should be loaded
+   * @return pointer to the newly created synchronisable
+   */
+  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
+  {
+    SynchronisableHeader header(mem);
+
+    if(!header.isDataAvailable())
+    {
+      mem += header.getDataSize();
+      return 0;
+    }
+
+    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
+
+    Identifier* id = ClassByID(header.getClassID());
+    if (!id)
+    {
+        for(int i = 0; i<160; i++)
+            COUT(0) << "classid: " << i << " identifier: " << ClassByID(i) << endl;
+        COUT(0) << "Assertion failed: id" << std::endl;
+        COUT(0) << "Possible reason for this error: Client received a synchronizable object whose class has no factory." << std::endl;
+        abort();
+    }
+    assert(id);
+    BaseObject* creator = 0;
+    if (header.getCreatorID() != OBJECTID_UNKNOWN)
+    {
+      Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header.getCreatorID());
+      if (!synchronisable_creator)
+      {
+        mem += header.getDataSize(); //.TODO: this suckz.... remove size from header
+        assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
+        return 0;
+      }
+      else
+        creator = orxonox_cast<BaseObject*>(synchronisable_creator);
+    }
+    assert(getSynchronisable(header.getObjectID())==0);   //make sure no object with this id exists
+    BaseObject *bo = id->fabricate(creator);
+    assert(bo);
+    Synchronisable *no = orxonox_cast<Synchronisable*>(bo);
+    assert(no);
+    no->objectID=header.getObjectID();
+    no->creatorID=header.getCreatorID(); //TODO: remove this
+    no->classID=header.getClassID();
+    COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
+          // update data and create object/entity...
+    assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
+    Synchronisable::objectMap_[header.getObjectID()] = no;
+    bool b = no->updateData(mem, mode, true);
+    assert(b);
+    if (b)
+    {
+//        b = no->create();
+        assert(b);
+    }
+    return no;
+  }
+
+
+  /**
+   * Finds and deletes the Synchronisable with the appropriate objectID
+   * @param objectID objectID of the Synchronisable
+   * @return true/false
+   */
+  bool Synchronisable::deleteObject(uint32_t objectID){
+    if(!getSynchronisable(objectID))
+      return false;
+    assert(getSynchronisable(objectID)->objectID==objectID);
+    Synchronisable *s = getSynchronisable(objectID);
+    if(s)
+      delete s;
+    else
+      return false;
+    return true;
+  }
+
+  /**
+   * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
+   * @param objectID objectID of the Synchronisable
+   * @return pointer to the Synchronisable with the objectID
+   */
+  Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID){
+    std::map<uint32_t, Synchronisable*>::iterator it1;
+    it1 = objectMap_.find(objectID);
+    if (it1 != objectMap_.end())
+      return it1->second;
+
+//     ObjectList<Synchronisable>::iterator it;
+//     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
+//       if( it->getObjectID()==objectID ){
+//         objectMap_[objectID] = *it;
+//         return *it;
+//       }
+//     }
+    // if the objects not in the map it should'nt exist at all anymore
+    return NULL;
+  }
+
+
+  /**
+   * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory
+   * takes a pointer to already allocated memory (must have at least getSize bytes length)
+   * structure of the bitstream:
+   * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...|
+   * length of varx: size saved int syncvarlist
+   * @param mem pointer to allocated memory with enough size
+   * @param id gamestateid of the gamestate to be saved (important for priorities)
+   * @param mode defines the direction in which the data will be send/received
+   *             0x1: server->client
+   *             0x2: client->server (not recommended)
+   *             0x3: bidirectional
+   * @return true: if !doSync or if everything was successfully saved
+   */
+  uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
+    if(mode==0x0)
+      mode=state_;
+    //if this tick is we dont synchronise, then abort now
+    if(!doSync(id, mode))
+      return 0;
+    uint32_t tempsize = 0;
+#ifndef NDEBUG
+    if (this->classID==0)
+      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+#endif
+
+    if (this->classID == static_cast<uint32_t>(-1))
+        this->classID = this->getIdentifier()->getNetworkID();
+
+    assert(ClassByID(this->classID));
+    assert(this->classID==this->getIdentifier()->getNetworkID());
+    std::vector<SynchronisableVariableBase*>::iterator i;
+
+    // start copy header
+    SynchronisableHeader header(mem);
+    mem += SynchronisableHeader::getSize();
+    // end copy header
+
+
+    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
+    // copy to location
+    for(i=syncList.begin(); i!=syncList.end(); ++i){
+      tempsize += (*i)->getData( mem, mode );
+      //tempsize += (*i)->getSize( mode );
+    }
+    
+    tempsize += SynchronisableHeader::getSize();
+    header.setObjectID( this->objectID );
+    header.setCreatorID( this->creatorID );
+    header.setClassID( this->classID );
+    header.setDataAvailable( true );
+    header.setDataSize( tempsize );
+    
+#ifndef NDEBUG
+    uint32_t size;
+    size=getSize(id, mode);
+    assert(tempsize==size);
+#endif
+    return tempsize;
+  }
+
+
+  /**
+   * This function takes a bytestream and loads the data into the registered variables
+   * @param mem pointer to the bytestream
+   * @param mode same as in getData
+   * @return true/false
+   */
+  bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){
+    if(mode==0x0)
+      mode=state_;
+    std::vector<SynchronisableVariableBase *>::iterator i;
+    if(syncList.empty()){
+      assert(0);
+      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
+      return false;
+    }
+
+    uint8_t* data=mem;
+    // start extract header
+    SynchronisableHeader syncHeader(mem);
+    assert(syncHeader.getObjectID()==this->objectID);
+    assert(syncHeader.getCreatorID()==this->creatorID);
+    assert(syncHeader.getClassID()==this->classID);
+    if(syncHeader.isDataAvailable()==false){
+      mem += syncHeader.getDataSize();
+      return true;
+    }
+
+    mem += SynchronisableHeader::getSize();
+    // stop extract header
+
+    //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
+    for(i=syncList.begin(); i!=syncList.end(); i++)
+    {
+      assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream
+      (*i)->putData( mem, mode, forceCallback );
+    }
+    assert(mem == data+syncHeader.getDataSize());
+    return true;
+  }
+
+  /**
+  * This function returns the total amount of bytes needed by getData to save the whole content of the variables
+  * @param id id of the gamestate
+  * @param mode same as getData
+  * @return amount of bytes
+  */
+  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
+    int tsize=SynchronisableHeader::getSize();
+    if (mode==0x0)
+      mode=state_;
+    if (!doSync(id, mode))
+      return 0;
+    assert( mode==state_ );
+    tsize += this->dataSize_;
+    std::vector<SynchronisableVariableBase*>::iterator i;
+    for(i=stringList.begin(); i!=stringList.end(); ++i){
+      tsize += (*i)->getSize( mode );
+    }
+    return tsize;
+  }
+
+  /**
+   * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction)
+   * @param id gamestate id
+   * @return true/false
+   */
+  bool Synchronisable::doSync(int32_t id, uint8_t mode){
+    if(mode==0x0)
+      mode=state_;
+    return ( (objectMode_&mode)!=0 && (!syncList.empty() ) );
+  }
+
+  /**
+   * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones
+   * @param mem pointer to the bytestream
+   */
+  bool Synchronisable::isMyData(uint8_t* mem)
+  {
+    SynchronisableHeader header(mem);
+    assert(header.getObjectID()==this->objectID);
+    return header.isDataAvailable();
+  }
+
+  /**
+   * This function sets the synchronisation mode of the object
+   * If set to 0x0 variables will not be synchronised at all
+   * If set to 0x1 variables will only be synchronised to the client
+   * If set to 0x2 variables will only be synchronised to the server
+   * If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar)
+   * @param mode same as in registerVar
+   */
+  void Synchronisable::setObjectMode(uint8_t mode){
+    assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
+    objectMode_=mode;
+  }
+
+
+}
Index: /code/branches/libraries2/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/Synchronisable.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/Synchronisable.h	(revision 5713)
@@ -0,0 +1,216 @@
+/*
+ *   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, (C) 2007
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Synchronisable_H__
+#define _Synchronisable_H__
+
+#include "network/NetworkPrereqs.h"
+
+#include <cassert>
+#include <cstring>
+#include <vector>
+#include <map>
+#include <queue>
+
+#include "util/mbool.h"
+#include "core/OrxonoxClass.h"
+#include "SynchronisableVariable.h"
+#include "NetworkCallback.h"
+
+
+namespace orxonox
+{
+
+  namespace ObjectDirection{
+    enum Value{
+      ToClient=0x1,
+      ToServer=0x2,
+      Bidirectional=0x3
+    };
+  }
+
+  namespace Priority{
+    enum Value{
+      VeryHigh    = -100,
+      High        = -15,
+      Normal      = 0,
+      Low         = 15,
+      VeryLow     = 100
+    };
+  }
+
+  /**
+   * @brief: stores information about a Synchronisable 
+   * 
+   * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize)
+   * in an emulated bitset.
+   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
+   * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
+   * Byte 5 to 8: objectID
+   * Byte 9 to 12: classID
+   * Byte 13 to 16: creatorID
+   */
+  class _NetworkExport SynchronisableHeader{
+    private:
+      uint8_t *data_;
+    public:
+      SynchronisableHeader(uint8_t* data)
+        { data_ = data; }
+      inline static uint32_t getSize()
+        { return 16; }
+      inline uint32_t getDataSize() const
+        { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits
+      inline void setDataSize(uint32_t size)
+        { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
+      inline bool isDataAvailable() const
+        { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
+      inline void setDataAvailable( bool b)
+        { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
+      inline uint32_t getObjectID() const
+        { return *(uint32_t*)(data_+4); }
+      inline void setObjectID(uint32_t objectID)
+        { *(uint32_t*)(data_+4) = objectID; }
+      inline uint32_t getClassID() const
+        { return *(uint32_t*)(data_+8); }
+      inline void setClassID(uint32_t classID)
+        { *(uint32_t*)(data_+8) = classID; }
+      inline uint32_t getCreatorID() const
+        { return *(uint32_t*)(data_+12); }
+      inline void setCreatorID(uint32_t creatorID)
+        { *(uint32_t*)(data_+12) = creatorID; }
+      inline void operator=(SynchronisableHeader& h)
+        { memcpy(data_, h.data_, getSize()); }
+  };
+
+
+  /**
+  * This class is the base class of all the Objects in the universe that need to be synchronised over the network
+  * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
+  * @author Oliver Scheuss
+  */
+  class _NetworkExport Synchronisable : virtual public OrxonoxClass{
+  public:
+    friend class packet::Gamestate;
+    virtual ~Synchronisable();
+
+    static void setClient(bool b);
+
+    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
+    static bool deleteObject(uint32_t objectID);
+    static Synchronisable *getSynchronisable(uint32_t objectID);
+    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
+    static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
+
+    inline uint32_t getObjectID() const {return objectID;}
+    inline unsigned int getCreatorID() const {return creatorID;}
+    inline uint32_t getClassID() const {return classID;}
+    inline unsigned int getPriority() const { return objectFrequency_;}
+
+  protected:
+    Synchronisable(BaseObject* creator);
+    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
+    //template <class T> void unregisterVariable(T& var);
+    void setObjectMode(uint8_t mode);
+    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
+
+
+  private:
+    uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
+    uint32_t getSize(int32_t id, uint8_t mode=0x0);
+    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
+    bool isMyData(uint8_t* mem);
+    bool doSync(int32_t id, uint8_t mode=0x0);
+
+    uint32_t objectID;
+    uint32_t creatorID;
+    uint32_t classID;
+
+    std::vector<SynchronisableVariableBase*> syncList;
+    std::vector<SynchronisableVariableBase*> stringList;
+    uint32_t dataSize_; //size of all variables except strings
+    static uint8_t state_; // detemines wheter we are server (default) or client
+    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
+    unsigned int objectFrequency_;
+    int objectMode_;
+    static std::map<uint32_t, Synchronisable *> objectMap_;
+    static std::queue<uint32_t> deletedObjects_;
+  };
+
+  // ================= Specialisation declarations
+  
+//   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  
+  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+  {
+    if (bidirectional)
+    {
+      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
+      this->dataSize_ += syncList.back()->getSize(state_);
+    }
+    else
+    {
+      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
+      if ( this->state_ == mode )
+        this->dataSize_ += syncList.back()->getSize(state_);
+    }
+  }
+  
+
+
+//   template <class T> void Synchronisable::unregisterVariable(T& var){
+//     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
+//     while(it!=syncList.end()){
+//       if( ((*it)->getReference()) == &var ){
+//         delete (*it);
+//         syncList.erase(it);
+//         return;
+//       }
+//       else
+//         it++;
+//     }
+//     bool unregistered_nonexistent_variable = false;
+//     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
+//     // the variable has not been registered before
+//   }
+
+  
+}
+
+#endif /* _Synchronisable_H__ */
Index: /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableSpecialisations.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableSpecialisations.cc	(revision 5713)
@@ -0,0 +1,111 @@
+/*
+ *   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:
+ *      Dumeni Manatschal, (C) 2007
+ *      Oliver Scheuss, (C) 2007
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include <string>
+#include "util/Math.h"
+#include "Synchronisable.h"
+#include "SynchronisableVariable.h"
+
+// ================ template spezialisation
+  
+  
+namespace orxonox{
+  
+  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+  {
+    SynchronisableVariableBase* sv;
+    if (bidirectional)
+      sv = new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb);
+    else
+      sv = new SynchronisableVariable<const std::string>(variable, mode, cb);
+    syncList.push_back(sv);
+    stringList.push_back(sv);
+  }
+  
+  template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable(variable.r, mode, cb, bidirectional);
+    registerVariable(variable.g, mode, cb, bidirectional);
+    registerVariable(variable.b, mode, cb, bidirectional);
+    registerVariable(variable.a, mode, cb, bidirectional);
+  }
+  template <> void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    return Synchronisable::registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
+  }
+
+  template <> void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable(variable.x, mode, cb, bidirectional);
+    registerVariable(variable.y, mode, cb, bidirectional);
+  }
+  
+  template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable(variable.x, mode, cb, bidirectional);
+    registerVariable(variable.y, mode, cb, bidirectional);
+    registerVariable(variable.z, mode, cb, bidirectional);
+  }
+  template <> void Synchronisable::registerVariable( Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable( (const Vector3&)variable, mode, cb, bidirectional);
+  }
+
+  template <> void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable(variable.x, mode, cb, bidirectional);
+    registerVariable(variable.y, mode, cb, bidirectional);
+    registerVariable(variable.z, mode, cb, bidirectional);
+    registerVariable(variable.w, mode, cb, bidirectional);
+  }
+  template <> void Synchronisable::registerVariable( Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable( (const Vector4&)variable, mode, cb, bidirectional);
+  }
+  
+  template <> void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable(variable.getMemory(), mode, cb, bidirectional);
+  }
+  
+  template <> void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable(variable.x, mode, cb, bidirectional);
+    registerVariable(variable.y, mode, cb, bidirectional);
+    registerVariable(variable.z, mode, cb, bidirectional);
+    registerVariable(variable.w, mode, cb, bidirectional);
+  }
+  template <> void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
+  {
+    registerVariable( (const Quaternion&)variable, mode, cb, bidirectional);
+  }
+
+  
+
+} //namespace
Index: /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableVariable.cc
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableVariable.cc	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableVariable.cc	(revision 5713)
@@ -0,0 +1,36 @@
+/*
+ *   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 "SynchronisableVariable.h"
+
+namespace orxonox{
+
+uint8_t SynchronisableVariableBase::state_ = 0;
+
+
+} //namespace
Index: /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableVariable.h
===================================================================
--- /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableVariable.h	(revision 5713)
+++ /code/branches/libraries2/src/libraries/network/synchronisable/SynchronisableVariable.h	(revision 5713)
@@ -0,0 +1,258 @@
+/*
+ *   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 _SynchronisableVariable_H__
+#define _SynchronisableVariable_H__
+
+#include "network/NetworkPrereqs.h"
+
+#include <cassert>
+#include <cstring>
+#include "util/Serialise.h"
+#include "util/TypeTraits.h"
+#include "core/GameMode.h"
+#include "network/synchronisable/NetworkCallbackManager.h"
+
+namespace orxonox{
+  
+  namespace VariableDirection{
+    enum Value{
+      ToClient=0x1,
+      ToServer=0x2
+    };
+  }
+  namespace Bidirectionality{
+    enum Value{
+      ServerMaster=0x1,
+      ClientMaster=0x2
+    };
+  }
+  
+  class _NetworkExport SynchronisableVariableBase
+  {
+    public:
+      virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0;
+      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0;
+      virtual uint32_t getSize(uint8_t mode)=0;
+      virtual void* getReference()=0;
+      virtual uint8_t getMode()=0;
+      virtual ~SynchronisableVariableBase() {}
+    protected:
+      static uint8_t state_;
+  };
+
+  template <class T>
+  class SynchronisableVariable: public SynchronisableVariableBase
+  {
+    public:
+      SynchronisableVariable(T& variable, uint8_t syncDirection=VariableDirection::ToClient, NetworkCallbackBase *cb=0);
+      virtual ~SynchronisableVariable();
+
+      virtual inline uint8_t getMode(){ return mode_; }
+      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
+      virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
+      virtual inline uint32_t getSize(uint8_t mode);
+      virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); }
+    protected:
+      
+      T& variable_;
+      uint8_t mode_;
+      NetworkCallbackBase *callback_;
+  };
+  
+  template <class T>
+  class SynchronisableVariableBidirectional: public SynchronisableVariable<T>
+  {
+    public:
+      SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb=0);
+      virtual ~SynchronisableVariableBidirectional();
+      
+      virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^
+      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
+      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
+      virtual inline uint32_t getSize(uint8_t mode);
+    private:
+      T varBuffer_;
+      uint8_t varReference_;
+  };
+
+  // ================= Unidirectional Part ===============
+
+  template <class T> SynchronisableVariable<T>::SynchronisableVariable(T& variable, uint8_t syncDirection, NetworkCallbackBase *cb):
+      variable_( variable ), mode_( syncDirection ), callback_( cb )
+  {
+    if ( state_ == 0x0 )
+    {
+      state_ = GameMode::isMaster() ? 0x1 : 0x2;  // set the appropriate mode here
+    }
+  }
+  
+  template <class T> SynchronisableVariable<T>::~SynchronisableVariable()
+  {
+    if (this->callback_ != 0)
+    {
+      NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
+      // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback
+    }
+  }
+
+  template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
+  {
+    if ( mode == this->mode_ )
+    {
+      saveAndIncrease( this->variable_, mem );
+      return returnSize( this->variable_ );
+    }
+    else
+      return 0;
+  }
+
+  template <class T> void SynchronisableVariable<T>::putData(uint8_t*& mem, uint8_t mode, bool forceCallback)
+  {
+    assert ( mode == 0x1 || mode == 0x2 );
+    bool callback = false;
+    if ( mode == this->mode_ ) //don't do anything
+      return;
+  // check whether we need to consider a callback
+    if ( this->callback_ != 0 )
+    {
+      if( forceCallback || !checkEquality( this->variable_, mem ) )
+        callback = true;
+    }
+  // write the data
+    loadAndIncrease( this->variable_, mem );
+  // now do a callback if neccessary
+    if ( callback )
+      NetworkCallbackManager::triggerCallback( this->callback_ );
+  }
+
+  template <class T> inline uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
+  {
+    if ( mode == this->mode_ )
+      return returnSize( this->variable_ );
+    else
+      return 0;
+  }
+
+
+
+
+// ================= Bidirectional Part ================
+
+    template <class T> SynchronisableVariableBidirectional<T>::SynchronisableVariableBidirectional(T& variable, uint8_t master, NetworkCallbackBase *cb):
+    SynchronisableVariable<T>( variable, master, cb ), varBuffer_( variable ), varReference_( 0 )
+    {
+    }
+
+    template <class T> SynchronisableVariableBidirectional<T>::~SynchronisableVariableBidirectional()
+    {
+    }
+
+    template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
+    {
+      if ( this->mode_ == mode )
+      {   // we are master for this variable and have to check whether to change the varReference
+        if( this->varBuffer_ != this->variable_ )
+        {
+          this->varReference_++;
+          memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(this->variable_));
+        }
+      }
+  // write the reference number to the stream
+      *static_cast<uint8_t*>(mem) = varReference_;
+      mem += sizeof(this->varReference_);
+  // now write the content
+      saveAndIncrease( this->variable_, mem );
+      return SynchronisableVariableBidirectional::getSize(mode);
+    }
+
+    template <class T> void SynchronisableVariableBidirectional<T>::putData(uint8_t*& mem, uint8_t mode, bool forceCallback)
+    {
+      bool callback = false;
+      if ( this->mode_ == mode )
+      {   //        MASTER
+        // check that the client (source of the data) has a recent version of this variable
+        if ( *static_cast<uint8_t*>(mem) != this->varReference_ )
+        { // wrong reference number, so discard the data
+//           COUT(0) << "discharding data" << endl;
+          mem += getSize( mode ); // SynchronisableVariableBidirectional::getSize returns size of variable + reference
+          return;
+        }
+        else{
+          // apply data
+          if ( checkEquality( this->variable_, mem+sizeof(varReference_) )==true )
+          {
+            mem += getSize( mode );
+            return;
+          }
+          else
+          {
+            mem += sizeof(varReference_);
+            memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(T));
+            if ( this->callback_ != 0 )
+              callback = true;
+          }
+        }
+      }
+      else
+      {   // we are slave for this variable
+        if (*static_cast<uint8_t*>(mem) == this->varReference_ && !forceCallback)
+        {
+          mem += getSize( mode ); //just skip the variable because nothing changed
+          return;
+        }
+        else
+        {
+          this->varReference_ = *static_cast<uint8_t*>(mem);
+          mem += sizeof(varReference_);
+          if ( checkEquality( this->variable_, mem ) == false )
+          {
+            // value changed so remark for callback
+            if ( this->callback_ != 0 )
+              callback = true;
+          }
+        }
+      }
+  // now write the data
+      loadAndIncrease(this->variable_, mem);
+  // now do a callback if neccessary
+      if ( callback )
+        NetworkCallbackManager::triggerCallback( this->callback_ );
+    }
+
+    template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
+    {
+      return returnSize( this->variable_ ) + sizeof(varReference_);
+    }
+  
+
+}
+
+
+#endif /* _SynchronisableVariable_H__ */
