Changeset 436 for code/branches/FICN/src/network/ClientInformation.cc
- Timestamp:
- Dec 9, 2007, 12:42:46 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/ClientInformation.cc
r432 r436 16 16 ClientInformation::ClientInformation() 17 17 { 18 gamestateID_=GAMESTATEID_INITIAL; 18 19 preve=0; 19 20 nexte=0; 21 this->head=false; 22 } 23 24 ClientInformation::ClientInformation(bool head) 25 { 26 gamestateID_=GAMESTATEID_INITIAL; 27 preve=0; 28 nexte=0; 29 this->head=head; 20 30 } 21 31 // … … 54 64 } 55 65 56 void ClientInformation::setPrev(ClientInformation *prev){ 57 this->preve = prev; 66 bool ClientInformation::setPrev(ClientInformation *prev){ 67 if(!head) 68 this->preve = prev; 69 else 70 return false; 71 return true; 58 72 } 59 73 60 voidClientInformation::setNext(ClientInformation *next){74 bool ClientInformation::setNext(ClientInformation *next){ 61 75 this->nexte = next; 76 return true; 62 77 } 63 78 64 voidClientInformation::insertAfter(ClientInformation *ins){79 ClientInformation *ClientInformation::insertAfter(ClientInformation *ins){ 65 80 this->nexte->setPrev(ins); 66 81 ins->setNext(this->nexte); 67 82 ins->setPrev(this); 68 83 this->nexte = ins; 84 return ins; 69 85 } 70 86 71 voidClientInformation::insertBefore(ClientInformation *ins){87 ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){ 72 88 this->prev()->setNext(ins); 73 89 ins->setPrev(this->preve); 74 90 this->preve=ins; 75 91 ins->setNext(this); 92 return ins; 93 } 94 95 void ClientInformation::setID(int clientID){ 96 clientID_ = clientID; 97 } 98 void ClientInformation::setPeer(ENetPeer *peer){ 99 peer_ = peer; 100 } 101 102 void ClientInformation::setGamestateID(int id){ 103 gamestateID_=id; 104 } 105 106 int ClientInformation::getID(){ 107 return clientID_; 108 } 109 ENetPeer *ClientInformation::getPeer(){ 110 return peer_; 111 } 112 113 int ClientInformation::getGamestateID(){ 114 return gamestateID_; 115 } 116 117 ClientInformation *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 127 bool 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 137 bool 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 */ 153 ClientInformation *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 */ 167 ClientInformation *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; 76 173 } 77 174
Note: See TracChangeset
for help on using the changeset viewer.