2020-03-29 09:16:53 +00:00
|
|
|
/*
|
|
|
|
* IRC - Internet Relay Chat, src/modules/svsnick.c
|
|
|
|
* (C) 2001 The UnrealIRCd Team
|
|
|
|
*
|
|
|
|
* svsnick command
|
|
|
|
*
|
|
|
|
* See file AUTHORS in IRC package for additional names of
|
|
|
|
* the programmers.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unrealircd.h"
|
|
|
|
|
|
|
|
CMD_FUNC(cmd_svsnick);
|
|
|
|
|
|
|
|
#define MSG_SVSNICK "SVSNICK"
|
|
|
|
|
|
|
|
ModuleHeader MOD_HEADER
|
|
|
|
= {
|
|
|
|
"svsnick",
|
|
|
|
"5.0",
|
|
|
|
"command /svsnick",
|
|
|
|
"UnrealIRCd Team",
|
2022-01-15 05:16:34 +00:00
|
|
|
"unrealircd-6",
|
2020-03-29 09:16:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MOD_INIT()
|
|
|
|
{
|
|
|
|
CommandAdd(modinfo->handle, MSG_SVSNICK, cmd_svsnick, MAXPARA, CMD_SERVER);
|
|
|
|
MARK_AS_OFFICIAL_MODULE(modinfo);
|
|
|
|
return MOD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_LOAD()
|
|
|
|
{
|
|
|
|
return MOD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_UNLOAD()
|
|
|
|
{
|
|
|
|
return MOD_SUCCESS;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
** cmd_svsnick
|
|
|
|
** parv[1] = old nickname
|
|
|
|
** parv[2] = new nickname
|
|
|
|
** parv[3] = timestamp
|
|
|
|
*/
|
|
|
|
CMD_FUNC(cmd_svsnick)
|
|
|
|
{
|
|
|
|
Client *acptr;
|
|
|
|
Client *ocptr; /* Other client */
|
|
|
|
MessageTag *mtags = NULL;
|
2022-01-15 05:16:34 +00:00
|
|
|
char nickname[NICKLEN+1];
|
|
|
|
char oldnickname[NICKLEN+1];
|
2023-05-05 22:12:01 +00:00
|
|
|
time_t ts;
|
2020-03-29 09:16:53 +00:00
|
|
|
|
2023-05-05 22:12:01 +00:00
|
|
|
if (!IsSvsCmdOk(client) || parc < 4 || (strlen(parv[2]) > NICKLEN))
|
2020-03-29 09:16:53 +00:00
|
|
|
return; /* This looks like an error anyway -Studded */
|
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
if (hunt_server(client, NULL, "SVSNICK", 1, parc, parv) != HUNTED_ISME)
|
2020-03-29 09:16:53 +00:00
|
|
|
return; /* Forwarded, done */
|
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
strlcpy(nickname, parv[2], sizeof(nickname));
|
|
|
|
if (do_nick_name(nickname) == 0)
|
2020-03-29 09:16:53 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
if (!(acptr = find_user(parv[1], NULL)))
|
2020-03-29 09:16:53 +00:00
|
|
|
return; /* User not found, bail out */
|
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
if ((ocptr = find_client(nickname, NULL)) && ocptr != acptr) /* Collision */
|
2020-03-29 09:16:53 +00:00
|
|
|
{
|
|
|
|
exit_client(acptr, NULL,
|
2023-05-05 22:12:01 +00:00
|
|
|
"Nickname collision due to forced "
|
2020-03-29 09:16:53 +00:00
|
|
|
"nickname change, your nick was overruled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the new nickname is identical to the old one, ignore it */
|
2022-01-15 05:16:34 +00:00
|
|
|
if (!strcmp(acptr->name, nickname))
|
2020-03-29 09:16:53 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
strlcpy(oldnickname, acptr->name, sizeof(oldnickname));
|
|
|
|
|
2020-03-29 09:16:53 +00:00
|
|
|
if (acptr != ocptr)
|
|
|
|
acptr->umodes &= ~UMODE_REGNICK;
|
2023-05-05 22:12:01 +00:00
|
|
|
ts = atol(parv[3]);
|
2020-03-29 09:16:53 +00:00
|
|
|
|
|
|
|
/* no 'recv_mtags' here, we do not inherit from SVSNICK but generate a new NICK event */
|
|
|
|
new_message(acptr, NULL, &mtags);
|
2023-05-05 22:12:01 +00:00
|
|
|
mtag_add_issued_by(&mtags, client, recv_mtags);
|
2022-01-15 05:16:34 +00:00
|
|
|
RunHook(HOOKTYPE_LOCAL_NICKCHANGE, acptr, mtags, nickname);
|
|
|
|
sendto_local_common_channels(acptr, acptr, 0, mtags, ":%s NICK :%s", acptr->name, nickname);
|
|
|
|
sendto_one(acptr, mtags, ":%s NICK :%s", acptr->name, nickname);
|
2023-05-05 22:12:01 +00:00
|
|
|
sendto_server(NULL, 0, 0, mtags, ":%s NICK %s :%lld", acptr->id, nickname, (long long)ts);
|
2020-03-29 09:16:53 +00:00
|
|
|
|
2023-05-05 22:12:01 +00:00
|
|
|
add_history(acptr, 1, WHOWAS_EVENT_NICK_CHANGE);
|
|
|
|
acptr->lastnick = ts; /* needs to be done AFTER add_history() */
|
2020-03-29 09:16:53 +00:00
|
|
|
del_from_client_hash_table(acptr->name, acptr);
|
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
unreal_log(ULOG_INFO, "nick", "FORCED_NICK_CHANGE", acptr,
|
2023-05-05 22:12:01 +00:00
|
|
|
"$client.details has been forced to change their nickname to $new_nick_name",
|
2022-01-15 05:16:34 +00:00
|
|
|
log_data_string("new_nick_name", nickname));
|
2020-03-29 09:16:53 +00:00
|
|
|
|
2022-01-15 05:16:34 +00:00
|
|
|
strlcpy(acptr->name, nickname, sizeof acptr->name);
|
|
|
|
add_to_client_hash_table(nickname, acptr);
|
|
|
|
RunHook(HOOKTYPE_POST_LOCAL_NICKCHANGE, acptr, mtags, oldnickname);
|
|
|
|
free_message_tags(mtags);
|
2020-03-29 09:16:53 +00:00
|
|
|
}
|