mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [Network] Use std::string for the internal handling of admin/rcon passwords
parent
6db52d52d0
commit
ebe32ad912
|
@ -664,8 +664,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
|
|||
{
|
||||
if (this->status != ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
|
||||
char password[NETWORK_PASSWORD_LENGTH];
|
||||
p->Recv_string(password, sizeof(password));
|
||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||
|
||||
if (_settings_client.network.admin_password.empty() ||
|
||||
_settings_client.network.admin_password.compare(password) != 0) {
|
||||
|
|
|
@ -516,7 +516,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit()
|
|||
* @param pass The password for the remote command.
|
||||
* @param command The actual command.
|
||||
*/
|
||||
NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const char *pass, const char *command)
|
||||
NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const std::string &pass, const char *command)
|
||||
{
|
||||
Packet *p = new Packet(PACKET_CLIENT_RCON);
|
||||
p->Send_string(pass);
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
|
||||
static NetworkRecvStatus SendSetPassword(const std::string &password);
|
||||
static NetworkRecvStatus SendSetName(const char *name);
|
||||
static NetworkRecvStatus SendRCon(const char *password, const char *command);
|
||||
static NetworkRecvStatus SendRCon(const std::string &password, const char *command);
|
||||
static NetworkRecvStatus SendMove(CompanyID company, const std::string &password);
|
||||
|
||||
static bool IsConnected();
|
||||
|
|
|
@ -1431,15 +1431,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
|||
{
|
||||
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
|
||||
char pass[NETWORK_PASSWORD_LENGTH];
|
||||
char command[NETWORK_RCONCOMMAND_LENGTH];
|
||||
|
||||
if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY;
|
||||
|
||||
p->Recv_string(pass, sizeof(pass));
|
||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||
p->Recv_string(command, sizeof(command));
|
||||
|
||||
if (_settings_client.network.rcon_password.compare(pass) != 0) {
|
||||
if (_settings_client.network.rcon_password.compare(password) != 0) {
|
||||
DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue