diff options
author | rubidium <rubidium@openttd.org> | 2009-01-21 23:07:11 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-01-21 23:07:11 +0000 |
commit | 840217d71713862488169cbb744b4671d35325e1 (patch) | |
tree | 5d6f9b8b5093af32d97cae67f8ff82af91a50f66 /src | |
parent | a7ff5d4aaefbb4d94bb7b600b60d5e281cb39e6d (diff) | |
download | openttd-840217d71713862488169cbb744b4671d35325e1.tar.xz |
(svn r15200) -Feature: give server admins a tool to combat profanity in nick names (based on patch by dihedral)
Diffstat (limited to 'src')
-rw-r--r-- | src/console_cmds.cpp | 29 | ||||
-rw-r--r-- | src/network/network_func.h | 1 | ||||
-rw-r--r-- | src/network/network_server.cpp | 25 |
3 files changed, 55 insertions, 0 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 2d104be47..e7b262450 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -555,6 +555,33 @@ DEF_CONSOLE_CMD(ConServerInfo) return true; } +DEF_CONSOLE_CMD(ConClientNickChange) +{ + if (argc != 3) { + IConsoleHelp("Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'"); + IConsoleHelp("For client-id's, see the command 'clients'"); + return true; + } + + ClientID client_id = (ClientID)atoi(argv[1]); + + if (client_id == CLIENT_ID_SERVER) { + IConsoleError("Please use the command 'name' to change your own name!"); + return true; + } + + if (NetworkFindClientInfoFromClientID(client_id) == NULL) { + IConsoleError("Invalid client"); + return true; + } + + if (!NetworkServerChangeClientName(client_id, argv[2])) { + IConsoleError("Cannot give a client a duplicate name"); + } + + return true; +} + DEF_CONSOLE_CMD(ConKick) { NetworkClientInfo *ci; @@ -1690,6 +1717,8 @@ void IConsoleStdLibRegister() IConsoleCmdRegister("reset_company", ConResetCompany); IConsoleCmdHookAdd("reset_company", ICONSOLE_HOOK_ACCESS, ConHookServerOnly); IConsoleAliasRegister("clean_company", "reset_company %A"); + IConsoleCmdRegister("client_name", ConClientNickChange); + IConsoleCmdHookAdd("client_name", ICONSOLE_HOOK_ACCESS, ConHookServerOnly); IConsoleCmdRegister("kick", ConKick); IConsoleCmdHookAdd("kick", ICONSOLE_HOOK_ACCESS, ConHookServerOnly); IConsoleCmdRegister("ban", ConBan); diff --git a/src/network/network_func.h b/src/network/network_func.h index 043684c2b..e51ff38d7 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -50,6 +50,7 @@ void NetworkServerYearlyLoop(); void NetworkServerChangeOwner(Owner current_owner, Owner new_owner); void NetworkServerShowStatusToConsole(); bool NetworkServerStart(); +bool NetworkServerChangeClientName(ClientID client_id, const char *new_name); NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index); NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index a81ba049e..d291bb92a 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1442,6 +1442,31 @@ bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]) return found_name; } +/** + * Change the client name of the given client + * @param client_id the client to change the name of + * @param new_name the new name for the client + * @return true iff the name was changed + */ +bool NetworkServerChangeClientName(ClientID client_id, const char *new_name) +{ + NetworkClientInfo *ci; + /* Check if the name's already in use */ + FOR_ALL_CLIENT_INFOS(ci) { + if (strcmp(ci->client_name, new_name) == 0) return false; + } + + ci = NetworkFindClientInfoFromClientID(client_id); + if (ci == NULL) return false; + + NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, true, ci->client_name, new_name); + + strecpy(ci->client_name, new_name, lastof(ci->client_name)); + + NetworkUpdateClientInfo(client_id); + return true; +} + // Reads a packet from the stream bool NetworkServer_ReadPackets(NetworkClientSocket *cs) { |