Index: code/branches/merge/src/network/Client.cc
===================================================================
--- code/branches/merge/src/network/Client.cc	(revision 1294)
+++ code/branches/merge/src/network/Client.cc	(revision 1299)
@@ -120,7 +120,7 @@
     isConnected=client_connection.createConnection();
     if(isConnected){
-      COUT(4) << "sending connectrequest" << std::endl;
-      client_connection.addPacket(pck_gen.generateConnectRequest());
-      client_connection.sendPackets();
+      COUT(3) << "sending connectrequest" << std::endl;
+      if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
+        COUT(1) << "could not create connection" << std::endl;
     }else
       COUT(1) << "could not create connection" << std::endl;
@@ -229,4 +229,5 @@
   */
   void Client::tick(float time){
+//     COUT(3) << ".";
     if(client_connection.isConnected() && isSynched_){
       COUT(4) << "popping partial gamestate: " << std::endl;
@@ -260,8 +261,9 @@
       if(!isSynched_)
         isSynched_=true;
-      client_connection.addPacket(pck_gen.acknowledgement(id));
+      if(!client_connection.addPacket(pck_gen.acknowledgement(id)))
+        return;
         // we do this at the end of a tick
-       if(!client_connection.sendPackets())
-         COUT(2) << "Could not send acknowledgment" << std::endl;
+      if(!client_connection.sendPackets())
+        COUT(2) << "Could not send acknowledgment" << std::endl;
     }
   }
Index: code/branches/merge/src/network/ClientInformation.cc
===================================================================
--- code/branches/merge/src/network/ClientInformation.cc	(revision 1294)
+++ code/branches/merge/src/network/ClientInformation.cc	(revision 1299)
@@ -121,4 +121,6 @@
 
   ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
+    if(!this)
+      return NULL;
     this->prev()->setNext(ins);
     ins->setPrev(this->preve);
@@ -132,25 +134,42 @@
   }
 
-  void ClientInformation::setPeer(ENetPeer *peer){
+  bool ClientInformation::setPeer(ENetPeer *peer){
+    if(!this)
+      return false;
     peer_ = peer;
-  }
-
-  void ClientInformation::setGamestateID(int id){
+    return true;
+  }
+
+  bool ClientInformation::setGamestateID(int id){
+    if(!this)
+      return false;
     gamestateID_=id;
+    return true;
   }
 
   int ClientInformation::getID() {
-    return clientID_;
+    if(!this)
+      return CLIENTID_UNKNOWN;
+    else
+      return clientID_;
   }
 
   ENetPeer *ClientInformation::getPeer() {
-    return peer_;
+    if(this)
+      return peer_;
+    else
+      return NULL;
   }
 
   int ClientInformation::getGamestateID() {
-    return gamestateID_;
+    if(this)
+      return gamestateID_;
+    else
+      return -1;
   }
 
   ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
+    if(!this)
+      return NULL;
     ClientInformation *temp = this;
     while(temp->next()!=0){
@@ -163,4 +182,6 @@
 
   bool ClientInformation::removeClient(int clientID) {
+    if(!this || clientID==CLIENTID_UNKNOWN)
+      return false;
     ClientInformation *temp = this;
     while(temp!=0 && temp->getID()!=clientID)
@@ -173,4 +194,6 @@
 
   bool ClientInformation::removeClient(ENetPeer *peer) {
+    if(!this || !peer)
+      return false;
     ClientInformation *temp = this;
     while(temp!=0){
@@ -196,6 +219,5 @@
     if (temp->head)
       temp=temp->next();
-    //bugfix: temp to temp->next(), get last elem if not found, not segflt
-    while(temp->next()!=0 && temp->getID()!=clientID){
+    while(temp!=0 && temp->getID()!=clientID){
       temp = temp->next();
     }
@@ -212,6 +234,5 @@
   ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
     ClientInformation *temp = this;
-    //bugfix: temp to temp->next(), get last elem if not found, not segflt
-    while(temp->next()!=0){
+    while(temp!=0){
       if(temp->head){
         temp = temp->next();
@@ -226,10 +247,16 @@
   }
 
-  void ClientInformation::setSynched(bool s) {
+  bool ClientInformation::setSynched(bool s) {
+    if(!this)
+      return false;
     synched_=s;
+    return true;
   }
 
   bool ClientInformation::getSynched() {
-    return synched_;
+    if(this)
+      return synched_;
+    else
+      return false;
   }
 
Index: code/branches/merge/src/network/ClientInformation.h
===================================================================
--- code/branches/merge/src/network/ClientInformation.h	(revision 1294)
+++ code/branches/merge/src/network/ClientInformation.h	(revision 1299)
@@ -46,4 +46,5 @@
 
 #define GAMESTATEID_INITIAL -1
+#define CLIENTID_UNKNOWN -2
 
 namespace network
@@ -70,6 +71,6 @@
     // set functions
     void setID(int clientID);
-    void setPeer(ENetPeer *peer);
-    void setGamestateID(int id);
+    bool setPeer(ENetPeer *peer);
+    bool setGamestateID(int id);
     inline void setShipID(int id){ShipID_=id;}
     
@@ -88,5 +89,5 @@
     ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
 
-    void setSynched(bool s);
+    bool setSynched(bool s);
     bool getSynched();
 
Index: code/branches/merge/src/network/ConnectionManager.cc
===================================================================
--- code/branches/merge/src/network/ConnectionManager.cc	(revision 1294)
+++ code/branches/merge/src/network/ConnectionManager.cc	(revision 1299)
@@ -101,4 +101,6 @@
     ENetPacket *packet=getPacket(address);
     ClientInformation *temp =head_->findClient(&address);
+    if(!temp)
+      return NULL;
     clientID=temp->getID();
     return packet;
@@ -124,5 +126,8 @@
 
   bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    if(enet_peer_send(peer, (enet_uint8)head_->findClient(&(peer->address))->getID() , packet)!=0)
+    ClientInformation *temp = head_->findClient(&(peer->address));
+    if(!temp)
+      return false;
+    if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
       return false;
     return true;
@@ -130,5 +135,8 @@
 
   bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
-    if(enet_peer_send(head_->findClient(clientID)->getPeer(), (enet_uint8)clientID, packet)!=0)
+    ClientInformation *temp = head_->findClient(clientID);
+    if(!temp)
+      return false;
+    if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0)
       return false;
     return true;
@@ -195,4 +203,6 @@
           if(head_->findClient(&event->peer->address))
             processData(event);
+          else
+            COUT(3) << "received a packet from a client we don't know" << std::endl;
           break;
         case ENET_EVENT_TYPE_DISCONNECT:
@@ -233,5 +243,6 @@
       case ENET_EVENT_TYPE_DISCONNECT:
         COUT(4) << "disconnecting all clients" << std::endl;
-        delete head_->findClient(&(event.peer->address));
+        if(head_->findClient(&(event.peer->address)))
+          delete head_->findClient(&(event.peer->address));
         //maybe needs bugfix: might also be a reason for the server to crash
         temp = temp->next();
@@ -259,4 +270,8 @@
   bool ConnectionManager::addClient(ENetEvent *event) {
     ClientInformation *temp = head_->insertBack(new ClientInformation);
+    if(!temp){
+      COUT(2) << "Conn.Man. could not add client" << std::endl;
+      return false;
+    }
     if(temp->prev()->head) { //not good if you use anything else than insertBack
       temp->prev()->setID(0); //bugfix: not necessary but usefull
@@ -266,5 +281,5 @@
       temp->setID(temp->prev()->getID()+1);
     temp->setPeer(event->peer);
-    COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
+    COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
     return true;
   }
@@ -283,5 +298,5 @@
 
   void ConnectionManager::syncClassid(int clientID) {
-    unsigned int network_id=0;
+    unsigned int network_id=0, failures=0;
     std::string classname;
     orxonox::Identifier *id;
@@ -295,6 +310,7 @@
       COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
 
-      addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
-
+      while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){
+        failures++;
+      }
       ++it;
     }
@@ -305,12 +321,18 @@
   bool ConnectionManager::createClient(int clientID){
     ClientInformation *temp = head_->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;
     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
-    createShip(temp);
-    COUT(4) << "created spaceship" << std::endl;
+    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(4) << "sending welcome" << std::endl;
+    COUT(3) << "sending welcome" << std::endl;
     sendWelcome(temp->getID(), temp->getShipID(), true);
     return true;
@@ -319,6 +341,9 @@
   bool ConnectionManager::removeClient(int clientID){
     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
+    ClientInformation *client = head_->findClient(clientID);
+    if(!client)
+      return false;
     while(it){
-      if(it->objectID!=head_->findClient(clientID)->getShipID()){
+      if(it->objectID!=client->getShipID()){
         ++it;
         continue;
@@ -333,4 +358,6 @@
   
   bool ConnectionManager::createShip(ClientInformation *client){
+    if(!client)
+      return false;
     orxonox::Identifier* id = ID("SpaceShip");
     if(!id){
@@ -369,7 +396,9 @@
   
   bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
-    addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
-    sendPackets();
-    return true;
+    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
+      sendPackets();
+      return true;
+    }else
+      return false;
   }
   
Index: code/branches/merge/src/network/GameStateManager.cc
===================================================================
--- code/branches/merge/src/network/GameStateManager.cc	(revision 1294)
+++ code/branches/merge/src/network/GameStateManager.cc	(revision 1299)
@@ -117,5 +117,4 @@
         client = it->second;
       GameState *server = reference;
-      //head_->findClient(clientID)->setGamestateID(id);
       COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << std::endl;
       if(client)
@@ -127,5 +126,4 @@
       GameState *server = reference;
 //       ackGameState(clientID, reference->id);
-      //head_->findClient(clientID)->setGamestateID(id);
       return encode(server);
       // return an undiffed gamestate and set appropriate flags
@@ -427,5 +425,5 @@
   void GameStateManager::ackGameState(int clientID, int gamestateID) {
     ClientInformation *temp = head_->findClient(clientID);
-    if(!temp)
+    if(temp==0)
       return;
     int curid = temp->getGamestateID();
@@ -434,5 +432,6 @@
 //     deleteUnusedGameState(curid);
     //increase gamestateused
-    --(gameStateUsed.find(curid)->second);
+    if(curid!=GAMESTATEID_INITIAL)
+      --(gameStateUsed.find(curid)->second);
     ++(gameStateUsed.find(gamestateID)->second);
     temp->setGamestateID(gamestateID);
@@ -460,5 +459,8 @@
   
   void GameStateManager::removeClient(ClientInformation* client){
-    gameStateUsed[client->getGamestateID()]--;
+    if(!client)
+      return;
+    if(client->getGamestateID()>=0)
+      gameStateUsed[client->getGamestateID()]--;
     head_->removeClient(client->getID());
   }
Index: code/branches/merge/src/network/PacketBuffer.cc
===================================================================
--- code/branches/merge/src/network/PacketBuffer.cc	(revision 1294)
+++ code/branches/merge/src/network/PacketBuffer.cc	(revision 1299)
@@ -63,4 +63,5 @@
       // change this!!!!!!! 
       last->packet = ev->packet;
+      last->address = ev->peer->address;
       //last->address = ev->peer->address;
     } else {
@@ -72,4 +73,5 @@
       // save the packet to the new element
       last->packet = ev->packet;
+      last->address = ev->peer->address;
       //last->address = ev->peer->address;
     }
Index: code/branches/merge/src/network/PacketDecoder.cc
===================================================================
--- code/branches/merge/src/network/PacketDecoder.cc	(revision 1294)
+++ code/branches/merge/src/network/PacketDecoder.cc	(revision 1299)
@@ -111,4 +111,5 @@
     void *data = (void *)new unsigned char[length];
     memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
+    enet_packet_destroy( packet );
     return true;
   }
Index: code/branches/merge/src/network/Server.cc
===================================================================
--- code/branches/merge/src/network/Server.cc	(revision 1294)
+++ code/branches/merge/src/network/Server.cc	(revision 1299)
@@ -117,7 +117,9 @@
     ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
     //std::cout <<"adding packets" << std::endl;
-    connection->addPacketAll(packet);
+    if(connection->addPacketAll(packet))
     //std::cout <<"added packets" << std::endl;
-    return connection->sendPackets();
+      return connection->sendPackets();
+    else
+      return false;
   }
 
@@ -162,7 +164,9 @@
       //clientID here is a reference to grab clientID from ClientInformation
       packet = connection->getPacket(clientID);
+      if(!packet)
+        continue;
       //if statement to catch case that packetbuffer is empty
       if( !elaborate(packet, clientID) ) 
-        COUT(4) << "Server: PacketBuffer empty" << std::endl;
+        COUT(3) << "Server: could not elaborate" << std::endl;
     }
   }
@@ -238,5 +242,5 @@
   
   bool Server::processConnectRequest( connectRequest *con, int clientID ){
-    COUT(4) << "processing connectRequest " << std::endl;
+    COUT(3) << "processing connectRequest " << std::endl;
     //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
     connection->createClient(clientID);
@@ -250,4 +254,5 @@
         COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
     else
+      if(clients->findClient(clientID))
         clients->findClient(clientID)->failures_=0;
   }
@@ -255,5 +260,6 @@
   void Server::disconnectClient(int clientID){
     ClientInformation *client = clients->findClient(clientID);
-    disconnectClient(client);
+    if(client)
+      disconnectClient(client);
   }
   void Server::disconnectClient( ClientInformation *client){
Index: code/branches/merge/src/network/diffTest.cc
===================================================================
--- code/branches/merge/src/network/diffTest.cc	(revision 1294)
+++ code/branches/merge/src/network/diffTest.cc	(revision 1299)
@@ -466,4 +466,6 @@
 bool addClientTest( ENetEvent* event, ClientInformation*& head ) {
   ClientInformation *temp = head->insertBack(new ClientInformation);
+  if(!temp)
+    return false;
   if(temp->prev()->head) {
     temp->prev()->setID(0);
@@ -475,9 +477,10 @@
   std::cout << "added client id: " << temp->getID() << std::endl;
 
-  temp->setSynched(true);
-  return true;
+  return temp->setSynched(true);
 }
 
 void printClientInformationBox( ClientInformation* box ) {
+  if(!box)
+    return;
   std::cout << "ClientList: id: " << box->getID() << "\t";
   std::cout << "g_id: " << box->getGamestateID() << " \t";
