Index: code/branches/merge/src/network/ClientInformation.cc
===================================================================
--- code/branches/merge/src/network/ClientInformation.cc	(revision 1306)
+++ code/branches/merge/src/network/ClientInformation.cc	(revision 1318)
@@ -45,9 +45,11 @@
 namespace network
 {
+  boost::recursive_mutex ClientInformation::mutex_;
+  
   ClientInformation::ClientInformation() {
     gamestateID_=GAMESTATEID_INITIAL;
     preve=0;
     nexte=0;
-    this->head=false;
+    this->head_=false;
     synched_=false;
   }
@@ -57,5 +59,5 @@
     preve=0;
     nexte=0;
-    this->head=head;
+    this->head_=head;
     synched_=false;
   }
@@ -80,4 +82,5 @@
 
   ClientInformation::~ClientInformation() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(preve!=0)
       preve->setNext(this->nexte);
@@ -87,4 +90,5 @@
 
   ClientInformation *ClientInformation::next() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this!=0)
       return this->nexte;
@@ -93,4 +97,5 @@
   }
   ClientInformation *ClientInformation::prev() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this!=0)
       return this->preve;
@@ -100,5 +105,6 @@
 
   bool ClientInformation::setPrev(ClientInformation *prev) {
-    if(!head)
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!head_)
       this->preve = prev;
     else
@@ -108,4 +114,5 @@
 
   bool ClientInformation::setNext(ClientInformation *next) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     this->nexte = next;
     return true;
@@ -113,4 +120,5 @@
 
   ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     this->nexte->setPrev(ins);
     ins->setNext(this->nexte);
@@ -121,4 +129,5 @@
 
   ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this)
       return NULL;
@@ -131,8 +140,10 @@
 
   void ClientInformation::setID(int clientID){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     clientID_ = clientID;
   }
 
   bool ClientInformation::setPeer(ENetPeer *peer){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this)
       return false;
@@ -142,4 +153,5 @@
 
   bool ClientInformation::setGamestateID(int id){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this)
       return false;
@@ -149,4 +161,5 @@
 
   int ClientInformation::getID() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this)
       return CLIENTID_UNKNOWN;
@@ -156,4 +169,5 @@
 
   ENetPeer *ClientInformation::getPeer() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this)
       return peer_;
@@ -161,6 +175,30 @@
       return NULL;
   }
+  
+  bool ClientInformation::getHead(){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    return head_;
+  }
+  
+  void ClientInformation::setHead(bool h){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    head_=h;
+  }
+  
+  int ClientInformation::getFailures(){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    return failures_;
+  }
+  void ClientInformation::addFailure(){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    failures_++;
+  }
+  void ClientInformation::resetFailures(){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    failures_=0;
+  }
 
   int ClientInformation::getGamestateID() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this)
       return gamestateID_;
@@ -170,4 +208,5 @@
 
   ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this)
       return NULL;
@@ -182,4 +221,5 @@
 
   bool ClientInformation::removeClient(int clientID) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this || clientID==CLIENTID_UNKNOWN)
       return false;
@@ -194,9 +234,10 @@
 
   bool ClientInformation::removeClient(ENetPeer *peer) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this || !peer)
       return false;
     ClientInformation *temp = this;
     while(temp!=0){
-      if(!temp->head)
+      if(!temp->head_)
         if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
           break;
@@ -216,6 +257,7 @@
   */
   ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
-    ClientInformation *temp = this;
-    if (temp->head)
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    ClientInformation *temp = this;
+    if (temp->head_)
       temp=temp->next();
     while(temp!=0 && temp->getID()!=clientID){
@@ -233,7 +275,8 @@
   */
   ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     ClientInformation *temp = this;
     while(temp!=0){
-      if(temp->head){
+      if(temp->head_){
         temp = temp->next();
         continue;
@@ -248,4 +291,5 @@
 
   bool ClientInformation::setSynched(bool s) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(!this)
       return false;
@@ -255,4 +299,5 @@
 
   bool ClientInformation::getSynched() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this)
       return synched_;
Index: code/branches/merge/src/network/ClientInformation.h
===================================================================
--- code/branches/merge/src/network/ClientInformation.h	(revision 1306)
+++ code/branches/merge/src/network/ClientInformation.h	(revision 1318)
@@ -44,4 +44,5 @@
 
 #include <enet/enet.h>
+#include <boost/thread/recursive_mutex.hpp>
 
 #define GAMESTATEID_INITIAL -1
@@ -63,8 +64,4 @@
     ClientInformation *next();
     ClientInformation *prev();
-    bool setNext(ClientInformation *next);
-    bool setPrev(ClientInformation *prev);
-    ClientInformation *insertAfter(ClientInformation *ins);
-    ClientInformation *insertBefore(ClientInformation *ins);
     ClientInformation *insertBack(ClientInformation *ins);
     
@@ -80,5 +77,10 @@
     int getGamestateID();
     ENetPeer *getPeer();
+    bool getHead();
+    void setHead(bool h);
     
+    int getFailures();
+    void addFailure();
+    void resetFailures();
     
     bool removeClient(int clientID);
@@ -92,8 +94,11 @@
     bool getSynched();
 
-    bool head;
-    unsigned short failures_;
 
-  private:
+    private:
+      bool setNext(ClientInformation *next);
+      bool setPrev(ClientInformation *prev);
+    ClientInformation *insertAfter(ClientInformation *ins);
+    ClientInformation *insertBefore(ClientInformation *ins);
+    
     ClientInformation *preve;
     ClientInformation *nexte;
@@ -104,4 +109,8 @@
     int ShipID_;   // this is the unique objectID
     bool synched_;
+    bool head_;
+    unsigned short failures_;
+    static boost::recursive_mutex mutex_;
+    
   };
 
Index: code/branches/merge/src/network/ConnectionManager.cc
===================================================================
--- code/branches/merge/src/network/ConnectionManager.cc	(revision 1306)
+++ code/branches/merge/src/network/ConnectionManager.cc	(revision 1318)
@@ -274,5 +274,5 @@
       return false;
     }
-    if(temp->prev()->head) { //not good if you use anything else than insertBack
+    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);
Index: code/branches/merge/src/network/PacketBuffer.cc
===================================================================
--- code/branches/merge/src/network/PacketBuffer.cc	(revision 1306)
+++ code/branches/merge/src/network/PacketBuffer.cc	(revision 1318)
@@ -41,5 +41,5 @@
 namespace network
 {
-  boost::mutex networkPacketBufferMutex;
+   boost::recursive_mutex PacketBuffer::mutex_;
 
   PacketBuffer::PacketBuffer() {
@@ -52,5 +52,5 @@
 
   bool PacketBuffer::push(ENetEvent *ev) {
-    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
     //   if(closed)
@@ -61,5 +61,5 @@
       last=first;
       last->next=NULL;
-      // change this!!!!!!! 
+      // change this!!!!!!!  ---- we are not doing stl so we won't change this
       last->packet = ev->packet;
       last->address = ev->peer->address;
@@ -76,7 +76,6 @@
       //last->address = ev->peer->address;
     }
-    // pseudo bugfix: added a return false statement for error handling
-    if ( last->packet == ev->packet ) return true;
-    return false;
+    lock.unlock();
+    return true;
   }
 
@@ -84,23 +83,10 @@
   //moving first pointer to next element
   ENetPacket *PacketBuffer::pop() {
-    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
-    //std::cout << "packetbuffer pop" << std::endl;
-    if(first!=NULL /*&& !closed*/){
-      QueueItem *temp = first;
-      // get packet
-      ENetPacket *pck=first->packet;
-      // remove first element
-      first = first->next;
-      delete temp;
-      //std::cout << "pop size of packet " << pck->dataLength << std::endl;
-      return pck;
-    } else{
-      //std::cout << "nothing to return" << std::endl;
-      return NULL;
-    }
+    ENetAddress address;
+    return pop(address);
   }
 
   ENetPacket *PacketBuffer::pop(ENetAddress &address) {
-    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     //std::cout << "packetbuffer pop(address)" << std::endl;
     if(first!=NULL /*&& !closed*/){
@@ -112,7 +98,9 @@
       first = first->next;
       delete temp;
+      lock.unlock();
       //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
       return pck;
     } else{
+      lock.unlock();
       return NULL;
     }
Index: code/branches/merge/src/network/PacketBuffer.h
===================================================================
--- code/branches/merge/src/network/PacketBuffer.h	(revision 1306)
+++ code/branches/merge/src/network/PacketBuffer.h	(revision 1318)
@@ -45,4 +45,5 @@
 
 #include <enet/enet.h>
+#include <boost/thread/recursive_mutex.hpp>
 
 namespace network
@@ -76,5 +77,5 @@
     QueueItem *last;
     bool closed;
-
+    static boost::recursive_mutex mutex_;
   };
 
Index: code/branches/merge/src/network/Server.cc
===================================================================
--- code/branches/merge/src/network/Server.cc	(revision 1306)
+++ code/branches/merge/src/network/Server.cc	(revision 1318)
@@ -192,5 +192,5 @@
     bool added=false;
     while(temp != NULL){
-      if(temp->head){
+      if(temp->getHead()){
         temp=temp->next();
         //think this works without continue
@@ -214,7 +214,7 @@
       //std::cout << "adding gamestate" << std::endl;
       if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ){
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->failures_ << std::endl; 
-        temp->failures_++;
-        if(temp->failures_ > 20 )
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 
+        temp->addFailure();
+        if(temp->getFailures() > 20 )
           disconnectClient(temp);
       //std::cout << "added gamestate" << std::endl;
@@ -254,5 +254,5 @@
     else
       if(clients->findClient(clientID))
-        clients->findClient(clientID)->failures_=0;
+        clients->findClient(clientID)->resetFailures();
   }
 
