Mercurial > pidgin
annotate src/protocols/irc/cmds.c @ 13845:d0ff520f87da
[gaim-migrate @ 16301]
This is tcl /cmd support. It doesn't currently let tcl plugins return error
message (I couldn't ever get that to work). But other than that it works.
Ethan please look over this when you get a chance.
committer: Tailor Script <tailor@pidgin.im>
| author | Etan Reisner <pidgin@unreliablesource.net> |
|---|---|
| date | Wed, 21 Jun 2006 04:57:27 +0000 |
| parents | 1a095ac881ce |
| children | 1a862fb5e713 |
| rev | line source |
|---|---|
| 6333 | 1 /** |
| 2 * @file cmds.c | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> | |
| 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 2 of the License, or | |
| 11 * (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 */ | |
| 22 | |
| 23 #include "internal.h" | |
| 24 | |
| 25 #include "conversation.h" | |
| 8504 | 26 #include "debug.h" |
| 6333 | 27 #include "notify.h" |
| 8624 | 28 #include "util.h" |
| 8504 | 29 |
| 6333 | 30 #include "irc.h" |
| 31 | |
| 32 | |
| 33 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops); | |
| 34 | |
| 35 int irc_cmd_default(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 36 { | |
| 11338 | 37 GaimConversation *convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, target, irc->account); |
| 6333 | 38 char *buf; |
| 39 | |
| 40 if (!convo) | |
| 6350 | 41 return 1; |
| 6333 | 42 |
| 43 buf = g_strdup_printf(_("Unknown command: %s"), cmd); | |
| 11338 | 44 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_IM) |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
45 gaim_conv_im_write(GAIM_CONV_IM(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 46 else |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
47 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 48 g_free(buf); |
| 49 | |
| 50 return 1; | |
| 51 } | |
| 52 | |
| 53 int irc_cmd_away(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 54 { | |
|
12669
879f90dbd21f
[gaim-migrate @ 15012]
Richard Laager <rlaager@wiktel.com>
parents:
12013
diff
changeset
|
55 char *buf, *message; |
| 6333 | 56 |
| 57 if (args[0] && strcmp(cmd, "back")) { | |
|
12669
879f90dbd21f
[gaim-migrate @ 15012]
Richard Laager <rlaager@wiktel.com>
parents:
12013
diff
changeset
|
58 message = gaim_markup_strip_html(args[0]); |
|
879f90dbd21f
[gaim-migrate @ 15012]
Richard Laager <rlaager@wiktel.com>
parents:
12013
diff
changeset
|
59 gaim_util_chrreplace(message, '\n', ' '); |
| 6333 | 60 buf = irc_format(irc, "v:", "AWAY", message); |
| 61 g_free(message); | |
| 62 } else { | |
| 63 buf = irc_format(irc, "v", "AWAY"); | |
| 64 } | |
| 65 irc_send(irc, buf); | |
| 66 g_free(buf); | |
| 67 | |
| 68 return 0; | |
| 69 } | |
| 70 | |
| 71 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 72 { | |
| 73 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
| 10933 | 74 char *action, *escaped, *dst, **newargs; |
| 6333 | 75 const char *src; |
| 76 GaimConversation *convo; | |
| 77 | |
| 78 if (!args || !args[0] || !gc) | |
| 79 return 0; | |
| 80 | |
| 6376 | 81 action = g_malloc(strlen(args[0]) + 10); |
| 6333 | 82 |
| 83 sprintf(action, "\001ACTION "); | |
| 84 | |
| 85 src = args[0]; | |
| 86 dst = action + 8; | |
| 87 while (*src) { | |
| 88 if (*src == '\n') { | |
| 89 if (*(src + 1) == '\0') { | |
| 90 break; | |
| 91 } else { | |
| 92 *dst++ = ' '; | |
| 93 src++; | |
| 94 continue; | |
| 95 } | |
| 96 } | |
| 97 *dst++ = *src++; | |
| 98 } | |
| 99 *dst++ = '\001'; | |
| 100 *dst = '\0'; | |
| 101 | |
| 102 newargs = g_new0(char *, 2); | |
| 103 newargs[0] = g_strdup(target); | |
| 104 newargs[1] = action; | |
| 105 irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
| 106 g_free(newargs[0]); | |
| 107 g_free(newargs[1]); | |
| 108 g_free(newargs); | |
| 109 | |
| 11338 | 110 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, target, irc->account); |
| 9130 | 111 if (convo) { |
| 10933 | 112 escaped = g_markup_escape_text(args[0], -1); |
| 113 action = g_strdup_printf("/me %s", escaped); | |
| 114 g_free(escaped); | |
| 6333 | 115 if (action[strlen(action) - 1] == '\n') |
| 116 action[strlen(action) - 1] = '\0'; | |
| 11338 | 117 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) |
| 9130 | 118 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), |
| 119 gaim_connection_get_display_name(gc), | |
| 120 0, action, time(NULL)); | |
| 121 else | |
| 122 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), | |
| 123 action, 0, time(NULL)); | |
| 6333 | 124 g_free(action); |
| 125 } | |
| 126 | |
| 127 return 1; | |
| 128 } | |
| 129 | |
| 130 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 131 { | |
| 132 char *buf; | |
| 133 | |
| 134 if (!args || !args[0] || !(args[1] || target)) | |
| 135 return 0; | |
| 136 | |
| 137 buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 138 irc_send(irc, buf); | |
| 139 g_free(buf); | |
| 140 | |
| 141 return 0; | |
| 142 } | |
| 143 | |
| 144 int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 145 { | |
| 146 char *buf; | |
| 147 | |
| 148 if (!args || !args[0]) | |
| 149 return 0; | |
| 150 | |
| 151 if (args[1]) | |
| 152 buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 153 else | |
| 154 buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 155 irc_send(irc, buf); | |
| 156 g_free(buf); | |
| 157 | |
| 158 return 0; | |
| 159 } | |
| 160 | |
| 161 int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 162 { | |
| 163 char *buf; | |
| 164 GaimConversation *convo; | |
| 165 | |
| 166 if (!args || !args[0]) | |
| 167 return 0; | |
| 168 | |
| 11338 | 169 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, target, irc->account); |
| 10246 | 170 if (!convo) |
| 6350 | 171 return 0; |
| 6333 | 172 |
| 173 if (args[1]) | |
| 174 buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 175 else | |
| 176 buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 177 irc_send(irc, buf); | |
| 178 g_free(buf); | |
| 179 | |
| 180 return 0; | |
| 181 } | |
| 182 | |
| 8114 | 183 int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 184 { | |
| 8352 | 185 gaim_roomlist_show_with_account(irc->account); |
| 8114 | 186 |
| 187 return 0; | |
| 188 } | |
| 189 | |
| 6333 | 190 int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 191 { | |
| 192 GaimConnection *gc; | |
| 193 char *buf; | |
| 194 | |
| 195 if (!args) | |
| 196 return 0; | |
| 197 | |
| 198 if (!strcmp(cmd, "mode")) { | |
| 10208 | 199 if (!args[0] && irc_ischannel(target)) |
| 6333 | 200 buf = irc_format(irc, "vc", "MODE", target); |
| 201 else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
| 202 buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
| 203 else if (args[0]) | |
| 204 buf = irc_format(irc, "vv", "MODE", args[0]); | |
| 205 else | |
| 6350 | 206 return 0; |
| 6333 | 207 } else if (!strcmp(cmd, "umode")) { |
| 208 if (!args[0]) | |
| 6350 | 209 return 0; |
| 6333 | 210 gc = gaim_account_get_connection(irc->account); |
| 211 buf = irc_format(irc, "vnv", "MODE", gaim_connection_get_display_name(gc), args[0]); | |
| 6365 | 212 } else { |
| 213 return 0; | |
| 6333 | 214 } |
| 6365 | 215 |
| 6333 | 216 irc_send(irc, buf); |
| 217 g_free(buf); | |
| 218 | |
| 219 return 0; | |
| 220 } | |
| 221 | |
| 222 int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 223 { | |
| 224 char *buf; | |
| 225 | |
| 10208 | 226 if (!args || (!args[0] && !irc_ischannel(target))) |
| 6333 | 227 return 0; |
| 228 | |
| 229 buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 230 irc_send(irc, buf); | |
| 231 g_free(buf); | |
| 232 | |
| 233 irc->nameconv = g_strdup(target); | |
| 234 | |
| 235 return 0; | |
| 236 } | |
| 237 | |
| 238 int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 239 { | |
| 240 char *buf; | |
| 241 | |
| 242 if (!args || !args[0]) | |
| 243 return 0; | |
| 244 | |
| 245 buf = irc_format(irc, "v:", "NICK", args[0]); | |
| 246 irc_send(irc, buf); | |
| 247 g_free(buf); | |
| 248 | |
| 249 return 0; | |
| 250 } | |
| 251 | |
| 252 int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 253 { | |
| 254 char **nicks, **ops, *sign, *mode; | |
| 255 int i = 0, used = 0; | |
| 256 | |
| 257 if (!args || !args[0] || !*args[0]) | |
| 258 return 0; | |
| 259 | |
| 260 if (!strcmp(cmd, "op")) { | |
| 261 sign = "+"; | |
| 262 mode = "o"; | |
| 263 } else if (!strcmp(cmd, "deop")) { | |
| 264 sign = "-"; | |
| 265 mode = "o"; | |
| 266 } else if (!strcmp(cmd, "voice")) { | |
| 267 sign = "+"; | |
| 268 mode = "v"; | |
| 269 } else if (!strcmp(cmd, "devoice")) { | |
| 270 sign = "-"; | |
| 271 mode = "v"; | |
| 272 } else { | |
| 273 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); | |
| 274 return 0; | |
| 275 } | |
| 276 | |
| 277 nicks = g_strsplit(args[0], " ", -1); | |
| 278 | |
| 279 for (i = 0; nicks[i]; i++) | |
| 280 /* nothing */; | |
| 281 ops = g_new0(char *, i * 2 + 1); | |
| 282 | |
| 283 for (i = 0; nicks[i]; i++) { | |
| 284 if (!*nicks[i]) | |
| 285 continue; | |
| 286 ops[used++] = mode; | |
| 287 ops[used++] = nicks[i]; | |
| 288 } | |
| 289 | |
| 290 irc_do_mode(irc, target, sign, ops); | |
| 291 g_free(ops); | |
| 292 | |
| 6350 | 293 return 0; |
| 6333 | 294 } |
| 295 | |
| 296 int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 297 { | |
| 298 char *buf; | |
| 299 | |
| 300 if (!args) | |
| 301 return 0; | |
| 302 | |
| 303 if (args[1]) | |
| 304 buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 305 else | |
| 306 buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 307 irc_send(irc, buf); | |
| 308 g_free(buf); | |
| 309 | |
| 310 return 0; | |
| 311 } | |
| 312 | |
| 313 int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 314 { | |
| 315 char *stamp; | |
| 316 char *buf; | |
| 317 | |
| 318 if (args && args[0]) { | |
| 10208 | 319 if (irc_ischannel(args[0])) |
| 6333 | 320 return 0; |
| 321 stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 322 buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 323 g_free(stamp); | |
| 324 } else { | |
| 6350 | 325 stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 326 buf = irc_format(irc, "v:", "PING", stamp); |
| 327 g_free(stamp); | |
| 328 } | |
| 329 irc_send(irc, buf); | |
| 330 g_free(buf); | |
| 331 | |
| 332 return 0; | |
| 333 } | |
| 334 | |
| 335 int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 336 { | |
| 337 const char *cur, *end; | |
| 338 char *msg, *buf; | |
| 339 | |
| 340 if (!args || !args[0] || !args[1]) | |
| 341 return 0; | |
| 342 | |
| 343 cur = args[1]; | |
| 344 end = args[1]; | |
| 345 while (*end && *cur) { | |
| 346 end = strchr(cur, '\n'); | |
| 347 if (!end) | |
| 348 end = cur + strlen(cur); | |
| 349 msg = g_strndup(cur, end - cur); | |
| 350 buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
| 351 irc_send(irc, buf); | |
| 352 g_free(msg); | |
| 353 g_free(buf); | |
| 354 cur = end + 1; | |
| 355 } | |
| 356 | |
| 357 return 0; | |
| 358 } | |
| 359 | |
| 360 int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 361 { | |
| 362 char *buf; | |
| 363 | |
| 9440 | 364 if (!irc->quitting) { |
| 11763 | 365 /* |
| 366 * Use gaim_account_get_string(irc->account, "quitmsg", IRC_DEFAULT_QUIT) | |
| 367 * and uncomment the appropriate account preference in irc.c if we | |
| 368 * decide we want custom quit messages. | |
| 369 */ | |
| 370 buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : IRC_DEFAULT_QUIT); | |
| 9440 | 371 irc_send(irc, buf); |
| 372 g_free(buf); | |
| 373 | |
| 374 irc->quitting = TRUE; | |
| 13837 | 375 |
| 376 gaim_account_set_status(irc->account, "offline", TRUE, NULL); | |
| 9440 | 377 } |
| 6333 | 378 |
| 379 return 0; | |
| 380 } | |
| 381 | |
| 382 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 383 { | |
| 384 char *buf; | |
| 385 | |
| 386 if (!args || !args[0]) | |
| 387 return 0; | |
| 388 | |
| 389 buf = irc_format(irc, "v", args[0]); | |
| 390 irc_send(irc, buf); | |
| 391 g_free(buf); | |
| 392 | |
| 393 return 0; | |
| 394 } | |
| 395 | |
| 396 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 397 { | |
| 398 GaimConversation *convo; | |
| 399 GaimConnection *gc; | |
| 400 | |
| 401 if (!args || !args[0]) | |
| 402 return 0; | |
| 403 | |
| 11338 | 404 convo = gaim_conversation_new(GAIM_CONV_TYPE_IM, irc->account, args[0]); |
| 6333 | 405 |
| 406 if (args[1]) { | |
| 407 gc = gaim_account_get_connection(irc->account); | |
| 408 irc_cmd_privmsg(irc, cmd, target, args); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
409 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), |
| 6982 | 410 args[1], GAIM_MESSAGE_SEND, time(NULL)); |
| 6333 | 411 } |
| 412 | |
| 413 return 0; | |
| 414 } | |
| 415 | |
| 416 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 417 { | |
| 418 char *buf; | |
| 419 | |
| 420 if (!args || !args[0]) | |
| 421 return 0; | |
| 422 | |
| 10208 | 423 if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 424 return 0; |
| 425 | |
| 426 if (args[1]) | |
| 427 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 428 else | |
| 429 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 430 irc_send(irc, buf); | |
| 431 g_free(buf); | |
| 432 | |
| 433 return 0; | |
| 434 } | |
| 435 | |
| 12013 | 436 int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 437 { | |
| 438 char *capital_cmd, *buf; | |
| 439 | |
| 440 if (!args || !args[0]) | |
| 441 return 0; | |
| 442 | |
| 443 /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 444 capital_cmd = g_ascii_strup(cmd, -1); | |
| 445 buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 446 irc_send(irc, buf); | |
| 447 g_free(capital_cmd); | |
| 448 g_free(buf); | |
| 449 | |
| 450 return 0; | |
| 451 } | |
| 452 | |
| 10564 | 453 int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 454 { | |
| 455 char *buf; | |
| 456 | |
| 457 buf = irc_format(irc, "v", "TIME"); | |
| 458 irc_send(irc, buf); | |
| 459 g_free(buf); | |
| 460 | |
| 461 return 0; | |
| 462 } | |
| 463 | |
| 6333 | 464 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 465 { | |
| 466 char *buf; | |
| 467 const char *topic; | |
| 468 GaimConversation *convo; | |
| 469 | |
| 470 if (!args) | |
| 471 return 0; | |
| 472 | |
| 11338 | 473 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, target, irc->account); |
| 10246 | 474 if (!convo) |
| 6350 | 475 return 0; |
| 6333 | 476 |
| 477 if (!args[0]) { | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
478 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(convo)); |
| 6333 | 479 |
| 8504 | 480 if (topic) { |
| 9762 | 481 char *tmp, *tmp2; |
|
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10609
diff
changeset
|
482 tmp = g_markup_escape_text(topic, -1); |
| 9762 | 483 tmp2 = gaim_markup_linkify(tmp); |
| 484 buf = g_strdup_printf(_("current topic is: %s"), tmp2); | |
| 8504 | 485 g_free(tmp); |
| 9762 | 486 g_free(tmp2); |
| 8504 | 487 } else |
| 6333 | 488 buf = g_strdup(_("No topic is set")); |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
489 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), target, buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 490 g_free(buf); |
| 491 | |
| 492 return 0; | |
| 493 } | |
| 494 | |
| 495 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 496 irc_send(irc, buf); | |
| 497 g_free(buf); | |
| 498 | |
| 499 return 0; | |
| 500 } | |
| 501 | |
| 502 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 503 { | |
| 504 char *buf; | |
| 505 | |
| 506 if (!args || !args[0]) | |
| 6350 | 507 return 0; |
| 6333 | 508 |
| 509 if (!strcmp(cmd, "wallops")) | |
| 510 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 511 else if (!strcmp(cmd, "operwall")) | |
| 512 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 513 else |
| 514 return 0; | |
| 6333 | 515 |
| 516 irc_send(irc, buf); | |
| 517 g_free(buf); | |
| 518 | |
| 519 return 0; | |
| 520 } | |
| 521 | |
| 522 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 523 { | |
| 524 char *buf; | |
| 525 | |
| 526 if (!args || !args[0]) | |
| 527 return 0; | |
| 528 | |
| 10609 | 529 if (args[1]) { |
| 530 buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); | |
| 531 irc->whois.nick = g_strdup(args[1]); | |
| 532 } else { | |
| 533 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
| 534 irc->whois.nick = g_strdup(args[0]); | |
| 535 } | |
| 536 | |
| 6333 | 537 irc_send(irc, buf); |
| 538 g_free(buf); | |
| 539 | |
| 540 return 0; | |
| 541 } | |
| 542 | |
| 543 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
| 544 { | |
| 545 char *buf, mode[5]; | |
| 546 int i = 0; | |
| 547 | |
| 548 if (!sign) | |
| 549 return; | |
| 550 | |
| 551 while (ops[i]) { | |
| 552 if (ops[i + 2] && ops[i + 4]) { | |
| 553 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 554 ops[i], ops[i + 2], ops[i + 4]); | |
| 555 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 556 ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 557 i += 6; | |
| 558 } else if (ops[i + 2]) { | |
| 559 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 560 sign, ops[i], ops[i + 2]); | |
| 561 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 562 ops[i + 1], ops[i + 3]); | |
| 563 i += 4; | |
| 564 } else { | |
| 565 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 566 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 567 i += 2; | |
| 568 } | |
| 569 irc_send(irc, buf); | |
| 570 g_free(buf); | |
| 571 } | |
| 6350 | 572 |
| 573 return; | |
| 6333 | 574 } |
