1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 13:43:12 +02:00
Files
unrealircd/src/modules/m_sethost.c
T
Bram Matthys ad9d0370fa Added remove-chanmode-after-X-minutes in +f & checks for /sethost&/chghost to same host.
- Added checks for /sethost&/chghost to same host.
- Added remove-chanmode-after-X-minutes in +f.
  The format is +f [30j#R5]:15, where 5 is the "do -R after 5 minutes". For a default
  action like +i you would have to do the same: +f [30j#i5]:15 (remove 'i' after 5 minutes).
  Additionally, 2 config items are added:
  - set::modef-default-unsettime, if this is set to for example '5' then things like
    +f [30j]:15 will be transormed into +f [30j#i5]:15. It's just a default, the user can still
    override it. By default this feature is not used.
  - set::modef-max-unsettime, specifies the maximum amount of time for the <time> parameter,
    by default this is set to 60 (=1 hour), the value should be between 0 and 255.
  I didn't do the extended tests I usually do but it seems stable, also the docs are updated
  but are probably updated again later to make it a bit more readable.
  Feel free to report any bugs as soon as you discover them.
  The only thing I could think of is: _usually_ only 1 server will have the -i/-R/.. timer
  running, so if that server splits (or even worse dies) it will only be -i/-R/.. at that server
  and when they sync back they merge chanmodes so +i/+R is set again.
  I don't consider this a huge problem but maybe it can be inconveniently, if people have
  a lot of trouble with this I'll have to consider a 50% recode of the +f system :/.
2003-10-18 18:44:54 +00:00

252 lines
5.8 KiB
C

/*
* IRC - Internet Relay Chat, src/modules/m_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 "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#include "proto.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif
DLLFUNC int m_sethost(aClient *cptr, aClient *sptr, int parc, char *parv[]);
/* Place includes here */
#define MSG_SETHOST "SETHOST" /* sethost */
#define TOK_SETHOST "AA" /* 127 4ever !;) */
ModuleHeader MOD_HEADER(m_sethost)
= {
"sethost", /* Name of module */
"$Id$", /* Version */
"command /sethost", /* Short description of module */
"3.2-b8-1",
NULL
};
DLLFUNC int MOD_INIT(m_sethost)(ModuleInfo *modinfo)
{
/*
* We call our add_Command crap here
*/
add_Command(MSG_SETHOST, TOK_SETHOST, m_sethost, MAXPARA);
return MOD_SUCCESS;
}
DLLFUNC int MOD_LOAD(m_sethost)(int module_load)
{
return MOD_SUCCESS;
}
DLLFUNC int MOD_UNLOAD(m_sethost)(int module_unload)
{
if (del_Command(MSG_SETHOST, TOK_SETHOST, m_sethost) < 0)
{
sendto_realops("Failed to delete commands when unloading %s",
MOD_HEADER(m_sethost).name);
}
return MOD_SUCCESS;
}
/*
m_sethost() added by Stskeeps (30/04/1999)
(modified at 15/05/1999) by Stskeeps | Potvin
:prefix SETHOST newhost
parv[0] - sender
parv[1] - newhost
*/
DLLFUNC int m_sethost(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
char *vhost, *s;
#ifndef DISABLE_USERMOD
int permit = 0; /* 0 = opers(glob/locop) 1 = global oper 2 = not MY clients.. */
#else
int permit = 2;
#endif
int legalhost = 1; /* is legal characters? */
if (!MyConnect(sptr))
goto have_permit1;
switch (permit)
{
case 0:
if (!IsAnOper(sptr))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
parv[0]);
return 0;
}
break;
case 1:
if (!IsOper(sptr))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
parv[0]);
return 0;
}
break;
case 2:
if (MyConnect(sptr))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
parv[0]);
return 0;
}
default:
sendto_ops_butone(IsServer(cptr) ? cptr : NULL, sptr,
":%s WALLOPS :[SETHOST] Somebody fixing this corrupted server? !(0|1) !!!",
me.name);
break;
}
have_permit1:
if (parc < 2)
vhost = NULL;
else
vhost = parv[1];
/* bad bad bad boys .. ;p */
if (vhost == NULL)
{
if (MyConnect(sptr))
{
sendto_one(sptr,
":%s NOTICE %s :*** Syntax: /SetHost <new host>",
me.name, parv[0]);
}
return 0;
}
if (strlen(parv[1]) < 1)
{
if (MyConnect(sptr))
sendto_one(sptr,
":%s NOTICE %s :*** /SetHost Error: Atleast write SOMETHING that makes sense (':' string)",
me.name, sptr->name);
return 0;
}
/* too large huh? */
if (strlen(parv[1]) > (HOSTLEN))
{
/* ignore us as well if we're not a child of 3k */
if (MyConnect(sptr))
sendto_one(sptr,
":%s NOTICE %s :*** /SetHost Error: Hostnames are limited to %i characters.",
me.name, sptr->name, HOSTLEN);
return 0;
}
/* illegal?! */
for (s = vhost; *s; s++)
{
if (!isallowed(*s) && !(*s == ':'))
{
legalhost = 0;
}
}
if (legalhost == 0)
{
sendto_one(sptr,
":%s NOTICE %s :*** /SetHost Error: A hostname may contain a-z, A-Z, 0-9, '-' & '.' - Please only use them",
me.name, parv[0]);
return 0;
}
if (!strcmp(GetHost(sptr), vhost))
{
sendto_one(sptr,
":%s NOTICE %s :*** /SetHost Error: requested host is same as current host.",
me.name, parv[0]);
return 0;
}
/* uh uh .. too small */
switch (UHOST_ALLOWED)
{
case UHALLOW_NEVER:
if (MyClient(sptr))
{
sendto_one(sptr, ":%s NOTICE %s :*** /SetHost is disabled", me.name, sptr->name);
return 0;
}
break;
case UHALLOW_ALWAYS:
break;
case UHALLOW_NOCHANS:
if (MyClient(sptr) && sptr->user->joined)
{
sendto_one(sptr, ":%s NOTICE %s :*** /SetHost can not be used while you are on a channel", me.name, sptr->name);
return 0;
}
break;
case UHALLOW_REJOIN:
rejoin_doparts(sptr);
/* join sent later when the host has been changed */
break;
}
/* hide it */
sptr->umodes |= UMODE_HIDE;
sptr->umodes |= UMODE_SETHOST;
/* get it in */
if (sptr->user->virthost)
{
MyFree(sptr->user->virthost);
sptr->user->virthost = NULL;
}
sptr->user->virthost = strdup(vhost);
/* spread it out */
sendto_serv_butone_token(cptr, sptr->name, MSG_SETHOST, TOK_SETHOST,
"%s", parv[1]);
if (UHOST_ALLOWED == UHALLOW_REJOIN)
rejoin_dojoinandmode(sptr);
if (MyConnect(sptr))
{
sendto_one(sptr, ":%s MODE %s :+xt", sptr->name, sptr->name);
sendto_one(sptr,
":%s NOTICE %s :Your nick!user@host-mask is now (%s!%s@%s) - To disable it type /mode %s -x",
me.name, parv[0], parv[0], sptr->user->username, vhost,
parv[0]);
}
return 0;
}