| 1 |
michael |
1159 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
michael |
1159 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 1999 Bahamut development team. |
| 5 |
|
|
* Copyright (c) 2011-2014 ircd-hybrid development team |
| 6 |
michael |
1159 |
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
*/ |
| 22 |
|
|
|
| 23 |
|
|
/*! \file m_svsmode.c |
| 24 |
|
|
* \brief Includes required functions for processing the SVSMODE command. |
| 25 |
michael |
1160 |
* \version $Id$ |
| 26 |
michael |
1159 |
*/ |
| 27 |
|
|
|
| 28 |
|
|
#include "stdinc.h" |
| 29 |
|
|
#include "client.h" |
| 30 |
|
|
#include "ircd.h" |
| 31 |
michael |
3347 |
#include "server.h" |
| 32 |
michael |
1159 |
#include "send.h" |
| 33 |
|
|
#include "channel_mode.h" |
| 34 |
|
|
#include "parse.h" |
| 35 |
|
|
#include "modules.h" |
| 36 |
|
|
#include "irc_string.h" |
| 37 |
michael |
3347 |
#include "user.h" |
| 38 |
michael |
1309 |
#include "conf.h" |
| 39 |
michael |
1159 |
|
| 40 |
|
|
|
| 41 |
michael |
3300 |
/*! \brief SVSMODE command handler |
| 42 |
michael |
1159 |
* |
| 43 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 44 |
|
|
* originally comes from. This can be a local or remote client. |
| 45 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 46 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 47 |
|
|
* pointers. |
| 48 |
|
|
* \note Valid arguments for this command are: |
| 49 |
michael |
3096 |
* - parv[0] = command |
| 50 |
michael |
1159 |
* - parv[1] = nickname |
| 51 |
michael |
2055 |
* - parv[2] = TS (or mode, depending on svs version) |
| 52 |
|
|
* - parv[3] = mode (or services id if old svs version) |
| 53 |
|
|
* - parv[4] = optional argument (services id) |
| 54 |
michael |
1159 |
*/ |
| 55 |
michael |
2820 |
static int |
| 56 |
michael |
3156 |
ms_svsmode(struct Client *source_p, int parc, char *parv[]) |
| 57 |
michael |
1159 |
{ |
| 58 |
|
|
struct Client *target_p = NULL; |
| 59 |
|
|
int what = MODE_ADD; |
| 60 |
michael |
2056 |
unsigned int flag = 0, setmodes = 0; |
| 61 |
michael |
3246 |
const char *modes = NULL, *extarg = NULL; |
| 62 |
michael |
1159 |
time_t ts = 0; |
| 63 |
|
|
|
| 64 |
michael |
1221 |
if (!HasFlag(source_p, FLAGS_SERVICE)) |
| 65 |
michael |
2820 |
return 0; |
| 66 |
michael |
1159 |
|
| 67 |
michael |
2055 |
if ((parc >= 4) && ((*parv[3] == '+') || (*parv[3] == '-'))) |
| 68 |
|
|
{ |
| 69 |
|
|
ts = atol(parv[2]); |
| 70 |
|
|
modes = parv[3]; |
| 71 |
|
|
extarg = (parc > 4) ? parv[4] : NULL; |
| 72 |
|
|
} |
| 73 |
|
|
else |
| 74 |
|
|
{ |
| 75 |
|
|
modes = parv[2]; |
| 76 |
|
|
extarg = (parc > 3) ? parv[3] : NULL; |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
michael |
3156 |
if ((target_p = find_person(source_p, parv[1])) == NULL) |
| 80 |
michael |
2820 |
return 0; |
| 81 |
michael |
1159 |
|
| 82 |
michael |
2055 |
if (ts && (ts != target_p->tsinfo)) |
| 83 |
michael |
2820 |
return 0; |
| 84 |
michael |
1159 |
|
| 85 |
michael |
2056 |
setmodes = target_p->umodes; |
| 86 |
michael |
1809 |
|
| 87 |
michael |
3246 |
for (const char *m = modes; *m; ++m) |
| 88 |
michael |
1159 |
{ |
| 89 |
|
|
switch (*m) |
| 90 |
|
|
{ |
| 91 |
|
|
case '+': |
| 92 |
|
|
what = MODE_ADD; |
| 93 |
|
|
break; |
| 94 |
|
|
case '-': |
| 95 |
|
|
what = MODE_DEL; |
| 96 |
|
|
break; |
| 97 |
michael |
1163 |
|
| 98 |
|
|
case 'd': |
| 99 |
michael |
2055 |
if (!EmptyString(extarg)) |
| 100 |
michael |
1559 |
strlcpy(target_p->svid, extarg, sizeof(target_p->svid)); |
| 101 |
michael |
1163 |
break; |
| 102 |
|
|
|
| 103 |
michael |
2056 |
case 'x': |
| 104 |
michael |
2137 |
if (!EmptyString(extarg) && valid_hostname(extarg)) |
| 105 |
michael |
2145 |
user_set_hostmask(target_p, extarg, what); |
| 106 |
michael |
2056 |
break; |
| 107 |
|
|
|
| 108 |
michael |
1159 |
case 'o': |
| 109 |
michael |
1219 |
if (what == MODE_DEL && HasUMode(target_p, UMODE_OPER)) |
| 110 |
michael |
1159 |
{ |
| 111 |
|
|
ClearOper(target_p); |
| 112 |
|
|
Count.oper--; |
| 113 |
|
|
|
| 114 |
|
|
if (MyConnect(target_p)) |
| 115 |
|
|
{ |
| 116 |
|
|
dlink_node *dm = NULL; |
| 117 |
|
|
|
| 118 |
michael |
1632 |
detach_conf(target_p, CONF_OPER); |
| 119 |
michael |
1219 |
ClrOFlag(target_p); |
| 120 |
michael |
1159 |
DelUMode(target_p, ConfigFileEntry.oper_only_umodes); |
| 121 |
michael |
2820 |
|
| 122 |
|
|
if ((dm = dlinkFindDelete(&oper_list, target_p))) |
| 123 |
|
|
free_dlink_node(dm); |
| 124 |
michael |
1159 |
} |
| 125 |
|
|
} |
| 126 |
|
|
|
| 127 |
|
|
break; |
| 128 |
|
|
|
| 129 |
michael |
1163 |
case 'i': |
| 130 |
|
|
if (what == MODE_ADD && !HasUMode(target_p, UMODE_INVISIBLE)) |
| 131 |
|
|
{ |
| 132 |
|
|
AddUMode(target_p, UMODE_INVISIBLE); |
| 133 |
|
|
++Count.invisi; |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
|
|
if (what == MODE_DEL && HasUMode(target_p, UMODE_INVISIBLE)) |
| 137 |
|
|
{ |
| 138 |
|
|
DelUMode(target_p, UMODE_INVISIBLE); |
| 139 |
|
|
--Count.invisi; |
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
|
break; |
| 143 |
|
|
|
| 144 |
michael |
2246 |
case 'S': /* Only servers may set +S in a burst */ |
| 145 |
michael |
2511 |
case 'W': /* Only servers may set +W in a burst */ |
| 146 |
michael |
2246 |
break; |
| 147 |
|
|
|
| 148 |
michael |
1159 |
default: |
| 149 |
|
|
if ((flag = user_modes[(unsigned char)*m])) |
| 150 |
michael |
2022 |
{ |
| 151 |
|
|
if (what == MODE_ADD) |
| 152 |
|
|
AddUMode(target_p, flag); |
| 153 |
|
|
else |
| 154 |
|
|
DelUMode(target_p, flag); |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
michael |
1159 |
break; |
| 158 |
|
|
} |
| 159 |
|
|
} |
| 160 |
|
|
|
| 161 |
|
|
if (extarg) |
| 162 |
michael |
3156 |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s SVSMODE %s %lu %s %s", |
| 163 |
michael |
3186 |
source_p->id, |
| 164 |
|
|
target_p->id, (unsigned long)target_p->tsinfo, modes, extarg); |
| 165 |
michael |
1159 |
else |
| 166 |
michael |
3156 |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s SVSMODE %s %lu %s", |
| 167 |
michael |
3186 |
source_p->id, |
| 168 |
|
|
target_p->id, (unsigned long)target_p->tsinfo, modes); |
| 169 |
michael |
1159 |
|
| 170 |
michael |
2056 |
if (MyConnect(target_p) && (setmodes != target_p->umodes)) |
| 171 |
michael |
1159 |
{ |
| 172 |
michael |
3215 |
char modebuf[IRCD_BUFSIZE] = ""; |
| 173 |
michael |
1159 |
|
| 174 |
michael |
2056 |
send_umode(target_p, target_p, setmodes, 0xffffffff, modebuf); |
| 175 |
michael |
1159 |
} |
| 176 |
michael |
2820 |
|
| 177 |
|
|
return 0; |
| 178 |
michael |
1159 |
} |
| 179 |
michael |
1230 |
|
| 180 |
michael |
2820 |
static struct Message svsmode_msgtab = |
| 181 |
|
|
{ |
| 182 |
michael |
2055 |
"SVSMODE", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
| 183 |
michael |
2820 |
{ m_ignore, m_ignore, ms_svsmode, m_ignore, m_ignore, m_ignore } |
| 184 |
michael |
1230 |
}; |
| 185 |
|
|
|
| 186 |
|
|
static void |
| 187 |
|
|
module_init(void) |
| 188 |
|
|
{ |
| 189 |
|
|
mod_add_cmd(&svsmode_msgtab); |
| 190 |
|
|
} |
| 191 |
|
|
|
| 192 |
|
|
static void |
| 193 |
|
|
module_exit(void) |
| 194 |
|
|
{ |
| 195 |
|
|
mod_del_cmd(&svsmode_msgtab); |
| 196 |
|
|
} |
| 197 |
|
|
|
| 198 |
michael |
2820 |
struct module module_entry = |
| 199 |
|
|
{ |
| 200 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
| 201 |
|
|
.name = NULL, |
| 202 |
|
|
.version = "$Revision$", |
| 203 |
|
|
.handle = NULL, |
| 204 |
|
|
.modinit = module_init, |
| 205 |
|
|
.modexit = module_exit, |
| 206 |
|
|
.flags = 0 |
| 207 |
|
|
}; |