Changeset 1705 for code/branches/network/src/network/Server.cc
- Timestamp:
- Sep 4, 2008, 9:45:05 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Server.cc
r1699 r1705 45 45 46 46 #include "ConnectionManager.h" 47 #include "PacketTypes.h" 48 #include "GameStateManager.h" 47 #include "GamestateManager.h" 49 48 #include "ClientInformation.h" 50 49 #include "util/Sleep.h" … … 53 52 #include "packet/Chat.h" 54 53 #include "packet/Packet.h" 54 #include "packet/Welcome.h" 55 55 56 56 namespace network … … 65 65 Server::Server() { 66 66 timeSinceLastUpdate_=0; 67 packet_gen = PacketGenerator();68 67 connection = new ConnectionManager(); 69 gamestates = new GameStateManager();68 gamestates_ = new GamestateManager(); 70 69 } 71 70 72 71 Server::Server(int port){ 73 72 timeSinceLastUpdate_=0; 74 packet_gen = PacketGenerator();75 73 connection = new ConnectionManager(port); 76 gamestates = new GameStateManager();74 gamestates_ = new GamestateManager(); 77 75 } 78 76 … … 84 82 Server::Server(int port, std::string bindAddress) { 85 83 timeSinceLastUpdate_=0; 86 packet_gen = PacketGenerator();87 84 connection = new ConnectionManager(port, bindAddress); 88 gamestates = new GameStateManager();85 gamestates_ = new GamestateManager(); 89 86 } 90 87 … … 96 93 Server::Server(int port, const char *bindAddress) { 97 94 timeSinceLastUpdate_=0; 98 packet_gen = PacketGenerator();99 95 connection = new ConnectionManager(port, bindAddress); 100 gamestates = new GameStateManager();96 gamestates_ = new GamestateManager(); 101 97 } 102 98 … … 173 169 timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_; 174 170 // timeSinceLastUpdate_-=1./NETWORK_FREQUENCY; 175 gamestates ->processGameStates();171 gamestates_->processGamestates(); 176 172 updateGamestate(); 177 173 } … … 191 187 void Server::processQueue() { 192 188 ENetEvent *event; 193 int clientID=-1;194 189 while(!connection->queueEmpty()){ 195 190 //std::cout << "Client " << clientID << " sent: " << std::endl; … … 209 204 break; 210 205 case ENET_EVENT_TYPE_RECEIVE: 211 if(ClientInformation::findClient(&event->peer->address)){ 212 clientID = ClientInformation::findClient(&event->peer->address)->getID(); 213 if( !elaborate(event->packet, clientID) ) 214 COUT(3) << "Server: could not elaborate" << std::endl; 215 } 206 if(!processPacket(event->packet, event->peer)) 207 COUT(3) << "processing incoming packet failed" << std::endl; 216 208 break; 217 209 default: … … 227 219 */ 228 220 void Server::updateGamestate() { 229 gamestates ->update();221 gamestates_->update(); 230 222 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 231 223 //std::cout << "updated gamestate, sending it" << std::endl; … … 236 228 } 237 229 230 bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){ 231 packet::Packet p = packet::Packet(packet, peer); 232 return p.getPacketContent()->process(); 233 } 234 238 235 /** 239 236 * sends the gamestate … … 257 254 int cid = temp->getID(); //get client id 258 255 COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl; 259 GameStateCompressed *gs = gamestates->popGameState(cid);256 packet::Gamestate *gs = gamestates_->popGameState(cid); 260 257 if(gs==NULL){ 261 258 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; … … 263 260 } 264 261 //std::cout << "adding gamestate" << std::endl; 265 ENetPacket *packet = packet_gen.gstate(gs); 266 if(!packet) 267 continue; 268 if ( !(connection->addPacket(packet, cid)) ){ 262 packet::Packet packet(gs); 263 packet.setClientID(cid); 264 if ( !packet.send() ){ 269 265 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 270 266 temp->addFailure(); … … 277 273 temp=temp->next(); 278 274 // now delete gamestate 279 delete[] gs->data;280 275 delete gs; 281 276 } … … 286 281 //COUT(5) << "Server: had no gamestates to send" << std::endl; 287 282 return true; 288 }289 290 void Server::processAck( ack *data, int clientID) {291 COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;292 gamestates->ackGameState(clientID, data->a);293 delete data;294 }295 296 bool Server::processConnectRequest( connectRequest *con, int clientID ){297 //(COUT(3) << "processing connectRequest " << std::endl;298 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);299 //createClient(clientID);300 delete con;301 return true;302 }303 304 bool Server::ackGamestateID(int gamestateID, int clientID){305 gamestates->ackGameState(clientID, gamestateID);306 return true;307 }308 309 void Server::processGamestate( GameStateCompressed *data, int clientID){310 COUT(4) << "processing partial gamestate from client " << clientID << std::endl;311 gamestates->addGameState(data, clientID);312 /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;313 else314 if(clients->findClient(clientID))315 clients->findClient(clientID)->resetFailures();*/316 283 } 317 284 … … 359 326 temp->setSynched(true); 360 327 COUT(3) << "sending welcome" << std::endl; 361 connection->sendWelcome(temp->getID(), temp->getShipID(), true); 328 packet::Packet packet(new packet::Welcome(temp->getID(), temp->getShipID())); 329 assert(packet.send()); 362 330 return true; 363 331 } … … 421 389 void Server::disconnectClient( ClientInformation *client){ 422 390 connection->disconnectClient(client); 423 gamestates ->removeClient(client);391 gamestates_->removeClient(client); 424 392 } 425 393
Note: See TracChangeset
for help on using the changeset viewer.