Changeset 4dbac87 in network-game
- Timestamp:
- Jul 17, 2013, 1:48:16 AM (12 years ago)
- Branches:
- master
- Children:
- 855f153
- Parents:
- 6b641af
- Location:
- common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
common/MessageProcessor.cpp
r6b641af r4dbac87 48 48 return -1; // don't do any further processing 49 49 }else { 50 if (ret > -1) { 51 cout << "Received message" << endl; 52 cout << "id: " << msg->id << endl; 53 cout << "type: " << msg->type << endl; 54 cout << "buffer: " << msg->buffer << endl; 55 } 50 cout << "Received message" << endl; 51 cout << "id: " << msg->id << endl; 52 cout << "type: " << msg->type << endl; 53 cout << "buffer: " << msg->buffer << endl; 56 54 57 NETWORK_MSG ack; 58 ack.id = msg->id; 59 ack.type = MSG_TYPE_ACK; 55 if (ackedMessages.find(msg->id) != ackedMessages.end()) { 56 ackedMessages[msg->id] = getCurrentMillis(); 60 57 61 sendto(sock, (char*)&ack, sizeof(NETWORK_MSG), 0, (struct sockaddr *)source, sizeof(struct sockaddr_in)); 58 NETWORK_MSG ack; 59 ack.id = msg->id; 60 ack.type = MSG_TYPE_ACK; 61 62 sendto(sock, (char*)&ack, sizeof(NETWORK_MSG), 0, (struct sockaddr *)source, sizeof(struct sockaddr_in)); 63 }else 64 cout << "Got duplicate ack" << endl; 62 65 } 63 66 … … 91 94 it++; 92 95 } 96 97 map<unsigned int, unsigned long long>::iterator it2 = ackedMessages.begin(); 98 99 while (it2 != ackedMessages.end()) { 100 if ((getCurrentMillis() - it2->second) > 500) 101 ackedMessages.erase(it2++); 102 else 103 it2++; 104 } 93 105 } -
common/MessageProcessor.h
r6b641af r4dbac87 79 79 int lastUsedId; 80 80 map<int, MessageContainer> sentMessages; 81 map<unsigned int, unsigned long long> ackedMessages; 81 82 }; 82 83
Note:
See TracChangeset
for help on using the changeset viewer.