Sun, 15 Apr 2007 03:43:17 +0000
propagate from branch 'im.pidgin.pidgin' (head 88b7040408c88e4516c008f4eac579f98ef53e85)
to branch 'im.pidgin.rlaager.merging.msnp13-and-pidgin' (head 198222e01a7dc9f8795f68ec618a48c3478e04a8)
| 6333 | 1 | /** |
| 2 | * @file cmds.c | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
3 | * |
| 15884 | 4 | * purple |
| 6333 | 5 | * |
| 6 | * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
7 | * |
| 6333 | 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 | { | |
| 15884 | 37 | PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_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); | |
| 15884 | 44 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_IM) |
| 45 | purple_conv_im_write(PURPLE_CONV_IM(convo), "", buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
| 6333 | 46 | else |
| 15884 | 47 | purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "", buf, PURPLE_MESSAGE_SYSTEM|PURPLE_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
c15115dcfc23
[gaim-migrate @ 15012]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12013
diff
changeset
|
55 | char *buf, *message; |
| 6333 | 56 | |
| 57 | if (args[0] && strcmp(cmd, "back")) { | |
| 15884 | 58 | message = purple_markup_strip_html(args[0]); |
| 59 | purple_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 | { | |
| 15884 | 73 | PurpleConnection *gc = purple_account_get_connection(irc->account); |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
74 | char *action, *escaped, *dst, **newargs; |
| 6333 | 75 | const char *src; |
| 15884 | 76 | PurpleConversation *convo; |
| 6333 | 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 | ||
| 15884 | 110 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, target, irc->account); |
| 9130 | 111 | if (convo) { |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
112 | escaped = g_markup_escape_text(args[0], -1); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
113 | action = g_strdup_printf("/me %s", escaped); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
114 | g_free(escaped); |
| 6333 | 115 | if (action[strlen(action) - 1] == '\n') |
| 116 | action[strlen(action) - 1] = '\0'; | |
| 15884 | 117 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_CHAT) |
| 118 | serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), | |
| 119 | purple_connection_get_display_name(gc), | |
| 9130 | 120 | 0, action, time(NULL)); |
| 121 | else | |
| 15884 | 122 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
| 9130 | 123 | action, 0, time(NULL)); |
| 6333 | 124 | g_free(action); |
| 125 | } | |
| 126 | ||
| 127 | return 1; | |
| 128 | } | |
| 129 | ||
| 13943 | 130 | int irc_cmd_ctcp_version(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 131 | { | |
| 132 | char *buf; | |
| 133 | ||
| 134 | ||
| 135 | if (!args || !args[0]) | |
| 136 | return 0; | |
| 137 | ||
| 138 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], "\001VERSION\001"); | |
| 139 | irc_send(irc, buf); | |
| 140 | g_free(buf); | |
| 141 | ||
| 142 | return 0; | |
| 143 | } | |
| 144 | ||
| 6333 | 145 | int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 146 | { | |
| 147 | char *buf; | |
| 148 | ||
| 149 | if (!args || !args[0] || !(args[1] || target)) | |
| 150 | return 0; | |
| 151 | ||
| 152 | buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 153 | irc_send(irc, buf); | |
| 154 | g_free(buf); | |
| 155 | ||
| 156 | return 0; | |
| 157 | } | |
| 158 | ||
| 159 | int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 160 | { | |
| 161 | char *buf; | |
| 162 | ||
| 163 | if (!args || !args[0]) | |
| 164 | return 0; | |
| 165 | ||
| 166 | if (args[1]) | |
| 167 | buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 168 | else | |
| 169 | buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 170 | irc_send(irc, buf); | |
| 171 | g_free(buf); | |
| 172 | ||
| 173 | return 0; | |
| 174 | } | |
| 175 | ||
| 176 | int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 177 | { | |
| 178 | char *buf; | |
| 15884 | 179 | PurpleConversation *convo; |
| 6333 | 180 | |
| 181 | if (!args || !args[0]) | |
| 182 | return 0; | |
| 183 | ||
| 15884 | 184 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, target, irc->account); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10208
diff
changeset
|
185 | if (!convo) |
| 6350 | 186 | return 0; |
| 6333 | 187 | |
| 188 | if (args[1]) | |
| 189 | buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 190 | else | |
| 191 | buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 192 | irc_send(irc, buf); | |
| 193 | g_free(buf); | |
| 194 | ||
| 195 | return 0; | |
| 196 | } | |
| 197 | ||
| 8114 | 198 | int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 199 | { | |
| 15884 | 200 | purple_roomlist_show_with_account(irc->account); |
| 8114 | 201 | |
| 202 | return 0; | |
| 203 | } | |
| 204 | ||
| 6333 | 205 | int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 206 | { | |
| 15884 | 207 | PurpleConnection *gc; |
| 6333 | 208 | char *buf; |
| 209 | ||
| 210 | if (!args) | |
| 211 | return 0; | |
| 212 | ||
| 213 | if (!strcmp(cmd, "mode")) { | |
| 10208 | 214 | if (!args[0] && irc_ischannel(target)) |
| 6333 | 215 | buf = irc_format(irc, "vc", "MODE", target); |
| 216 | else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
| 217 | buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
| 218 | else if (args[0]) | |
| 219 | buf = irc_format(irc, "vv", "MODE", args[0]); | |
| 220 | else | |
| 6350 | 221 | return 0; |
| 6333 | 222 | } else if (!strcmp(cmd, "umode")) { |
| 223 | if (!args[0]) | |
| 6350 | 224 | return 0; |
| 15884 | 225 | gc = purple_account_get_connection(irc->account); |
| 226 | buf = irc_format(irc, "vnv", "MODE", purple_connection_get_display_name(gc), args[0]); | |
| 6365 | 227 | } else { |
| 228 | return 0; | |
| 6333 | 229 | } |
| 6365 | 230 | |
| 6333 | 231 | irc_send(irc, buf); |
| 232 | g_free(buf); | |
| 233 | ||
| 234 | return 0; | |
| 235 | } | |
| 236 | ||
| 237 | int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 238 | { | |
| 239 | char *buf; | |
| 240 | ||
| 10208 | 241 | if (!args || (!args[0] && !irc_ischannel(target))) |
| 6333 | 242 | return 0; |
| 243 | ||
| 244 | buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 245 | irc_send(irc, buf); | |
| 246 | g_free(buf); | |
| 247 | ||
| 248 | return 0; | |
| 249 | } | |
| 250 | ||
| 251 | int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 252 | { | |
| 253 | char *buf; | |
| 254 | ||
| 255 | if (!args || !args[0]) | |
| 256 | return 0; | |
| 257 | ||
| 258 | buf = irc_format(irc, "v:", "NICK", args[0]); | |
| 259 | irc_send(irc, buf); | |
| 260 | g_free(buf); | |
| 261 | ||
| 262 | return 0; | |
| 263 | } | |
| 264 | ||
| 265 | int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 266 | { | |
| 267 | char **nicks, **ops, *sign, *mode; | |
| 268 | int i = 0, used = 0; | |
| 269 | ||
| 270 | if (!args || !args[0] || !*args[0]) | |
| 271 | return 0; | |
| 272 | ||
| 273 | if (!strcmp(cmd, "op")) { | |
| 274 | sign = "+"; | |
| 275 | mode = "o"; | |
| 276 | } else if (!strcmp(cmd, "deop")) { | |
| 277 | sign = "-"; | |
| 278 | mode = "o"; | |
| 279 | } else if (!strcmp(cmd, "voice")) { | |
| 280 | sign = "+"; | |
| 281 | mode = "v"; | |
| 282 | } else if (!strcmp(cmd, "devoice")) { | |
| 283 | sign = "-"; | |
| 284 | mode = "v"; | |
| 285 | } else { | |
| 15884 | 286 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); |
| 6333 | 287 | return 0; |
| 288 | } | |
| 289 | ||
| 290 | nicks = g_strsplit(args[0], " ", -1); | |
| 291 | ||
| 292 | for (i = 0; nicks[i]; i++) | |
| 293 | /* nothing */; | |
| 294 | ops = g_new0(char *, i * 2 + 1); | |
| 295 | ||
| 296 | for (i = 0; nicks[i]; i++) { | |
| 297 | if (!*nicks[i]) | |
| 298 | continue; | |
| 299 | ops[used++] = mode; | |
| 300 | ops[used++] = nicks[i]; | |
| 301 | } | |
| 302 | ||
| 303 | irc_do_mode(irc, target, sign, ops); | |
| 304 | g_free(ops); | |
| 305 | ||
| 6350 | 306 | return 0; |
| 6333 | 307 | } |
| 308 | ||
| 309 | int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 310 | { | |
| 311 | char *buf; | |
| 312 | ||
| 313 | if (!args) | |
| 314 | return 0; | |
| 315 | ||
| 316 | if (args[1]) | |
| 317 | buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 318 | else | |
| 319 | buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 320 | irc_send(irc, buf); | |
| 321 | g_free(buf); | |
| 322 | ||
| 323 | return 0; | |
| 324 | } | |
| 325 | ||
| 326 | int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 327 | { | |
| 328 | char *stamp; | |
| 329 | char *buf; | |
| 330 | ||
| 331 | if (args && args[0]) { | |
| 10208 | 332 | if (irc_ischannel(args[0])) |
| 6333 | 333 | return 0; |
| 334 | stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 335 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 336 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
337 | } else if (target) { |
| 6350 | 338 | stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 339 | buf = irc_format(irc, "v:", "PING", stamp); |
| 340 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
341 | } else { |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
342 | stamp = g_strdup_printf("%lu", time(NULL)); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
343 | buf = irc_format(irc, "vv", "PING", stamp); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
344 | g_free(stamp); |
| 6333 | 345 | } |
| 346 | irc_send(irc, buf); | |
| 347 | g_free(buf); | |
| 348 | ||
| 349 | return 0; | |
| 350 | } | |
| 351 | ||
| 352 | int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 353 | { | |
| 354 | const char *cur, *end; | |
| 355 | char *msg, *buf; | |
| 356 | ||
| 357 | if (!args || !args[0] || !args[1]) | |
| 358 | return 0; | |
| 359 | ||
| 360 | cur = args[1]; | |
| 361 | end = args[1]; | |
| 362 | while (*end && *cur) { | |
| 363 | end = strchr(cur, '\n'); | |
| 364 | if (!end) | |
| 365 | end = cur + strlen(cur); | |
| 366 | msg = g_strndup(cur, end - cur); | |
| 367 | buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
| 368 | irc_send(irc, buf); | |
| 369 | g_free(msg); | |
| 370 | g_free(buf); | |
| 371 | cur = end + 1; | |
| 372 | } | |
| 373 | ||
| 374 | return 0; | |
| 375 | } | |
| 376 | ||
| 377 | int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 378 | { | |
| 379 | char *buf; | |
| 380 | ||
| 9440 | 381 | if (!irc->quitting) { |
| 11763 | 382 | /* |
| 15884 | 383 | * Use purple_account_get_string(irc->account, "quitmsg", IRC_DEFAULT_QUIT) |
| 11763 | 384 | * and uncomment the appropriate account preference in irc.c if we |
| 385 | * decide we want custom quit messages. | |
| 386 | */ | |
| 387 | buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : IRC_DEFAULT_QUIT); | |
| 9440 | 388 | irc_send(irc, buf); |
| 389 | g_free(buf); | |
| 390 | ||
| 391 | irc->quitting = TRUE; | |
|
13839
e27a7f02055c
[gaim-migrate @ 16286]
Mark Doliner <markdoliner@pidgin.im>
parents:
12669
diff
changeset
|
392 | |
|
13974
c6ff47f81057
[gaim-migrate @ 16411]
Mark Doliner <markdoliner@pidgin.im>
parents:
13943
diff
changeset
|
393 | if (!irc->account->disconnecting) |
| 15884 | 394 | purple_account_set_status(irc->account, "offline", TRUE, NULL); |
| 9440 | 395 | } |
| 6333 | 396 | |
| 397 | return 0; | |
| 398 | } | |
| 399 | ||
| 400 | int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 401 | { | |
| 402 | char *buf; | |
| 403 | ||
| 404 | if (!args || !args[0]) | |
| 405 | return 0; | |
| 406 | ||
| 407 | buf = irc_format(irc, "v", args[0]); | |
| 408 | irc_send(irc, buf); | |
| 409 | g_free(buf); | |
| 410 | ||
| 411 | return 0; | |
| 412 | } | |
| 413 | ||
| 414 | int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 415 | { | |
| 15884 | 416 | PurpleConversation *convo; |
| 417 | PurpleConnection *gc; | |
| 6333 | 418 | |
| 419 | if (!args || !args[0]) | |
| 420 | return 0; | |
| 421 | ||
| 15884 | 422 | convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, irc->account, args[0]); |
| 423 | purple_conversation_present(convo); | |
| 6333 | 424 | |
| 425 | if (args[1]) { | |
| 15884 | 426 | gc = purple_account_get_connection(irc->account); |
| 6333 | 427 | irc_cmd_privmsg(irc, cmd, target, args); |
| 15884 | 428 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
| 429 | args[1], PURPLE_MESSAGE_SEND, time(NULL)); | |
| 6333 | 430 | } |
| 431 | ||
| 432 | return 0; | |
| 433 | } | |
| 434 | ||
| 435 | int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 436 | { | |
| 437 | char *buf; | |
| 438 | ||
| 439 | if (!args || !args[0]) | |
| 440 | return 0; | |
| 441 | ||
| 10208 | 442 | if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 443 | return 0; |
| 444 | ||
| 445 | if (args[1]) | |
| 446 | buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 447 | else | |
| 448 | buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 449 | irc_send(irc, buf); | |
| 450 | g_free(buf); | |
| 451 | ||
| 452 | return 0; | |
| 453 | } | |
| 454 | ||
| 12013 | 455 | int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 456 | { | |
| 457 | char *capital_cmd, *buf; | |
| 458 | ||
| 459 | if (!args || !args[0]) | |
| 460 | return 0; | |
| 461 | ||
| 462 | /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 463 | capital_cmd = g_ascii_strup(cmd, -1); | |
| 464 | buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 465 | irc_send(irc, buf); | |
| 466 | g_free(capital_cmd); | |
| 467 | g_free(buf); | |
| 468 | ||
| 469 | return 0; | |
| 470 | } | |
| 471 | ||
| 10564 | 472 | int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 473 | { | |
| 474 | char *buf; | |
| 475 | ||
| 476 | buf = irc_format(irc, "v", "TIME"); | |
| 477 | irc_send(irc, buf); | |
| 478 | g_free(buf); | |
| 479 | ||
| 480 | return 0; | |
| 481 | } | |
| 482 | ||
| 6333 | 483 | int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 484 | { | |
| 485 | char *buf; | |
| 486 | const char *topic; | |
| 15884 | 487 | PurpleConversation *convo; |
| 6333 | 488 | |
| 489 | if (!args) | |
| 490 | return 0; | |
| 491 | ||
| 15884 | 492 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, target, irc->account); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10208
diff
changeset
|
493 | if (!convo) |
| 6350 | 494 | return 0; |
| 6333 | 495 | |
| 496 | if (!args[0]) { | |
| 15884 | 497 | topic = purple_conv_chat_get_topic (PURPLE_CONV_CHAT(convo)); |
| 6333 | 498 | |
| 8504 | 499 | if (topic) { |
| 9762 | 500 | char *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10609
diff
changeset
|
501 | tmp = g_markup_escape_text(topic, -1); |
| 15884 | 502 | tmp2 = purple_markup_linkify(tmp); |
| 9762 | 503 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); |
| 8504 | 504 | g_free(tmp); |
| 9762 | 505 | g_free(tmp2); |
| 8504 | 506 | } else |
| 6333 | 507 | buf = g_strdup(_("No topic is set")); |
| 15884 | 508 | purple_conv_chat_write(PURPLE_CONV_CHAT(convo), target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 509 | g_free(buf); |
| 510 | ||
| 511 | return 0; | |
| 512 | } | |
| 513 | ||
| 514 | buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 515 | irc_send(irc, buf); | |
| 516 | g_free(buf); | |
| 517 | ||
| 518 | return 0; | |
| 519 | } | |
| 520 | ||
| 521 | int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 522 | { | |
| 523 | char *buf; | |
| 524 | ||
| 525 | if (!args || !args[0]) | |
| 6350 | 526 | return 0; |
| 6333 | 527 | |
| 528 | if (!strcmp(cmd, "wallops")) | |
| 529 | buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 530 | else if (!strcmp(cmd, "operwall")) | |
| 531 | buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 532 | else |
| 533 | return 0; | |
| 6333 | 534 | |
| 535 | irc_send(irc, buf); | |
| 536 | g_free(buf); | |
| 537 | ||
| 538 | return 0; | |
| 539 | } | |
| 540 | ||
| 541 | int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 542 | { | |
| 543 | char *buf; | |
| 544 | ||
| 545 | if (!args || !args[0]) | |
| 546 | return 0; | |
| 547 | ||
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
548 | if (args[1]) { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
549 | buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
550 | irc->whois.nick = g_strdup(args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
551 | } else { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
552 | buf = irc_format(irc, "vn", "WHOIS", args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
553 | irc->whois.nick = g_strdup(args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
554 | } |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
555 | |
| 6333 | 556 | irc_send(irc, buf); |
| 557 | g_free(buf); | |
| 558 | ||
| 559 | return 0; | |
| 560 | } | |
| 561 | ||
| 562 | static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
| 563 | { | |
| 564 | char *buf, mode[5]; | |
| 565 | int i = 0; | |
| 566 | ||
| 567 | if (!sign) | |
| 568 | return; | |
| 569 | ||
| 570 | while (ops[i]) { | |
| 571 | if (ops[i + 2] && ops[i + 4]) { | |
| 572 | g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 573 | ops[i], ops[i + 2], ops[i + 4]); | |
| 574 | buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 575 | ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 576 | i += 6; | |
| 577 | } else if (ops[i + 2]) { | |
| 578 | g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 579 | sign, ops[i], ops[i + 2]); | |
| 580 | buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 581 | ops[i + 1], ops[i + 3]); | |
| 582 | i += 4; | |
| 583 | } else { | |
| 584 | g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 585 | buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 586 | i += 2; | |
| 587 | } | |
| 588 | irc_send(irc, buf); | |
| 589 | g_free(buf); | |
| 590 | } | |
| 6350 | 591 | |
| 592 | return; | |
| 6333 | 593 | } |