diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-29 19:47:58 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-30 00:01:49 +0200 |
commit | fd95736bac4ef79ba36cff18d09c039a1c713f80 (patch) | |
tree | e8c201ee2b47023a05678ecf2b4f154fdf6e2ca7 /src/network/network_server.cpp | |
parent | f0e1cd01298237dc32413fb0c19e145c45baa2e8 (diff) | |
download | openttd-fd95736bac4ef79ba36cff18d09c039a1c713f80.tar.xz |
Codechange: [Network] Use std::string for server side logic of kicking and banning clients
Diffstat (limited to 'src/network/network_server.cpp')
-rw-r--r-- | src/network/network_server.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index d15263e53..b981b11a0 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -429,12 +429,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo() * @param error The error to disconnect for. * @param reason In case of kicking a client, specifies the reason for kicking the client. */ -NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, const char *reason) +NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, const std::string &reason) { Packet *p = new Packet(PACKET_SERVER_ERROR); p->Send_uint8(error); - if (reason != nullptr) p->Send_string(reason); + if (!reason.empty()) p->Send_string(reason); this->SendPacket(p); StringID strid = GetNetworkErrorMsg(error); @@ -447,7 +447,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err DEBUG(net, 1, "'%s' made an error and has been disconnected: %s", client_name, GetString(strid).c_str()); - if (error == NETWORK_ERROR_KICKED && reason != nullptr) { + if (error == NETWORK_ERROR_KICKED && !reason.empty()) { NetworkTextMessage(NETWORK_ACTION_KICKED, CC_DEFAULT, false, client_name, reason, strid); } else { NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", strid); @@ -2054,7 +2054,7 @@ void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std * @param client_id The client to kick. * @param reason In case of kicking a client, specifies the reason for kicking the client. */ -void NetworkServerKickClient(ClientID client_id, const char *reason) +void NetworkServerKickClient(ClientID client_id, const std::string &reason) { if (client_id == CLIENT_ID_SERVER) return; NetworkClientSocket::GetByClientID(client_id)->SendError(NETWORK_ERROR_KICKED, reason); @@ -2066,7 +2066,7 @@ void NetworkServerKickClient(ClientID client_id, const char *reason) * @param ban Whether to ban or kick. * @param reason In case of kicking a client, specifies the reason for kicking the client. */ -uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason) +uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason) { return NetworkServerKickOrBanIP(NetworkClientSocket::GetByClientID(client_id)->GetClientIP(), ban, reason); } @@ -2077,7 +2077,7 @@ uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason) * @param ban Whether to ban or just kick. * @param reason In case of kicking a client, specifies the reason for kicking the client. */ -uint NetworkServerKickOrBanIP(const char *ip, bool ban, const char *reason) +uint NetworkServerKickOrBanIP(const std::string &ip, bool ban, const std::string &reason) { /* Add address to ban-list */ if (ban) { @@ -2101,7 +2101,7 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban, const char *reason) for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) { if (cs->client_id == CLIENT_ID_SERVER) continue; if (cs->client_id == _redirect_console_to_client) continue; - if (cs->client_address.IsInNetmask(ip)) { + if (cs->client_address.IsInNetmask(ip.c_str())) { NetworkServerKickClient(cs->client_id, reason); n++; } |