[5ebff60] | 1 | /********************************************************************\ |
---|
[0298d11] | 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[0e788f5] | 4 | * Copyright 2002-2012 Wilmer van der Gaast and others * |
---|
[0298d11] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* IRC commands */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
[6f10697] | 22 | if not, write to the Free Software Foundation, Inc., 51 Franklin St., |
---|
| 23 | Fifth Floor, Boston, MA 02110-1301 USA |
---|
[0298d11] | 24 | */ |
---|
| 25 | |
---|
| 26 | #define BITLBEE_CORE |
---|
| 27 | #include "bitlbee.h" |
---|
[674a01d] | 28 | #include "help.h" |
---|
[0431ea1] | 29 | #include "ipc.h" |
---|
[58b63de6] | 30 | #include "base64.h" |
---|
[0298d11] | 31 | |
---|
[5ebff60] | 32 | static void irc_cmd_pass(irc_t *irc, char **cmd) |
---|
[0298d11] | 33 | { |
---|
[5ebff60] | 34 | if (irc->status & USTATUS_LOGGED_IN) { |
---|
[a199d33] | 35 | char *send_cmd[] = { "identify", cmd[1], NULL }; |
---|
[5ebff60] | 36 | |
---|
[a199d33] | 37 | /* We're already logged in, this client seems to send the PASS |
---|
| 38 | command last. (Possibly it won't send it at all if it turns |
---|
| 39 | out we don't require it, which will break this feature.) |
---|
| 40 | Try to identify using the given password. */ |
---|
[5ebff60] | 41 | root_command(irc, send_cmd); |
---|
[daae10f] | 42 | return; |
---|
[a199d33] | 43 | } |
---|
| 44 | /* Handling in pre-logged-in state, first see if this server is |
---|
| 45 | password-protected: */ |
---|
[5ebff60] | 46 | else if (global.conf->auth_pass && |
---|
| 47 | (strncmp(global.conf->auth_pass, "md5:", 4) == 0 ? |
---|
| 48 | md5_verify_password(cmd[1], global.conf->auth_pass + 4) == 0 : |
---|
| 49 | strcmp(cmd[1], global.conf->auth_pass) == 0)) { |
---|
[79e826a] | 50 | irc->status |= USTATUS_AUTHORIZED; |
---|
[5ebff60] | 51 | irc_check_login(irc); |
---|
| 52 | } else if (global.conf->auth_pass) { |
---|
| 53 | irc_send_num(irc, 464, ":Incorrect password"); |
---|
| 54 | } else { |
---|
[a199d33] | 55 | /* Remember the password and try to identify after USER/NICK. */ |
---|
[5ebff60] | 56 | irc_setpass(irc, cmd[1]); |
---|
| 57 | irc_check_login(irc); |
---|
[a199d33] | 58 | } |
---|
[0298d11] | 59 | } |
---|
| 60 | |
---|
[58b63de6] | 61 | static gboolean irc_sasl_plain_parse(char *input, char **user, char **pass) |
---|
| 62 | { |
---|
| 63 | int i, part, len; |
---|
| 64 | guint8 *decoded; |
---|
[c4e61db] | 65 | char *parts[3]; |
---|
[58b63de6] | 66 | |
---|
| 67 | /* bitlbee's base64_decode wrapper adds an extra null terminator at the end */ |
---|
| 68 | len = base64_decode(input, &decoded); |
---|
| 69 | |
---|
| 70 | /* this loop splits the decoded string into the parts array, like this: |
---|
| 71 | "username\0username\0password" -> {"username", "username", "password"} */ |
---|
| 72 | |
---|
| 73 | for (i = 0, part = 0; i < len && part < 3; part++) { |
---|
| 74 | /* set each of parts[] to point to the beginning of a string */ |
---|
| 75 | parts[part] = (char *) decoded + i; |
---|
| 76 | |
---|
| 77 | /* move the cursor forward to the next null terminator*/ |
---|
| 78 | i += strlen(parts[part]) + 1; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /* sanity checks */ |
---|
[c788e15] | 82 | if (part != 3 || i != (len + 1) || (parts[0][0] && strcmp(parts[0], parts[1]) != 0)) { |
---|
[58b63de6] | 83 | g_free(decoded); |
---|
| 84 | return FALSE; |
---|
| 85 | } else { |
---|
[c788e15] | 86 | *user = g_strdup(parts[1]); |
---|
[58b63de6] | 87 | *pass = g_strdup(parts[2]); |
---|
| 88 | g_free(decoded); |
---|
| 89 | return TRUE; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | static gboolean irc_sasl_check_pass(irc_t *irc, char *user, char *pass) |
---|
| 94 | { |
---|
| 95 | storage_status_t status; |
---|
| 96 | |
---|
| 97 | /* just check the password here to be able to reply with useful numerics |
---|
| 98 | * the actual identification will be handled later */ |
---|
[8e6ecfe] | 99 | status = auth_check_pass(irc, user, pass); |
---|
[58b63de6] | 100 | |
---|
| 101 | if (status == STORAGE_OK) { |
---|
| 102 | if (!irc->user->nick) { |
---|
| 103 | /* set the nick here so we have it for the following numeric */ |
---|
| 104 | irc->user->nick = g_strdup(user); |
---|
| 105 | } |
---|
| 106 | irc_send_num(irc, 903, ":Password accepted"); |
---|
| 107 | return TRUE; |
---|
| 108 | |
---|
| 109 | } else if (status == STORAGE_INVALID_PASSWORD) { |
---|
| 110 | irc_send_num(irc, 904, ":Incorrect password"); |
---|
| 111 | } else if (status == STORAGE_NO_SUCH_USER) { |
---|
| 112 | irc_send_num(irc, 904, ":The nick is (probably) not registered"); |
---|
| 113 | } else { |
---|
| 114 | irc_send_num(irc, 904, ":Unknown SASL authentication error"); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return FALSE; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | static void irc_cmd_authenticate(irc_t *irc, char **cmd) |
---|
| 121 | { |
---|
| 122 | /* require the CAP to be enabled, and don't allow authentication before server password */ |
---|
| 123 | if (!(irc->caps & CAP_SASL) || |
---|
| 124 | (global.conf->authmode == AUTHMODE_CLOSED && !(irc->status & USTATUS_AUTHORIZED))) { |
---|
| 125 | return; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | if (irc->status & USTATUS_SASL_PLAIN_PENDING) { |
---|
| 129 | char *user, *pass; |
---|
| 130 | |
---|
| 131 | irc->status &= ~USTATUS_SASL_PLAIN_PENDING; |
---|
| 132 | |
---|
| 133 | if (!irc_sasl_plain_parse(cmd[1], &user, &pass)) { |
---|
| 134 | irc_send_num(irc, 904, ":SASL authentication failed"); |
---|
| 135 | return; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /* let's not support the nick != user case |
---|
| 139 | * if NICK is received after SASL, it will just fail after registration */ |
---|
| 140 | if (user && irc->user->nick && strcmp(user, irc->user->nick) != 0) { |
---|
| 141 | irc_send_num(irc, 902, ":Your SASL username does not match your nickname"); |
---|
| 142 | |
---|
| 143 | } else if (irc_sasl_check_pass(irc, user, pass)) { |
---|
| 144 | /* and here we do the same thing as the PASS command*/ |
---|
| 145 | if (irc->status & USTATUS_LOGGED_IN) { |
---|
| 146 | char *send_cmd[] = { "identify", pass, NULL }; |
---|
| 147 | root_command(irc, send_cmd); |
---|
| 148 | } else { |
---|
| 149 | /* no check_login here - wait for CAP END */ |
---|
| 150 | irc_setpass(irc, pass); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | g_free(user); |
---|
| 155 | g_free(pass); |
---|
| 156 | |
---|
| 157 | } else if (irc->status & USTATUS_IDENTIFIED) { |
---|
| 158 | irc_send_num(irc, 907, ":You have already authenticated"); |
---|
| 159 | |
---|
| 160 | } else if (strcmp(cmd[1], "*") == 0) { |
---|
| 161 | irc_send_num(irc, 906, ":SASL authentication aborted"); |
---|
| 162 | irc->status &= ~USTATUS_SASL_PLAIN_PENDING; |
---|
| 163 | |
---|
| 164 | } else if (g_strcasecmp(cmd[1], "PLAIN") == 0) { |
---|
| 165 | irc_write(irc, "AUTHENTICATE +"); |
---|
| 166 | irc->status |= USTATUS_SASL_PLAIN_PENDING; |
---|
| 167 | |
---|
| 168 | } else { |
---|
| 169 | irc_send_num(irc, 908, "PLAIN :is the available SASL mechanism"); |
---|
| 170 | irc_send_num(irc, 904, ":SASL authentication failed"); |
---|
| 171 | irc->status &= ~USTATUS_SASL_PLAIN_PENDING; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
[5ebff60] | 175 | static void irc_cmd_user(irc_t *irc, char **cmd) |
---|
[0298d11] | 176 | { |
---|
[5ebff60] | 177 | irc->user->user = g_strdup(cmd[1]); |
---|
| 178 | irc->user->fullname = g_strdup(cmd[4]); |
---|
| 179 | |
---|
| 180 | irc_check_login(irc); |
---|
[0298d11] | 181 | } |
---|
| 182 | |
---|
[5ebff60] | 183 | static void irc_cmd_nick(irc_t *irc, char **cmd) |
---|
[0298d11] | 184 | { |
---|
[9a9b520] | 185 | irc_user_t *iu; |
---|
[5ebff60] | 186 | |
---|
| 187 | if ((iu = irc_user_by_name(irc, cmd[1])) && iu != irc->user) { |
---|
| 188 | irc_send_num(irc, 433, "%s :This nick is already in use", cmd[1]); |
---|
| 189 | } else if (!nick_ok(NULL, cmd[1])) { |
---|
[0298d11] | 190 | /* [SH] Invalid characters. */ |
---|
[5ebff60] | 191 | irc_send_num(irc, 432, "%s :This nick contains invalid characters", cmd[1]); |
---|
| 192 | } else if (irc->status & USTATUS_LOGGED_IN) { |
---|
[3558fea] | 193 | /* WATCH OUT: iu from the first if reused here to check if the |
---|
| 194 | new nickname is the same (other than case, possibly). If it |
---|
| 195 | is, no need to reset identify-status. */ |
---|
[5ebff60] | 196 | if ((irc->status & USTATUS_IDENTIFIED) && iu != irc->user) { |
---|
| 197 | irc_setpass(irc, NULL); |
---|
[ffa1173] | 198 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[5ebff60] | 199 | irc_umode_set(irc, "-R", 1); |
---|
[58b63de6] | 200 | |
---|
| 201 | if (irc->caps & CAP_SASL) { |
---|
| 202 | irc_send_num(irc, 901, "%s!%s@%s :You are now logged out", |
---|
| 203 | irc->user->nick, irc->user->user, irc->user->host); |
---|
| 204 | } |
---|
| 205 | |
---|
[5ebff60] | 206 | irc_rootmsg(irc, "Changing nicks resets your identify status. " |
---|
| 207 | "Re-identify or register a new account if you want " |
---|
| 208 | "your configuration to be saved. See \x02help " |
---|
| 209 | "nick_changes\x02."); |
---|
[ffa1173] | 210 | } |
---|
[5ebff60] | 211 | |
---|
| 212 | if (strcmp(cmd[1], irc->user->nick) != 0) { |
---|
| 213 | irc_user_set_nick(irc->user, cmd[1]); |
---|
| 214 | } |
---|
| 215 | } else { |
---|
| 216 | g_free(irc->user->nick); |
---|
| 217 | irc->user->nick = g_strdup(cmd[1]); |
---|
| 218 | |
---|
| 219 | irc_check_login(irc); |
---|
[0298d11] | 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
[5ebff60] | 223 | static void irc_cmd_quit(irc_t *irc, char **cmd) |
---|
[0298d11] | 224 | { |
---|
[5ebff60] | 225 | if (cmd[1] && *cmd[1]) { |
---|
| 226 | irc_abort(irc, 0, "Quit: %s", cmd[1]); |
---|
| 227 | } else { |
---|
| 228 | irc_abort(irc, 0, "Leaving..."); |
---|
| 229 | } |
---|
[0298d11] | 230 | } |
---|
| 231 | |
---|
[5ebff60] | 232 | static void irc_cmd_ping(irc_t *irc, char **cmd) |
---|
[0298d11] | 233 | { |
---|
[5ebff60] | 234 | irc_write(irc, ":%s PONG %s :%s", irc->root->host, |
---|
| 235 | irc->root->host, cmd[1] ? cmd[1] : irc->root->host); |
---|
[0298d11] | 236 | } |
---|
| 237 | |
---|
[5ebff60] | 238 | static void irc_cmd_pong(irc_t *irc, char **cmd) |
---|
[3923003] | 239 | { |
---|
| 240 | /* We could check the value we get back from the user, but in |
---|
| 241 | fact we don't care, we're just happy s/he's still alive. */ |
---|
| 242 | irc->last_pong = gettime(); |
---|
| 243 | irc->pinging = 0; |
---|
| 244 | } |
---|
| 245 | |
---|
[5ebff60] | 246 | static void irc_cmd_join(irc_t *irc, char **cmd) |
---|
[b9e020a] | 247 | { |
---|
[58646d9] | 248 | char *comma, *s = cmd[1]; |
---|
[5ebff60] | 249 | |
---|
| 250 | while (s) { |
---|
[58646d9] | 251 | irc_channel_t *ic; |
---|
[5ebff60] | 252 | |
---|
| 253 | if ((comma = strchr(s, ','))) { |
---|
[58646d9] | 254 | *comma = '\0'; |
---|
[5ebff60] | 255 | } |
---|
| 256 | |
---|
| 257 | if ((ic = irc_channel_by_name(irc, s)) == NULL && |
---|
| 258 | (ic = irc_channel_new(irc, s))) { |
---|
| 259 | if (strcmp(set_getstr(&ic->set, "type"), "control") != 0) { |
---|
[324c378] | 260 | /* Autoconfiguration is for control channels only ATM. */ |
---|
[5ebff60] | 261 | } else if (bee_group_by_name(ic->irc->b, ic->name + 1, FALSE)) { |
---|
| 262 | set_setstr(&ic->set, "group", ic->name + 1); |
---|
| 263 | set_setstr(&ic->set, "fill_by", "group"); |
---|
| 264 | } else if (set_setstr(&ic->set, "protocol", ic->name + 1)) { |
---|
| 265 | set_setstr(&ic->set, "fill_by", "protocol"); |
---|
| 266 | } else if (set_setstr(&ic->set, "account", ic->name + 1)) { |
---|
| 267 | set_setstr(&ic->set, "fill_by", "account"); |
---|
| 268 | } else { |
---|
[13fa2db] | 269 | /* The set commands above will run this already, |
---|
| 270 | but if we didn't hit any, we have to fill the |
---|
| 271 | channel with the default population. */ |
---|
[5ebff60] | 272 | bee_irc_channel_update(ic->irc, ic, NULL); |
---|
[324c378] | 273 | } |
---|
[5ebff60] | 274 | } else if (ic == NULL) { |
---|
| 275 | irc_send_num(irc, 479, "%s :Invalid channel name", s); |
---|
[58646d9] | 276 | goto next; |
---|
| 277 | } |
---|
[5ebff60] | 278 | |
---|
| 279 | if (ic->flags & IRC_CHANNEL_JOINED) { |
---|
[58646d9] | 280 | /* Dude, you're already there... |
---|
| 281 | RFC doesn't have any reply for that though? */ |
---|
| 282 | goto next; |
---|
[5ebff60] | 283 | } |
---|
| 284 | |
---|
| 285 | if (ic->f->join && !ic->f->join(ic)) { |
---|
[58646d9] | 286 | /* The story is: FALSE either means the handler |
---|
| 287 | showed an error message, or is doing some work |
---|
| 288 | before the join should be confirmed. (In the |
---|
| 289 | latter case, the caller should take care of that |
---|
| 290 | confirmation.) TRUE means all's good, let the |
---|
| 291 | user join the channel right away. */ |
---|
| 292 | goto next; |
---|
[5ebff60] | 293 | } |
---|
| 294 | |
---|
| 295 | irc_channel_add_user(ic, irc->user); |
---|
| 296 | |
---|
[58646d9] | 297 | next: |
---|
[5ebff60] | 298 | if (comma) { |
---|
[58646d9] | 299 | s = comma + 1; |
---|
| 300 | *comma = ','; |
---|
[5ebff60] | 301 | } else { |
---|
[58646d9] | 302 | break; |
---|
[5ebff60] | 303 | } |
---|
[57119e8] | 304 | } |
---|
[b9e020a] | 305 | } |
---|
| 306 | |
---|
[5ebff60] | 307 | static void irc_cmd_names(irc_t *irc, char **cmd) |
---|
[b9e020a] | 308 | { |
---|
| 309 | irc_channel_t *ic; |
---|
[5ebff60] | 310 | |
---|
| 311 | if (cmd[1] && (ic = irc_channel_by_name(irc, cmd[1]))) { |
---|
| 312 | irc_send_names(ic); |
---|
| 313 | } |
---|
[b9e020a] | 314 | /* With no args, we should show /names of all chans. Make the code |
---|
| 315 | below work well if necessary. |
---|
| 316 | else |
---|
| 317 | { |
---|
[5ebff60] | 318 | GSList *l; |
---|
| 319 | |
---|
| 320 | for( l = irc->channels; l; l = l->next ) |
---|
| 321 | irc_send_names( l->data ); |
---|
[b9e020a] | 322 | } |
---|
| 323 | */ |
---|
| 324 | } |
---|
| 325 | |
---|
[5ebff60] | 326 | static void irc_cmd_part(irc_t *irc, char **cmd) |
---|
[b9e020a] | 327 | { |
---|
| 328 | irc_channel_t *ic; |
---|
[5ebff60] | 329 | |
---|
| 330 | if ((ic = irc_channel_by_name(irc, cmd[1])) == NULL) { |
---|
| 331 | irc_send_num(irc, 403, "%s :No such channel", cmd[1]); |
---|
| 332 | } else if (irc_channel_del_user(ic, irc->user, IRC_CDU_PART, cmd[2])) { |
---|
| 333 | if (ic->f->part) { |
---|
| 334 | ic->f->part(ic, NULL); |
---|
| 335 | } |
---|
| 336 | } else { |
---|
| 337 | irc_send_num(irc, 442, "%s :You're not on that channel", cmd[1]); |
---|
[b9e020a] | 338 | } |
---|
| 339 | } |
---|
| 340 | |
---|
[5ebff60] | 341 | static void irc_cmd_whois(irc_t *irc, char **cmd) |
---|
[b95932e] | 342 | { |
---|
| 343 | char *nick = cmd[1]; |
---|
[5ebff60] | 344 | irc_user_t *iu = irc_user_by_name(irc, nick); |
---|
| 345 | |
---|
| 346 | if (iu) { |
---|
| 347 | irc_send_whois(iu); |
---|
| 348 | } else { |
---|
| 349 | irc_send_num(irc, 401, "%s :Nick does not exist", nick); |
---|
| 350 | } |
---|
[b95932e] | 351 | } |
---|
| 352 | |
---|
[5ebff60] | 353 | static void irc_cmd_whowas(irc_t *irc, char **cmd) |
---|
[b95932e] | 354 | { |
---|
| 355 | /* For some reason irssi tries a whowas when whois fails. We can |
---|
| 356 | ignore this, but then the user never gets a "user not found" |
---|
| 357 | message from irssi which is a bit annoying. So just respond |
---|
| 358 | with not-found and irssi users will get better error messages */ |
---|
[5ebff60] | 359 | |
---|
| 360 | irc_send_num(irc, 406, "%s :Nick does not exist", cmd[1]); |
---|
| 361 | irc_send_num(irc, 369, "%s :End of WHOWAS", cmd[1]); |
---|
[b95932e] | 362 | } |
---|
| 363 | |
---|
[5ebff60] | 364 | static void irc_cmd_motd(irc_t *irc, char **cmd) |
---|
[9b69eb7] | 365 | { |
---|
[5ebff60] | 366 | irc_send_motd(irc); |
---|
[9b69eb7] | 367 | } |
---|
| 368 | |
---|
[5ebff60] | 369 | static void irc_cmd_mode(irc_t *irc, char **cmd) |
---|
[0298d11] | 370 | { |
---|
[5ebff60] | 371 | if (irc_channel_name_ok(cmd[1])) { |
---|
[b919363] | 372 | irc_channel_t *ic; |
---|
[5ebff60] | 373 | |
---|
| 374 | if ((ic = irc_channel_by_name(irc, cmd[1])) == NULL) { |
---|
| 375 | irc_send_num(irc, 403, "%s :No such channel", cmd[1]); |
---|
| 376 | } else if (cmd[2]) { |
---|
| 377 | if (*cmd[2] == '+' || *cmd[2] == '-') { |
---|
| 378 | irc_send_num(irc, 477, "%s :Can't change channel modes", cmd[1]); |
---|
| 379 | } else if (*cmd[2] == 'b') { |
---|
| 380 | irc_send_num(irc, 368, "%s :No bans possible", cmd[1]); |
---|
| 381 | } |
---|
| 382 | } else { |
---|
| 383 | irc_send_num(irc, 324, "%s +%s", cmd[1], ic->mode); |
---|
[0298d11] | 384 | } |
---|
[5ebff60] | 385 | } else { |
---|
| 386 | if (nick_cmp(NULL, cmd[1], irc->user->nick) == 0) { |
---|
| 387 | if (cmd[2]) { |
---|
| 388 | irc_umode_set(irc, cmd[2], 0); |
---|
| 389 | } else { |
---|
| 390 | irc_send_num(irc, 221, "+%s", irc->umode); |
---|
| 391 | } |
---|
| 392 | } else { |
---|
| 393 | irc_send_num(irc, 502, ":Don't touch their modes"); |
---|
[0298d11] | 394 | } |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | |
---|
[5ebff60] | 398 | static void irc_cmd_who(irc_t *irc, char **cmd) |
---|
[2f53ada] | 399 | { |
---|
| 400 | char *channel = cmd[1]; |
---|
| 401 | irc_channel_t *ic; |
---|
[a72af0d] | 402 | irc_user_t *iu; |
---|
[5ebff60] | 403 | |
---|
| 404 | if (!channel || *channel == '0' || *channel == '*' || !*channel) { |
---|
| 405 | irc_send_who(irc, irc->users, "**"); |
---|
| 406 | } else if ((ic = irc_channel_by_name(irc, channel))) { |
---|
| 407 | irc_send_who(irc, ic->users, channel); |
---|
| 408 | } else if ((iu = irc_user_by_name(irc, channel))) { |
---|
[a72af0d] | 409 | /* Tiny hack! */ |
---|
[5ebff60] | 410 | GSList *l = g_slist_append(NULL, iu); |
---|
| 411 | irc_send_who(irc, l, channel); |
---|
| 412 | g_slist_free(l); |
---|
| 413 | } else { |
---|
| 414 | irc_send_num(irc, 403, "%s :No such channel", channel); |
---|
[a72af0d] | 415 | } |
---|
[2f53ada] | 416 | } |
---|
| 417 | |
---|
[5ebff60] | 418 | static void irc_cmd_privmsg(irc_t *irc, char **cmd) |
---|
[b919363] | 419 | { |
---|
[280c56a] | 420 | irc_channel_t *ic; |
---|
| 421 | irc_user_t *iu; |
---|
[5ebff60] | 422 | |
---|
| 423 | if (!cmd[2]) { |
---|
| 424 | irc_send_num(irc, 412, ":No text to send"); |
---|
[24b8bbb] | 425 | return; |
---|
[280c56a] | 426 | } |
---|
[5ebff60] | 427 | |
---|
[24b8bbb] | 428 | /* Don't treat CTCP actions as real CTCPs, just convert them right now. */ |
---|
[5ebff60] | 429 | if (g_strncasecmp(cmd[2], "\001ACTION", 7) == 0) { |
---|
[24b8bbb] | 430 | cmd[2] += 4; |
---|
[5ebff60] | 431 | memcpy(cmd[2], "/me", 3); |
---|
| 432 | if (cmd[2][strlen(cmd[2]) - 1] == '\001') { |
---|
| 433 | cmd[2][strlen(cmd[2]) - 1] = '\0'; |
---|
| 434 | } |
---|
[24b8bbb] | 435 | } |
---|
[5ebff60] | 436 | |
---|
| 437 | if (irc_channel_name_ok(cmd[1]) && |
---|
| 438 | (ic = irc_channel_by_name(irc, cmd[1]))) { |
---|
| 439 | if (cmd[2][0] == '\001') { |
---|
[a7dbf45] | 440 | /* CTCPs to channels? Nah. Maybe later. */ |
---|
[5ebff60] | 441 | } else if (ic->f->privmsg) { |
---|
| 442 | ic->f->privmsg(ic, cmd[2]); |
---|
[a7dbf45] | 443 | } |
---|
[5ebff60] | 444 | } else if ((iu = irc_user_by_name(irc, cmd[1]))) { |
---|
| 445 | if (cmd[2][0] == '\001') { |
---|
[24b8bbb] | 446 | char **ctcp; |
---|
[5ebff60] | 447 | |
---|
| 448 | if (iu->f->ctcp == NULL) { |
---|
[24b8bbb] | 449 | return; |
---|
[5ebff60] | 450 | } |
---|
| 451 | if (cmd[2][strlen(cmd[2]) - 1] == '\001') { |
---|
| 452 | cmd[2][strlen(cmd[2]) - 1] = '\0'; |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | ctcp = split_command_parts(cmd[2] + 1, 0); |
---|
| 456 | iu->f->ctcp(iu, ctcp); |
---|
| 457 | } else if (iu->f->privmsg) { |
---|
[92c8d41] | 458 | iu->last_channel = NULL; |
---|
[5ebff60] | 459 | iu->f->privmsg(iu, cmd[2]); |
---|
[bce78c8] | 460 | } |
---|
[5ebff60] | 461 | } else { |
---|
| 462 | irc_send_num(irc, 401, "%s :No such nick/channel", cmd[1]); |
---|
[b919363] | 463 | } |
---|
[280c56a] | 464 | } |
---|
| 465 | |
---|
[5ebff60] | 466 | static void irc_cmd_notice(irc_t *irc, char **cmd) |
---|
[d7f8500] | 467 | { |
---|
[bbc69f7] | 468 | irc_user_t *iu; |
---|
[5ebff60] | 469 | |
---|
| 470 | if (!cmd[2]) { |
---|
| 471 | irc_send_num(irc, 412, ":No text to send"); |
---|
[d7f8500] | 472 | return; |
---|
| 473 | } |
---|
[5ebff60] | 474 | |
---|
[d7f8500] | 475 | /* At least for now just echo. IIRC some IRC clients use self-notices |
---|
| 476 | for lag checks, so try to support that. */ |
---|
[5ebff60] | 477 | if (nick_cmp(NULL, cmd[1], irc->user->nick) == 0) { |
---|
| 478 | irc_send_msg(irc->user, "NOTICE", irc->user->nick, cmd[2], NULL); |
---|
| 479 | } else if ((iu = irc_user_by_name(irc, cmd[1]))) { |
---|
| 480 | iu->f->privmsg(iu, cmd[2]); |
---|
| 481 | } |
---|
[d7f8500] | 482 | } |
---|
| 483 | |
---|
[5ebff60] | 484 | static void irc_cmd_nickserv(irc_t *irc, char **cmd) |
---|
[d860a8d] | 485 | { |
---|
| 486 | /* [SH] This aliases the NickServ command to PRIVMSG root */ |
---|
| 487 | /* [TV] This aliases the NS command to PRIVMSG root as well */ |
---|
[5ebff60] | 488 | root_command(irc, cmd + 1); |
---|
[d860a8d] | 489 | } |
---|
| 490 | |
---|
[5ebff60] | 491 | static void irc_cmd_oper_hack(irc_t *irc, char **cmd); |
---|
[280c56a] | 492 | |
---|
[5ebff60] | 493 | static void irc_cmd_oper(irc_t *irc, char **cmd) |
---|
[280c56a] | 494 | { |
---|
[060d066] | 495 | /* Very non-standard evil but useful/secure hack, see below. */ |
---|
[5ebff60] | 496 | if (irc->status & OPER_HACK_ANY) { |
---|
| 497 | return irc_cmd_oper_hack(irc, cmd); |
---|
[280c56a] | 498 | } |
---|
[5ebff60] | 499 | |
---|
| 500 | if (global.conf->oper_pass && |
---|
| 501 | (strncmp(global.conf->oper_pass, "md5:", 4) == 0 ? |
---|
| 502 | md5_verify_password(cmd[2], global.conf->oper_pass + 4) == 0 : |
---|
| 503 | strcmp(cmd[2], global.conf->oper_pass) == 0)) { |
---|
| 504 | irc_umode_set(irc, "+o", 1); |
---|
| 505 | irc_send_num(irc, 381, ":Password accepted"); |
---|
| 506 | } else { |
---|
| 507 | irc_send_num(irc, 491, ":Incorrect password"); |
---|
[280c56a] | 508 | } |
---|
| 509 | } |
---|
| 510 | |
---|
[5ebff60] | 511 | static void irc_cmd_oper_hack(irc_t *irc, char **cmd) |
---|
[060d066] | 512 | { |
---|
[5ebff60] | 513 | char *password = g_strjoinv(" ", cmd + 2); |
---|
| 514 | |
---|
[060d066] | 515 | /* /OPER can now also be used to enter IM/identify passwords without |
---|
| 516 | echoing. It's a hack but the extra password security is worth it. */ |
---|
[5ebff60] | 517 | if (irc->status & OPER_HACK_ACCOUNT_PASSWORD) { |
---|
[060d066] | 518 | account_t *a; |
---|
[5ebff60] | 519 | |
---|
| 520 | for (a = irc->b->accounts; a; a = a->next) { |
---|
| 521 | if (strcmp(a->pass, PASSWORD_PENDING) == 0) { |
---|
| 522 | set_setstr(&a->set, "password", password); |
---|
| 523 | irc_rootmsg(irc, "Password added to IM account " |
---|
| 524 | "%s", a->tag); |
---|
[060d066] | 525 | /* The IRC client may expect this. 491 suggests the OPER |
---|
| 526 | password was wrong, so the client won't expect a +o. |
---|
| 527 | It may however repeat the password prompt. We'll see. */ |
---|
[5ebff60] | 528 | irc_send_num(irc, 491, ":Password added to IM account " |
---|
| 529 | "%s", a->tag); |
---|
[060d066] | 530 | } |
---|
[5ebff60] | 531 | } |
---|
| 532 | } else if (irc->status & OPER_HACK_IDENTIFY) { |
---|
[fda194f] | 533 | char *send_cmd[] = { "identify", password, NULL, NULL }; |
---|
| 534 | irc->status &= ~OPER_HACK_IDENTIFY; |
---|
[5ebff60] | 535 | if (irc->status & OPER_HACK_IDENTIFY_NOLOAD) { |
---|
[fda194f] | 536 | send_cmd[1] = "-noload"; |
---|
| 537 | send_cmd[2] = password; |
---|
[5ebff60] | 538 | } else if (irc->status & OPER_HACK_IDENTIFY_FORCE) { |
---|
[fda194f] | 539 | send_cmd[1] = "-force"; |
---|
| 540 | send_cmd[2] = password; |
---|
| 541 | } |
---|
[5ebff60] | 542 | irc_send_num(irc, 491, ":Trying to identify"); |
---|
| 543 | root_command(irc, send_cmd); |
---|
| 544 | } else if (irc->status & OPER_HACK_REGISTER) { |
---|
[060d066] | 545 | char *send_cmd[] = { "register", password, NULL }; |
---|
[5ebff60] | 546 | irc_send_num(irc, 491, ":Trying to identify"); |
---|
| 547 | root_command(irc, send_cmd); |
---|
[060d066] | 548 | } |
---|
[5ebff60] | 549 | |
---|
[060d066] | 550 | irc->status &= ~OPER_HACK_ANY; |
---|
[5ebff60] | 551 | g_free(password); |
---|
[060d066] | 552 | } |
---|
| 553 | |
---|
[5ebff60] | 554 | static void irc_cmd_invite(irc_t *irc, char **cmd) |
---|
[280c56a] | 555 | { |
---|
[66b9e36a] | 556 | irc_channel_t *ic; |
---|
| 557 | irc_user_t *iu; |
---|
[5ebff60] | 558 | |
---|
| 559 | if ((iu = irc_user_by_name(irc, cmd[1])) == NULL) { |
---|
| 560 | irc_send_num(irc, 401, "%s :No such nick", cmd[1]); |
---|
[66b9e36a] | 561 | return; |
---|
[5ebff60] | 562 | } else if ((ic = irc_channel_by_name(irc, cmd[2])) == NULL) { |
---|
| 563 | irc_send_num(irc, 403, "%s :No such channel", cmd[2]); |
---|
[66b9e36a] | 564 | return; |
---|
| 565 | } |
---|
[5ebff60] | 566 | |
---|
| 567 | if (!ic->f->invite) { |
---|
| 568 | irc_send_num(irc, 482, "%s :Can't invite people here", cmd[2]); |
---|
| 569 | } else if (ic->f->invite(ic, iu)) { |
---|
| 570 | irc_send_num(irc, 341, "%s %s", iu->nick, ic->name); |
---|
| 571 | } |
---|
[0298d11] | 572 | } |
---|
| 573 | |
---|
[5ebff60] | 574 | static void irc_cmd_kick(irc_t *irc, char **cmd) |
---|
[7821ee8] | 575 | { |
---|
| 576 | irc_channel_t *ic; |
---|
| 577 | irc_user_t *iu; |
---|
[5ebff60] | 578 | |
---|
| 579 | if ((iu = irc_user_by_name(irc, cmd[2])) == NULL) { |
---|
| 580 | irc_send_num(irc, 401, "%s :No such nick", cmd[2]); |
---|
[7821ee8] | 581 | return; |
---|
[5ebff60] | 582 | } else if ((ic = irc_channel_by_name(irc, cmd[1])) == NULL) { |
---|
| 583 | irc_send_num(irc, 403, "%s :No such channel", cmd[1]); |
---|
[7821ee8] | 584 | return; |
---|
[5ebff60] | 585 | } else if (!ic->f->kick) { |
---|
| 586 | irc_send_num(irc, 482, "%s :Can't kick people here", cmd[1]); |
---|
[7821ee8] | 587 | return; |
---|
| 588 | } |
---|
[5ebff60] | 589 | |
---|
| 590 | ic->f->kick(ic, iu, cmd[3] ? cmd[3] : NULL); |
---|
[7821ee8] | 591 | } |
---|
| 592 | |
---|
[5ebff60] | 593 | static void irc_cmd_userhost(irc_t *irc, char **cmd) |
---|
[0298d11] | 594 | { |
---|
| 595 | int i; |
---|
[5ebff60] | 596 | |
---|
[0298d11] | 597 | /* [TV] Usable USERHOST-implementation according to |
---|
[5ebff60] | 598 | RFC1459. Without this, mIRC shows an error |
---|
| 599 | while connecting, and the used way of rejecting |
---|
| 600 | breaks standards. |
---|
[0298d11] | 601 | */ |
---|
[5ebff60] | 602 | |
---|
| 603 | for (i = 1; cmd[i]; i++) { |
---|
| 604 | irc_user_t *iu = irc_user_by_name(irc, cmd[i]); |
---|
| 605 | |
---|
| 606 | if (iu) { |
---|
| 607 | irc_send_num(irc, 302, ":%s=%c%s@%s", iu->nick, |
---|
| 608 | irc_user_get_away(iu) ? '-' : '+', |
---|
| 609 | iu->user, iu->host); |
---|
| 610 | } |
---|
[003a12b] | 611 | } |
---|
[0298d11] | 612 | } |
---|
| 613 | |
---|
[5ebff60] | 614 | static void irc_cmd_ison(irc_t *irc, char **cmd) |
---|
[0298d11] | 615 | { |
---|
[b4e4b95] | 616 | char buff[IRC_MAX_LINE]; |
---|
[0298d11] | 617 | int lenleft, i; |
---|
[5ebff60] | 618 | |
---|
[0298d11] | 619 | buff[0] = '\0'; |
---|
[5ebff60] | 620 | |
---|
[0298d11] | 621 | /* [SH] Leave room for : and \0 */ |
---|
| 622 | lenleft = IRC_MAX_LINE - 2; |
---|
[5ebff60] | 623 | |
---|
| 624 | for (i = 1; cmd[i]; i++) { |
---|
[42616d1] | 625 | char *this, *next; |
---|
[5ebff60] | 626 | |
---|
[42616d1] | 627 | this = cmd[i]; |
---|
[5ebff60] | 628 | while (*this) { |
---|
[003a12b] | 629 | irc_user_t *iu; |
---|
[5ebff60] | 630 | |
---|
| 631 | if ((next = strchr(this, ' '))) { |
---|
[42616d1] | 632 | *next = 0; |
---|
[5ebff60] | 633 | } |
---|
| 634 | |
---|
| 635 | if ((iu = irc_user_by_name(irc, this)) && |
---|
| 636 | iu->bu && iu->bu->flags & BEE_USER_ONLINE) { |
---|
| 637 | lenleft -= strlen(iu->nick) + 1; |
---|
| 638 | |
---|
| 639 | if (lenleft < 0) { |
---|
[42616d1] | 640 | break; |
---|
[5ebff60] | 641 | } |
---|
| 642 | |
---|
| 643 | strcat(buff, iu->nick); |
---|
| 644 | strcat(buff, " "); |
---|
[0298d11] | 645 | } |
---|
[5ebff60] | 646 | |
---|
| 647 | if (next) { |
---|
[42616d1] | 648 | *next = ' '; |
---|
| 649 | this = next + 1; |
---|
[5ebff60] | 650 | } else { |
---|
[42616d1] | 651 | break; |
---|
[5ebff60] | 652 | } |
---|
[0298d11] | 653 | } |
---|
[5ebff60] | 654 | |
---|
[42616d1] | 655 | /* *sigh* */ |
---|
[5ebff60] | 656 | if (lenleft < 0) { |
---|
[42616d1] | 657 | break; |
---|
[5ebff60] | 658 | } |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | if (strlen(buff) > 0) { |
---|
| 662 | buff[strlen(buff) - 1] = '\0'; |
---|
[0298d11] | 663 | } |
---|
[5ebff60] | 664 | |
---|
| 665 | irc_send_num(irc, 303, ":%s", buff); |
---|
[0298d11] | 666 | } |
---|
| 667 | |
---|
[5ebff60] | 668 | static void irc_cmd_watch(irc_t *irc, char **cmd) |
---|
[0298d11] | 669 | { |
---|
| 670 | int i; |
---|
[5ebff60] | 671 | |
---|
[0298d11] | 672 | /* Obviously we could also mark a user structure as being |
---|
| 673 | watched, but what if the WATCH command is sent right |
---|
| 674 | after connecting? The user won't exist yet then... */ |
---|
[5ebff60] | 675 | for (i = 1; cmd[i]; i++) { |
---|
[0298d11] | 676 | char *nick; |
---|
[003a12b] | 677 | irc_user_t *iu; |
---|
[5ebff60] | 678 | |
---|
| 679 | if (!cmd[i][0] || !cmd[i][1]) { |
---|
[0298d11] | 680 | break; |
---|
| 681 | } |
---|
[5ebff60] | 682 | |
---|
| 683 | nick = g_strdup(cmd[i] + 1); |
---|
| 684 | nick_lc(irc, nick); |
---|
| 685 | |
---|
| 686 | iu = irc_user_by_name(irc, nick); |
---|
| 687 | |
---|
| 688 | if (cmd[i][0] == '+') { |
---|
| 689 | if (!g_hash_table_lookup(irc->watches, nick)) { |
---|
| 690 | g_hash_table_insert(irc->watches, nick, nick); |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | if (iu && iu->bu && iu->bu->flags & BEE_USER_ONLINE) { |
---|
| 694 | irc_send_num(irc, 604, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 695 | iu->host, (int) time(NULL), "is online"); |
---|
| 696 | } else { |
---|
| 697 | irc_send_num(irc, 605, "%s %s %s %d :%s", nick, "*", "*", |
---|
| 698 | (int) time(NULL), "is offline"); |
---|
| 699 | } |
---|
| 700 | } else if (cmd[i][0] == '-') { |
---|
[0298d11] | 701 | gpointer okey, ovalue; |
---|
[5ebff60] | 702 | |
---|
| 703 | if (g_hash_table_lookup_extended(irc->watches, nick, &okey, &ovalue)) { |
---|
| 704 | g_hash_table_remove(irc->watches, okey); |
---|
| 705 | g_free(okey); |
---|
| 706 | |
---|
| 707 | irc_send_num(irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching"); |
---|
[0298d11] | 708 | } |
---|
| 709 | } |
---|
| 710 | } |
---|
| 711 | } |
---|
| 712 | |
---|
[5ebff60] | 713 | static void irc_cmd_topic(irc_t *irc, char **cmd) |
---|
[0298d11] | 714 | { |
---|
[5ebff60] | 715 | irc_channel_t *ic = irc_channel_by_name(irc, cmd[1]); |
---|
[4469e7e] | 716 | const char *new = cmd[2]; |
---|
[5ebff60] | 717 | |
---|
| 718 | if (ic == NULL) { |
---|
| 719 | irc_send_num(irc, 403, "%s :No such channel", cmd[1]); |
---|
| 720 | } else if (new) { |
---|
| 721 | if (ic->f->topic == NULL) { |
---|
| 722 | irc_send_num(irc, 482, "%s :Can't change this channel's topic", ic->name); |
---|
| 723 | } else if (ic->f->topic(ic, new)) { |
---|
| 724 | irc_send_topic(ic, TRUE); |
---|
| 725 | } |
---|
| 726 | } else { |
---|
| 727 | irc_send_topic(ic, FALSE); |
---|
[50e1776] | 728 | } |
---|
[0298d11] | 729 | } |
---|
| 730 | |
---|
[5ebff60] | 731 | static void irc_cmd_away(irc_t *irc, char **cmd) |
---|
[0298d11] | 732 | { |
---|
[5ebff60] | 733 | if (cmd[1] && *cmd[1]) { |
---|
| 734 | char away[strlen(cmd[1]) + 1]; |
---|
[0298d11] | 735 | int i, j; |
---|
[5ebff60] | 736 | |
---|
[0298d11] | 737 | /* Copy away string, but skip control chars. Mainly because |
---|
| 738 | Jabber really doesn't like them. */ |
---|
[5ebff60] | 739 | for (i = j = 0; cmd[1][i]; i++) { |
---|
| 740 | if ((unsigned char) (away[j] = cmd[1][i]) >= ' ') { |
---|
| 741 | j++; |
---|
| 742 | } |
---|
| 743 | } |
---|
[81186cab] | 744 | away[j] = '\0'; |
---|
[5ebff60] | 745 | |
---|
| 746 | irc_send_num(irc, 306, ":You're now away: %s", away); |
---|
| 747 | set_setstr(&irc->b->set, "away", away); |
---|
| 748 | } else { |
---|
| 749 | irc_send_num(irc, 305, ":Welcome back"); |
---|
| 750 | set_setstr(&irc->b->set, "away", NULL); |
---|
[0298d11] | 751 | } |
---|
| 752 | } |
---|
| 753 | |
---|
[5ebff60] | 754 | static void irc_cmd_list(irc_t *irc, char **cmd) |
---|
[23d6165] | 755 | { |
---|
| 756 | GSList *l; |
---|
[5ebff60] | 757 | |
---|
| 758 | for (l = irc->channels; l; l = l->next) { |
---|
[23d6165] | 759 | irc_channel_t *ic = l->data; |
---|
[5ebff60] | 760 | |
---|
| 761 | irc_send_num(irc, 322, "%s %d :%s", |
---|
| 762 | ic->name, g_slist_length(ic->users), ic->topic ? : ""); |
---|
[23d6165] | 763 | } |
---|
[5ebff60] | 764 | irc_send_num(irc, 323, ":%s", "End of /LIST"); |
---|
[23d6165] | 765 | } |
---|
| 766 | |
---|
[5ebff60] | 767 | static void irc_cmd_version(irc_t *irc, char **cmd) |
---|
[82898af] | 768 | { |
---|
[5ebff60] | 769 | irc_send_num(irc, 351, "%s-%s. %s :%s/%s ", |
---|
| 770 | PACKAGE, BITLBEE_VERSION, irc->root->host, ARCH, CPU); |
---|
[82898af] | 771 | } |
---|
| 772 | |
---|
[5ebff60] | 773 | static void irc_cmd_completions(irc_t *irc, char **cmd) |
---|
[0298d11] | 774 | { |
---|
| 775 | help_t *h; |
---|
| 776 | set_t *s; |
---|
| 777 | int i; |
---|
[5ebff60] | 778 | |
---|
| 779 | irc_send_msg_raw(irc->root, "NOTICE", irc->user->nick, "COMPLETIONS OK"); |
---|
| 780 | |
---|
| 781 | for (i = 0; root_commands[i].command; i++) { |
---|
| 782 | irc_send_msg_f(irc->root, "NOTICE", irc->user->nick, "COMPLETIONS %s", root_commands[i].command); |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | for (h = global.help; h; h = h->next) { |
---|
| 786 | irc_send_msg_f(irc->root, "NOTICE", irc->user->nick, "COMPLETIONS help %s", h->title); |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | for (s = irc->b->set; s; s = s->next) { |
---|
| 790 | irc_send_msg_f(irc->root, "NOTICE", irc->user->nick, "COMPLETIONS set %s", s->key); |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | irc_send_msg_raw(irc->root, "NOTICE", irc->user->nick, "COMPLETIONS END"); |
---|
[0298d11] | 794 | } |
---|
| 795 | |
---|
[5ebff60] | 796 | static void irc_cmd_rehash(irc_t *irc, char **cmd) |
---|
[f4a5940] | 797 | { |
---|
[5ebff60] | 798 | if (global.conf->runmode == RUNMODE_INETD) { |
---|
| 799 | ipc_master_cmd_rehash(NULL, NULL); |
---|
| 800 | } else { |
---|
| 801 | ipc_to_master(cmd); |
---|
| 802 | } |
---|
| 803 | |
---|
| 804 | irc_send_num(irc, 382, "%s :Rehashing", global.conf_file); |
---|
[f4a5940] | 805 | } |
---|
| 806 | |
---|
[0298d11] | 807 | static const command_t irc_commands[] = { |
---|
[0ef1c92] | 808 | { "cap", 1, irc_cmd_cap, 0 }, |
---|
[a199d33] | 809 | { "pass", 1, irc_cmd_pass, 0 }, |
---|
[0298d11] | 810 | { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, |
---|
| 811 | { "nick", 1, irc_cmd_nick, 0 }, |
---|
| 812 | { "quit", 0, irc_cmd_quit, 0 }, |
---|
| 813 | { "ping", 0, irc_cmd_ping, 0 }, |
---|
[3923003] | 814 | { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN }, |
---|
[b9e020a] | 815 | { "join", 1, irc_cmd_join, IRC_CMD_LOGGED_IN }, |
---|
| 816 | { "names", 1, irc_cmd_names, IRC_CMD_LOGGED_IN }, |
---|
| 817 | { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN }, |
---|
[b95932e] | 818 | { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN }, |
---|
| 819 | { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN }, |
---|
[9b69eb7] | 820 | { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN }, |
---|
[b919363] | 821 | { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, |
---|
[2f53ada] | 822 | { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN }, |
---|
[280c56a] | 823 | { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
[d7f8500] | 824 | { "notice", 1, irc_cmd_notice, IRC_CMD_LOGGED_IN }, |
---|
[d860a8d] | 825 | { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
| 826 | { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
[81186cab] | 827 | { "away", 0, irc_cmd_away, IRC_CMD_LOGGED_IN }, |
---|
[d7d677d] | 828 | { "version", 0, irc_cmd_version, IRC_CMD_LOGGED_IN }, |
---|
| 829 | { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN }, |
---|
[0298d11] | 830 | { "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN }, |
---|
| 831 | { "ison", 1, irc_cmd_ison, IRC_CMD_LOGGED_IN }, |
---|
| 832 | { "watch", 1, irc_cmd_watch, IRC_CMD_LOGGED_IN }, |
---|
[003a12b] | 833 | { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, |
---|
[7821ee8] | 834 | { "kick", 2, irc_cmd_kick, IRC_CMD_LOGGED_IN }, |
---|
[4469e7e] | 835 | { "topic", 1, irc_cmd_topic, IRC_CMD_LOGGED_IN }, |
---|
[003a12b] | 836 | { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, |
---|
[23d6165] | 837 | { "list", 0, irc_cmd_list, IRC_CMD_LOGGED_IN }, |
---|
[0431ea1] | 838 | { "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[565a1ea] | 839 | { "deaf", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[48721c3] | 840 | { "wallops", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[dfc8a46] | 841 | { "wall", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[f4a5940] | 842 | { "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY }, |
---|
[54879ab] | 843 | { "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[48721c3] | 844 | { "kill", 2, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[58b63de6] | 845 | { "authenticate", 1, irc_cmd_authenticate, 0 }, |
---|
[0298d11] | 846 | { NULL } |
---|
| 847 | }; |
---|
| 848 | |
---|
[5ebff60] | 849 | void irc_exec(irc_t *irc, char *cmd[]) |
---|
| 850 | { |
---|
[f1d38f2] | 851 | int i, n_arg; |
---|
[5ebff60] | 852 | |
---|
| 853 | if (!cmd[0]) { |
---|
[f73b969] | 854 | return; |
---|
[5ebff60] | 855 | } |
---|
| 856 | |
---|
| 857 | for (i = 0; irc_commands[i].command; i++) { |
---|
| 858 | if (g_strcasecmp(irc_commands[i].command, cmd[0]) == 0) { |
---|
[f1d38f2] | 859 | /* There should be no typo in the next line: */ |
---|
[5ebff60] | 860 | for (n_arg = 0; cmd[n_arg]; n_arg++) { |
---|
[25c4c78] | 861 | ; |
---|
[edf9657] | 862 | } |
---|
[5ebff60] | 863 | n_arg--; |
---|
| 864 | |
---|
| 865 | if (irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN) { |
---|
| 866 | irc_send_num(irc, 462, ":Only allowed before logging in"); |
---|
| 867 | } else if (irc_commands[i].flags & IRC_CMD_LOGGED_IN && !(irc->status & USTATUS_LOGGED_IN)) { |
---|
| 868 | irc_send_num(irc, 451, ":Register first"); |
---|
| 869 | } else if (irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr(irc->umode, 'o')) { |
---|
| 870 | irc_send_num(irc, 481, ":Permission denied - You're not an IRC operator"); |
---|
| 871 | } else if (n_arg < irc_commands[i].required_parameters) { |
---|
| 872 | irc_send_num(irc, 461, "%s :Need more parameters", cmd[0]); |
---|
| 873 | } else if (irc_commands[i].flags & IRC_CMD_TO_MASTER) { |
---|
[5424c76] | 874 | /* IPC doesn't make sense in inetd mode, |
---|
| 875 | but the function will catch that. */ |
---|
[5ebff60] | 876 | ipc_to_master(cmd); |
---|
| 877 | } else { |
---|
| 878 | irc_commands[i].execute(irc, cmd); |
---|
[f73b969] | 879 | } |
---|
[5ebff60] | 880 | |
---|
[2f13222] | 881 | return; |
---|
[0298d11] | 882 | } |
---|
[5ebff60] | 883 | } |
---|
| 884 | |
---|
| 885 | if (irc->status & USTATUS_LOGGED_IN) { |
---|
| 886 | irc_send_num(irc, 421, "%s :Unknown command", cmd[0]); |
---|
| 887 | } |
---|
[0298d11] | 888 | } |
---|