mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-12 15:53:44 +00:00
feat(traffic): count traffic by peer and by connection
Every server now splits its packet counts by peer: its own connections (players on auth and worlds), its master link, or other servers (the worlds on chat, every server on master, a world's chat link, which is now counted too). HTTP requests carrying X-Darkflame-Server count as another server's, the dashboard counts its own requests to the UGC server, and each HTTP client address is counted. The report also gets each RakNet connection's statistics (worlds name the player on it), trimmed to the 32 busiest with the rest summed. Counting stays on the main loop, except the dashboard's UGC fetches, which only touch the locked recorder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -327,6 +327,17 @@ int main(int argc, char** argv) {
|
||||
zoneID);
|
||||
WorldMigration::SetCleanupHandler(CleanupDisconnectedUser);
|
||||
DashboardActions::SetLogoutHandler(CleanupDisconnectedUser);
|
||||
// The network page's per-connection list says which player is on a connection (main thread, with the report)
|
||||
Game::server->SetConnectionIdentity([](const SystemAddress& sysAddr, TrafficStats::Connection& connection) {
|
||||
auto* const user = UserManager::Instance()->GetUser(sysAddr);
|
||||
if (!user) return;
|
||||
connection.accountId = user->GetAccountID();
|
||||
connection.account = user->GetUsername();
|
||||
if (auto* const character = user->GetLastUsedChar()) {
|
||||
connection.characterId = static_cast<uint64_t>(character->GetObjectID());
|
||||
connection.character = character->GetName();
|
||||
}
|
||||
});
|
||||
|
||||
//Connect to the chat server:
|
||||
uint32_t chatPort = GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("chat_server_port")).value_or(1501);
|
||||
@@ -543,6 +554,7 @@ int main(int argc, char** argv) {
|
||||
//Handle our chat packets:
|
||||
packet = Game::chatServer->Receive();
|
||||
while (packet) {
|
||||
ChatServerLink::CountReceived(packet->data, packet->length);
|
||||
HandlePacketChat(packet);
|
||||
Game::chatServer->DeallocatePacket(packet);
|
||||
packet = Game::chatServer->Receive();
|
||||
@@ -1432,10 +1444,7 @@ namespace {
|
||||
if (lastChar) objectID = lastChar->GetObjectID();
|
||||
}
|
||||
|
||||
const auto routed = ToChat(objectID);
|
||||
RakNet::BitStream bitStream;
|
||||
routed.WritePacket(bitStream);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, Game::chatSysAddr, false);
|
||||
ChatServerLink::Send(ToChat(objectID), SYSTEM_PRIORITY, RELIABLE_ORDERED);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user