add $ping command

This commit is contained in:
Martin Michelsen
2023-11-10 17:58:45 -08:00
parent a0f0230700
commit 90b7f0d0c0
5 changed files with 19 additions and 1 deletions
+1
View File
@@ -271,6 +271,7 @@ Some commands only work on the game server and not on the proxy server. The chat
* Information commands
* `$li`: Shows basic information about the lobby or game you're in. If you're on the proxy server, shows information about your connection instead (remote Guild Card number, client ID, etc.).
* `$ping` (game server only): Shows round-trip ping time from the server to you.
* `$what` (game server only): Shows the type, name, and stats of the nearest item on the ground.
* `$matcount` (game server only): Shows how many of each type of material you've used.
+6
View File
@@ -159,6 +159,11 @@ static void server_command_lobby_info(shared_ptr<Client> c, const std::string&)
send_text_message(c, join(lines, "\n"));
}
static void server_command_ping(shared_ptr<Client> c, const std::string&) {
c->ping_start_time = now();
send_command(c, 0x1D, 0x00);
}
static void proxy_command_lobby_info(shared_ptr<ProxyServer::LinkedSession> ses, const std::string&) {
string msg;
// On non-masked-GC sessions (BB), there is no remote Guild Card number, so we
@@ -1598,6 +1603,7 @@ static const unordered_map<string, ChatCommandDefinition> chat_commands({
{"$password", {server_command_password, nullptr}},
{"$patch", {server_command_patch, proxy_command_patch}},
{"$persist", {server_command_persist, nullptr}},
{"$ping", {server_command_ping, nullptr}},
{"$playrec", {server_command_playrec, nullptr}},
{"$rand", {server_command_rand, proxy_command_rand}},
{"$saverec", {server_command_saverec, nullptr}},
+1
View File
@@ -147,6 +147,7 @@ Client::Client(
should_send_to_lobby_server(false),
should_send_to_proxy_server(false),
bb_connection_phase(0xFF),
ping_start_time(0),
sub_version(-1),
x(0.0f),
z(0.0f),
+1
View File
@@ -166,6 +166,7 @@ struct Client : public std::enable_shared_from_this<Client> {
std::shared_ptr<XBNetworkLocation> xb_netloc;
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
uint8_t bb_connection_phase;
uint64_t ping_start_time;
// Patch server
std::vector<PatchFileChecksumRequest> patch_file_checksum_requests;
+10 -1
View File
@@ -322,6 +322,15 @@ void on_disconnect(shared_ptr<Client> c) {
////////////////////////////////////////////////////////////////////////////////
static void on_1D(shared_ptr<Client> c, uint16_t, uint32_t, string&) {
if (c->ping_start_time) {
uint64_t ping_usecs = now() - c->ping_start_time;
c->ping_start_time = 0;
double ping_ms = static_cast<double>(ping_usecs) / 1000.0;
send_text_message_printf(c, "To server: %gms", ping_ms);
}
}
static void on_05_XB(shared_ptr<Client> c, uint16_t, uint32_t, string&) {
// The Xbox Live service doesn't close the TCP connection when the player
// chooses Quit Game, so we manually disconnect the client when they send this
@@ -4360,7 +4369,7 @@ static on_command_t handlers[0x100][6] = {
/* 1A */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 1B */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 1C */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 1D */ {nullptr, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored},
/* 1D */ {nullptr, on_1D, on_1D, on_1D, on_1D, on_1D},
/* 1E */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 1F */ {nullptr, on_1F, on_1F, nullptr, nullptr, nullptr},
// PATCH DC PC GC XB BB