Changeset 198cf2d in network-game
- Timestamp:
- Jul 15, 2013, 12:14:43 AM (11 years ago)
- Branches:
- master
- Children:
- 3de664d
- Parents:
- 10f6fc2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/MessageProcessor.cpp
r10f6fc2 r198cf2d 2 2 3 3 #include <iostream> 4 5 #include "Common.h" 4 6 5 7 MessageProcessor::MessageProcessor() { … … 30 32 // add id to the NETWORK_MSG struct 31 33 if (msg->type == MSG_TYPE_ACK) { 32 sentMessages.erase(msg->id); 34 if (!sentMessages[msg->id].isAcked) { 35 sentMessages[msg->id].isAcked = true; 36 sentMessages[msg->id].timeAcked = getCurrentMillis(); 37 } 38 39 return -1; // don't do any further processing 33 40 }else { 34 41 NETWORK_MSG ack; … … 50 57 51 58 void MessageProcessor::cleanAckedMessages() { 52 // shouldn't be needed since I can just remove messages when I get their ACKs 59 map<int, MessageContainer>::iterator it; 60 61 for(it = sentMessages.begin(); it != sentMessages.end(); it++) { 62 if (it->second.isAcked && (getCurrentMillis() - it->second.timeAcked) > 1000) 63 sentMessages.erase(it); 64 } 53 65 } -
common/MessageProcessor.h
r10f6fc2 r198cf2d 73 73 NETWORK_MSG msg; 74 74 struct sockaddr_in clientAddr; 75 bool isAcked; 76 unsigned long long timeAcked; 75 77 }; 76 78 -
server/server.cpp
r10f6fc2 r198cf2d 149 149 timeLastUpdated = curTime; 150 150 151 msgProcessor.cleanAckedMessages(); 151 152 msgProcessor.resendUnackedMessages(sock); 152 153 … … 487 488 488 489 if (n >= 0) { 489 broadcastResponse = processMessage(clientMsg, from, m apPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed);490 broadcastResponse = processMessage(clientMsg, from, msgProcessor, mapPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed); 490 491 491 492 if (broadcastResponse)
Note:
See TracChangeset
for help on using the changeset viewer.