diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-14 17:33:29 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-30 10:15:22 +0200 |
commit | e58581f1f825da4d318b0b09fc12726788e95ccc (patch) | |
tree | 9d99b3939df44d3afd43fde4ac396095af5bf617 /src/network/network_admin.cpp | |
parent | 29f2bd27c44ef51f8af1299cf16012a4fa89cc61 (diff) | |
download | openttd-e58581f1f825da4d318b0b09fc12726788e95ccc.tar.xz |
Codechange: [Network] Let admin-game script use std::string
Diffstat (limited to 'src/network/network_admin.cpp')
-rw-r--r-- | src/network/network_admin.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index c58996711..82c9881bf 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -514,11 +514,9 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Pack { if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); - char json[NETWORK_GAMESCRIPT_JSON_LENGTH]; + std::string json = p->Recv_string(NETWORK_GAMESCRIPT_JSON_LENGTH); - p->Recv_string(json, sizeof(json)); - - DEBUG(net, 6, "[admin] GameScript JSON from '%s' (%s): %s", this->admin_name.c_str(), this->admin_version.c_str(), json); + DEBUG(net, 6, "[admin] GameScript JSON from '%s' (%s): %s", this->admin_name.c_str(), this->admin_version.c_str(), json.c_str()); Game::NewEvent(new ScriptEventAdminPort(json)); return NETWORK_RECV_STATUS_OKAY; @@ -561,12 +559,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const char *origi * Send GameScript JSON output. * @param json The JSON string. */ -NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const char *json) +NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::string_view json) { /* At the moment we cannot transmit anything larger than MTU. So we limit * the maximum amount of json data that can be sent. Account also for * the trailing \0 of the string */ - if (strlen(json) + 1 >= NETWORK_GAMESCRIPT_JSON_LENGTH) return NETWORK_RECV_STATUS_OKAY; + if (json.size() + 1 >= NETWORK_GAMESCRIPT_JSON_LENGTH) return NETWORK_RECV_STATUS_OKAY; Packet *p = new Packet(ADMIN_PACKET_SERVER_GAMESCRIPT); @@ -941,7 +939,7 @@ void NetworkAdminConsole(const char *origin, const char *string) * Send GameScript JSON to the admin network (if they did opt in for the respective update). * @param json The JSON data as received from the GameScript. */ -void NetworkAdminGameScript(const char *json) +void NetworkAdminGameScript(const std::string_view json) { for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) { if (as->update_frequency[ADMIN_UPDATE_GAMESCRIPT] & ADMIN_FREQUENCY_AUTOMATIC) { |