Index: code/trunk/src/network/ClientInformation.cc
===================================================================
--- code/trunk/src/network/ClientInformation.cc	(revision 1293)
+++ code/trunk/src/network/ClientInformation.cc	(revision 1360)
@@ -45,9 +45,12 @@
 namespace network
 {
+  boost::recursive_mutex ClientInformation::mutex_;
+  
   ClientInformation::ClientInformation() {
     gamestateID_=GAMESTATEID_INITIAL;
     preve=0;
     nexte=0;
-    this->head=false;
+    partialGamestateID_=GAMESTATEID_INITIAL-1;
+    this->head_=false;
     synched_=false;
   }
@@ -57,5 +60,6 @@
     preve=0;
     nexte=0;
-    this->head=head;
+    partialGamestateID_=GAMESTATEID_INITIAL-1;
+    this->head_=head;
     synched_=false;
   }
@@ -80,4 +84,5 @@
 
   ClientInformation::~ClientInformation() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(preve!=0)
       preve->setNext(this->nexte);
@@ -87,4 +92,5 @@
 
   ClientInformation *ClientInformation::next() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this!=0)
       return this->nexte;
@@ -93,4 +99,5 @@
   }
   ClientInformation *ClientInformation::prev() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     if(this!=0)
       return this->preve;
@@ -100,5 +107,6 @@
 
   bool ClientInformation::setPrev(ClientInformation *prev) {
-    if(!head)
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!head_)
       this->preve = prev;
     else
@@ -108,4 +116,5 @@
 
   bool ClientInformation::setNext(ClientInformation *next) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     this->nexte = next;
     return true;
@@ -113,4 +122,5 @@
 
   ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     this->nexte->setPrev(ins);
     ins->setNext(this->nexte);
@@ -121,4 +131,7 @@
 
   ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return NULL;
     this->prev()->setNext(ins);
     ins->setPrev(this->preve);
@@ -129,28 +142,91 @@
 
   void ClientInformation::setID(int clientID){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
     clientID_ = clientID;
   }
 
-  void ClientInformation::setPeer(ENetPeer *peer){
+  bool ClientInformation::setPeer(ENetPeer *peer){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return false;
     peer_ = peer;
-  }
-
-  void ClientInformation::setGamestateID(int id){
+    return true;
+  }
+
+  bool ClientInformation::setGamestateID(int id){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return false;
     gamestateID_=id;
+    return true;
+  }
+  
+  bool ClientInformation::setPartialGamestateID(int id){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return false;
+    partialGamestateID_=id;
+    return true;
   }
 
   int ClientInformation::getID() {
-    return clientID_;
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return CLIENTID_UNKNOWN;
+    else
+      return clientID_;
   }
 
   ENetPeer *ClientInformation::getPeer() {
-    return peer_;
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(this)
+      return peer_;
+    else
+      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() {
-    return gamestateID_;
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(this)
+      return gamestateID_;
+    else
+      return -1;
+  }
+  
+  int ClientInformation::getPartialGamestateID() {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(this)
+      return partialGamestateID_;
+    else
+      return -1;
   }
 
   ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return NULL;
     ClientInformation *temp = this;
     while(temp->next()!=0){
@@ -163,4 +239,7 @@
 
   bool ClientInformation::removeClient(int clientID) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this || clientID==CLIENTID_UNKNOWN)
+      return false;
     ClientInformation *temp = this;
     while(temp!=0 && temp->getID()!=clientID)
@@ -173,7 +252,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;
@@ -193,9 +275,9 @@
   */
   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();
-    //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();
     }
@@ -211,8 +293,8 @@
   */
   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){
-      if(temp->head){
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    ClientInformation *temp = this;
+    while(temp!=0){
+      if(temp->head_){
         temp = temp->next();
         continue;
@@ -226,10 +308,18 @@
   }
 
-  void ClientInformation::setSynched(bool s) {
+  bool ClientInformation::setSynched(bool s) {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(!this)
+      return false;
     synched_=s;
+    return true;
   }
 
   bool ClientInformation::getSynched() {
-    return synched_;
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    if(this)
+      return synched_;
+    else
+      return false;
   }
 
