Index: code/branches/netp5/src/network/CMakeLists.txt
===================================================================
--- code/branches/netp5/src/network/CMakeLists.txt	(revision 3200)
+++ code/branches/netp5/src/network/CMakeLists.txt	(revision 3201)
@@ -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/branches/netp5/src/network/Connection.cc
===================================================================
--- code/branches/netp5/src/network/Connection.cc	(revision 3201)
+++ code/branches/netp5/src/network/Connection.cc	(revision 3201)
@@ -0,0 +1,94 @@
+/*
+ *   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 <iostream>
+#include <cassert>
+
+#include "util/Debug.h"
+#include "util/Math.h"
+#include "util/Sleep.h"
+#include "ClientInformation.h"
+#include "synchronisable/Synchronisable.h"
+#include "packet/ClassID.h"
+
+namespace orxonox
+{
+  Connection *Connection::instance_=0;
+
+  Connection::Connection():
+    host_(0)
+  {
+    assert(instance_==0);
+    Connection::instance_=this;
+  }
+
+  Connection::~Connection(){
+    Connection::instance_=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_);
+
+    if( 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:
+          disconnectClient( &event );
+          break;
+        case ENET_EVENT_TYPE_RECEIVE:
+          processPacket( &event );
+          break;
+        case ENET_EVENT_TYPE_NONE:
+          break;
+      }
+    }
+  }
+
+}
Index: code/branches/netp5/src/network/Connection.h
===================================================================
--- code/branches/netp5/src/network/Connection.h	(revision 3201)
+++ code/branches/netp5/src/network/Connection.h	(revision 3201)
@@ -0,0 +1,94 @@
+/*
+ *   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"
+
+#include <string>
+#include <map>
+#include <enet/enet.h>
+
+#include "packet/Packet.h"
+
+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 Connection{
+  public:
+    ~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){ return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT ); }
+    void disconnectPeer(ENetPeer *peer){ enet_peer_disconnect(peer, 0); }
+    
+    void processQueue();
+    virtual void addClient(ENetEvent* event)=0;
+    virtual void disconnectClient(ENetEvent* event)=0;
+    virtual bool processPacket(ENetEvent* event){ packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer); return p->process(); }
+    
+    ENetHost *host_;
+  private:
+    ENetAddress *bindAddress_;
+
+    static Connection *instance_;
+
+  };
+
+}
+
+#endif /* _Connection_H__ */
Index: code/branches/netp5/src/network/ConnectionManager.cc
===================================================================
--- code/branches/netp5/src/network/ConnectionManager.cc	(revision 3200)
+++ 	(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/branches/netp5/src/network/ConnectionManager.h
===================================================================
--- code/branches/netp5/src/network/ConnectionManager.h	(revision 3200)
+++ 	(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/branches/netp5/src/network/NetworkPrereqs.h
===================================================================
--- code/branches/netp5/src/network/NetworkPrereqs.h	(revision 3200)
+++ code/branches/netp5/src/network/NetworkPrereqs.h	(revision 3201)
@@ -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;
Index: code/branches/netp5/src/network/Server.cc
===================================================================
--- code/branches/netp5/src/network/Server.cc	(revision 3200)
+++ code/branches/netp5/src/network/Server.cc	(revision 3201)
@@ -46,5 +46,5 @@
 
 
-#include "ConnectionManager.h"
+// #include "ConnectionManager.h"
 #include "ClientConnectionListener.h"
 #include "GamestateManager.h"
@@ -58,4 +58,5 @@
 #include "packet/Welcome.h"
 #include "packet/DeleteObjects.h"
+#include "packet/ClassID.h"
 #include "util/Convert.h"
 #include "ChatListener.h"
@@ -74,11 +75,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 +90,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 +108,6 @@
   */
   void Server::open() {
-    connection->createListener();
+    COUT(4) << "opening server" << endl;
+    this->openListener();
     return;
   }
@@ -128,14 +117,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,5 +144,5 @@
   */
   void Server::update(const Clock& time) {
-    processQueue();
+    ServerConnection::processQueue();
     gamestates_->processGamestates();
     //this steers our network frequency
@@ -174,5 +156,5 @@
 
   bool Server::queuePacket(ENetPacket *packet, int clientID){
-    return connection->addPacket(packet, clientID);
+    return ServerConnection::addPacket(packet, clientID);
   }
   
@@ -191,37 +173,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 +267,5 @@
 
 
-  bool Server::addClient(ENetEvent *event){
+  void Server::addClient(ENetEvent *event){
     static unsigned int newid=1;
 
@@ -325,11 +274,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 +285,8 @@
     }
 
-    newid++;
+    ++newid;
 
     COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
-    return createClient(temp->getID());
+    createClient(temp->getID());
 }
 
@@ -357,5 +300,5 @@
     
     // synchronise class ids
-    connection->syncClassid(temp->getID());
+    syncClassid(temp->getID());
     
     // now synchronise functionIDs
@@ -382,26 +325,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 +363,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/branches/netp5/src/network/Server.h
===================================================================
--- code/branches/netp5/src/network/Server.h	(revision 3200)
+++ code/branches/netp5/src/network/Server.h	(revision 3201)
@@ -35,4 +35,5 @@
 
 #include "Host.h"
+#include "ServerConnection.h"
 #include "GamestateManager.h"
 
@@ -44,10 +45,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 +60,4 @@
     double getPacketLoss(unsigned int clientID);
   protected:
-    void processQueue();
     void updateGamestate();
   private:
@@ -67,8 +66,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 +75,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/branches/netp5/src/network/ServerConnection.cc
===================================================================
--- code/branches/netp5/src/network/ServerConnection.cc	(revision 3201)
+++ code/branches/netp5/src/network/ServerConnection.cc	(revision 3201)
@@ -0,0 +1,156 @@
+/*
+ *   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 "ClientInformation.h"
+
+#include "core/CoreIncludes.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_;
+  }
+
+  bool ServerConnection::openListener() {
+    enet_initialize();
+    atexit(enet_deinitialize);
+    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0);
+    if ( this->host_ == NULL )
+      return false;
+  }
+
+  bool ServerConnection::closeListener() {
+    this->bListening_=false;
+    disconnectClients();
+    enet_host_destroy(this->host_);
+  }
+
+  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)
+  {
+    disconnectPeer( client->getPeer() );
+    delete client;
+  }
+  
+  void ServerConnection::disconnectClient( 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( temp->getPeer() );
+      temp = temp->next();
+    }
+    temp = ClientInformation::getBegin();
+    while( temp!=0 ){
+      if( service( &event ) )
+      {
+        switch (event.type)
+        {
+        case ENET_EVENT_TYPE_NONE: break;
+        case ENET_EVENT_TYPE_CONNECT: break;
+        case ENET_EVENT_TYPE_RECEIVE:
+          enet_packet_destroy(event.packet);
+          break;
+        case ENET_EVENT_TYPE_DISCONNECT:
+          if(ClientInformation::findClient(&(event.peer->address)))
+            delete ClientInformation::findClient(&(event.peer->address));
+          temp = ClientInformation::getBegin();
+          break;
+        }
+      }
+    }
+    return;
+  }
+
+
+  int ServerConnection::getClientID(ENetPeer* peer) {
+    return getClientID(&(peer->address));
+  }
+
+  int ServerConnection::getClientID(ENetAddress* address) {
+    return ClientInformation::findClient(address)->getID();
+  }
+
+  ENetPeer *ServerConnection::getClientPeer(int clientID) {
+    return ClientInformation::findClient(clientID)->getPeer();
+  }
+
+
+}
Index: code/branches/netp5/src/network/ServerConnection.h
===================================================================
--- code/branches/netp5/src/network/ServerConnection.h	(revision 3201)
+++ code/branches/netp5/src/network/ServerConnection.h	(revision 3201)
@@ -0,0 +1,81 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   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 ){ enet_address_set_host (this->bindAddress_, bindAddress.c_str()); }
+    void setPort( unsigned int port ){ this->bindAddress_->port = port; }
+    
+    bool openListener();
+    bool closeListener();
+    static bool addPacket(ENetPacket *packet, unsigned int ID);
+    static bool addPacketAll(ENetPacket *packet);
+    virtual void disconnectClient(ClientInformation *client);
+    void disconnectClient( 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__ */
