Index: code/trunk/src/core/Core.cc
===================================================================
--- code/trunk/src/core/Core.cc	(revision 3213)
+++ code/trunk/src/core/Core.cc	(revision 3214)
@@ -47,4 +47,6 @@
 #  endif
 #  include <windows.h>
+#  undef min
+#  undef max
 #elif defined(ORXONOX_PLATFORM_APPLE)
 #  include <sys/param.h>
Index: code/trunk/src/core/CorePrecompiledHeaders.h
===================================================================
--- code/trunk/src/core/CorePrecompiledHeaders.h	(revision 3213)
+++ code/trunk/src/core/CorePrecompiledHeaders.h	(revision 3214)
@@ -35,10 +35,14 @@
 #include "CorePrereqs.h"
 
+#include <cassert>
 #include <fstream>
 #include <iostream>
 #include <list>
+#include <locale>
 #include <map>
+#include <queue>
 #include <set>
 #include <sstream>
+#include <stack>
 #include <string>
 #include <vector>
@@ -47,28 +51,26 @@
 #ifdef ORXONOX_COMPILER_MSVC
 
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include <OgreMath.h>
+#include <OgreVector2.h>
+#include <OgreVector3.h>
+#include <OgreVector4.h>
+#include <OgreQuaternion.h>
+#include <OgreColourValue.h>
+
+#include <boost/shared_ptr.hpp> // 12
+#include <boost/preprocessor/cat.hpp> // 12
+// Included by both filesystem and thread but still relatively small
+#include <boost/iterator/iterator_facade.hpp> // 10
+
+// Just in case some header included windows.h
+#undef min
 #undef max
-#undef min
-
-#include <ois/OISKeyboard.h>
-#include <ois/OISMouse.h>
-#include <ois/OISJoyStick.h>
-#include <tinyxml/ticpp.h>
-// Included by both filesystem and thread but still relatively small
-#include <boost/iterator/iterator_facade.hpp>
 
 #endif /* ORXONOX_COMPILER_MSVC */
 
 
-#include "util/Convert.h"
 #include "util/Debug.h"
-#include "util/Exception.h"
 #include "util/Math.h"
-#include "util/mbool.h"
 #include "util/MultiType.h"
-#include "util/OrxAssert.h"
-#include "util/OrxEnum.h"
-#include "util/String.h"
 #include "util/SubString.h"
 
Index: code/trunk/src/network/CMakeLists.txt
===================================================================
--- code/trunk/src/network/CMakeLists.txt	(revision 3213)
+++ code/trunk/src/network/CMakeLists.txt	(revision 3214)
@@ -24,5 +24,5 @@
   ClientInformation.cc
   ClientConnectionListener.cc
-  ConnectionManager.cc
+  Connection.cc
   FunctionCallManager.cc
   GamestateManager.cc
@@ -33,4 +33,5 @@
   PacketBuffer.cc
   Server.cc
+  ServerConnection.cc
   TrafficControl.cc
 )
Index: code/trunk/src/network/ChatListener.cc
===================================================================
--- code/trunk/src/network/ChatListener.cc	(revision 3213)
+++ code/trunk/src/network/ChatListener.cc	(revision 3214)
@@ -28,5 +28,4 @@
 
 #include "ChatListener.h"
-
 #include "core/CoreIncludes.h"
 
Index: code/trunk/src/network/ChatListener.h
===================================================================
--- code/trunk/src/network/ChatListener.h	(revision 3213)
+++ code/trunk/src/network/ChatListener.h	(revision 3214)
@@ -31,6 +31,4 @@
 
 #include "NetworkPrereqs.h"
-
-#include "ClientInformation.h"
 #include "core/OrxonoxClass.h"
 
Index: code/trunk/src/network/Client.cc
===================================================================
--- code/trunk/src/network/Client.cc	(revision 3213)
+++ code/trunk/src/network/Client.cc	(revision 3214)
@@ -39,20 +39,17 @@
 //
 
+#include "Client.h"
+
 #include <cassert>
-#include <enet/enet.h>
 
-#include "Client.h"
-#include "Host.h"
+#include "util/Debug.h"
+#include "core/Clock.h"
 #include "synchronisable/Synchronisable.h"
-#include "core/Clock.h"
-#include "core/CoreIncludes.h"
-#include "packet/Packet.h"
+#include "packet/Chat.h"
+#include "packet/Gamestate.h"
 #include "FunctionCallManager.h"
-
-// #include "packet/Acknowledgement.h"
 
 namespace orxonox
 {
-//   SetConsoleCommandShortcut(Client, chat);
 
 
@@ -61,9 +58,8 @@
   * initializes the address and the port to default localhost:NETWORK_PORT
   */
-  Client::Client(): client_connection(NETWORK_PORT,"127.0.0.1"){
-    // set server address to localhost
-    isConnected=false;
-    isSynched_=false;
-    gameStateFailure_=false;
+  Client::Client():
+      isSynched_(false),
+      gameStateFailure_(false)
+  {
   }
 
@@ -73,23 +69,14 @@
   * @param port port of the application on the server
   */
-  Client::Client(const std::string& address, int port) : client_connection(port, address){
-    isConnected=false;
-    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 char *address, int port) : client_connection(port, address){
-    isConnected=false;
-    isSynched_=false;
-    gameStateFailure_=false;
+  Client::Client(const std::string& address, int port):
+      isSynched_(false),
+      gameStateFailure_(false)
+  {
+      setPort( port );
+      setServerAddress( address );
   }
 
   Client::~Client(){
-    if(isConnected)
+    if ( ClientConnection::isConnected() )
       closeConnection();
   }
@@ -101,8 +88,5 @@
   bool Client::establishConnection(){
     Synchronisable::setClient(true);
-    isConnected=client_connection.createConnection();
-    if(!isConnected)
-      COUT(1) << "could not create connection laber" << std::endl;
-    return isConnected;
+    return ClientConnection::establishConnection();
   }
 
@@ -112,10 +96,11 @@
   */
   bool Client::closeConnection(){
-    isConnected=false;
-    return client_connection.closeConnection();
+    return ClientConnection::closeConnection();
   }
 
   bool Client::queuePacket(ENetPacket *packet, int clientID){
-    return client_connection.addPacket(packet);
+    bool b = ClientConnection::addPacket(packet);
+    assert(b);
+    return b;
   }
 
@@ -143,8 +128,10 @@
     //this steers our network frequency
     timeSinceLastUpdate_+=time.getDeltaTime();
-    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
+    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    {
       timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
       //     COUT(3) << ".";
-      if(client_connection.isConnected() && isSynched_){
+      if ( isConnected() && isSynched_ )
+      {
         COUT(4) << "popping partial gamestate: " << std::endl;
         packet::Gamestate *gs = gamestate.getGamestate();
@@ -159,16 +146,7 @@
       }
     }
+    sendPackets(); // flush the enet queue
     
-    ENetEvent *event;
-    // stop if the packet queue is empty
-    while(!(client_connection.queueEmpty())){
-      event = client_connection.getEvent();
-      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
-      packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
-      // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
-      bool b = packet->process();
-      assert(b);
-      delete event;
-    }
+    Connection::processQueue();
     if(gamestate.processGamestates())
     {
Index: code/trunk/src/network/Client.h
===================================================================
--- code/trunk/src/network/Client.h	(revision 3213)
+++ code/trunk/src/network/Client.h	(revision 3214)
@@ -45,10 +45,7 @@
 
 #include <string>
-
-#include "Host.h"
-#include "packet/Chat.h"
 #include "ClientConnection.h"
 #include "GamestateClient.h"
-
+#include "Host.h"
 
 namespace orxonox
@@ -61,9 +58,8 @@
   *
   */
-  class _NetworkExport Client : public Host{
+  class _NetworkExport Client : public Host, public ClientConnection{
   public:
     Client();
     Client(const std::string& address, int port);
-    Client(const char *address, int port);
     ~Client();
 
@@ -74,5 +70,4 @@
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message) { return false; }
-    //bool sendChat(packet::Chat *chat);
 
     void update(const Clock& time);
@@ -82,7 +77,5 @@
     virtual bool isServer_(){return false;}
 
-    ClientConnection client_connection;
     GamestateClient gamestate;
-    bool isConnected;
     bool isSynched_;
 
Index: code/trunk/src/network/ClientConnection.cc
===================================================================
--- code/trunk/src/network/ClientConnection.cc	(revision 3213)
+++ code/trunk/src/network/ClientConnection.cc	(revision 3214)
@@ -27,218 +27,56 @@
  */
 
-//
-// C++ Interface: ClientConnection
-//
-// Description: The Class ClientConnection manages the servers conenctions to the clients.
-// each connection is provided by a new process. communication between master process and
-// connection processes is provided by ...
-//
-//
-// Author:  Oliver Scheuss
-//
-
 #include "ClientConnection.h"
 
+#include <cassert>
 #include <enet/enet.h>
-#include <iostream>
-#include <cassert>
-// boost.thread library for multithreading support
-#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-
-#include "util/Sleep.h"
 #include "util/Debug.h"
 
 namespace orxonox
 {
-  //static boost::thread_group network_threads;
+  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;
 
-  static boost::recursive_mutex enet_mutex_g;
 
-  ClientConnection::ClientConnection(int port, const std::string& address) {
-    quit_=false;
-    server=NULL;
-    serverAddress = new ENetAddress();
-    enet_address_set_host(serverAddress, address.c_str());
-    serverAddress->port = port;
-    established=false;
-  }
-
-  ClientConnection::ClientConnection(int port, const char *address) {
-    quit_=false;
-    server=NULL;
-    serverAddress = new ENetAddress();
-    enet_address_set_host(serverAddress, address);
-    serverAddress->port = port;
-    established=false;
-  }
-
-  bool ClientConnection::waitEstablished(int milisec) {
-    for(int i=0; i<=milisec && !established; i++)
-      msleep(1);
-
-    return established;
+  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(established)
+    if(this->established_)
       closeConnection();
-    delete serverAddress; // surely was created
+    delete this->serverAddress_; // surely was created
   }
 
-  ENetEvent *ClientConnection::getEvent(){
-    if(!buffer.isEmpty())
-      return buffer.pop();
-    else
-      return NULL;
+  void ClientConnection::setServerAddress( const std::string& serverAddress ) {
+    enet_address_set_host (this->serverAddress_, serverAddress.c_str());
   }
 
-  bool ClientConnection::queueEmpty() {
-    return buffer.isEmpty();
+  void ClientConnection::setPort( unsigned int port ) {
+    this->serverAddress_->port = port;
   }
 
-  bool ClientConnection::createConnection() {
-    receiverThread_ = new boost::thread(boost::bind(&ClientConnection::receiverThread, this));
-    //network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
-    // wait 10 seconds for the connection to be established
-    return waitEstablished(NETWORK_CLIENT_CONNECT_TIMEOUT);
-  }
-
-  bool ClientConnection::closeConnection() {
-    quit_=true;
-    //network_threads.join_all();
-    receiverThread_->join();
-    established=false;
-    return true;
-  }
-
-
-  bool ClientConnection::addPacket(ENetPacket *packet) {
-    if(server==NULL)
-      return false;
-    if(packet==NULL){
-      COUT(3) << "Cl.con: addpacket: invalid packet" << std::endl;
+  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;
     }
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    if(enet_peer_send(server, 0, packet)<0)
-      return false;
-    else
-      return true;
-  }
-
-  bool ClientConnection::sendPackets() {
-    if(server==NULL)
-      return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    enet_host_flush(client);
-    lock.unlock();
-    return true;
-  }
-
-  void ClientConnection::receiverThread() {
-    // what about some error-handling here ?
-    atexit(enet_deinitialize);
-    ENetEvent *event;
+    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS);
+    if ( this->server_==NULL )
     {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_initialize();
-      client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
-      lock.unlock();
-    }
-    if(client==NULL) {
-      COUT(2) << "ClientConnection: could not create client host" << std::endl;
-      // add some error handling here ==========================
-      quit_=true;
-    }
-    //connect to the server
-    if(!establishConnection()){
-      COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
-      quit_=true;
-      return;
-    }
-    event = new ENetEvent;
-    //main loop
-    while(!quit_){
-      //std::cout << "connection loop" << std::endl;
-      {
-        boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
-          // we should never reach this point
-// 	        assert(0);
-          printf("ClientConnection: ENet returned with an error!\n");
-//           quit_=true;
-          continue;
-          // add some error handling here ========================
-        }
-        lock.unlock();
-      }
-      switch(event->type){
-        // log handling ================
-      case ENET_EVENT_TYPE_CONNECT:
-        break;
-      case ENET_EVENT_TYPE_RECEIVE:
-        //COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl;
-        if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
-        //COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl;
-        event = new ENetEvent;
-        break;
-      case ENET_EVENT_TYPE_DISCONNECT:
-        quit_=true;
-        printf("Received disconnect Packet from Server!\n");
-        // server closed the connection
-        return;
-        break;
-      case ENET_EVENT_TYPE_NONE:
-        //receiverThread_->yield();
-        msleep(1);
-        break;
-      }
-    }
-    delete event;
-    // now disconnect
-
-    if(!disconnectConnection())
-    {
-      printf("could not disconnect properly\n");
-      // if disconnecting failed destroy conn.
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_peer_reset(server);
-    }
-    else
-      printf("properly disconnected\n");
-    return;
-  }
-
-  bool ClientConnection::disconnectConnection() {
-    ENetEvent event;
-    if(this->quit_)
-      return true;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    enet_peer_disconnect(server, 0);
-    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
-      switch (event.type)
-      {
-      case ENET_EVENT_TYPE_NONE:
-      case ENET_EVENT_TYPE_CONNECT:
-      case ENET_EVENT_TYPE_RECEIVE:
-        enet_packet_destroy(event.packet);
-        break;
-      case ENET_EVENT_TYPE_DISCONNECT:
-        printf("received disconnect confirmation from server");
-        return true;
-      }
-    }
-    enet_peer_reset(server);
-    return false;
-  }
-
-  bool ClientConnection::establishConnection() {
-    ENetEvent event;
-    // connect to peer (server is type ENetPeer*)
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    server = enet_host_connect(client, serverAddress, NETWORK_CLIENT_CHANNELS);
-    if(server==NULL) {
       COUT(2) << "ClientConnection: server == NULL" << std::endl;
       // error handling
@@ -246,19 +84,61 @@
     }
     // handshake
-    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){
-      if( event.type == ENET_EVENT_TYPE_CONNECT ){
-        established=true;
+    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(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl;
+    COUT(1) << "Could not connect to server" << endl;
     return false;
   }
 
-  bool ClientConnection::processData(ENetEvent *event) {
-    COUT(5) << "Cl.Con: got packet, pushing to queue" << std::endl;
-    // just add packet to the buffer
-    // this can be extended with some preprocessing
-    return buffer.push(event);
+  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/trunk/src/network/ClientConnection.h
===================================================================
--- code/trunk/src/network/ClientConnection.h	(revision 3213)
+++ code/trunk/src/network/ClientConnection.h	(revision 3214)
@@ -26,81 +26,42 @@
  *
  */
-
-//
-// C++ Interface: ClientConnection
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
+ 
 #ifndef _ClientConnection_H__
 #define _ClientConnection_H__
 
 #include "NetworkPrereqs.h"
-
-#include <string>
-#include "PacketBuffer.h"
-
-namespace boost { class thread; }
+#include "Connection.h"
 
 namespace orxonox
 {
 
-    const int NETWORK_PORT = 55556;
-    const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
-    const int NETWORK_CLIENT_WAIT_TIME = 10;
-    const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
-    const int NETWORK_CLIENT_CHANNELS = 2;
-
-
-  class _NetworkExport ClientConnection{
+  class _NetworkExport ClientConnection: public Connection{
   public:
-    ClientConnection(int port, const std::string& address);
-    ClientConnection(int port, const char* address);
-    ~ClientConnection();
+    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
-    bool createConnection();
-    bool closeConnection();
+    virtual bool establishConnection();
+    virtual bool closeConnection();
     // add a packet to queue for the server
     bool addPacket(ENetPacket *packet);
-    // send out all queued packets
-    bool sendPackets();
-    // send out all queued packets and save result in event
-    //bool sendPackets(ENetEvent *event);
-    bool waitEstablished(int milisec);
-    inline bool isConnected(){return established;}
-    inline bool checkConnection(){ return !quit_ && isConnected(); }
+    inline bool isConnected(){ return this->established_; }
   private:
-    ClientConnection(const ClientConnection& copy); // not used
-    bool processData(ENetEvent *event);
-    // implementation of the listener
-    void receiverThread(); //thread2
-    //packetbuffer
-    bool establishConnection();
+    virtual void addClient(ENetEvent* event);
+    virtual void disconnectPeer(ENetEvent* event);
+    
     bool disconnectConnection();
-    PacketBuffer buffer;
     // enet stuff
-    ENetHost *client;
-    ENetAddress *serverAddress;
-    // quit-variable (communication with threads)
-    bool quit_;
-    bool established;
+    ENetAddress *serverAddress_;
+    bool established_;
     // clientlist
-    ENetPeer *server;
-    boost::thread *receiverThread_;
+    ENetPeer *server_;
 };
-
-
-
-
-
-
 
 
Index: code/trunk/src/network/ClientConnectionListener.cc
===================================================================
--- code/trunk/src/network/ClientConnectionListener.cc	(revision 3213)
+++ code/trunk/src/network/ClientConnectionListener.cc	(revision 3214)
@@ -28,6 +28,8 @@
 
 #include "ClientConnectionListener.h"
+
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
+#include "ClientInformation.h"
 
 namespace orxonox{
Index: code/trunk/src/network/ClientConnectionListener.h
===================================================================
--- code/trunk/src/network/ClientConnectionListener.h	(revision 3213)
+++ code/trunk/src/network/ClientConnectionListener.h	(revision 3214)
@@ -1,7 +1,34 @@
-#ifndef _NETWORK_CLIENTCONNECTIONLISTENER__
-#define _NETWORK_CLIENTCONNECTIONLISTENER__
+/*
+ *   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 "ClientInformation.h"
 #include "core/OrxonoxClass.h"
 
@@ -26,3 +53,3 @@
 
 
-#endif
+#endif /* _ClientConnectionListener_H__ */
Index: code/trunk/src/network/ClientInformation.cc
===================================================================
--- code/trunk/src/network/ClientInformation.cc	(revision 3213)
+++ code/trunk/src/network/ClientInformation.cc	(revision 3214)
@@ -40,7 +40,5 @@
 
 #include "ClientInformation.h"
-
 #include <enet/enet.h>
-#include <iostream> //debug
 
 namespace orxonox
Index: code/trunk/src/network/Connection.cc
===================================================================
--- code/trunk/src/network/Connection.cc	(revision 3214)
+++ code/trunk/src/network/Connection.cc	(revision 3214)
@@ -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
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Connection.h"
+
+#include <cassert>
+#include <enet/enet.h>
+#include <OgreTimer.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_);
+    Ogre::Timer timer;
+
+    while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME && 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/trunk/src/network/Connection.h
===================================================================
--- code/trunk/src/network/Connection.h	(revision 3214)
+++ code/trunk/src/network/Connection.h	(revision 3214)
@@ -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/trunk/src/network/ConnectionManager.cc
===================================================================
--- code/trunk/src/network/ConnectionManager.cc	(revision 3213)
+++ 	(revision )
@@ -1,315 +1,0 @@
-/*
- *   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:
- *      ...
- *
- */
-
-//
-// C++ Interface: ConnectionManager
-//
-// Description: The Class ConnectionManager manages the servers conenctions to the clients.
-// each connection is provided by a new process. communication between master process and
-// connection processes is provided by ...
-//
-//
-// Author:  Oliver Scheuss
-//
-
-#include "ConnectionManager.h"
-
-#include <enet/enet.h>
-#include <iostream>
-#include <cassert>
-// boost.thread library for multithreading support
-#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-
-#include "util/Debug.h"
-#include "util/Math.h"
-#include "util/Sleep.h"
-#include "ClientInformation.h"
-#include "synchronisable/Synchronisable.h"
-#include "packet/ClassID.h"
-
-namespace std
-{
-  bool operator< (ENetAddress a, ENetAddress b) {
-    return a.host <= b.host;
-  }
-}
-
-namespace orxonox
-{
-  //boost::thread_group network_threads;
-  static boost::recursive_mutex enet_mutex_g;
-
-  ConnectionManager *ConnectionManager::instance_=0;
-
-  ConnectionManager::ConnectionManager():receiverThread_(0){
-    assert(instance_==0);
-    instance_=this;
-    quit_=false;
-    bindAddress = new ENetAddress();
-    bindAddress->host = ENET_HOST_ANY;
-    bindAddress->port = NETWORK_PORT;
-  }
-
-  ConnectionManager::ConnectionManager(int port){
-    assert(instance_==0);
-    instance_=this;
-    quit_=false;
-    bindAddress = new ENetAddress();
-    bindAddress->host = ENET_HOST_ANY;
-    bindAddress->port = port;
-  }
-
-  ConnectionManager::ConnectionManager(int port, const std::string& address) :receiverThread_(0) {
-    assert(instance_==0);
-    instance_=this;
-    quit_=false;
-    bindAddress = new ENetAddress();
-    enet_address_set_host (bindAddress, address.c_str());
-    bindAddress->port = NETWORK_PORT;
-  }
-
-  ConnectionManager::ConnectionManager(int port, const char *address) : receiverThread_(0) {
-    assert(instance_==0);
-    instance_=this;
-    quit_=false;
-    bindAddress = new ENetAddress();
-    enet_address_set_host (bindAddress, address);
-    bindAddress->port = NETWORK_PORT;
-  }
-
-  ConnectionManager::~ConnectionManager(){
-    if(!quit_)
-      quitListener();
-    instance_=0;
-    delete bindAddress;
-  }
-
-
-  ENetEvent *ConnectionManager::getEvent(){
-    if(!buffer.isEmpty())
-      return buffer.pop();
-    else
-      return NULL;
-  }
-
-  bool ConnectionManager::queueEmpty() {
-    return buffer.isEmpty();
-  }
-
-  void ConnectionManager::createListener() {
-    receiverThread_ = new boost::thread(boost::bind(&ConnectionManager::receiverThread, this));
-    return;
-  }
-
-  bool ConnectionManager::quitListener() {
-    quit_=true;
-    receiverThread_->join();
-    delete receiverThread_;
-    return true;
-  }
-
-
-  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
-      return false;
-    return true;
-  }
-
-  bool ConnectionManager::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 addPacket(packet, temp->getPeer());
-    }
-  }
-
-  bool ConnectionManager::addPacketAll(ENetPacket *packet) {
-    if(!instance_)
-      return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-//    for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){
-//      COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
-//      if(enet_peer_send(i->getPeer(), 0, packet)!=0)
-//        return false;
-//    }
-    enet_host_broadcast( instance_->server, 0, packet);
-    return true;
-  }
-
-  // we actually dont need that function, because host_service does that for us
-  bool ConnectionManager::sendPackets() {
-    if(server==NULL || !instance_)
-      return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    enet_host_flush(server);
-    lock.unlock();
-    return true;
-  }
-
-  void ConnectionManager::receiverThread() {
-    // what about some error-handling here ?
-    ENetEvent *event;
-    atexit(enet_deinitialize);
-    { //scope of the mutex
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_initialize();
-      server = enet_host_create(bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
-      lock.unlock();
-    }
-    if(server==NULL){
-      // add some error handling here ==========================
-      quit_=true;
-      return;
-    }
-
-    event = new ENetEvent;
-    while(!quit_)
-    {
-      { //mutex scope
-        boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
-          // we should never reach this point
-          printf("ConnectionManager: ENet returned with an error\n");
-//           quit_=true;
-//           printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
-          continue;
-          // add some error handling here ========================
-        }
-        lock.unlock();
-      }
-      switch(event->type){
-        // log handling ================
-        case ENET_EVENT_TYPE_CONNECT:
-//             printf("====================================================================");
-        case ENET_EVENT_TYPE_DISCONNECT:
-//           printf("====================================================================");
-        case ENET_EVENT_TYPE_RECEIVE:
-          processData(event);
-          event = new ENetEvent;
-          break;
-        case ENET_EVENT_TYPE_NONE:
-          //receiverThread_->yield();
-          msleep(1);
-          break;
-      }
-//       usleep(100);
-      //receiverThread_->yield(); //TODO: find apropriate
-    }
-    disconnectClients();
-    // if we're finishied, destroy server
-    {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_host_destroy(server);
-      lock.unlock();
-    }
-  }
-
-  //### added some bugfixes here, but we cannot test them because
-  //### the server crashes everytime because of some gamestates
-  //### (trying to resolve that now)
-  void ConnectionManager::disconnectClients() {
-    ENetEvent event;
-    ClientInformation *temp = ClientInformation::getBegin()->next();
-    while(temp!=0){
-      {
-        boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-        enet_peer_disconnect(temp->getPeer(), 0);
-        lock.unlock();
-      }
-      temp = temp->next();
-    }
-    //bugfix: might be the reason why server crashes when clients disconnects
-    temp = ClientInformation::getBegin()->next();
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
-      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:
-        COUT(4) << "disconnecting all clients" << std::endl;
-        if(ClientInformation::findClient(&(event.peer->address)))
-          delete ClientInformation::findClient(&(event.peer->address));
-        //maybe needs bugfix: might also be a reason for the server to crash
-        temp = temp->next();
-        break;
-      }
-    }
-    return;
-  }
-
-
-  int ConnectionManager::getClientID(ENetPeer* peer) {
-    return getClientID(&(peer->address));
-  }
-
-  int ConnectionManager::getClientID(ENetAddress* address) {
-    return ClientInformation::findClient(address)->getID();
-  }
-
-  ENetPeer *ConnectionManager::getClientPeer(int clientID) {
-    return ClientInformation::findClient(clientID)->getPeer();
-  }
-
-
-  void ConnectionManager::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;
-  }
-  
-
-  void ConnectionManager::disconnectClient(ClientInformation *client){
-    {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_peer_disconnect(client->getPeer(), 0);
-      lock.unlock();
-    }
-  }
-
-
-}
Index: code/trunk/src/network/ConnectionManager.h
===================================================================
--- code/trunk/src/network/ConnectionManager.h	(revision 3213)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/*
- *   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:
- *      ...
- *
- */
-
-//
-// C++ Interface: ConnectionManager
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef _ConnectionManager_H__
-#define _ConnectionManager_H__
-
-#include "NetworkPrereqs.h"
-
-#include <string>
-#include <map>
-
-#include "PacketBuffer.h"
-#include "packet/Packet.h"
-
-namespace boost { class thread; }
-
-namespace orxonox
-{
-    const int NETWORK_PORT = 55556;
-    const int NETWORK_MAX_CONNECTIONS = 50;
-    const int NETWORK_WAIT_TIMEOUT = 1;
-    const int NETWORK_DEFAULT_CHANNEL = 0;
-
-  struct _NetworkExport ClientList{
-    ENetEvent *event;
-    int ID;
-    ClientList *next;
-  };
-
-  class _NetworkExport ConnectionManager{
-    public:
-    ConnectionManager();
-    ConnectionManager(int port);
-    ConnectionManager(int port, const char *address);
-    ConnectionManager(int port, const std::string& address);
-    ~ConnectionManager();
-    ENetEvent *getEvent();
-    bool queueEmpty();
-    void createListener();
-    bool quitListener();
-    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
-    static bool addPacket(ENetPacket *packet, unsigned int ID);
-    static bool addPacketAll(ENetPacket *packet);
-    bool sendPackets();
-    void disconnectClient(ClientInformation *client);
-    void syncClassid(unsigned int clientID);
-    bool checkReceiverThread(){ return !quit_; }
-
-  private:
-    ConnectionManager(const ConnectionManager& copy); // not used
-    inline bool processData(ENetEvent *event){ return buffer.push(event); }
-    void receiverThread();
-    void disconnectClients();
-    int getClientID(ENetPeer* peer);
-    int getClientID(ENetAddress* address);
-    ENetPeer *getClientPeer(int clientID);
-    PacketBuffer buffer;
-
-    ENetHost *server;
-    ENetAddress *bindAddress;
-
-    bool quit_; // quit-variable (communication with threads)
-
-    boost::thread *receiverThread_;
-    static ConnectionManager *instance_;
-
-  };
-
-}
-
-#endif /* _ConnectionManager_H__ */
Index: code/trunk/src/network/FunctionCallManager.h
===================================================================
--- code/trunk/src/network/FunctionCallManager.h	(revision 3213)
+++ code/trunk/src/network/FunctionCallManager.h	(revision 3214)
@@ -1,10 +1,37 @@
+/*
+ *   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 NETWORKFUNCTIONCALLMANAGER_H
-#define NETWORKFUNCTIONCALLMANAGER_H
+#ifndef _FunctionCallManager_H__
+#define _FunctionCallManager_H__
 
 #include "NetworkPrereqs.h"
-#include "packet/FunctionCalls.h"
+
 #include <map>
-
+#include "util/UtilPrereqs.h"
 
 namespace orxonox {
@@ -12,6 +39,4 @@
 	@author
 */
-
-class MultiType;
 
 class _NetworkExport FunctionCallManager
@@ -42,3 +67,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _FunctionCallManager_H__ */
Index: code/trunk/src/network/GamestateClient.cc
===================================================================
--- code/trunk/src/network/GamestateClient.cc	(revision 3213)
+++ code/trunk/src/network/GamestateClient.cc	(revision 3214)
@@ -29,12 +29,10 @@
 #include "GamestateClient.h"
 
-#include <cassert>
-#include <zlib.h>
-
-#include "core/CoreIncludes.h"
-#include "core/BaseObject.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"
 
 
Index: code/trunk/src/network/GamestateClient.h
===================================================================
--- code/trunk/src/network/GamestateClient.h	(revision 3213)
+++ code/trunk/src/network/GamestateClient.h	(revision 3214)
@@ -41,9 +41,8 @@
 #define _GamestateClient_H__
 
+#include "NetworkPrereqs.h"
+
 #include <map>
-//
-#include "NetworkPrereqs.h"
 #include "core/CorePrereqs.h"
-#include "packet/Gamestate.h"
 #include "GamestateHandler.h"
 
Index: code/trunk/src/network/GamestateHandler.cc
===================================================================
--- code/trunk/src/network/GamestateHandler.cc	(revision 3213)
+++ code/trunk/src/network/GamestateHandler.cc	(revision 3214)
@@ -1,6 +1,32 @@
-#include <cassert>
+/*
+ *   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 "packet/Packet.h"
+#include <cassert>
 
 namespace orxonox {
Index: code/trunk/src/network/GamestateHandler.h
===================================================================
--- code/trunk/src/network/GamestateHandler.h	(revision 3213)
+++ code/trunk/src/network/GamestateHandler.h	(revision 3214)
@@ -26,11 +26,9 @@
  *
  */
-#ifndef NETWORKGAMESTATEHANDLER_H
-#define NETWORKGAMESTATEHANDLER_H
 
-#include <string>
+#ifndef _GamestateHandler_H__
+#define _GamestateHandler_H__
 
 #include "NetworkPrereqs.h"
-#include "packet/Chat.h"
 
 namespace orxonox {
@@ -58,3 +56,3 @@
 }
 
-#endif
+#endif /* _GamestateHandler_H__ */
Index: code/trunk/src/network/GamestateManager.cc
===================================================================
--- code/trunk/src/network/GamestateManager.cc	(revision 3213)
+++ code/trunk/src/network/GamestateManager.cc	(revision 3214)
@@ -41,15 +41,12 @@
 #include "GamestateManager.h"
 
-#include <utility>
-#include <iostream>
-#include <zlib.h>
 #include <cassert>
 
-#include "core/CoreIncludes.h"
-#include "core/BaseObject.h"
+#include "util/Debug.h"
 #include "ClientInformation.h"
-#include "synchronisable/Synchronisable.h"
+#include "packet/Acknowledgement.h"
+#include "packet/Gamestate.h"
 #include "synchronisable/NetworkCallbackManager.h"
-#include "packet/Acknowledgement.h"
+#include "TrafficControl.h"
 
 namespace orxonox
Index: code/trunk/src/network/GamestateManager.h
===================================================================
--- code/trunk/src/network/GamestateManager.h	(revision 3213)
+++ code/trunk/src/network/GamestateManager.h	(revision 3214)
@@ -42,14 +42,12 @@
 
 #include "NetworkPrereqs.h"
+
+#include <map>
 #include "GamestateHandler.h"
-#include "TrafficControl.h"
-#include <map>
-
-#include "packet/Gamestate.h"
 
 namespace orxonox
 {
 
-    const int KEEP_GAMESTATES = 10;
+  const int KEEP_GAMESTATES = 10;
 
   /**
Index: code/trunk/src/network/Host.cc
===================================================================
--- code/trunk/src/network/Host.cc	(revision 3213)
+++ code/trunk/src/network/Host.cc	(revision 3214)
@@ -27,9 +27,11 @@
  */
 
+#include "Host.h"
+
 #include <cassert>
+#include <string>
 
-#include "Host.h"
 #include "core/ConsoleCommand.h"
-#include "packet/Packet.h"
+#include "core/ObjectList.h"
 #include "ChatListener.h"
 
Index: code/trunk/src/network/Host.h
===================================================================
--- code/trunk/src/network/Host.h	(revision 3213)
+++ code/trunk/src/network/Host.h	(revision 3214)
@@ -26,11 +26,9 @@
  *
  */
-#ifndef NETWORKHOST_H
-#define NETWORKHOST_H
 
-#include <string>
+#ifndef _NETWORK_Host_H__
+#define _NETWORK_Host_H__
 
 #include "NetworkPrereqs.h"
-#include "packet/Chat.h"
 
 namespace orxonox {
@@ -86,3 +84,3 @@
 }
 
-#endif
+#endif /* _NETWORK_Host_H__ */
Index: code/trunk/src/network/NetworkFunction.cc
===================================================================
--- code/trunk/src/network/NetworkFunction.cc	(revision 3213)
+++ code/trunk/src/network/NetworkFunction.cc	(revision 3214)
@@ -28,6 +28,5 @@
 
 #include "NetworkFunction.h"
-#include <string>
-#include "synchronisable/Synchronisable.h"
+#include "core/CoreIncludes.h"
 
 namespace orxonox
@@ -42,5 +41,5 @@
   std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
 
-  NetworkFunctionBase::NetworkFunctionBase(std::string name)
+  NetworkFunctionBase::NetworkFunctionBase(const std::string& name)
   {
     RegisterRootObject(NetworkFunctionBase);
@@ -58,5 +57,5 @@
   
   
-  NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, std::string name, const NetworkFunctionPointer& p):
+  NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
     NetworkFunctionBase(name)
   {
@@ -75,5 +74,5 @@
   
   
-  NetworkMemberFunctionBase::NetworkMemberFunctionBase(std::string name, const NetworkFunctionPointer& p):
+  NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p):
     NetworkFunctionBase(name)
   {
Index: code/trunk/src/network/NetworkFunction.h
===================================================================
--- code/trunk/src/network/NetworkFunction.h	(revision 3213)
+++ code/trunk/src/network/NetworkFunction.h	(revision 3214)
@@ -27,20 +27,19 @@
  */
 
-#ifndef NETWORKFUNCTION_H
-#define NETWORKFUNCTION_H
+#ifndef _NetworkFunction_H__
+#define _NetworkFunction_H__
 
 #include "NetworkPrereqs.h"
+
+#include <cassert>
+#include <cstring>
+#include <map>
+#include <string>
+#include <boost/preprocessor/cat.hpp>
+
 #include "core/OrxonoxClass.h"
-
-#include <string>
-#include <map>
-#include <cassert>
-#include <boost/preprocessor/cat.hpp>
-#include "util/MultiType.h"
 #include "core/Functor.h"
+#include "FunctionCallManager.h"
 #include "synchronisable/Synchronisable.h"
-#include "OrxonoxConfig.h"
-#include "FunctionCallManager.h"
-
 
 namespace orxonox
@@ -72,13 +71,13 @@
 class _NetworkExport NetworkFunctionBase: virtual public OrxonoxClass {
   public:
-    NetworkFunctionBase(std::string name);
+    NetworkFunctionBase(const std::string& name);
     ~NetworkFunctionBase();
     
-    inline void         setNetworkID(uint32_t id)       { this->networkID_ = id; }
+    virtual void        setNetworkID(uint32_t id)       { this->networkID_ = id; }
     inline uint32_t     getNetworkID() const            { return this->networkID_; }
-    inline std::string  getName() const                 { return name_; }
+    inline const std::string& getName() const           { return name_; }
     static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
     
-    static inline void setNetworkID(std::string name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
+    static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
     
   protected:
@@ -95,5 +94,5 @@
 class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
   public:
-    NetworkFunctionStatic(FunctorStatic* functor, std::string name, const NetworkFunctionPointer& p);
+    NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p);
     ~NetworkFunctionStatic();
     
@@ -105,4 +104,5 @@
     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]; }
@@ -120,7 +120,8 @@
 class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase {
   public:
-    NetworkMemberFunctionBase(std::string name, const NetworkFunctionPointer& p);
+    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]; }
@@ -143,5 +144,5 @@
 template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
   public:
-    NetworkMemberFunction(FunctorMember<T>* functor, std::string name, const NetworkFunctionPointer& p);
+    NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p);
     ~NetworkMemberFunction();
     
@@ -181,5 +182,5 @@
 };
 
-template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, std::string name, const NetworkFunctionPointer& p):
+template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p):
     NetworkMemberFunctionBase(name, p), functor_(functor)
 {
@@ -199,5 +200,5 @@
 }
 
-template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, std::string name )
+template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
 {
   NetworkFunctionPointer destptr;
@@ -207,5 +208,5 @@
 }
 
-template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, std::string name )
+template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
 {
   NetworkFunctionPointer destptr;
@@ -237,3 +238,3 @@
 }
 
-#endif
+#endif /* _NetworkFunction_H__ */
Index: code/trunk/src/network/NetworkPrecompiledHeaders.h
===================================================================
--- code/trunk/src/network/NetworkPrecompiledHeaders.h	(revision 3213)
+++ code/trunk/src/network/NetworkPrecompiledHeaders.h	(revision 3214)
@@ -35,8 +35,10 @@
 #include "NetworkPrereqs.h"
 
+#include <cassert>
 #include <fstream>
 #include <iostream>
 #include <list>
 #include <map>
+#include <queue>
 #include <set>
 #include <sstream>
@@ -47,4 +49,11 @@
 #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>
@@ -52,18 +61,6 @@
 #undef min
 
-// Too larg PCH file if you include this and only 10% faster
-//#include <boost/thread/recursive_mutex.hpp>
-
-#include "util/CRC32.h"
 #include "util/Debug.h"
-#include "util/Math.h"
-#include "util/mbool.h"
-#include "util/MultiType.h"
-#include "util/String.h"
-
-#include "core/Core.h"
-#include "core/CoreIncludes.h"
-#include "core/Functor.h"
-#include "core/GameMode.h"
+#include "core/Identifier.h"
 
 #endif /* ORXONOX_COMPILER_MSVC */
Index: code/trunk/src/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/network/NetworkPrereqs.h	(revision 3213)
+++ code/trunk/src/network/NetworkPrereqs.h	(revision 3214)
@@ -89,5 +89,5 @@
   class ClientFrameListener;
   class ClientInformation;
-  class ConnectionManager;
+  class Connection;
   class FunctionCallManager;
   class GamestateClient;
@@ -104,4 +104,5 @@
   class PacketBuffer;
   class Server;
+  class ServerConnection;
   class ServerFrameListener;
   class Synchronisable;
@@ -113,4 +114,5 @@
   struct QueueItem;
   struct syncData;
+  class TrafficControl;
   class obj;
   class objInfo;
@@ -127,4 +129,14 @@
     class Packet;
     class Welcome;
+
+    namespace PacketFlag
+    {
+      enum Enum
+      {
+        Reliable   = 1,
+        Unsequence = 2,
+        NoAllocate = 4
+      };
+    }
   }
 }
Index: code/trunk/src/network/PacketBuffer.cc
===================================================================
--- code/trunk/src/network/PacketBuffer.cc	(revision 3213)
+++ code/trunk/src/network/PacketBuffer.cc	(revision 3214)
@@ -33,10 +33,5 @@
 #include "PacketBuffer.h"
 
-#include <enet/enet.h>
-#include <iostream>
-#include <queue>
-#include <string>
-#include <boost/bind.hpp>
-#include <boost/thread/mutex.hpp>
+//#include <iostream>
 #include <boost/thread/recursive_mutex.hpp>
 
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 3213)
+++ code/trunk/src/network/Server.cc	(revision 3214)
@@ -42,25 +42,20 @@
 
 #include <enet/enet.h>
-#include <iostream>
 #include <cassert>
-
-
-#include "ConnectionManager.h"
-#include "ClientConnectionListener.h"
+#include <string>
+
+#include "util/Debug.h"
+#include "core/Clock.h"
+#include "core/ObjectList.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"
-#include "ClientInformation.h"
-#include "util/Sleep.h"
-#include "core/Clock.h"
-#include "core/ConsoleCommand.h"
-#include "core/CoreIncludes.h"
-#include "packet/Chat.h"
-#include "packet/Packet.h"
-#include "packet/Welcome.h"
-#include "packet/DeleteObjects.h"
-#include "util/Convert.h"
-#include "ChatListener.h"
-#include "FunctionCallManager.h"
-#include "packet/FunctionIDs.h"
-
 
 namespace orxonox
@@ -74,11 +69,10 @@
   Server::Server() {
     timeSinceLastUpdate_=0;
-    connection = new ConnectionManager();
     gamestates_ = new GamestateManager();
   }
 
   Server::Server(int port){
+    this->setPort( port );
     timeSinceLastUpdate_=0;
-    connection = new ConnectionManager(port);
     gamestates_ = new GamestateManager();
   }
@@ -90,26 +84,14 @@
   */
   Server::Server(int port, const std::string& bindAddress) {
+    this->setPort( port );
+    this->setBindAddress( bindAddress );
     timeSinceLastUpdate_=0;
-    connection = new ConnectionManager(port, bindAddress);
     gamestates_ = new GamestateManager();
   }
 
   /**
-  * Constructor
-  * @param port Port to listen on
-  * @param bindAddress Address to listen on
-  */
-  Server::Server(int port, const char *bindAddress) {
-    timeSinceLastUpdate_=0;
-    connection = new ConnectionManager(port, bindAddress);
-    gamestates_ = new GamestateManager();
-  }
-
-  /**
   * @brief Destructor
   */
   Server::~Server(){
-    if(connection)
-      delete connection;
     if(gamestates_)
       delete gamestates_;
@@ -120,5 +102,6 @@
   */
   void Server::open() {
-    connection->createListener();
+    COUT(4) << "opening server" << endl;
+    this->openListener();
     return;
   }
@@ -128,14 +111,7 @@
   */
   void Server::close() {
-    ClientInformation *temp = ClientInformation::getBegin();
-    ClientInformation *temp2;
-    // disconnect all connected clients
-    while( temp )
-    {
-      temp2 = temp;
-      temp = temp->next();
-      disconnectClient( temp2 );
-    }
-    connection->quitListener();
+    COUT(4) << "closing server" << endl;
+    this->disconnectClients();
+    this->closeListener();
     return;
   }
@@ -162,17 +138,19 @@
   */
   void Server::update(const Clock& time) {
-    processQueue();
+    Connection::processQueue();
     gamestates_->processGamestates();
     //this steers our network frequency
     timeSinceLastUpdate_+=time.getDeltaTime();
-    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
+    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    {
       timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
       updateGamestate();
       FunctionCallManager::sendCalls();
     }
+    sendPackets(); // flush the enet queue
   }
 
   bool Server::queuePacket(ENetPacket *packet, int clientID){
-    return connection->addPacket(packet, clientID);
+    return ServerConnection::addPacket(packet, clientID);
   }
   
@@ -191,37 +169,4 @@
     assert(ClientInformation::findClient(clientID));
     return ClientInformation::findClient(clientID)->getPacketLoss();
-  }
-  
-  /**
-  * processes all the packets waiting in the queue
-  */
-  void Server::processQueue() {
-    ENetEvent *event;
-    while(!connection->queueEmpty()){
-      //std::cout << "Client " << clientID << " sent: " << std::endl;
-      //clientID here is a reference to grab clientID from ClientInformation
-      event = connection->getEvent();
-      if(!event)
-        continue;
-      assert(event->type != ENET_EVENT_TYPE_NONE);
-      switch( event->type ) {
-      case ENET_EVENT_TYPE_CONNECT:
-        COUT(4) << "processing event_Type_connect" << std::endl;
-        addClient(event);
-        break;
-      case ENET_EVENT_TYPE_DISCONNECT:
-        if(ClientInformation::findClient(&event->peer->address))
-          disconnectClient(event);
-        break;
-      case ENET_EVENT_TYPE_RECEIVE:
-        if(!processPacket(event->packet, event->peer))
-          COUT(3) << "processing incoming packet failed" << std::endl;
-        break;
-      default:
-        break;
-      }
-      delete event;
-      //if statement to catch case that packetbuffer is empty
-    }
   }
 
@@ -318,5 +263,5 @@
 
 
-  bool Server::addClient(ENetEvent *event){
+  void Server::addClient(ENetEvent *event){
     static unsigned int newid=1;
 
@@ -325,11 +270,5 @@
     if(!temp){
       COUT(2) << "Server: could not add client" << std::endl;
-      return false;
-    }
-    /*if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack
-      newid=1;
-    }
-    else
-      newid=temp->prev()->getID()+1;*/
+    }
     temp->setID(newid);
     temp->setPeer(event->peer);
@@ -342,8 +281,8 @@
     }
 
-    newid++;
+    ++newid;
 
     COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
-    return createClient(temp->getID());
+    createClient(temp->getID());
 }
 
@@ -357,5 +296,5 @@
     
     // synchronise class ids
-    connection->syncClassid(temp->getID());
+    syncClassid(temp->getID());
     
     // now synchronise functionIDs
@@ -382,26 +321,7 @@
     return true;
   }
-
-  bool Server::disconnectClient(ENetEvent *event){
-    COUT(4) << "removing client from list" << std::endl;
-    //return removeClient(head_->findClient(&(peer->address))->getID());
-
-    //boost::recursive_mutex::scoped_lock lock(head_->mutex_);
-    ClientInformation *client = ClientInformation::findClient(&event->peer->address);
-    if(!client)
-      return false;
-    else
-      disconnectClient( client );
-    return true;
-  }
-
-  void Server::disconnectClient(int clientID){
-    ClientInformation *client = ClientInformation::findClient(clientID);
-    if(client)
-      disconnectClient(client);
-  }
   
-  void Server::disconnectClient( ClientInformation *client){
-    connection->disconnectClient(client);
+  void Server::disconnectClient( ClientInformation *client ){
+    ServerConnection::disconnectClient( client );
     gamestates_->removeClient(client);
 // inform all the listeners
@@ -439,3 +359,14 @@
   }
 
+  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/trunk/src/network/Server.h
===================================================================
--- code/trunk/src/network/Server.h	(revision 3213)
+++ code/trunk/src/network/Server.h	(revision 3214)
@@ -32,8 +32,7 @@
 #include "NetworkPrereqs.h"
 
-#include <string>
-
+#include "core/CorePrereqs.h"
 #include "Host.h"
-#include "GamestateManager.h"
+#include "ServerConnection.h"
 
 namespace orxonox
@@ -44,10 +43,9 @@
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host{
+  class _NetworkExport Server : public Host, public ServerConnection{
   public:
     Server();
     Server(int port);
     Server(int port, const std::string& bindAddress);
-    Server(int port, const char *bindAddress);
     ~Server();
 
@@ -60,5 +58,4 @@
     double getPacketLoss(unsigned int clientID);
   protected:
-    void processQueue();
     void updateGamestate();
   private:
@@ -67,8 +64,6 @@
     unsigned int playerID(){return 0;}
 
-    bool addClient(ENetEvent *event);
+    void addClient(ENetEvent *event);
     bool createClient(int clientID);
-    bool disconnectClient(ENetEvent *event);
-    void disconnectClient(int clientID);
     void disconnectClient( ClientInformation *client);
     bool processPacket( ENetPacket *packet, ENetPeer *peer );
@@ -78,7 +73,6 @@
     virtual bool broadcast(const std::string& message);
     bool sendChat(const std::string& message, unsigned int clientID);
+    void syncClassid(unsigned int clientID);
 
-    //void processChat( chat *data, int clientId);
-    ConnectionManager *connection;
     GamestateManager *gamestates_;
 
Index: code/trunk/src/network/ServerConnection.cc
===================================================================
--- code/trunk/src/network/ServerConnection.cc	(revision 3214)
+++ code/trunk/src/network/ServerConnection.cc	(revision 3214)
@@ -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){
+      disconnectPeer( &event );
+      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/trunk/src/network/ServerConnection.h
===================================================================
--- code/trunk/src/network/ServerConnection.h	(revision 3214)
+++ code/trunk/src/network/ServerConnection.h	(revision 3214)
@@ -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/trunk/src/network/TrafficControl.cc
===================================================================
--- code/trunk/src/network/TrafficControl.cc	(revision 3213)
+++ code/trunk/src/network/TrafficControl.cc	(revision 3214)
@@ -29,10 +29,10 @@
 #include "TrafficControl.h"
 
-#include "synchronisable/Synchronisable.h"
+#include <cassert>
+#include <boost/bind.hpp>
+
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
-
-#include <cassert>
-#include <boost/bind.hpp>
+#include "synchronisable/Synchronisable.h"
 
 namespace orxonox {
Index: code/trunk/src/network/TrafficControl.h
===================================================================
--- code/trunk/src/network/TrafficControl.h	(revision 3213)
+++ code/trunk/src/network/TrafficControl.h	(revision 3214)
@@ -25,16 +25,13 @@
  *      ...
  *
+
  */
-#ifndef NETWORK_TRAFFICCONTROL_H
-#define NETWORK_TRAFFICCONTROL_H
+#ifndef _TrafficControl_H__
+#define _TrafficControl_H__
 
 #include "NetworkPrereqs.h"
 
-#include <string>
 #include <list>
 #include <map>
-#include <utility>
-#include <algorithm>
-#include "core/OrxonoxClass.h"
 #include "network/ClientConnectionListener.h"
 
@@ -143,4 +140,3 @@
 }
 
-#endif
-
+#endif /* _TrafficControl_H__ */
Index: code/trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.cc	(revision 3213)
+++ code/trunk/src/network/packet/Acknowledgement.cc	(revision 3214)
@@ -27,9 +27,8 @@
  */
 
+#include "Acknowledgement.h"
 
-#include "Acknowledgement.h"
-#include "network/Host.h"
+#include "util/Debug.h"
 #include "network/GamestateHandler.h"
-#include "core/CoreIncludes.h"
 
 namespace orxonox {
Index: code/trunk/src/network/packet/Acknowledgement.h
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.h	(revision 3213)
+++ code/trunk/src/network/packet/Acknowledgement.h	(revision 3214)
@@ -26,13 +26,13 @@
  *
  */
-#ifndef NETWORKACKNOLEDGEMENT_H
-#define NETWORKACKNOLEDGEMENT_H
 
-#include "../NetworkPrereqs.h"
+#ifndef _Acknowledgement_H__
+#define _Acknowledgement_H__
+
+#include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
+namespace orxonox {
 const unsigned int ACKID_NACK = 0;
-
-namespace orxonox {
 namespace packet {
 /**
@@ -56,3 +56,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _Acknowledgement_H__ */
Index: code/trunk/src/network/packet/Chat.cc
===================================================================
--- code/trunk/src/network/packet/Chat.cc	(revision 3213)
+++ code/trunk/src/network/packet/Chat.cc	(revision 3214)
@@ -29,6 +29,6 @@
 #include "Chat.h"
 
-#include <enet/enet.h>
-#include <cassert>
+#include <cstring>
+#include <string>
 #include "network/Host.h"
 
@@ -36,5 +36,5 @@
 namespace packet {
   
-#define   PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
+#define   PACKET_FLAGS_CHAT PacketFlag::Reliable
 #define   _PACKETID         0
 const int _PLAYERID     =   _PACKETID + sizeof(ENUM::Type);
@@ -42,5 +42,5 @@
 #define   _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
 
-Chat::Chat( std::string message, unsigned int playerID )
+Chat::Chat( const std::string& message, unsigned int playerID )
  : Packet()
 {
Index: code/trunk/src/network/packet/Chat.h
===================================================================
--- code/trunk/src/network/packet/Chat.h	(revision 3213)
+++ code/trunk/src/network/packet/Chat.h	(revision 3214)
@@ -1,11 +1,34 @@
+/*
+ *   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 NETWORKCHAT_H
-#define NETWORKCHAT_H
+#ifndef _NETWORK_Chat_H__
+#define _NETWORK_Chat_H__
 
-#include "../NetworkPrereqs.h"
-
-#include <string>
-#include <cstring>
-
+#include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
@@ -18,5 +41,5 @@
 {
 public:
-  Chat( std::string message, unsigned int playerID );
+  Chat( const std::string& message, unsigned int playerID );
   Chat( uint8_t* data, unsigned int clientID );
   ~Chat();
@@ -35,3 +58,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _NETWORK_Chat_H__ */
Index: code/trunk/src/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/network/packet/ClassID.cc	(revision 3213)
+++ code/trunk/src/network/packet/ClassID.cc	(revision 3214)
@@ -27,15 +27,14 @@
  */
 
+#include "ClassID.h"
 
-
-#include "ClassID.h"
-#include <enet/enet.h>
-#include "core/CoreIncludes.h"
-#include "core/Factory.h"
+#include <cassert>
+#include <cstdlib>
 #include <cstring>
-#include <string>
-#include <cassert>
 #include <map>
 #include <queue>
+#include <string>
+
+#include "core/CoreIncludes.h"
 
 namespace orxonox {
@@ -43,5 +42,5 @@
 
 
-#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_CLASSID  PacketFlag::Reliable
 #define _PACKETID             0
 
Index: code/trunk/src/network/packet/ClassID.h
===================================================================
--- code/trunk/src/network/packet/ClassID.h	(revision 3213)
+++ code/trunk/src/network/packet/ClassID.h	(revision 3214)
@@ -26,11 +26,9 @@
  *
  */
-#ifndef NETWORKCLASSID_H
-#define NETWORKCLASSID_H
 
-#include "../NetworkPrereqs.h"
+#ifndef _NETWORK_ClassID_H__
+#define _NETWORK_ClassID_H__
 
-#include <string>
-
+#include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
@@ -58,3 +56,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _NETWORK_ClassID_H__ */
Index: code/trunk/src/network/packet/DeleteObjects.cc
===================================================================
--- code/trunk/src/network/packet/DeleteObjects.cc	(revision 3213)
+++ code/trunk/src/network/packet/DeleteObjects.cc	(revision 3214)
@@ -29,13 +29,13 @@
 
 #include "DeleteObjects.h"
-#include <enet/enet.h>
+
+#include <cassert>
+#include "util/Debug.h"
 #include "network/synchronisable/Synchronisable.h"
-#include "core/CoreIncludes.h"
-#include <cassert>
 
 namespace orxonox {
 namespace packet {
 
-#define PACKET_FLAG_DELETE  ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAG_DELETE  PacketFlag::Reliable
 #define _PACKETID           0
 #define _QUANTITY           _PACKETID + sizeof(ENUM::Type)
@@ -90,4 +90,5 @@
     Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
   }
+  delete this;
   return true;
 }
Index: code/trunk/src/network/packet/DeleteObjects.h
===================================================================
--- code/trunk/src/network/packet/DeleteObjects.h	(revision 3213)
+++ code/trunk/src/network/packet/DeleteObjects.h	(revision 3214)
@@ -26,11 +26,9 @@
  *
  */
-#ifndef NETWORKPACKETDELETEOBJECTS_H
-#define NETWORKPACKETDELETEOBJECTS_H
+#ifndef _DeleteObjects_H__
+#define _DeleteObjects_H__
 
-#include "../NetworkPrereqs.h"
-
+#include "network/NetworkPrereqs.h"
 #include "Packet.h"
-
 
 namespace orxonox {
@@ -57,3 +55,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _DeleteObjects_H__ */
Index: code/trunk/src/network/packet/FunctionCalls.cc
===================================================================
--- code/trunk/src/network/packet/FunctionCalls.cc	(revision 3213)
+++ code/trunk/src/network/packet/FunctionCalls.cc	(revision 3214)
@@ -29,15 +29,13 @@
 #include "FunctionCalls.h"
 
-#include <enet/enet.h>
 #include <cassert>
 #include <cstring>
-#include "network/Host.h"
+#include "util/MultiType.h"
 #include "network/NetworkFunction.h"
-#include "util/MultiType.h"
 
 namespace orxonox {
 namespace packet {
   
-#define   PACKET_FLAGS_FUNCTIONCALLS ENET_PACKET_FLAG_RELIABLE
+#define   PACKET_FLAGS_FUNCTIONCALLS PacketFlag::Reliable
 #define   _PACKETID         0
 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
Index: code/trunk/src/network/packet/FunctionCalls.h
===================================================================
--- code/trunk/src/network/packet/FunctionCalls.h	(revision 3213)
+++ code/trunk/src/network/packet/FunctionCalls.h	(revision 3214)
@@ -1,17 +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:
+ *      Oliver Scheuss <scheusso [at] ee.ethz.ch>
+ *   Co-authors:
+ *      ...
+ *
+ */
 
-#ifndef NETWORKFUNCTIONCALLS_H
-#define NETWORKFUNCTIONCALLS_H
+#ifndef _FunctionCalls_H__
+#define _FunctionCalls_H__
 
-#include "../NetworkPrereqs.h"
+#include "network/NetworkPrereqs.h"
 
-#include <string>
-#include <cstring>
-
+#include <cassert>
+#include "util/UtilPrereqs.h"
 #include "Packet.h"
-#include <cassert>
 
 namespace orxonox {
-
-class MultiType;
 
 namespace packet {
@@ -44,3 +67,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _FunctionCalls_H__ */
Index: code/trunk/src/network/packet/FunctionIDs.cc
===================================================================
--- code/trunk/src/network/packet/FunctionIDs.cc	(revision 3213)
+++ code/trunk/src/network/packet/FunctionIDs.cc	(revision 3214)
@@ -27,13 +27,14 @@
  */
 
+#include "FunctionIDs.h"
 
+#include <cassert>
+#include <cstring>
+#include <queue>
+#include <string>
 
-#include "FunctionIDs.h"
+#include "util/Debug.h"
+#include "core/ObjectList.h"
 #include "network/NetworkFunction.h"
-#include <enet/enet.h>
-#include "core/CoreIncludes.h"
-#include <string>
-#include <cassert>
-#include <queue>
 
 namespace orxonox {
@@ -41,5 +42,5 @@
 
 
-#define PACKET_FLAGS_FUNCTIONIDS  ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_FUNCTIONIDS  PacketFlag::Reliable
 #define _PACKETID                 0
 
Index: code/trunk/src/network/packet/FunctionIDs.h
===================================================================
--- code/trunk/src/network/packet/FunctionIDs.h	(revision 3213)
+++ code/trunk/src/network/packet/FunctionIDs.h	(revision 3214)
@@ -26,11 +26,9 @@
  *
  */
-#ifndef NETWORKFUNCTIONIDS_H
-#define NETWORKFUNCTIONIDS_H
 
-#include "../NetworkPrereqs.h"
+#ifndef _FunctionIDs_H__
+#define _FunctionIDs_H__
 
-#include <string>
-
+#include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
@@ -58,3 +56,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _FunctionIDs_H__ */
Index: code/trunk/src/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/network/packet/Gamestate.cc	(revision 3213)
+++ code/trunk/src/network/packet/Gamestate.cc	(revision 3214)
@@ -28,15 +28,12 @@
 
 #include "Gamestate.h"
-#include <enet/enet.h>
+
 #include <zlib.h>
-#include <cassert>
-#include "../GamestateHandler.h"
-#include "../synchronisable/Synchronisable.h"
-#include "../TrafficControl.h"
+
+#include "util/Debug.h"
 #include "core/GameMode.h"
-#include "core/CoreIncludes.h"
-
-
-
+#include "core/ObjectList.h"
+#include "network/synchronisable/Synchronisable.h"
+#include "network/GamestateHandler.h"
 
 namespace orxonox {
@@ -46,5 +43,5 @@
 #define GAMESTATE_START(data) (data + GamestateHeader::getSize())
 
-#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
 
 
Index: code/trunk/src/network/packet/Gamestate.h
===================================================================
--- code/trunk/src/network/packet/Gamestate.h	(revision 3213)
+++ code/trunk/src/network/packet/Gamestate.h	(revision 3214)
@@ -28,18 +28,16 @@
 
 
-#ifndef NETWORK_PACKETGAMESTATE_H
-#define NETWORK_PACKETGAMESTATE_H
+#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"
-#include "network/TrafficControl.h"
-#include <string.h>
-#include <map>
-#include <vector>
-#include <cassert>
-#ifndef NDEBUG
-#include "util/CRC32.h"
-#endif
 
 namespace orxonox {
@@ -138,3 +136,3 @@
 }
 
-#endif
+#endif /* _Gamestate_H__ */
Index: code/trunk/src/network/packet/Packet.cc
===================================================================
--- code/trunk/src/network/packet/Packet.cc	(revision 3213)
+++ code/trunk/src/network/packet/Packet.cc	(revision 3214)
@@ -31,15 +31,13 @@
 
 #include <cassert>
+#include <cstring>
 #include <enet/enet.h>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-
-#include "network/ConnectionManager.h"
-#include "network/ClientInformation.h"
-
+#include <boost/static_assert.hpp>
+
+#include "util/Debug.h"
 #include "Acknowledgement.h"
-#include "DeleteObjects.h"
 #include "Chat.h"
 #include "ClassID.h"
+#include "DeleteObjects.h"
 #include "FunctionCalls.h"
 #include "FunctionIDs.h"
@@ -47,5 +45,5 @@
 #include "Welcome.h"
 #include "network/Host.h"
-#include "core/CoreIncludes.h"
+#include "network/ClientInformation.h"
 
 namespace orxonox{
@@ -53,10 +51,13 @@
 namespace packet{
 
-#define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE
+// 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_;
-//! Static mutex for any packetMap_ access
-static boost::recursive_mutex packetMap_mutex_g;
 
 Packet::Packet(){
@@ -108,5 +109,5 @@
   }
   else if (this->data_) {
-    // This destructor was probably called as a consequence to ENet executing our callback.
+    // 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.
@@ -142,5 +143,4 @@
       // Assures we don't create a packet and destroy it right after in another thread
       // without having a reference in the packetMap_
-      boost::recursive_mutex::scoped_lock lock(packetMap_mutex_g);
       packetMap_[(size_t)(void*)enetPacket_] = this;
     }
@@ -218,4 +218,5 @@
   // Data was created by ENet
   p->bDataENetAllocated_ = true;
+  p->enetPacket_ = packet;
 
   return p;
@@ -228,5 +229,4 @@
 */
 void Packet::deletePacket(ENetPacket *enetPacket){
-  boost::recursive_mutex::scoped_lock lock(packetMap_mutex_g);
   // 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((size_t)enetPacket);
@@ -236,5 +236,5 @@
   delete it->second;
   packetMap_.erase(it);
-  COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl;
+  COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
 }
 
Index: code/trunk/src/network/packet/Packet.h
===================================================================
--- code/trunk/src/network/packet/Packet.h	(revision 3213)
+++ code/trunk/src/network/packet/Packet.h	(revision 3214)
@@ -26,9 +26,8 @@
  *
  */
-#ifndef NETWORKPACKET_H
-#define NETWORKPACKET_H
+#ifndef _NETWORK_Packet_H__
+#define _NETWORK_Packet_H__
 
 #include "network/NetworkPrereqs.h"
-
 #include <map>
 
@@ -102,3 +101,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _NETWORK_Packet_H__ */
Index: code/trunk/src/network/packet/Welcome.cc
===================================================================
--- code/trunk/src/network/packet/Welcome.cc	(revision 3213)
+++ code/trunk/src/network/packet/Welcome.cc	(revision 3214)
@@ -29,16 +29,15 @@
  */
 
+#include "Welcome.h"
 
-#include "Welcome.h"
-#include <enet/enet.h>
 #include <cassert>
+#include "util/Debug.h"
 #include "network/Host.h"
 #include "network/synchronisable/Synchronisable.h"
-#include "core/CoreIncludes.h"
 
 namespace orxonox {
 namespace packet {
 
-#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_CLASSID  PacketFlag::Reliable
 #define _PACKETID             0
 #define _CLIENTID             _PACKETID + sizeof(ENUM::Type)
Index: code/trunk/src/network/packet/Welcome.h
===================================================================
--- code/trunk/src/network/packet/Welcome.h	(revision 3213)
+++ code/trunk/src/network/packet/Welcome.h	(revision 3214)
@@ -26,9 +26,8 @@
  *
  */
-#ifndef NETWORKWELCOME_H
-#define NETWORKWELCOME_H
+#ifndef _NETWORK_Welcome_H__
+#define _NETWORK_Welcome_H__
 
-#include "../NetworkPrereqs.h"
-
+#include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
@@ -56,3 +55,3 @@
 } //namespace orxonox
 
-#endif
+#endif /* _NETWORK_Welcome_H__ */
Index: code/trunk/src/network/synchronisable/NetworkCallback.h
===================================================================
--- code/trunk/src/network/synchronisable/NetworkCallback.h	(revision 3213)
+++ code/trunk/src/network/synchronisable/NetworkCallback.h	(revision 3214)
@@ -28,6 +28,6 @@
 
 
-#ifndef _NETWORK_CALLBACK__
-#define _NETWORK_CALLBACK__
+#ifndef _NetworkCallback_H__
+#define _NetworkCallback_H__
 
 #include "network/NetworkPrereqs.h"
@@ -61,3 +61,3 @@
 
 
-#endif
+#endif /* _NetworkCallback_H__ */
Index: code/trunk/src/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- code/trunk/src/network/synchronisable/NetworkCallbackManager.cc	(revision 3213)
+++ code/trunk/src/network/synchronisable/NetworkCallbackManager.cc	(revision 3214)
@@ -27,5 +27,4 @@
  */
  
-
 #include "NetworkCallbackManager.h"
 #include "NetworkCallback.h"
Index: code/trunk/src/network/synchronisable/NetworkCallbackManager.h
===================================================================
--- code/trunk/src/network/synchronisable/NetworkCallbackManager.h	(revision 3213)
+++ code/trunk/src/network/synchronisable/NetworkCallbackManager.h	(revision 3214)
@@ -28,8 +28,9 @@
 
 
-#ifndef _NETWORK_CALLBACKMANAGER__
-#define _NETWORK_CALLBACKMANAGER__
+#ifndef _NetworkCallbackManager_H__
+#define _NetworkCallbackManager_H__
 
 #include "network/NetworkPrereqs.h"
+
 #include <set>
 #include <queue>
@@ -52,3 +53,3 @@
 
 
-#endif
+#endif /* _NetworkCallbackManager_H__ */
Index: code/trunk/src/network/synchronisable/Synchronisable.cc
===================================================================
--- code/trunk/src/network/synchronisable/Synchronisable.cc	(revision 3213)
+++ code/trunk/src/network/synchronisable/Synchronisable.cc	(revision 3214)
@@ -31,14 +31,9 @@
 #include "Synchronisable.h"
 
-#include <cstring>
-#include <string>
-#include <iostream>
-#include <cassert>
-
+#include <cstdlib>
 #include "core/CoreIncludes.h"
 #include "core/BaseObject.h"
-// #include "core/Identifier.h"
-
 #include "network/Host.h"
+
 namespace orxonox
 {
Index: code/trunk/src/network/synchronisable/Synchronisable.h
===================================================================
--- code/trunk/src/network/synchronisable/Synchronisable.h	(revision 3213)
+++ code/trunk/src/network/synchronisable/Synchronisable.h	(revision 3214)
@@ -32,15 +32,14 @@
 #include "network/NetworkPrereqs.h"
 
-#include <list>
+#include <cassert>
+#include <cstring>
 #include <vector>
 #include <map>
 #include <queue>
-#include <cassert>
-#include <string>
-#include "util/Math.h"
+
 #include "util/mbool.h"
 #include "core/OrxonoxClass.h"
+#include "SynchronisableVariable.h"
 #include "NetworkCallback.h"
-#include "SynchronisableVariable.h"
 
 /*#define REGISTERDATA(varname, ...) \
Index: code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc	(revision 3213)
+++ code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc	(revision 3214)
@@ -28,6 +28,8 @@
  */
 
-#include "network/synchronisable/Synchronisable.h"
 #include <string>
+#include "util/Math.h"
+#include "Synchronisable.h"
+#include "SynchronisableVariable.h"
 
 // ================ template spezialisation
Index: code/trunk/src/network/synchronisable/SynchronisableVariable.cc
===================================================================
--- code/trunk/src/network/synchronisable/SynchronisableVariable.cc	(revision 3213)
+++ code/trunk/src/network/synchronisable/SynchronisableVariable.cc	(revision 3214)
@@ -29,5 +29,4 @@
 #include "SynchronisableVariable.h"
 
-
 namespace orxonox{
 
Index: code/trunk/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- code/trunk/src/network/synchronisable/SynchronisableVariable.h	(revision 3213)
+++ code/trunk/src/network/synchronisable/SynchronisableVariable.h	(revision 3214)
@@ -28,16 +28,13 @@
 
 
-#ifndef _NETWORK_SYNCHRONISABLEVARIABLE__
-#define _NETWORK_SYNCHRONISABLEVARIABLE__
+#ifndef _SynchronisableVariable_H__
+#define _SynchronisableVariable_H__
 
 #include "network/NetworkPrereqs.h"
 
-#include <string>
 #include <cassert>
+#include <cstring>
 #include "util/Serialise.h"
-#include "core/Core.h"
-#include "core/CoreIncludes.h"
 #include "core/GameMode.h"
-#include "network/synchronisable/NetworkCallback.h"
 #include "network/synchronisable/NetworkCallbackManager.h"
 
@@ -253,3 +250,3 @@
 
 
-#endif
+#endif /* _SynchronisableVariable_H__ */
Index: code/trunk/src/orxonox/OrxonoxPrecompiledHeaders.h
===================================================================
--- code/trunk/src/orxonox/OrxonoxPrecompiledHeaders.h	(revision 3213)
+++ code/trunk/src/orxonox/OrxonoxPrecompiledHeaders.h	(revision 3214)
@@ -35,4 +35,5 @@
 #include "OrxonoxPrereqs.h"
 
+#include <cassert>
 #include <deque>
 #include <fstream>
@@ -84,6 +85,4 @@
 #include "util/Math.h"
 #include "util/OgreForwardRefs.h"
-#include "util/OrxAssert.h"
-#include "util/String.h"
 #include "util/SubString.h"
 
Index: code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc	(revision 3213)
+++ code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc	(revision 3214)
@@ -59,6 +59,4 @@
         PawnManager::touch();
         this->bAlive_ = true;
-        this->fire_ = 0x0;
-        this->firehack_ = 0x0;
         this->bReload_ = false;
 
@@ -122,5 +120,4 @@
         registerVariable(this->health_,        variableDirection::toclient);
         registerVariable(this->initialHealth_, variableDirection::toclient);
-        registerVariable(this->fire_,          variableDirection::toserver);
         registerVariable(this->bReload_,       variableDirection::toserver);
     }
@@ -130,16 +127,4 @@
         SUPER(Pawn, tick, dt);
 
-//        if (this->weaponSystem_ && GameMode::isMaster())
-//        {
-//            for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
-//                if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
-//                    this->weaponSystem_->fire(firemode);
-//
-//            if (this->bReload_)
-//                this->weaponSystem_->reload();
-//        }
-//
-//        this->fire_ = this->firehack_;
-//        this->firehack_ = 0x0;
         this->bReload_ = false;
 
Index: code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h	(revision 3213)
+++ code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h	(revision 3214)
@@ -137,6 +137,4 @@
 
             WeaponSystem* weaponSystem_;
-            unsigned int fire_;
-            unsigned int firehack_;
             bool bReload_;
 
Index: code/trunk/src/util/Clipboard.cc
===================================================================
--- code/trunk/src/util/Clipboard.cc	(revision 3213)
+++ code/trunk/src/util/Clipboard.cc	(revision 3214)
@@ -42,5 +42,10 @@
 /////////////
 
+#ifndef WIN32_LEAN_AND_MEAN
+#  define WIN32_LEAN_AND_MEAN
+#endif
 #include <windows.h>
+#undef min
+#undef max
 #include "Debug.h"
 
Index: code/trunk/src/util/Math.h
===================================================================
--- code/trunk/src/util/Math.h	(revision 3213)
+++ code/trunk/src/util/Math.h	(revision 3214)
@@ -47,8 +47,13 @@
 #include <OgreColourValue.h>
 
-// Certain headers might define min and max macros
-#if defined(max) || defined(min) || defined(sgn) || defined(clamp) || defined(square) || defined(mod)
-#  error An inline math function was overridden by a macro
-#endif
+// Certain headers might define unwanted macros...
+#undef max
+#undef min
+#undef sgn
+#undef clamp
+#undef sqrt
+#undef square
+#undef mod
+#undef rnd
 
 namespace orxonox
Index: code/trunk/src/util/Sleep.cc
===================================================================
--- code/trunk/src/util/Sleep.cc	(revision 3213)
+++ code/trunk/src/util/Sleep.cc	(revision 3214)
@@ -37,5 +37,10 @@
 
 #ifdef ORXONOX_PLATFORM_WINDOWS
+#ifndef WIN32_LEAN_AND_MEAN
+#  define WIN32_LEAN_AND_MEAN
+#endif
 #include <windows.h>
+#undef min
+#undef max
 
 namespace orxonox
