1
0
Fork 0

Codechange: use std::string_view for kicking/banning

pull/14048/head
Rubidium 2025-04-20 11:23:58 +02:00 committed by rubidium42
parent a0246bc8a7
commit d99edf2bbc
3 changed files with 10 additions and 10 deletions

View File

@ -79,9 +79,9 @@ void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64_t data = 0, bool from_admin = false);
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg);
void NetworkServerKickClient(ClientID client_id, const std::string &reason);
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason);
uint NetworkServerKickOrBanIP(const std::string &ip, bool ban, const std::string &reason);
void NetworkServerKickClient(ClientID client_id, std::string_view reason);
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason);
uint NetworkServerKickOrBanIP(std::string_view ip, bool ban, std::string_view reason);
void NetworkInitChatMessage();
void NetworkReInitChatBoxSize();

View File

@ -356,7 +356,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo()
* @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 std::string &reason)
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, std::string_view reason)
{
Debug(net, 9, "client[{}] SendError(): error={}", this->client_id, error);
@ -1917,7 +1917,7 @@ static IntervalTimer<TimerGameEconomy> _economy_network_daily({TimerGameEconomy:
* Get the IP address/hostname of the connected client.
* @return The IP address.
*/
const std::string &ServerNetworkGameSocketHandler::GetClientIP()
std::string_view ServerNetworkGameSocketHandler::GetClientIP()
{
return this->client_address.GetHostname();
}
@ -2028,7 +2028,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 std::string &reason)
void NetworkServerKickClient(ClientID client_id, std::string_view reason)
{
if (client_id == CLIENT_ID_SERVER) return;
NetworkClientSocket::GetByClientID(client_id)->SendError(NETWORK_ERROR_KICKED, reason);
@ -2040,7 +2040,7 @@ void NetworkServerKickClient(ClientID client_id, const std::string &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 std::string &reason)
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason)
{
return NetworkServerKickOrBanIP(NetworkClientSocket::GetByClientID(client_id)->GetClientIP(), ban, reason);
}
@ -2051,7 +2051,7 @@ uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &r
* @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 std::string &ip, bool ban, const std::string &reason)
uint NetworkServerKickOrBanIP(std::string_view ip, bool ban, std::string_view reason)
{
/* Add address to ban-list */
if (ban) {

View File

@ -93,7 +93,7 @@ public:
NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id);
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
NetworkRecvStatus SendError(NetworkErrorCode error, const std::string &reason = {});
NetworkRecvStatus SendError(NetworkErrorCode error, std::string_view reason = {});
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const std::string &msg, int64_t data);
NetworkRecvStatus SendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg);
NetworkRecvStatus SendJoin(ClientID client_id);
@ -115,7 +115,7 @@ public:
return "server";
}
const std::string &GetClientIP();
std::string_view GetClientIP();
std::string_view GetPeerPublicKey() const { return this->peer_public_key; }
static ServerNetworkGameSocketHandler *GetByClientID(ClientID client_id);