unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

sethost.c (3618B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/sethost.c
      3  *   (C) 1999-2001 Carsten Munk (Techie/Stskeeps) <stskeeps@tspre.org>
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers. 
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 #include "unrealircd.h"
     24 
     25 CMD_FUNC(cmd_sethost);
     26 
     27 /* Place includes here */
     28 #define MSG_SETHOST 	"SETHOST"	/* sethost */
     29 
     30 ModuleHeader MOD_HEADER
     31   = {
     32 	"sethost",	/* Name of module */
     33 	"5.0", /* Version */
     34 	"command /sethost", /* Short description of module */
     35 	"UnrealIRCd Team",
     36 	"unrealircd-6",
     37     };
     38 
     39 MOD_INIT()
     40 {
     41 	CommandAdd(modinfo->handle, MSG_SETHOST, cmd_sethost, MAXPARA, CMD_USER);
     42 	MARK_AS_OFFICIAL_MODULE(modinfo);
     43 	return MOD_SUCCESS;
     44 }
     45 
     46 MOD_LOAD()
     47 {
     48 	return MOD_SUCCESS;
     49 }
     50 
     51 MOD_UNLOAD()
     52 {
     53 	return MOD_SUCCESS;
     54 }
     55 
     56 /*
     57    cmd_sethost() added by Stskeeps (30/04/1999)
     58                (modified at 15/05/1999) by Stskeeps | Potvin
     59    :prefix SETHOST newhost
     60    parv[1] - newhost
     61 */
     62 CMD_FUNC(cmd_sethost)
     63 {
     64 	const char *vhost;
     65 
     66 	if (MyUser(client) && !ValidatePermissionsForPath("self:set:host",client,NULL,NULL,NULL))
     67 	{
     68   		sendnumeric(client, ERR_NOPRIVILEGES);
     69 		return;
     70 	}
     71 
     72 	if (parc < 2)
     73 		vhost = NULL;
     74 	else
     75 		vhost = parv[1];
     76 
     77 	if (BadPtr(vhost))
     78 	{	
     79 		if (MyConnect(client))
     80 			sendnotice(client, "*** Syntax: /SetHost <new host>");
     81 		return;
     82 	}
     83 
     84 	if (strlen(parv[1]) > (HOSTLEN))
     85 	{
     86 		if (MyConnect(client))
     87 			sendnotice(client, "*** /SetHost Error: Hostnames are limited to %i characters.", HOSTLEN);
     88 		return;
     89 	}
     90 
     91 	if (!valid_host(vhost, 0))
     92 	{
     93 		sendnotice(client, "*** /SetHost Error: A hostname may only contain a-z, A-Z, 0-9, '-' & '.'.");
     94 		return;
     95 	}
     96 	if (vhost[0] == ':')
     97 	{
     98 		sendnotice(client, "*** A hostname cannot start with ':'");
     99 		return;
    100 	}
    101 
    102 	if (MyUser(client) && !strcmp(GetHost(client), vhost))
    103 	{
    104 		sendnotice(client, "/SetHost Error: requested host is same as current host.");
    105 		return;
    106 	}
    107 
    108 	userhost_save_current(client);
    109 
    110 	switch (UHOST_ALLOWED)
    111 	{
    112 		case UHALLOW_NEVER:
    113 			if (MyUser(client))
    114 			{
    115 				sendnotice(client, "*** /SetHost is disabled");
    116 				return;
    117 			}
    118 			break;
    119 		case UHALLOW_ALWAYS:
    120 			break;
    121 		case UHALLOW_NOCHANS:
    122 			if (MyUser(client) && client->user->joined)
    123 			{
    124 				sendnotice(client, "*** /SetHost can not be used while you are on a channel");
    125 				return;
    126 			}
    127 			break;
    128 		case UHALLOW_REJOIN:
    129 			/* join sent later when the host has been changed */
    130 			break;
    131 	}
    132 
    133 	/* hide it */
    134 	client->umodes |= UMODE_HIDE;
    135 	client->umodes |= UMODE_SETHOST;
    136 	/* get it in */
    137 	safe_strdup(client->user->virthost, vhost);
    138 	/* spread it out */
    139 	sendto_server(client, 0, 0, NULL, ":%s SETHOST %s", client->id, parv[1]);
    140 
    141 	userhost_changed(client);
    142 
    143 	if (MyConnect(client))
    144 	{
    145 		sendto_one(client, NULL, ":%s MODE %s :+xt", client->name, client->name);
    146 		sendnotice(client, 
    147 		    "Your nick!user@host-mask is now (%s!%s@%s) - To disable it type /mode %s -x",
    148 		     client->name, client->user->username, vhost,
    149 		    client->name);
    150 	}
    151 }