Mercurial > pidgin
annotate src/protocols/irc/cmds.c @ 9294:01dee77a079d
[gaim-migrate @ 10097]
Gary Kramlich kickassified our Napster icon!
Now when you sign on to Napster you'll see an EVEN BETTER icon!
Improvements:
-Beveled edges
-The space between the top of the guy's head and the head phones
is transparent and not white, like the guy's face
He's our powers, magnified
And he's fighting on, the planet's side
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Tue, 15 Jun 2004 11:59:53 +0000 |
| parents | 6430b09ccc71 |
| children | 00242c2419c3 |
| 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 { | |
| 37 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); | |
| 38 char *buf; | |
| 39 | |
| 40 if (!convo) | |
| 6350 | 41 return 1; |
| 6333 | 42 |
| 43 buf = g_strdup_printf(_("Unknown command: %s"), cmd); | |
| 44 if (gaim_conversation_get_type(convo) == GAIM_CONV_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 { | |
| 55 char *buf, *message, *cur; | |
| 56 | |
| 57 if (args[0] && strcmp(cmd, "back")) { | |
| 58 message = strdup(args[0]); | |
| 59 for (cur = message; *cur; cur++) { | |
| 60 if (*cur == '\n') | |
| 61 *cur = ' '; | |
| 62 } | |
| 63 buf = irc_format(irc, "v:", "AWAY", message); | |
| 64 g_free(message); | |
| 65 } else { | |
| 66 buf = irc_format(irc, "v", "AWAY"); | |
| 67 } | |
| 68 irc_send(irc, buf); | |
| 69 g_free(buf); | |
| 70 | |
| 71 return 0; | |
| 72 } | |
| 73 | |
| 74 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 75 { | |
| 76 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
| 77 char *action, *dst, **newargs; | |
| 78 const char *src; | |
| 79 GaimConversation *convo; | |
| 80 | |
| 81 if (!args || !args[0] || !gc) | |
| 82 return 0; | |
| 83 | |
| 6376 | 84 action = g_malloc(strlen(args[0]) + 10); |
| 6333 | 85 |
| 86 sprintf(action, "\001ACTION "); | |
| 87 | |
| 88 src = args[0]; | |
| 89 dst = action + 8; | |
| 90 while (*src) { | |
| 91 if (*src == '\n') { | |
| 92 if (*(src + 1) == '\0') { | |
| 93 break; | |
| 94 } else { | |
| 95 *dst++ = ' '; | |
| 96 src++; | |
| 97 continue; | |
| 98 } | |
| 99 } | |
| 100 *dst++ = *src++; | |
| 101 } | |
| 102 *dst++ = '\001'; | |
| 103 *dst = '\0'; | |
| 104 | |
| 105 newargs = g_new0(char *, 2); | |
| 106 newargs[0] = g_strdup(target); | |
| 107 newargs[1] = action; | |
| 108 irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
| 109 g_free(newargs[0]); | |
| 110 g_free(newargs[1]); | |
| 111 g_free(newargs); | |
| 112 | |
| 113 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 9130 | 114 if (convo) { |
| 6333 | 115 action = g_strdup_printf("/me %s", args[0]); |
| 116 if (action[strlen(action) - 1] == '\n') | |
| 117 action[strlen(action) - 1] = '\0'; | |
| 9130 | 118 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) |
| 119 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), | |
| 120 gaim_connection_get_display_name(gc), | |
| 121 0, action, time(NULL)); | |
| 122 else | |
| 123 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), | |
| 124 action, 0, time(NULL)); | |
| 6333 | 125 g_free(action); |
| 126 } | |
| 127 | |
| 128 return 1; | |
| 129 } | |
| 130 | |
| 131 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 132 { | |
| 133 char *buf; | |
| 134 | |
| 135 if (!args || !args[0] || !(args[1] || target)) | |
| 136 return 0; | |
| 137 | |
| 138 buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 139 irc_send(irc, buf); | |
| 140 g_free(buf); | |
| 141 | |
| 142 return 0; | |
| 143 } | |
| 144 | |
| 145 int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 146 { | |
| 147 char *buf; | |
| 148 | |
| 149 if (!args || !args[0]) | |
| 150 return 0; | |
| 151 | |
| 152 if (args[1]) | |
| 153 buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 154 else | |
| 155 buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 156 irc_send(irc, buf); | |
| 157 g_free(buf); | |
| 158 | |
| 159 return 0; | |
| 160 } | |
| 161 | |
| 162 int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 163 { | |
| 164 char *buf; | |
| 165 GaimConversation *convo; | |
| 166 | |
| 167 if (!args || !args[0]) | |
| 168 return 0; | |
| 169 | |
| 170 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 171 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
| 6350 | 172 return 0; |
| 6333 | 173 |
| 174 if (args[1]) | |
| 175 buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 176 else | |
| 177 buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 178 irc_send(irc, buf); | |
| 179 g_free(buf); | |
| 180 | |
| 181 return 0; | |
| 182 } | |
| 183 | |
| 8114 | 184 int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 185 { | |
| 8352 | 186 gaim_roomlist_show_with_account(irc->account); |
| 8114 | 187 |
| 188 return 0; | |
| 189 } | |
| 190 | |
| 6333 | 191 int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 192 { | |
| 193 GaimConnection *gc; | |
| 194 char *buf; | |
| 195 | |
| 196 if (!args) | |
| 197 return 0; | |
| 198 | |
| 199 if (!strcmp(cmd, "mode")) { | |
| 200 if (!args[0] && (*target == '#' || *target == '&')) | |
| 201 buf = irc_format(irc, "vc", "MODE", target); | |
| 202 else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
| 203 buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
| 204 else if (args[0]) | |
| 205 buf = irc_format(irc, "vv", "MODE", args[0]); | |
| 206 else | |
| 6350 | 207 return 0; |
| 6333 | 208 } else if (!strcmp(cmd, "umode")) { |
| 209 if (!args[0]) | |
| 6350 | 210 return 0; |
| 6333 | 211 gc = gaim_account_get_connection(irc->account); |
| 212 buf = irc_format(irc, "vnv", "MODE", gaim_connection_get_display_name(gc), args[0]); | |
| 6365 | 213 } else { |
| 214 return 0; | |
| 6333 | 215 } |
| 6365 | 216 |
| 6333 | 217 irc_send(irc, buf); |
| 218 g_free(buf); | |
| 219 | |
| 220 return 0; | |
| 221 } | |
| 222 | |
| 223 int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 224 { | |
| 225 char *buf; | |
| 226 | |
| 227 if (!args) | |
| 228 return 0; | |
| 229 | |
| 230 buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 231 irc_send(irc, buf); | |
| 232 g_free(buf); | |
| 233 | |
| 234 irc->nameconv = g_strdup(target); | |
| 235 | |
| 236 return 0; | |
| 237 } | |
| 238 | |
| 239 int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 240 { | |
| 241 char *buf; | |
| 242 | |
| 243 if (!args || !args[0]) | |
| 244 return 0; | |
| 245 | |
| 246 buf = irc_format(irc, "v:", "NICK", args[0]); | |
| 247 irc_send(irc, buf); | |
| 248 g_free(buf); | |
| 249 | |
| 250 return 0; | |
| 251 } | |
| 252 | |
| 253 int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 254 { | |
| 255 char **nicks, **ops, *sign, *mode; | |
| 256 int i = 0, used = 0; | |
| 257 | |
| 258 if (!args || !args[0] || !*args[0]) | |
| 259 return 0; | |
| 260 | |
| 261 if (!strcmp(cmd, "op")) { | |
| 262 sign = "+"; | |
| 263 mode = "o"; | |
| 264 } else if (!strcmp(cmd, "deop")) { | |
| 265 sign = "-"; | |
| 266 mode = "o"; | |
| 267 } else if (!strcmp(cmd, "voice")) { | |
| 268 sign = "+"; | |
| 269 mode = "v"; | |
| 270 } else if (!strcmp(cmd, "devoice")) { | |
| 271 sign = "-"; | |
| 272 mode = "v"; | |
| 273 } else { | |
| 274 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); | |
| 275 return 0; | |
| 276 } | |
| 277 | |
| 278 nicks = g_strsplit(args[0], " ", -1); | |
| 279 | |
| 280 for (i = 0; nicks[i]; i++) | |
| 281 /* nothing */; | |
| 282 ops = g_new0(char *, i * 2 + 1); | |
| 283 | |
| 284 for (i = 0; nicks[i]; i++) { | |
| 285 if (!*nicks[i]) | |
| 286 continue; | |
| 287 ops[used++] = mode; | |
| 288 ops[used++] = nicks[i]; | |
| 289 } | |
| 290 | |
| 291 irc_do_mode(irc, target, sign, ops); | |
| 292 g_free(ops); | |
| 293 | |
| 6350 | 294 return 0; |
| 6333 | 295 } |
| 296 | |
| 297 int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 298 { | |
| 299 char *buf; | |
| 300 | |
| 301 if (!args) | |
| 302 return 0; | |
| 303 | |
| 304 if (args[1]) | |
| 305 buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 306 else | |
| 307 buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 308 irc_send(irc, buf); | |
| 309 g_free(buf); | |
| 310 | |
| 311 return 0; | |
| 312 } | |
| 313 | |
| 314 int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 315 { | |
| 316 char *stamp; | |
| 317 char *buf; | |
| 318 | |
| 319 if (args && args[0]) { | |
| 320 if (*args[0] == '#' || *args[0] == '&') | |
| 321 return 0; | |
| 322 stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 323 buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 324 g_free(stamp); | |
| 325 } else { | |
| 6350 | 326 stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 327 buf = irc_format(irc, "v:", "PING", stamp); |
| 328 g_free(stamp); | |
| 329 } | |
| 330 irc_send(irc, buf); | |
| 331 g_free(buf); | |
| 332 | |
| 333 return 0; | |
| 334 } | |
| 335 | |
| 336 int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 337 { | |
| 338 const char *cur, *end; | |
| 339 char *msg, *buf; | |
| 340 | |
| 341 if (!args || !args[0] || !args[1]) | |
| 342 return 0; | |
| 343 | |
| 344 cur = args[1]; | |
| 345 end = args[1]; | |
| 346 while (*end && *cur) { | |
| 347 end = strchr(cur, '\n'); | |
| 348 if (!end) | |
| 349 end = cur + strlen(cur); | |
| 350 msg = g_strndup(cur, end - cur); | |
| 351 buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
| 352 irc_send(irc, buf); | |
| 353 g_free(msg); | |
| 354 g_free(buf); | |
| 355 cur = end + 1; | |
| 356 } | |
| 357 | |
| 358 return 0; | |
| 359 } | |
| 360 | |
| 361 int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 362 { | |
| 363 char *buf; | |
| 364 | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6365
diff
changeset
|
365 buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : "Download Gaim: " GAIM_WEBSITE); |
| 6333 | 366 irc_send(irc, buf); |
| 367 g_free(buf); | |
| 368 | |
| 369 return 0; | |
| 370 } | |
| 371 | |
| 372 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 373 { | |
| 374 char *buf; | |
| 375 | |
| 376 if (!args || !args[0]) | |
| 377 return 0; | |
| 378 | |
| 379 buf = irc_format(irc, "v", args[0]); | |
| 380 irc_send(irc, buf); | |
| 381 g_free(buf); | |
| 382 | |
| 383 return 0; | |
| 384 } | |
| 385 | |
| 386 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 387 { | |
| 388 GaimConversation *convo; | |
| 389 GaimConnection *gc; | |
| 390 | |
| 391 if (!args || !args[0]) | |
| 392 return 0; | |
| 393 | |
| 394 convo = gaim_conversation_new(GAIM_CONV_IM, irc->account, args[0]); | |
| 395 | |
| 396 if (args[1]) { | |
| 397 gc = gaim_account_get_connection(irc->account); | |
| 398 irc_cmd_privmsg(irc, cmd, target, args); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
399 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), |
| 6982 | 400 args[1], GAIM_MESSAGE_SEND, time(NULL)); |
| 6333 | 401 } |
| 402 | |
| 403 return 0; | |
| 404 } | |
| 405 | |
| 406 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 407 { | |
| 408 char *buf; | |
| 409 | |
| 410 if (!args || !args[0]) | |
| 411 return 0; | |
| 412 | |
| 413 if (*target != '#' && *target != '&') /* not a channel, punt */ | |
| 414 return 0; | |
| 415 | |
| 416 if (args[1]) | |
| 417 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 418 else | |
| 419 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 420 irc_send(irc, buf); | |
| 421 g_free(buf); | |
| 422 | |
| 423 return 0; | |
| 424 } | |
| 425 | |
| 426 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 427 { | |
| 428 char *buf; | |
| 429 const char *topic; | |
| 430 GaimConversation *convo; | |
| 431 | |
| 432 if (!args) | |
| 433 return 0; | |
| 434 | |
| 435 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 436 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
| 6350 | 437 return 0; |
| 6333 | 438 |
| 439 if (!args[0]) { | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
440 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(convo)); |
| 6333 | 441 |
| 8504 | 442 if (topic) { |
| 443 char *tmp = gaim_escape_html(topic); | |
| 444 buf = g_strdup_printf(_("current topic is: %s"), tmp); | |
| 445 g_free(tmp); | |
| 446 } else | |
| 6333 | 447 buf = g_strdup(_("No topic is set")); |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
448 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), target, buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 449 g_free(buf); |
| 450 | |
| 451 return 0; | |
| 452 } | |
| 453 | |
| 454 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 455 irc_send(irc, buf); | |
| 456 g_free(buf); | |
| 457 | |
| 458 return 0; | |
| 459 } | |
| 460 | |
| 461 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 462 { | |
| 463 char *buf; | |
| 464 | |
| 465 if (!args || !args[0]) | |
| 6350 | 466 return 0; |
| 6333 | 467 |
| 468 if (!strcmp(cmd, "wallops")) | |
| 469 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 470 else if (!strcmp(cmd, "operwall")) | |
| 471 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 472 else |
| 473 return 0; | |
| 6333 | 474 |
| 475 irc_send(irc, buf); | |
| 476 g_free(buf); | |
| 477 | |
| 478 return 0; | |
| 479 } | |
| 480 | |
| 481 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 482 { | |
| 483 char *buf; | |
| 484 | |
| 485 if (!args || !args[0]) | |
| 486 return 0; | |
| 487 | |
| 488 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
| 489 irc_send(irc, buf); | |
| 490 g_free(buf); | |
| 491 irc->whois.nick = g_strdup(args[0]); | |
| 492 | |
| 493 return 0; | |
| 494 } | |
| 495 | |
| 496 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
| 497 { | |
| 498 char *buf, mode[5]; | |
| 499 int i = 0; | |
| 500 | |
| 501 if (!sign) | |
| 502 return; | |
| 503 | |
| 504 while (ops[i]) { | |
| 505 if (ops[i + 2] && ops[i + 4]) { | |
| 506 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 507 ops[i], ops[i + 2], ops[i + 4]); | |
| 508 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 509 ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 510 i += 6; | |
| 511 } else if (ops[i + 2]) { | |
| 512 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 513 sign, ops[i], ops[i + 2]); | |
| 514 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 515 ops[i + 1], ops[i + 3]); | |
| 516 i += 4; | |
| 517 } else { | |
| 518 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 519 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 520 i += 2; | |
| 521 } | |
| 522 irc_send(irc, buf); | |
| 523 g_free(buf); | |
| 524 } | |
| 6350 | 525 |
| 526 return; | |
| 6333 | 527 } |
