Changeset 68d94de in network-game
- Timestamp:
- Dec 24, 2013, 3:02:22 PM (11 years ago)
- Branches:
- master
- Children:
- 8554263
- Parents:
- e1af80c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
re1af80c r68d94de 130 130 131 131 MessageProcessor msgProcessor; 132 ofstream outputLog;133 132 134 133 int main(int argc, char **argv) … … 141 140 map<unsigned int, Projectile> mapProjectiles; 142 141 unsigned int curPlayerId = -1; 142 ofstream outputLog; 143 143 144 int scoreBlue, scoreRed; 144 145 … … 341 342 memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length); 342 343 server.sin_port = htons(atoi(argv[2])); 344 345 msgProcessor = MessageProcessor(sock, &outputLog); 343 346 344 347 al_start_timer(timer); … … 370 373 msgTo.type = MSG_TYPE_PICKUP_FLAG; 371 374 memcpy(msgTo.buffer, &curPlayerId, 4); 372 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);375 msgProcessor.sendMessage(&msgTo, &server); 373 376 } 374 377 break; … … 391 394 msgTo.type = MSG_TYPE_DROP_FLAG; 392 395 memcpy(msgTo.buffer, &curPlayerId, 4); 393 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);396 msgProcessor.sendMessage(&msgTo, &server); 394 397 } 395 398 } … … 414 417 memcpy(msgTo.buffer+8, &pos.y, 4); 415 418 416 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);419 msgProcessor.sendMessage(&msgTo, &server); 417 420 } 418 421 else … … 449 452 memcpy(msgTo.buffer+4, &target->id, 4); 450 453 451 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);454 msgProcessor.sendMessage(&msgTo, &server); 452 455 } 453 456 } … … 456 459 } 457 460 458 if (msgProcessor.receiveMessage(&msgFrom, sock, &from, &outputLog) >= 0)461 if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0) 459 462 processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, mapProjectiles, curPlayerId, scoreBlue, scoreRed); 460 463 … … 463 466 redraw = false; 464 467 465 msgProcessor.resendUnackedMessages(sock, &outputLog); 466 //msgProcessor.cleanAckedMessages(&outputLog); 468 msgProcessor.resendUnackedMessages(); 467 469 468 470 if (debugging && wndCurrent == wndGame) … … 981 983 strcpy(msgTo.buffer, gameName.c_str()); 982 984 983 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);985 msgProcessor.sendMessage(&msgTo, &server); 984 986 985 987 break; … … 1362 1364 memcpy(msgTo.buffer+username.size()+password.size()+2, &playerClass, 4); 1363 1365 1364 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1366 msgProcessor.sendMessage(&msgTo, &server); 1365 1367 } 1366 1368 … … 1379 1381 strcpy(msgTo.buffer+username.size()+1, strPassword.c_str()); 1380 1382 1381 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1383 msgProcessor.sendMessage(&msgTo, &server); 1382 1384 1383 1385 state = STATE_LOBBY; … … 1404 1406 strcpy(msgTo.buffer, username.c_str()); 1405 1407 1406 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1408 msgProcessor.sendMessage(&msgTo, &server); 1407 1409 } 1408 1410 … … 1420 1422 strcpy(msgTo.buffer, msg.c_str()); 1421 1423 1422 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1424 msgProcessor.sendMessage(&msgTo, &server); 1423 1425 } 1424 1426 … … 1438 1440 strcpy(msgTo.buffer, msg.c_str()); 1439 1441 1440 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1442 msgProcessor.sendMessage(&msgTo, &server); 1441 1443 } 1442 1444 … … 1453 1455 strcpy(msgTo.buffer, msg.c_str()); 1454 1456 1455 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1457 msgProcessor.sendMessage(&msgTo, &server); 1456 1458 } 1457 1459 … … 1467 1469 msgTo.type = MSG_TYPE_LEAVE_GAME; 1468 1470 1469 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);1471 msgProcessor.sendMessage(&msgTo, &server); 1470 1472 } 1471 1473 -
common/MessageProcessor.cpp
re1af80c r68d94de 13 13 14 14 MessageProcessor::MessageProcessor() { 15 this->sock = 0; 16 this->outputLog = NULL; 17 lastUsedId = 0; 18 } 19 20 MessageProcessor::MessageProcessor(int sock, ofstream* outputLog) { 21 this->sock = sock; 22 this->outputLog = outputLog; 15 23 lastUsedId = 0; 16 24 } … … 19 27 } 20 28 21 int MessageProcessor::sendMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest, ofstream* outputLog) {29 int MessageProcessor::sendMessage(NETWORK_MSG *msg, struct sockaddr_in *dest) { 22 30 cout << "Sending message of type " << msg->type << endl; 23 31 … … 35 43 } 36 44 37 int MessageProcessor::receiveMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *source, ofstream* outputLog) {45 int MessageProcessor::receiveMessage(NETWORK_MSG *msg, struct sockaddr_in *source) { 38 46 socklen_t socklen = sizeof(struct sockaddr_in); 39 47 … … 84 92 } 85 93 86 void MessageProcessor::resendUnackedMessages( int sock, ofstream* outputLog) {94 void MessageProcessor::resendUnackedMessages() { 87 95 map<unsigned int, map<unsigned long, MessageContainer> >::iterator it; 88 96 map<unsigned long, MessageContainer>::iterator it2; … … 99 107 } 100 108 101 void MessageProcessor::cleanAckedMessages( ofstream* outputLog) {109 void MessageProcessor::cleanAckedMessages() { 102 110 map<unsigned int, map<unsigned long, MessageContainer> >::iterator it = sentMessages.begin(); 103 111 map<unsigned long, MessageContainer>::iterator it2; -
common/MessageProcessor.h
re1af80c r68d94de 10 10 class MessageProcessor { 11 11 private: 12 int sock; 13 ofstream* outputLog; 12 14 int lastUsedId; 13 15 … … 18 20 map<unsigned long, map<unsigned int, unsigned long long> > ackedMessages; 19 21 20 unsigned long pid;22 //unsigned long pid; 21 23 22 24 public: 23 25 MessageProcessor(); 26 MessageProcessor(int sock, ofstream* outputLog = NULL); 24 27 ~MessageProcessor(); 25 28 26 int sendMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest, ofstream* outputLog = NULL);27 int receiveMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest, ofstream* outputLog = NULL);28 void resendUnackedMessages( int sock, ofstream* outputLog = NULL);29 void cleanAckedMessages( ofstream* outputLog = NULL);29 int sendMessage(NETWORK_MSG *msg, struct sockaddr_in *dest); 30 int receiveMessage(NETWORK_MSG *msg, struct sockaddr_in *source); 31 void resendUnackedMessages(); 32 void cleanAckedMessages(); 30 33 31 34 map<unsigned int, map<unsigned long, MessageContainer> >& getSentMessages();
Note:
See TracChangeset
for help on using the changeset viewer.