Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 9, 2007, 12:42:46 PM (16 years ago)
Author:
scheusso
Message:

extended gamestatehandling for diffed and not diffed gamestates (initial states, etc)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/ClientInformation.cc

    r432 r436  
    1616ClientInformation::ClientInformation()
    1717{
     18  gamestateID_=GAMESTATEID_INITIAL;
    1819  preve=0;
    1920  nexte=0;
     21  this->head=false;
     22}
     23
     24ClientInformation::ClientInformation(bool head)
     25{
     26  gamestateID_=GAMESTATEID_INITIAL;
     27  preve=0;
     28  nexte=0;
     29  this->head=head;
    2030}
    2131//
     
    5464}
    5565
    56 void ClientInformation::setPrev(ClientInformation *prev){
    57   this->preve = prev;
     66bool ClientInformation::setPrev(ClientInformation *prev){
     67  if(!head)
     68    this->preve = prev;
     69  else
     70    return false;
     71  return true;
    5872}
    5973
    60 void ClientInformation::setNext(ClientInformation *next){
     74bool ClientInformation::setNext(ClientInformation *next){
    6175  this->nexte = next;
     76  return true;
    6277}
    6378
    64 void ClientInformation::insertAfter(ClientInformation *ins){
     79ClientInformation *ClientInformation::insertAfter(ClientInformation *ins){
    6580  this->nexte->setPrev(ins);
    6681  ins->setNext(this->nexte);
    6782  ins->setPrev(this);
    6883  this->nexte = ins;
     84  return ins;
    6985}
    7086
    71 void ClientInformation::insertBefore(ClientInformation *ins){
     87ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
    7288  this->prev()->setNext(ins);
    7389  ins->setPrev(this->preve);
    7490  this->preve=ins;
    7591  ins->setNext(this);
     92  return ins;
     93}
     94
     95void ClientInformation::setID(int clientID){
     96  clientID_ = clientID;
     97}
     98void ClientInformation::setPeer(ENetPeer *peer){
     99  peer_ = peer;
     100}
     101
     102void ClientInformation::setGamestateID(int id){
     103  gamestateID_=id;
     104}
     105
     106int ClientInformation::getID(){
     107  return clientID_;
     108}
     109ENetPeer *ClientInformation::getPeer(){
     110  return peer_;
     111}
     112
     113int ClientInformation::getGamestateID(){
     114  return gamestateID_;
     115}
     116
     117ClientInformation *ClientInformation::insertBack(ClientInformation *ins){
     118  ClientInformation *temp = this;
     119  while(temp->next()!=0){
     120    temp = temp->next();
     121  }
     122  temp->setNext(ins);
     123  ins->setPrev(temp);
     124  return ins;
     125}
     126
     127bool ClientInformation::removeClient(int clientID){
     128  ClientInformation *temp = this;
     129  while(temp!=0 && temp->getID()!=clientID)
     130    temp = temp->next();
     131  if(temp==0)
     132    return false;
     133  delete temp;
     134  return true;
     135}
     136
     137bool ClientInformation::removeClient(ENetPeer *peer){
     138  ClientInformation *temp = this;
     139  while(temp!=0 && (temp->getPeer()->address.host!=peer->address.host || temp->getPeer()->address.port!=peer->address.port))
     140    temp = temp->next();
     141  if(temp==0)
     142    return false;
     143  delete temp;
     144  return true;
     145}
     146
     147/**
     148 * This function goes forward through the list and looks for an element with clientID
     149 * This function should only be applied to the head of the list
     150 * @param clientID id to look for
     151 * @return pointer to the element in the list or 0 if the search was unsuccessfull
     152 */
     153ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards){
     154  ClientInformation *temp = this;
     155  while(temp!=0 && temp->getID()!=clientID)
     156    temp = temp->next();
     157  // returns 0 if nothing has been found
     158  return temp;
     159}
     160
     161/**
     162 * This function goes forward through the list and looks for an element with clientID
     163 * This function should only be applied to the head of the list
     164 * @param peer peer to look for
     165 * @return pointer to the element in the list
     166 */
     167ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards){
     168  ClientInformation *temp = this;
     169  while(temp!=0 && (temp->getPeer()->address.host!=address->host || temp->getPeer()->address.port != address->port))
     170    temp = temp->next();
     171  // returns 0 if nothing has been found
     172  return temp;
    76173}
    77174
Note: See TracChangeset for help on using the changeset viewer.