Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 22, 2008, 2:02:06 PM (16 years ago)
Author:
rgrieder
Message:

merged merge branch back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/ClientInformation.cc

    r1293 r1360  
    4545namespace network
    4646{
     47  boost::recursive_mutex ClientInformation::mutex_;
     48 
    4749  ClientInformation::ClientInformation() {
    4850    gamestateID_=GAMESTATEID_INITIAL;
    4951    preve=0;
    5052    nexte=0;
    51     this->head=false;
     53    partialGamestateID_=GAMESTATEID_INITIAL-1;
     54    this->head_=false;
    5255    synched_=false;
    5356  }
     
    5760    preve=0;
    5861    nexte=0;
    59     this->head=head;
     62    partialGamestateID_=GAMESTATEID_INITIAL-1;
     63    this->head_=head;
    6064    synched_=false;
    6165  }
     
    8084
    8185  ClientInformation::~ClientInformation() {
     86    boost::recursive_mutex::scoped_lock lock(mutex_);
    8287    if(preve!=0)
    8388      preve->setNext(this->nexte);
     
    8792
    8893  ClientInformation *ClientInformation::next() {
     94    boost::recursive_mutex::scoped_lock lock(mutex_);
    8995    if(this!=0)
    9096      return this->nexte;
     
    9399  }
    94100  ClientInformation *ClientInformation::prev() {
     101    boost::recursive_mutex::scoped_lock lock(mutex_);
    95102    if(this!=0)
    96103      return this->preve;
     
    100107
    101108  bool ClientInformation::setPrev(ClientInformation *prev) {
    102     if(!head)
     109    boost::recursive_mutex::scoped_lock lock(mutex_);
     110    if(!head_)
    103111      this->preve = prev;
    104112    else
     
    108116
    109117  bool ClientInformation::setNext(ClientInformation *next) {
     118    boost::recursive_mutex::scoped_lock lock(mutex_);
    110119    this->nexte = next;
    111120    return true;
     
    113122
    114123  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
     124    boost::recursive_mutex::scoped_lock lock(mutex_);
    115125    this->nexte->setPrev(ins);
    116126    ins->setNext(this->nexte);
     
    121131
    122132  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
     133    boost::recursive_mutex::scoped_lock lock(mutex_);
     134    if(!this)
     135      return NULL;
    123136    this->prev()->setNext(ins);
    124137    ins->setPrev(this->preve);
     
    129142
    130143  void ClientInformation::setID(int clientID){
     144    boost::recursive_mutex::scoped_lock lock(mutex_);
    131145    clientID_ = clientID;
    132146  }
    133147
    134   void ClientInformation::setPeer(ENetPeer *peer){
     148  bool ClientInformation::setPeer(ENetPeer *peer){
     149    boost::recursive_mutex::scoped_lock lock(mutex_);
     150    if(!this)
     151      return false;
    135152    peer_ = peer;
    136   }
    137 
    138   void ClientInformation::setGamestateID(int id){
     153    return true;
     154  }
     155
     156  bool ClientInformation::setGamestateID(int id){
     157    boost::recursive_mutex::scoped_lock lock(mutex_);
     158    if(!this)
     159      return false;
    139160    gamestateID_=id;
     161    return true;
     162  }
     163 
     164  bool ClientInformation::setPartialGamestateID(int id){
     165    boost::recursive_mutex::scoped_lock lock(mutex_);
     166    if(!this)
     167      return false;
     168    partialGamestateID_=id;
     169    return true;
    140170  }
    141171
    142172  int ClientInformation::getID() {
    143     return clientID_;
     173    boost::recursive_mutex::scoped_lock lock(mutex_);
     174    if(!this)
     175      return CLIENTID_UNKNOWN;
     176    else
     177      return clientID_;
    144178  }
    145179
    146180  ENetPeer *ClientInformation::getPeer() {
    147     return peer_;
     181    boost::recursive_mutex::scoped_lock lock(mutex_);
     182    if(this)
     183      return peer_;
     184    else
     185      return NULL;
     186  }
     187 
     188  bool ClientInformation::getHead(){
     189    boost::recursive_mutex::scoped_lock lock(mutex_);
     190    return head_;
     191  }
     192 
     193  void ClientInformation::setHead(bool h){
     194    boost::recursive_mutex::scoped_lock lock(mutex_);
     195    head_=h;
     196  }
     197 
     198  int ClientInformation::getFailures(){
     199    boost::recursive_mutex::scoped_lock lock(mutex_);
     200    return failures_;
     201  }
     202  void ClientInformation::addFailure(){
     203    boost::recursive_mutex::scoped_lock lock(mutex_);
     204    failures_++;
     205  }
     206  void ClientInformation::resetFailures(){
     207    boost::recursive_mutex::scoped_lock lock(mutex_);
     208    failures_=0;
    148209  }
    149210
    150211  int ClientInformation::getGamestateID() {
    151     return gamestateID_;
     212    boost::recursive_mutex::scoped_lock lock(mutex_);
     213    if(this)
     214      return gamestateID_;
     215    else
     216      return -1;
     217  }
     218 
     219  int ClientInformation::getPartialGamestateID() {
     220    boost::recursive_mutex::scoped_lock lock(mutex_);
     221    if(this)
     222      return partialGamestateID_;
     223    else
     224      return -1;
    152225  }
    153226
    154227  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
     228    boost::recursive_mutex::scoped_lock lock(mutex_);
     229    if(!this)
     230      return NULL;
    155231    ClientInformation *temp = this;
    156232    while(temp->next()!=0){
     
    163239
    164240  bool ClientInformation::removeClient(int clientID) {
     241    boost::recursive_mutex::scoped_lock lock(mutex_);
     242    if(!this || clientID==CLIENTID_UNKNOWN)
     243      return false;
    165244    ClientInformation *temp = this;
    166245    while(temp!=0 && temp->getID()!=clientID)
     
    173252
    174253  bool ClientInformation::removeClient(ENetPeer *peer) {
     254    boost::recursive_mutex::scoped_lock lock(mutex_);
     255    if(!this || !peer)
     256      return false;
    175257    ClientInformation *temp = this;
    176258    while(temp!=0){
    177       if(!temp->head)
     259      if(!temp->head_)
    178260        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
    179261          break;
     
    193275  */
    194276  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
    195     ClientInformation *temp = this;
    196     if (temp->head)
     277    boost::recursive_mutex::scoped_lock lock(mutex_);
     278    ClientInformation *temp = this;
     279    if (temp->head_)
    197280      temp=temp->next();
    198     //bugfix: temp to temp->next(), get last elem if not found, not segflt
    199     while(temp->next()!=0 && temp->getID()!=clientID){
     281    while(temp!=0 && temp->getID()!=clientID){
    200282      temp = temp->next();
    201283    }
     
    211293  */
    212294  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
    213     ClientInformation *temp = this;
    214     //bugfix: temp to temp->next(), get last elem if not found, not segflt
    215     while(temp->next()!=0){
    216       if(temp->head){
     295    boost::recursive_mutex::scoped_lock lock(mutex_);
     296    ClientInformation *temp = this;
     297    while(temp!=0){
     298      if(temp->head_){
    217299        temp = temp->next();
    218300        continue;
     
    226308  }
    227309
    228   void ClientInformation::setSynched(bool s) {
     310  bool ClientInformation::setSynched(bool s) {
     311    boost::recursive_mutex::scoped_lock lock(mutex_);
     312    if(!this)
     313      return false;
    229314    synched_=s;
     315    return true;
    230316  }
    231317
    232318  bool ClientInformation::getSynched() {
    233     return synched_;
     319    boost::recursive_mutex::scoped_lock lock(mutex_);
     320    if(this)
     321      return synched_;
     322    else
     323      return false;
    234324  }
    235325
Note: See TracChangeset for help on using the changeset viewer.