Mercurial > pidgin
annotate src/protocols/irc/cmds.c @ 13119:fcde3faa1f57
[gaim-migrate @ 15481]
This adds support for displaying log timestamps in their original timezone. If your OS's definition of struct tm sucks, then the log timestamps will show up in your local timezone, but converted, so the time is accurate. Yay! Anyway, this all works, as I've renamed lots of my log files locally, but currently, there's no code to save new logs in this name format. That's held up on a portability issue and backwards compatibility issue.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Sat, 04 Feb 2006 20:55:52 +0000 |
| parents | 879f90dbd21f |
| children | 1a095ac881ce |
| 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; | |
| 375 } | |
| 6333 | 376 |
| 377 return 0; | |
| 378 } | |
| 379 | |
| 380 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 381 { | |
| 382 char *buf; | |
| 383 | |
| 384 if (!args || !args[0]) | |
| 385 return 0; | |
| 386 | |
| 387 buf = irc_format(irc, "v", args[0]); | |
| 388 irc_send(irc, buf); | |
| 389 g_free(buf); | |
| 390 | |
| 391 return 0; | |
| 392 } | |
| 393 | |
| 394 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 395 { | |
| 396 GaimConversation *convo; | |
| 397 GaimConnection *gc; | |
| 398 | |
| 399 if (!args || !args[0]) | |
| 400 return 0; | |
| 401 | |
| 11338 | 402 convo = gaim_conversation_new(GAIM_CONV_TYPE_IM, irc->account, args[0]); |
| 6333 | 403 |
| 404 if (args[1]) { | |
| 405 gc = gaim_account_get_connection(irc->account); | |
| 406 irc_cmd_privmsg(irc, cmd, target, args); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
407 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), |
| 6982 | 408 args[1], GAIM_MESSAGE_SEND, time(NULL)); |
| 6333 | 409 } |
| 410 | |
| 411 return 0; | |
| 412 } | |
| 413 | |
| 414 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 415 { | |
| 416 char *buf; | |
| 417 | |
| 418 if (!args || !args[0]) | |
| 419 return 0; | |
| 420 | |
| 10208 | 421 if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 422 return 0; |
| 423 | |
| 424 if (args[1]) | |
| 425 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 426 else | |
| 427 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 428 irc_send(irc, buf); | |
| 429 g_free(buf); | |
| 430 | |
| 431 return 0; | |
| 432 } | |
| 433 | |
| 12013 | 434 int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 435 { | |
| 436 char *capital_cmd, *buf; | |
| 437 | |
| 438 if (!args || !args[0]) | |
| 439 return 0; | |
| 440 | |
| 441 /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 442 capital_cmd = g_ascii_strup(cmd, -1); | |
| 443 buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 444 irc_send(irc, buf); | |
| 445 g_free(capital_cmd); | |
| 446 g_free(buf); | |
| 447 | |
| 448 return 0; | |
| 449 } | |
| 450 | |
| 10564 | 451 int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 452 { | |
| 453 char *buf; | |
| 454 | |
| 455 buf = irc_format(irc, "v", "TIME"); | |
| 456 irc_send(irc, buf); | |
| 457 g_free(buf); | |
| 458 | |
| 459 return 0; | |
| 460 } | |
| 461 | |
| 6333 | 462 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 463 { | |
| 464 char *buf; | |
| 465 const char *topic; | |
| 466 GaimConversation *convo; | |
| 467 | |
| 468 if (!args) | |
| 469 return 0; | |
| 470 | |
| 11338 | 471 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, target, irc->account); |
| 10246 | 472 if (!convo) |
| 6350 | 473 return 0; |
| 6333 | 474 |
| 475 if (!args[0]) { | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
476 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(convo)); |
| 6333 | 477 |
| 8504 | 478 if (topic) { |
| 9762 | 479 char *tmp, *tmp2; |
|
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10609
diff
changeset
|
480 tmp = g_markup_escape_text(topic, -1); |
| 9762 | 481 tmp2 = gaim_markup_linkify(tmp); |
| 482 buf = g_strdup_printf(_("current topic is: %s"), tmp2); | |
| 8504 | 483 g_free(tmp); |
| 9762 | 484 g_free(tmp2); |
| 8504 | 485 } else |
| 6333 | 486 buf = g_strdup(_("No topic is set")); |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
487 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), target, buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 488 g_free(buf); |
| 489 | |
| 490 return 0; | |
| 491 } | |
| 492 | |
| 493 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 494 irc_send(irc, buf); | |
| 495 g_free(buf); | |
| 496 | |
| 497 return 0; | |
| 498 } | |
| 499 | |
| 500 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 501 { | |
| 502 char *buf; | |
| 503 | |
| 504 if (!args || !args[0]) | |
| 6350 | 505 return 0; |
| 6333 | 506 |
| 507 if (!strcmp(cmd, "wallops")) | |
| 508 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 509 else if (!strcmp(cmd, "operwall")) | |
| 510 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 511 else |
| 512 return 0; | |
| 6333 | 513 |
| 514 irc_send(irc, buf); | |
| 515 g_free(buf); | |
| 516 | |
| 517 return 0; | |
| 518 } | |
| 519 | |
| 520 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 521 { | |
| 522 char *buf; | |
| 523 | |
| 524 if (!args || !args[0]) | |
| 525 return 0; | |
| 526 | |
| 10609 | 527 if (args[1]) { |
| 528 buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); | |
| 529 irc->whois.nick = g_strdup(args[1]); | |
| 530 } else { | |
| 531 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
| 532 irc->whois.nick = g_strdup(args[0]); | |
| 533 } | |
| 534 | |
| 6333 | 535 irc_send(irc, buf); |
| 536 g_free(buf); | |
| 537 | |
| 538 return 0; | |
| 539 } | |
| 540 | |
| 541 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
| 542 { | |
| 543 char *buf, mode[5]; | |
| 544 int i = 0; | |
| 545 | |
| 546 if (!sign) | |
| 547 return; | |
| 548 | |
| 549 while (ops[i]) { | |
| 550 if (ops[i + 2] && ops[i + 4]) { | |
| 551 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 552 ops[i], ops[i + 2], ops[i + 4]); | |
| 553 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 554 ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 555 i += 6; | |
| 556 } else if (ops[i + 2]) { | |
| 557 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 558 sign, ops[i], ops[i + 2]); | |
| 559 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 560 ops[i + 1], ops[i + 3]); | |
| 561 i += 4; | |
| 562 } else { | |
| 563 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 564 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 565 i += 2; | |
| 566 } | |
| 567 irc_send(irc, buf); | |
| 568 g_free(buf); | |
| 569 } | |
| 6350 | 570 |
| 571 return; | |
| 6333 | 572 } |
