Index: /code/branches/network/src/network/Client.cc
===================================================================
--- /code/branches/network/src/network/Client.cc	(revision 1408)
+++ /code/branches/network/src/network/Client.cc	(revision 1409)
@@ -120,7 +120,7 @@
     isConnected=client_connection.createConnection();
     if(isConnected){
-      COUT(3) << "sending connectrequest" << std::endl;
-      if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
-        COUT(1) << "could not send connection request !!!!!!!!!" << std::endl;
+//       COUT(3) << "sending connectrequest" << std::endl;
+//       if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
+//         COUT(1) << "could not send connection request !!!!!!!!!" << std::endl;
     }else
       COUT(1) << "could not create connection laber" << std::endl;
@@ -239,10 +239,10 @@
       }
     }
-    ENetPacket *packet;
+    ENetEvent *event;
     // stop if the packet queue is empty
     while(!(client_connection.queueEmpty())){
-      packet = client_connection.getPacket();
-      COUT(5) << "tick packet size " << packet->dataLength << std::endl;
-      elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
+      event = client_connection.getEvent();
+      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
+      elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
     }
     if(!client_connection.sendPackets())
Index: /code/branches/network/src/network/ClientConnection.cc
===================================================================
--- /code/branches/network/src/network/ClientConnection.cc	(revision 1408)
+++ /code/branches/network/src/network/ClientConnection.cc	(revision 1409)
@@ -75,5 +75,5 @@
 
 
-  ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
+  /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
     if(!buffer.isEmpty()) {
       //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl;
@@ -88,4 +88,11 @@
     ENetAddress address; //sems that address is not needed
     return getPacket(address);
+  }*/
+  
+  ENetEvent *ClientConnection::getEvent(){
+    if(!buffer.isEmpty())
+      return buffer.pop();
+    else
+      return NULL;
   }
 
@@ -144,5 +151,5 @@
     enet_initialize();
     atexit(enet_deinitialize);
-    ENetEvent event;
+    ENetEvent *event;
     client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
     if(client==NULL) {
@@ -159,11 +166,12 @@
     //main loop
     while(!quit){
+      event = new ENetEvent;
       //std::cout << "connection loop" << std::endl;
-      if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)<0){
+      if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){
         // we should never reach this point
         quit=true;
         // add some error handling here ========================
       }
-      switch(event.type){
+      switch(event->type){
         // log handling ================
       case ENET_EVENT_TYPE_CONNECT:
@@ -171,5 +179,5 @@
       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;
+        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;
         break;
Index: /code/branches/network/src/network/ClientConnection.h
===================================================================
--- /code/branches/network/src/network/ClientConnection.h	(revision 1408)
+++ /code/branches/network/src/network/ClientConnection.h	(revision 1409)
@@ -63,6 +63,7 @@
     ClientConnection(int port, std::string address);
     ClientConnection(int port, const char* address);
-    ENetPacket *getPacket(ENetAddress &address); // thread1
-    ENetPacket *getPacket(); // thread1
+    //ENetPacket *getPacket(ENetAddress &address); // thread1
+    //ENetPacket *getPacket(); // thread1
+    ENetEvent *getEvent();
     // check wheter the packet queue is empty
     bool queueEmpty();
Index: /code/branches/network/src/network/ConnectionManager.cc
===================================================================
--- /code/branches/network/src/network/ConnectionManager.cc	(revision 1408)
+++ /code/branches/network/src/network/ConnectionManager.cc	(revision 1409)
@@ -44,6 +44,6 @@
 #include "core/CoreIncludes.h"
 #include "core/BaseObject.h"
+#include "objects/SpaceShip.h"
 #include "util/Math.h"
-#include "objects/SpaceShip.h"
 #include "ClientInformation.h"
 #include "ConnectionManager.h"
@@ -94,15 +94,15 @@
   }
 
-  ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
+  /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
     if(!buffer.isEmpty())
       return buffer.pop(address);
     else
       return NULL;
-  }
+  }*/
 /**
 This function only pops the first element in PacketBuffer (first in first out)
 used by processQueue in Server.cc
 */
-  ENetPacket *ConnectionManager::getPacket(int &clientID) {
+  /*ENetPacket *ConnectionManager::getPacket(int &clientID) {
     ENetAddress address;
     ENetPacket *packet=getPacket(address);
@@ -112,4 +112,11 @@
     clientID=temp->getID();
     return packet;
+  }*/
+  
+  ENetEvent *ConnectionManager::getEvent(){
+    if(!buffer.isEmpty())
+      return buffer.pop();
+    else
+      return NULL;
   }
 
@@ -176,7 +183,7 @@
   void ConnectionManager::receiverThread() {
     // what about some error-handling here ?
+    ENetEvent *event;
     enet_initialize();
     atexit(enet_deinitialize);
-    ENetEvent *event = new ENetEvent;
     server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
     if(server==NULL){
@@ -187,4 +194,5 @@
 
     while(!quit){
+      event = new ENetEvent;
       if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
         // we should never reach this point
@@ -195,21 +203,24 @@
         // log handling ================
         case ENET_EVENT_TYPE_CONNECT:
-          addClient(event);
+          COUT(3) << "adding event_type_connect to queue" << std::endl;
+        case ENET_EVENT_TYPE_DISCONNECT:
+          //addClient(event);
           //this is a workaround to ensure thread safety
-          COUT(5) << "Con.Man: connection event has occured" << std::endl;
-          break;
+          //COUT(5) << "Con.Man: connection event has occured" << std::endl;
+          //break;
         case ENET_EVENT_TYPE_RECEIVE:
           //std::cout << "received data" << std::endl;
           COUT(5) << "Con.Man: receive event has occured" << std::endl;
           // only add, if client has connected yet and not been disconnected
-          if(head_->findClient(&event->peer->address))
+          //if(head_->findClient(&event->peer->address))
             processData(event);
-          else
-            COUT(3) << "received a packet from a client we don't know" << std::endl;
+//           else
+//             COUT(3) << "received a packet from a client we don't know" << std::endl;
           break;
-        case ENET_EVENT_TYPE_DISCONNECT:
-          clientDisconnect(event->peer);
-          break;
+        //case ENET_EVENT_TYPE_DISCONNECT:
+          //clientDisconnect(event->peer);
+          //break;
         case ENET_EVENT_TYPE_NONE:
+          delete event;
           //receiverThread_->yield();
           break;
@@ -262,8 +273,8 @@
   }
 
-  bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
+  /*bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
     COUT(4) << "removing client from list" << std::endl;
     return removeClient(head_->findClient(&(peer->address))->getID());
-  }
+  }*/
 /**
 This function adds a client that connects to the clientlist of the server
@@ -271,5 +282,5 @@
 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid
 */
-  bool ConnectionManager::addClient(ENetEvent *event) {
+  /*bool ConnectionManager::addClient(ENetEvent *event) {
     ClientInformation *temp = head_->insertBack(new ClientInformation);
     if(!temp){
@@ -286,5 +297,5 @@
     COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
     return true;
-  }
+  }*/
 
   int ConnectionManager::getClientID(ENetPeer peer) {
@@ -324,5 +335,5 @@
   }
 
-  bool ConnectionManager::createClient(int clientID){
+  /*bool ConnectionManager::createClient(int clientID){
     ClientInformation *temp = head_->findClient(clientID);
     if(!temp){
@@ -342,7 +353,7 @@
     sendWelcome(temp->getID(), temp->getShipID(), true);
     return true;
-  }
-  
-  bool ConnectionManager::removeClient(int clientID){
+  }*/
+  
+  /*bool ConnectionManager::removeClient(int clientID){
     boost::recursive_mutex::scoped_lock lock(head_->mutex_);
     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
@@ -361,7 +372,7 @@
     }
     return false;
-  }
-  
-  bool ConnectionManager::createShip(ClientInformation *client){
+  }*/
+  
+/*  bool ConnectionManager::createShip(ClientInformation *client){
     if(!client)
       return false;
@@ -389,5 +400,5 @@
     client->setShipID(no->objectID);
     return true;
-  }
+  }*/
   
   bool ConnectionManager::removeShip(ClientInformation *client){
Index: /code/branches/network/src/network/ConnectionManager.h
===================================================================
--- /code/branches/network/src/network/ConnectionManager.h	(revision 1408)
+++ /code/branches/network/src/network/ConnectionManager.h	(revision 1409)
@@ -77,6 +77,7 @@
     ConnectionManager(int port, const char *address, ClientInformation *head);
     ConnectionManager(int port, std::string address, ClientInformation *head);
-    ENetPacket *getPacket(ENetAddress &address); // thread1
-    ENetPacket *getPacket(int &clientID);
+    //ENetPacket *getPacket(ENetAddress &address); // thread1
+    //ENetPacket *getPacket(int &clientID);
+    ENetEvent *getEvent();
     bool queueEmpty();
     void createListener();
@@ -87,21 +88,21 @@
   //  bool sendPackets(ENetEvent *event);
     bool sendPackets();
-    bool createClient(int clientID);
+    //bool createClient(int clientID);
     void disconnectClient(ClientInformation *client);
+    void syncClassid(int clientID);
+    bool sendWelcome(int clientID, int shipID, bool allowed);
 
   private:
-    bool clientDisconnect(ENetPeer *peer);
-    bool removeClient(int clientID);
+//     bool clientDisconnect(ENetPeer *peer);
+//     bool removeClient(int clientID);
     bool processData(ENetEvent *event);
-    bool addClient(ENetEvent *event);
+    //bool addClient(ENetEvent *event);
     void receiverThread();
     void disconnectClients();
     int getClientID(ENetPeer peer);
     int getClientID(ENetAddress address);
-    void syncClassid(int clientID);
     ENetPeer *getClientPeer(int clientID);
-    bool createShip(ClientInformation *client);
+    //bool createShip(ClientInformation *client);
     bool removeShip(ClientInformation *client);
-    bool sendWelcome(int clientID, int shipID, bool allowed);
     bool addFakeConnectRequest(ENetEvent *ev);
     PacketBuffer buffer;
Index: /code/branches/network/src/network/PacketBuffer.cc
===================================================================
--- /code/branches/network/src/network/PacketBuffer.cc	(revision 1408)
+++ /code/branches/network/src/network/PacketBuffer.cc	(revision 1409)
@@ -62,6 +62,5 @@
       last->next=NULL;
       // change this!!!!!!!  ---- we are not doing stl so we won't change this
-      last->packet = ev->packet;
-      last->address = ev->peer->address;
+      last->event = ev;
       //last->address = ev->peer->address;
     } else {
@@ -72,6 +71,5 @@
       last->next=NULL;
       // save the packet to the new element
-      last->packet = ev->packet;
-      last->address = ev->peer->address;
+      last->event = ev;
       //last->address = ev->peer->address;
     }
@@ -82,10 +80,10 @@
   //returns the first element in the list without deleting it but
   //moving first pointer to next element
-  ENetPacket *PacketBuffer::pop() {
+  /*ENetPacket *PacketBuffer::pop() {
     ENetAddress address;
     return pop(address);
-  }
-
-  ENetPacket *PacketBuffer::pop(ENetAddress &address) {
+  }*/
+  
+  ENetEvent *PacketBuffer::pop(){
     boost::recursive_mutex::scoped_lock lock(mutex_);
     //std::cout << "packetbuffer pop(address)" << std::endl;
@@ -93,6 +91,26 @@
       QueueItem *temp = first;
       // get packet
-      ENetPacket *pck=first->packet;
-      address = first->address;
+      ENetEvent *ev=first->event;
+      //address = first->address;
+      // remove first element
+      first = first->next;
+      delete temp;
+      lock.unlock();
+      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
+      return ev;
+    } else{
+      lock.unlock();
+      return NULL;
+    }
+  }
+
+  /*ENetPacket *PacketBuffer::pop(ENetAddress &address) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    //std::cout << "packetbuffer pop(address)" << std::endl;
+    if(first!=NULL ){
+      QueueItem *temp = first;
+      // get packet
+      ENetPacket *pck=first->event->packet;
+      address = first->event->peer->address;
       // remove first element
       first = first->next;
@@ -105,5 +123,5 @@
       return NULL;
     }
-  }
+  }*/
 
   bool PacketBuffer::isEmpty() {
Index: /code/branches/network/src/network/PacketBuffer.h
===================================================================
--- /code/branches/network/src/network/PacketBuffer.h	(revision 1408)
+++ /code/branches/network/src/network/PacketBuffer.h	(revision 1409)
@@ -55,6 +55,6 @@
 
   struct QueueItem{
-    ENetPacket *packet;
-    ENetAddress address;
+    ENetEvent *event;
+    //ENetAddress address;
     QueueItem *next;
   };
@@ -68,6 +68,7 @@
     void print();
     // pops a packet from the queue
-    ENetPacket *pop();
-    ENetPacket *pop(ENetAddress &address);
+    //ENetPacket *pop();
+    //ENetPacket *pop(ENetAddress &address);
+    ENetEvent *pop();
     // pushs a packet to the queue
     bool push(ENetEvent *ev);
Index: /code/branches/network/src/network/Server.cc
===================================================================
--- /code/branches/network/src/network/Server.cc	(revision 1408)
+++ /code/branches/network/src/network/Server.cc	(revision 1409)
@@ -50,4 +50,5 @@
 //#include "NetworkFrameListener.h"
 #include "util/Sleep.h"
+#include "objects/SpaceShip.h"
 
 
@@ -165,15 +166,31 @@
   */
   void Server::processQueue() {
-    ENetPacket *packet;
+    ENetEvent *event;
     int clientID=-1;
     while(!connection->queueEmpty()){
       //std::cout << "Client " << clientID << " sent: " << std::endl;
       //clientID here is a reference to grab clientID from ClientInformation
-      packet = connection->getPacket(clientID);
-      if(!packet)
+      event = connection->getEvent();
+      if(!event)
         continue;
+      switch( event->type ) {
+      case ENET_EVENT_TYPE_CONNECT:
+        COUT(3) << "processing event_Type_connect" << std::endl;
+        addClient(event);
+        break;
+      case ENET_EVENT_TYPE_DISCONNECT:
+        if(clients->findClient(&event->peer->address))
+          disconnectClient(event);
+        break;
+      case ENET_EVENT_TYPE_RECEIVE:
+        if(clients->findClient(&event->peer->address)){
+          clientID = clients->findClient(&event->peer->address)->getID();
+          if( !elaborate(event->packet, clientID) ) 
+            COUT(3) << "Server: could not elaborate" << std::endl;
+        }
+        break;
+      }
+      delete event;
       //if statement to catch case that packetbuffer is empty
-      if( !elaborate(packet, clientID) ) 
-        COUT(3) << "Server: could not elaborate" << std::endl;
     }
   }
@@ -250,7 +267,7 @@
   
   bool Server::processConnectRequest( connectRequest *con, int clientID ){
-    COUT(3) << "processing connectRequest " << std::endl;
+    //(COUT(3) << "processing connectRequest " << std::endl;
     //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
-    connection->createClient(clientID);
+    //createClient(clientID);
     delete con;
     return true;
@@ -265,4 +282,91 @@
         clients->findClient(clientID)->resetFailures();
   }
+  
+  bool Server::addClient(ENetEvent *event){
+    ClientInformation *temp = clients->insertBack(new ClientInformation);
+    if(!temp){
+      COUT(2) << "Server: could not add client" << std::endl;
+      return false;
+    }
+    if(temp->prev()->getHead()) { //not good if you use anything else than insertBack
+      temp->prev()->setID(0); //bugfix: not necessary but usefull
+      temp->setID(1);
+    }
+    else
+      temp->setID(temp->prev()->getID()+1);
+    temp->setPeer(event->peer);
+    COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
+    return createClient(temp->getID());
+  }
+  
+  bool Server::createClient(int clientID){
+    ClientInformation *temp = clients->findClient(clientID);
+    if(!temp){
+      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
+      return false;
+    }
+    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+    connection->syncClassid(temp->getID());
+    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
+    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
+    if(!createShip(temp))
+      COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
+    else
+      COUT(3) << "created spaceship" << std::endl;
+    temp->setSynched(true);
+    COUT(3) << "sending welcome" << std::endl;
+    connection->sendWelcome(temp->getID(), temp->getShipID(), true);
+    return true;
+  }
+  
+  bool Server::createShip(ClientInformation *client){
+    if(!client)
+      return false;
+    orxonox::Identifier* id = ID("SpaceShip");
+    if(!id){
+      COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
+      return false;
+    }
+    orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
+    no->setPosition(orxonox::Vector3(0,0,80));
+    no->setScale(10);
+    //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));
+    no->setMesh("assff.mesh");
+    no->setMaxSpeed(500);
+    no->setMaxSideAndBackSpeed(50);
+    no->setMaxRotation(1.0);
+    no->setTransAcc(200);
+    no->setRotAcc(3.0);
+    no->setTransDamp(75);
+    no->setRotDamp(1.0);
+    no->setCamera("cam_"+client->getID());
+    no->classID = id->getNetworkID();
+    no->create();
+    
+    client->setShipID(no->objectID);
+    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_);
+    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
+    ClientInformation *client = clients->findClient(&event->peer->address);
+    if(!client)
+      return false;
+    while(it){
+      if(it->objectID!=client->getShipID()){
+        ++it;
+        continue;
+      }
+      orxonox::Iterator<orxonox::SpaceShip> temp=it;
+      ++it;
+      delete  *temp;
+      return clients->removeClient(event->peer);
+    }
+    return false;
+  }
 
   void Server::disconnectClient(int clientID){
Index: /code/branches/network/src/network/Server.h
===================================================================
--- /code/branches/network/src/network/Server.h	(revision 1408)
+++ /code/branches/network/src/network/Server.h	(revision 1409)
@@ -72,4 +72,8 @@
     void updateGamestate();
   private:
+    bool addClient(ENetEvent *event);
+    bool createClient(int clientID);
+    bool createShip(ClientInformation *client);
+    bool disconnectClient(ENetEvent *event);
     void disconnectClient(int clientID);
     void disconnectClient( ClientInformation *client);
Index: /code/branches/network/src/orxonox/objects/Camera.cc
===================================================================
--- /code/branches/network/src/orxonox/objects/Camera.cc	(revision 1408)
+++ /code/branches/network/src/orxonox/objects/Camera.cc	(revision 1409)
@@ -60,4 +60,5 @@
   {
     CameraHandler::getInstance()->releaseFocus(this);
+    GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName());
   }
 
