Skip to content

Commit c8f4533

Browse files
committed
fix: rate limit locators
and send relevant packets only to clients on the same map
1 parent f725fbd commit c8f4533

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

GhostServer/networkmanager.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ void NetworkManager::ReceiveUDPUpdates(std::vector<std::tuple<sf::Packet, sf::Ip
369369
} \
370370
}
371371

372+
#define SEND_TO_OTHERS_MAP(packet) \
373+
for (auto& other : this->clients) \
374+
if (other.ID != ID && other.currentMap == client->currentMap) { \
375+
other.tcpSocket->send(packet); \
376+
} \
377+
372378
#define BROADCAST(packet) \
373379
for (auto& other : this->clients) { \
374380
other.tcpSocket->send(packet); \
@@ -461,15 +467,21 @@ void NetworkManager::Treat(sf::Packet& packet, sf::IpAddress ip, unsigned short
461467
break;
462468
}
463469
case HEADER::TAUNT: {
464-
SEND_TO_OTHERS(packet);
470+
SEND_TO_OTHERS_MAP(packet);
465471
break;
466472
}
467473
case HEADER::LOCATOR: {
468-
SEND_TO_OTHERS(packet);
474+
if (client->lastLocator.time_since_epoch().count() != 0 &&
475+
std::chrono::steady_clock::now() - client->lastLocator < std::chrono::milliseconds(100)) {
476+
// Rate limit locators to 10Hz
477+
break;
478+
}
479+
client->lastLocator = std::chrono::steady_clock::now();
480+
SEND_TO_OTHERS_MAP(packet);
469481
break;
470482
}
471483
case HEADER::VOICE: {
472-
SEND_TO_OTHERS(packet);
484+
SEND_TO_OTHERS_MAP(packet);
473485
break;
474486
}
475487
default:

GhostServer/networkmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct Client {
6565
bool returnedHeartbeat;
6666
bool missedLastHeartbeat;
6767
bool spectator;
68+
std::chrono::time_point<std::chrono::steady_clock> lastLocator;
6869
};
6970

7071
enum class WhitelistEntryType {

0 commit comments

Comments
 (0)