Index: src/console_cmds.cpp =================================================================== --- src/console_cmds.cpp (revision 15193) +++ src/console_cmds.cpp (working copy) @@ -370,7 +370,6 @@ // * Network Core Console Commands * // // ********************************* // #ifdef ENABLE_NETWORK - DEF_CONSOLE_CMD(ConBan) { NetworkClientInfo *ci; @@ -555,6 +554,40 @@ return true; } +DEF_CONSOLE_CMD(ConClientNickChange) +{ + NetworkClientInfo *ci; + ClientID client_id; + char new_name[NETWORK_CLIENT_NAME_LENGTH]; + + if (argc == 0) { + IConsoleHelp("Change the nickname of a connected client. Usage: 'client_name '"); + IConsoleHelp("For client-id's, see the command 'clients'"); + return true; + } + + 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; + } + + ci = NetworkFindClientInfoFromClientID(client_id); + + if (ci == NULL) { + IConsoleError("Client not found"); + return true; + } + + strecpy(new_name, argv[2], lastof(argv[2])); + if (!NetworkServerChangeClientName(client_id, argv[2])) { + IConsoleError("Cannot use new name"); + } + + return true; +} + DEF_CONSOLE_CMD(ConKick) { NetworkClientInfo *ci; @@ -1690,6 +1723,8 @@ 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); Index: src/network/network_func.h =================================================================== --- src/network/network_func.h (revision 15193) +++ src/network/network_func.h (working copy) @@ -50,6 +50,7 @@ void NetworkServerChangeOwner(Owner current_owner, Owner new_owner); void NetworkServerShowStatusToConsole(); bool NetworkServerStart(); +bool NetworkServerChangeClientName(ClientID client_id, char new_name[NETWORK_CLIENT_NAME_LENGTH]); NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index); NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id); Index: src/network/network_server.cpp =================================================================== --- src/network/network_server.cpp (revision 15193) +++ src/network/network_server.cpp (working copy) @@ -1442,6 +1442,22 @@ return found_name; } +bool NetworkServerChangeClientName(ClientID client_id, char new_name[NETWORK_CLIENT_NAME_LENGTH]) +{ + NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + + if (!NetworkFindName(new_name)) { + return false; + } + + NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, true, ci->client_name, new_name); + + strecpy(ci->client_name, new_name, lastof(new_name)); + + NetworkUpdateClientInfo(client_id); + return true; +} + // Reads a packet from the stream bool NetworkServer_ReadPackets(NetworkClientSocket *cs) {