1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-04 19:03:13 +02:00
Files
unrealircd/src/modules/sethost.c
T
Bram Matthys 3126a3fae4 BIG changes internally that will break all modules and required many
code changes in UnrealIRCd itself:
1) Clients are no longer freed directly by exit_client. Most fields
   are freed, but 'sptr' itself is not, so you can use IsDead() on it.
2) exit_client now returns void rather than int
3) ALL command functions return void rather than int.
   Of course this also affects do_cmd, command overrides, etc.

This is a direct consequence of the removal of 'cptr' earlier, as that
was used to signal certain things that are now no longer possible
(and it raises the question if things were always correctly signaled
in the first place, so may fix some bugs).
It also makes the code more resillient against cases where you forgot
to check if the client was freed. Still, you are encouraged to do an
IsDead(sptr) if you are calling functions that may kill clients,
such as command functions or things that may use spamfilter.

More changes will follow, such as the removal of FLUSH_BUFFER.
2019-10-04 10:28:41 +02:00

153 lines
3.5 KiB
C

/*
* IRC - Internet Relay Chat, src/modules/sethost.c
* (C) 1999-2001 Carsten Munk (Techie/Stskeeps) <stskeeps@tspre.org>
*
* 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_sethost);
/* Place includes here */
#define MSG_SETHOST "SETHOST" /* sethost */
ModuleHeader MOD_HEADER
= {
"sethost", /* Name of module */
"5.0", /* Version */
"command /sethost", /* Short description of module */
"UnrealIRCd Team",
"unrealircd-5",
};
MOD_INIT()
{
CommandAdd(modinfo->handle, MSG_SETHOST, cmd_sethost, MAXPARA, CMD_USER);
MARK_AS_OFFICIAL_MODULE(modinfo);
return MOD_SUCCESS;
}
MOD_LOAD()
{
return MOD_SUCCESS;
}
MOD_UNLOAD()
{
return MOD_SUCCESS;
}
/*
cmd_sethost() added by Stskeeps (30/04/1999)
(modified at 15/05/1999) by Stskeeps | Potvin
:prefix SETHOST newhost
parv[1] - newhost
*/
CMD_FUNC(cmd_sethost)
{
char *vhost;
if (MyUser(sptr) && !ValidatePermissionsForPath("self:set:host",sptr,NULL,NULL,NULL))
{
sendnumeric(sptr, ERR_NOPRIVILEGES);
return;
}
if (parc < 2)
vhost = NULL;
else
vhost = parv[1];
if (BadPtr(vhost))
{
if (MyConnect(sptr))
sendnotice(sptr, "*** Syntax: /SetHost <new host>");
return;
}
if (strlen(parv[1]) > (HOSTLEN))
{
if (MyConnect(sptr))
sendnotice(sptr, "*** /SetHost Error: Hostnames are limited to %i characters.", HOSTLEN);
return;
}
if (!valid_host(vhost))
{
sendnotice(sptr, "*** /SetHost Error: A hostname may only contain a-z, A-Z, 0-9, '-' & '.'.");
return;
}
if (vhost[0] == ':')
{
sendnotice(sptr, "*** A hostname cannot start with ':'");
return;
}
if (MyUser(sptr) && !strcmp(GetHost(sptr), vhost))
{
sendnotice(sptr, "/SetHost Error: requested host is same as current host.");
return;
}
userhost_save_current(sptr);
switch (UHOST_ALLOWED)
{
case UHALLOW_NEVER:
if (MyUser(sptr))
{
sendnotice(sptr, "*** /SetHost is disabled");
return;
}
break;
case UHALLOW_ALWAYS:
break;
case UHALLOW_NOCHANS:
if (MyUser(sptr) && sptr->user->joined)
{
sendnotice(sptr, "*** /SetHost can not be used while you are on a channel");
return;
}
break;
case UHALLOW_REJOIN:
/* join sent later when the host has been changed */
break;
}
/* hide it */
sptr->umodes |= UMODE_HIDE;
sptr->umodes |= UMODE_SETHOST;
/* get it in */
safe_strdup(sptr->user->virthost, vhost);
/* spread it out */
sendto_server(sptr, 0, 0, NULL, ":%s SETHOST %s", sptr->name, parv[1]);
userhost_changed(sptr);
if (MyConnect(sptr))
{
sendto_one(sptr, NULL, ":%s MODE %s :+xt", sptr->name, sptr->name);
sendnumeric(sptr, RPL_HOSTHIDDEN, vhost);
sendnotice(sptr,
"Your nick!user@host-mask is now (%s!%s@%s) - To disable it type /mode %s -x",
sptr->name, sptr->user->username, vhost,
sptr->name);
}
}