Changeset 1299 for code/branches/merge/src/network
- Timestamp:
- May 15, 2008, 10:08:41 PM (17 years ago)
- Location:
- code/branches/merge/src/network
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/src/network/Client.cc
r1284 r1299 120 120 isConnected=client_connection.createConnection(); 121 121 if(isConnected){ 122 COUT( 4) << "sending connectrequest" << std::endl;123 client_connection.addPacket(pck_gen.generateConnectRequest());124 client_connection.sendPackets();122 COUT(3) << "sending connectrequest" << std::endl; 123 if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets()) 124 COUT(1) << "could not create connection" << std::endl; 125 125 }else 126 126 COUT(1) << "could not create connection" << std::endl; … … 229 229 */ 230 230 void Client::tick(float time){ 231 // COUT(3) << "."; 231 232 if(client_connection.isConnected() && isSynched_){ 232 233 COUT(4) << "popping partial gamestate: " << std::endl; … … 260 261 if(!isSynched_) 261 262 isSynched_=true; 262 client_connection.addPacket(pck_gen.acknowledgement(id)); 263 if(!client_connection.addPacket(pck_gen.acknowledgement(id))) 264 return; 263 265 // we do this at the end of a tick 264 265 266 if(!client_connection.sendPackets()) 267 COUT(2) << "Could not send acknowledgment" << std::endl; 266 268 } 267 269 } -
code/branches/merge/src/network/ClientInformation.cc
r1264 r1299 121 121 122 122 ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){ 123 if(!this) 124 return NULL; 123 125 this->prev()->setNext(ins); 124 126 ins->setPrev(this->preve); … … 132 134 } 133 135 134 void ClientInformation::setPeer(ENetPeer *peer){ 136 bool ClientInformation::setPeer(ENetPeer *peer){ 137 if(!this) 138 return false; 135 139 peer_ = peer; 136 } 137 138 void ClientInformation::setGamestateID(int id){ 140 return true; 141 } 142 143 bool ClientInformation::setGamestateID(int id){ 144 if(!this) 145 return false; 139 146 gamestateID_=id; 147 return true; 140 148 } 141 149 142 150 int ClientInformation::getID() { 143 return clientID_; 151 if(!this) 152 return CLIENTID_UNKNOWN; 153 else 154 return clientID_; 144 155 } 145 156 146 157 ENetPeer *ClientInformation::getPeer() { 147 return peer_; 158 if(this) 159 return peer_; 160 else 161 return NULL; 148 162 } 149 163 150 164 int ClientInformation::getGamestateID() { 151 return gamestateID_; 165 if(this) 166 return gamestateID_; 167 else 168 return -1; 152 169 } 153 170 154 171 ClientInformation *ClientInformation::insertBack(ClientInformation *ins) { 172 if(!this) 173 return NULL; 155 174 ClientInformation *temp = this; 156 175 while(temp->next()!=0){ … … 163 182 164 183 bool ClientInformation::removeClient(int clientID) { 184 if(!this || clientID==CLIENTID_UNKNOWN) 185 return false; 165 186 ClientInformation *temp = this; 166 187 while(temp!=0 && temp->getID()!=clientID) … … 173 194 174 195 bool ClientInformation::removeClient(ENetPeer *peer) { 196 if(!this || !peer) 197 return false; 175 198 ClientInformation *temp = this; 176 199 while(temp!=0){ … … 196 219 if (temp->head) 197 220 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){ 221 while(temp!=0 && temp->getID()!=clientID){ 200 222 temp = temp->next(); 201 223 } … … 212 234 ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) { 213 235 ClientInformation *temp = this; 214 //bugfix: temp to temp->next(), get last elem if not found, not segflt 215 while(temp->next()!=0){ 236 while(temp!=0){ 216 237 if(temp->head){ 217 238 temp = temp->next(); … … 226 247 } 227 248 228 void ClientInformation::setSynched(bool s) { 249 bool ClientInformation::setSynched(bool s) { 250 if(!this) 251 return false; 229 252 synched_=s; 253 return true; 230 254 } 231 255 232 256 bool ClientInformation::getSynched() { 233 return synched_; 257 if(this) 258 return synched_; 259 else 260 return false; 234 261 } 235 262 -
code/branches/merge/src/network/ClientInformation.h
r1264 r1299 46 46 47 47 #define GAMESTATEID_INITIAL -1 48 #define CLIENTID_UNKNOWN -2 48 49 49 50 namespace network … … 70 71 // set functions 71 72 void setID(int clientID); 72 voidsetPeer(ENetPeer *peer);73 voidsetGamestateID(int id);73 bool setPeer(ENetPeer *peer); 74 bool setGamestateID(int id); 74 75 inline void setShipID(int id){ShipID_=id;} 75 76 … … 88 89 ClientInformation *findClient(ENetAddress *address, bool look_backwards=false); 89 90 90 voidsetSynched(bool s);91 bool setSynched(bool s); 91 92 bool getSynched(); 92 93 -
code/branches/merge/src/network/ConnectionManager.cc
r1282 r1299 101 101 ENetPacket *packet=getPacket(address); 102 102 ClientInformation *temp =head_->findClient(&address); 103 if(!temp) 104 return NULL; 103 105 clientID=temp->getID(); 104 106 return packet; … … 124 126 125 127 bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) { 126 if(enet_peer_send(peer, (enet_uint8)head_->findClient(&(peer->address))->getID() , packet)!=0) 128 ClientInformation *temp = head_->findClient(&(peer->address)); 129 if(!temp) 130 return false; 131 if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0) 127 132 return false; 128 133 return true; … … 130 135 131 136 bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) { 132 if(enet_peer_send(head_->findClient(clientID)->getPeer(), (enet_uint8)clientID, packet)!=0) 137 ClientInformation *temp = head_->findClient(clientID); 138 if(!temp) 139 return false; 140 if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0) 133 141 return false; 134 142 return true; … … 195 203 if(head_->findClient(&event->peer->address)) 196 204 processData(event); 205 else 206 COUT(3) << "received a packet from a client we don't know" << std::endl; 197 207 break; 198 208 case ENET_EVENT_TYPE_DISCONNECT: … … 233 243 case ENET_EVENT_TYPE_DISCONNECT: 234 244 COUT(4) << "disconnecting all clients" << std::endl; 235 delete head_->findClient(&(event.peer->address)); 245 if(head_->findClient(&(event.peer->address))) 246 delete head_->findClient(&(event.peer->address)); 236 247 //maybe needs bugfix: might also be a reason for the server to crash 237 248 temp = temp->next(); … … 259 270 bool ConnectionManager::addClient(ENetEvent *event) { 260 271 ClientInformation *temp = head_->insertBack(new ClientInformation); 272 if(!temp){ 273 COUT(2) << "Conn.Man. could not add client" << std::endl; 274 return false; 275 } 261 276 if(temp->prev()->head) { //not good if you use anything else than insertBack 262 277 temp->prev()->setID(0); //bugfix: not necessary but usefull … … 266 281 temp->setID(temp->prev()->getID()+1); 267 282 temp->setPeer(event->peer); 268 COUT( 4) << "Con.Man: added client id: " << temp->getID() << std::endl;283 COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl; 269 284 return true; 270 285 } … … 283 298 284 299 void ConnectionManager::syncClassid(int clientID) { 285 unsigned int network_id=0 ;300 unsigned int network_id=0, failures=0; 286 301 std::string classname; 287 302 orxonox::Identifier *id; … … 295 310 COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl; 296 311 297 addPacket(packet_gen.clid( (int)network_id, classname ), clientID); 298 312 while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){ 313 failures++; 314 } 299 315 ++it; 300 316 } … … 305 321 bool ConnectionManager::createClient(int clientID){ 306 322 ClientInformation *temp = head_->findClient(clientID); 323 if(!temp){ 324 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 325 return false; 326 } 307 327 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 308 328 syncClassid(temp->getID()); 309 329 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 310 330 // TODO: this is only a hack, untill we have a possibility to define default player-join actions 311 createShip(temp); 312 COUT(4) << "created spaceship" << std::endl; 331 if(!createShip(temp)) 332 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 333 else 334 COUT(3) << "created spaceship" << std::endl; 313 335 temp->setSynched(true); 314 COUT( 4) << "sending welcome" << std::endl;336 COUT(3) << "sending welcome" << std::endl; 315 337 sendWelcome(temp->getID(), temp->getShipID(), true); 316 338 return true; … … 319 341 bool ConnectionManager::removeClient(int clientID){ 320 342 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 343 ClientInformation *client = head_->findClient(clientID); 344 if(!client) 345 return false; 321 346 while(it){ 322 if(it->objectID!= head_->findClient(clientID)->getShipID()){347 if(it->objectID!=client->getShipID()){ 323 348 ++it; 324 349 continue; … … 333 358 334 359 bool ConnectionManager::createShip(ClientInformation *client){ 360 if(!client) 361 return false; 335 362 orxonox::Identifier* id = ID("SpaceShip"); 336 363 if(!id){ … … 369 396 370 397 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 371 addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID); 372 sendPackets(); 373 return true; 398 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ 399 sendPackets(); 400 return true; 401 }else 402 return false; 374 403 } 375 404 -
code/branches/merge/src/network/GameStateManager.cc
r1294 r1299 117 117 client = it->second; 118 118 GameState *server = reference; 119 //head_->findClient(clientID)->setGamestateID(id);120 119 COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << std::endl; 121 120 if(client) … … 127 126 GameState *server = reference; 128 127 // ackGameState(clientID, reference->id); 129 //head_->findClient(clientID)->setGamestateID(id);130 128 return encode(server); 131 129 // return an undiffed gamestate and set appropriate flags … … 427 425 void GameStateManager::ackGameState(int clientID, int gamestateID) { 428 426 ClientInformation *temp = head_->findClient(clientID); 429 if( !temp)427 if(temp==0) 430 428 return; 431 429 int curid = temp->getGamestateID(); … … 434 432 // deleteUnusedGameState(curid); 435 433 //increase gamestateused 436 --(gameStateUsed.find(curid)->second); 434 if(curid!=GAMESTATEID_INITIAL) 435 --(gameStateUsed.find(curid)->second); 437 436 ++(gameStateUsed.find(gamestateID)->second); 438 437 temp->setGamestateID(gamestateID); … … 460 459 461 460 void GameStateManager::removeClient(ClientInformation* client){ 462 gameStateUsed[client->getGamestateID()]--; 461 if(!client) 462 return; 463 if(client->getGamestateID()>=0) 464 gameStateUsed[client->getGamestateID()]--; 463 465 head_->removeClient(client->getID()); 464 466 } -
code/branches/merge/src/network/PacketBuffer.cc
r1264 r1299 63 63 // change this!!!!!!! 64 64 last->packet = ev->packet; 65 last->address = ev->peer->address; 65 66 //last->address = ev->peer->address; 66 67 } else { … … 72 73 // save the packet to the new element 73 74 last->packet = ev->packet; 75 last->address = ev->peer->address; 74 76 //last->address = ev->peer->address; 75 77 } -
code/branches/merge/src/network/PacketDecoder.cc
r1264 r1299 111 111 void *data = (void *)new unsigned char[length]; 112 112 memcpy(data, (void *)(packet->data+2*sizeof(int)), length); 113 enet_packet_destroy( packet ); 113 114 return true; 114 115 } -
code/branches/merge/src/network/Server.cc
r1264 r1299 117 117 ENetPacket *packet = packet_gen.chatMessage(msg.c_str()); 118 118 //std::cout <<"adding packets" << std::endl; 119 connection->addPacketAll(packet);119 if(connection->addPacketAll(packet)) 120 120 //std::cout <<"added packets" << std::endl; 121 return connection->sendPackets(); 121 return connection->sendPackets(); 122 else 123 return false; 122 124 } 123 125 … … 162 164 //clientID here is a reference to grab clientID from ClientInformation 163 165 packet = connection->getPacket(clientID); 166 if(!packet) 167 continue; 164 168 //if statement to catch case that packetbuffer is empty 165 169 if( !elaborate(packet, clientID) ) 166 COUT( 4) << "Server: PacketBuffer empty" << std::endl;170 COUT(3) << "Server: could not elaborate" << std::endl; 167 171 } 168 172 } … … 238 242 239 243 bool Server::processConnectRequest( connectRequest *con, int clientID ){ 240 COUT( 4) << "processing connectRequest " << std::endl;244 COUT(3) << "processing connectRequest " << std::endl; 241 245 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID); 242 246 connection->createClient(clientID); … … 250 254 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 251 255 else 256 if(clients->findClient(clientID)) 252 257 clients->findClient(clientID)->failures_=0; 253 258 } … … 255 260 void Server::disconnectClient(int clientID){ 256 261 ClientInformation *client = clients->findClient(clientID); 257 disconnectClient(client); 262 if(client) 263 disconnectClient(client); 258 264 } 259 265 void Server::disconnectClient( ClientInformation *client){ -
code/branches/merge/src/network/diffTest.cc
r1264 r1299 466 466 bool addClientTest( ENetEvent* event, ClientInformation*& head ) { 467 467 ClientInformation *temp = head->insertBack(new ClientInformation); 468 if(!temp) 469 return false; 468 470 if(temp->prev()->head) { 469 471 temp->prev()->setID(0); … … 475 477 std::cout << "added client id: " << temp->getID() << std::endl; 476 478 477 temp->setSynched(true); 478 return true; 479 return temp->setSynched(true); 479 480 } 480 481 481 482 void printClientInformationBox( ClientInformation* box ) { 483 if(!box) 484 return; 482 485 std::cout << "ClientList: id: " << box->getID() << "\t"; 483 486 std::cout << "g_id: " << box->getGamestateID() << " \t";
Note: See TracChangeset
for help on using the changeset viewer.