Mon, 21 Jul 2008 20:36:07 +0000
Correct some IRC comments for /ctcp
| 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16474
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6333 | 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 | ||
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
71 | int irc_cmd_ctcp(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
72 | { |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
73 | /* we have defined args as args[0] is target and args[1] is ctcp command */ |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
74 | char *buf; |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
75 | GString *string; |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
76 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
77 | /* check if we have args */ |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
78 | if (!args || !args[0] || !args[1]) |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
79 | return 0; |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
80 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
81 | /* TODO:strip newlines or send each line as separate ctcp or something |
|
23896
f75e9380c5c8
Correct some IRC comments for /ctcp
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
82 | * actually, this shouldn't be done here but somewhere else since irc should support escaping newlines */ |
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
83 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
84 | string = g_string_new(args[1]); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
85 | g_string_prepend_c (string,'\001'); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
86 | g_string_append_c (string,'\001'); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
87 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], string->str); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
88 | g_string_free(string,TRUE); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
89 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
90 | irc_send(irc, buf); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
91 | g_free(buf); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
92 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
93 | return 1; |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
94 | } |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
95 | |
| 6333 | 96 | int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 97 | { | |
| 15884 | 98 | PurpleConnection *gc = purple_account_get_connection(irc->account); |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
99 | char *action, *escaped, *dst, **newargs; |
| 6333 | 100 | const char *src; |
| 15884 | 101 | PurpleConversation *convo; |
| 6333 | 102 | |
| 103 | if (!args || !args[0] || !gc) | |
| 104 | return 0; | |
| 105 | ||
| 6376 | 106 | action = g_malloc(strlen(args[0]) + 10); |
| 6333 | 107 | |
| 108 | sprintf(action, "\001ACTION "); | |
| 109 | ||
| 110 | src = args[0]; | |
| 111 | dst = action + 8; | |
| 112 | while (*src) { | |
| 113 | if (*src == '\n') { | |
| 114 | if (*(src + 1) == '\0') { | |
| 115 | break; | |
| 116 | } else { | |
| 117 | *dst++ = ' '; | |
| 118 | src++; | |
| 119 | continue; | |
| 120 | } | |
| 121 | } | |
| 122 | *dst++ = *src++; | |
| 123 | } | |
| 124 | *dst++ = '\001'; | |
| 125 | *dst = '\0'; | |
| 126 | ||
| 127 | newargs = g_new0(char *, 2); | |
| 128 | newargs[0] = g_strdup(target); | |
| 129 | newargs[1] = action; | |
| 130 | irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
| 131 | g_free(newargs[0]); | |
| 132 | g_free(newargs[1]); | |
| 133 | g_free(newargs); | |
| 134 | ||
| 15884 | 135 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, target, irc->account); |
| 9130 | 136 | if (convo) { |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
137 | escaped = g_markup_escape_text(args[0], -1); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
138 | action = g_strdup_printf("/me %s", escaped); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
139 | g_free(escaped); |
| 6333 | 140 | if (action[strlen(action) - 1] == '\n') |
| 141 | action[strlen(action) - 1] = '\0'; | |
| 15884 | 142 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_CHAT) |
| 143 | serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), | |
| 144 | purple_connection_get_display_name(gc), | |
| 9130 | 145 | 0, action, time(NULL)); |
| 146 | else | |
| 15884 | 147 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
| 9130 | 148 | action, 0, time(NULL)); |
| 6333 | 149 | g_free(action); |
| 150 | } | |
| 151 | ||
| 152 | return 1; | |
| 153 | } | |
| 154 | ||
| 13943 | 155 | int irc_cmd_ctcp_version(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 156 | { | |
| 157 | char *buf; | |
| 158 | ||
| 159 | ||
| 160 | if (!args || !args[0]) | |
| 161 | return 0; | |
| 162 | ||
| 163 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], "\001VERSION\001"); | |
| 164 | irc_send(irc, buf); | |
| 165 | g_free(buf); | |
| 166 | ||
| 167 | return 0; | |
| 168 | } | |
| 169 | ||
| 6333 | 170 | int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 171 | { | |
| 172 | char *buf; | |
| 173 | ||
| 174 | if (!args || !args[0] || !(args[1] || target)) | |
| 175 | return 0; | |
| 176 | ||
| 177 | buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 178 | irc_send(irc, buf); | |
| 179 | g_free(buf); | |
| 180 | ||
| 181 | return 0; | |
| 182 | } | |
| 183 | ||
| 184 | int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 185 | { | |
| 186 | char *buf; | |
| 187 | ||
| 188 | if (!args || !args[0]) | |
| 189 | return 0; | |
| 190 | ||
| 191 | if (args[1]) | |
| 192 | buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 193 | else | |
| 194 | buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 195 | irc_send(irc, buf); | |
| 196 | g_free(buf); | |
| 197 | ||
| 198 | return 0; | |
| 199 | } | |
| 200 | ||
| 201 | int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 202 | { | |
| 203 | char *buf; | |
| 15884 | 204 | PurpleConversation *convo; |
| 6333 | 205 | |
| 206 | if (!args || !args[0]) | |
| 207 | return 0; | |
| 208 | ||
| 15884 | 209 | 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
|
210 | if (!convo) |
| 6350 | 211 | return 0; |
| 6333 | 212 | |
| 213 | if (args[1]) | |
| 214 | buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 215 | else | |
| 216 | buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 217 | irc_send(irc, buf); | |
| 218 | g_free(buf); | |
| 219 | ||
| 220 | return 0; | |
| 221 | } | |
| 222 | ||
| 8114 | 223 | int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 224 | { | |
| 15884 | 225 | purple_roomlist_show_with_account(irc->account); |
| 8114 | 226 | |
| 227 | return 0; | |
| 228 | } | |
| 229 | ||
| 6333 | 230 | int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 231 | { | |
| 15884 | 232 | PurpleConnection *gc; |
| 6333 | 233 | char *buf; |
| 234 | ||
| 235 | if (!args) | |
| 236 | return 0; | |
| 237 | ||
| 238 | if (!strcmp(cmd, "mode")) { | |
| 10208 | 239 | if (!args[0] && irc_ischannel(target)) |
| 6333 | 240 | buf = irc_format(irc, "vc", "MODE", target); |
| 241 | else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
| 242 | buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
| 243 | else if (args[0]) | |
| 244 | buf = irc_format(irc, "vv", "MODE", args[0]); | |
| 245 | else | |
| 6350 | 246 | return 0; |
| 6333 | 247 | } else if (!strcmp(cmd, "umode")) { |
| 248 | if (!args[0]) | |
| 6350 | 249 | return 0; |
| 15884 | 250 | gc = purple_account_get_connection(irc->account); |
| 251 | buf = irc_format(irc, "vnv", "MODE", purple_connection_get_display_name(gc), args[0]); | |
| 6365 | 252 | } else { |
| 253 | return 0; | |
| 6333 | 254 | } |
| 6365 | 255 | |
| 6333 | 256 | irc_send(irc, buf); |
| 257 | g_free(buf); | |
| 258 | ||
| 259 | return 0; | |
| 260 | } | |
| 261 | ||
| 262 | int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 263 | { | |
| 264 | char *buf; | |
| 265 | ||
| 10208 | 266 | if (!args || (!args[0] && !irc_ischannel(target))) |
| 6333 | 267 | return 0; |
| 268 | ||
| 269 | buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 270 | irc_send(irc, buf); | |
| 271 | g_free(buf); | |
| 272 | ||
| 273 | return 0; | |
| 274 | } | |
| 275 | ||
| 276 | int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 277 | { | |
| 278 | char *buf; | |
| 279 | ||
| 280 | if (!args || !args[0]) | |
| 281 | return 0; | |
| 282 | ||
| 283 | buf = irc_format(irc, "v:", "NICK", args[0]); | |
|
23118
7ba846a8187f
Fix irc nick collision handling, as requested by that demanding user elb.
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22521
diff
changeset
|
284 | g_free(irc->reqnick); |
|
7ba846a8187f
Fix irc nick collision handling, as requested by that demanding user elb.
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22521
diff
changeset
|
285 | irc->reqnick = g_strdup(args[0]); |
|
7ba846a8187f
Fix irc nick collision handling, as requested by that demanding user elb.
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22521
diff
changeset
|
286 | irc->nickused = FALSE; |
| 6333 | 287 | irc_send(irc, buf); |
| 288 | g_free(buf); | |
| 289 | ||
| 290 | return 0; | |
| 291 | } | |
| 292 | ||
| 293 | int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 294 | { | |
| 295 | char **nicks, **ops, *sign, *mode; | |
| 296 | int i = 0, used = 0; | |
| 297 | ||
| 298 | if (!args || !args[0] || !*args[0]) | |
| 299 | return 0; | |
| 300 | ||
| 301 | if (!strcmp(cmd, "op")) { | |
| 302 | sign = "+"; | |
| 303 | mode = "o"; | |
| 304 | } else if (!strcmp(cmd, "deop")) { | |
| 305 | sign = "-"; | |
| 306 | mode = "o"; | |
| 307 | } else if (!strcmp(cmd, "voice")) { | |
| 308 | sign = "+"; | |
| 309 | mode = "v"; | |
| 310 | } else if (!strcmp(cmd, "devoice")) { | |
| 311 | sign = "-"; | |
| 312 | mode = "v"; | |
| 313 | } else { | |
| 15884 | 314 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); |
| 6333 | 315 | return 0; |
| 316 | } | |
| 317 | ||
| 318 | nicks = g_strsplit(args[0], " ", -1); | |
| 319 | ||
| 320 | for (i = 0; nicks[i]; i++) | |
| 321 | /* nothing */; | |
| 322 | ops = g_new0(char *, i * 2 + 1); | |
| 323 | ||
| 324 | for (i = 0; nicks[i]; i++) { | |
| 22521 | 325 | if (*nicks[i]) { |
| 326 | ops[used++] = mode; | |
| 327 | ops[used++] = nicks[i]; | |
|
21694
ac3973a88b24
Plug a tiny little leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
328 | } |
| 6333 | 329 | } |
| 330 | ||
| 331 | irc_do_mode(irc, target, sign, ops); | |
| 332 | g_free(ops); | |
| 22521 | 333 | g_strfreev(nicks); |
| 6333 | 334 | |
| 6350 | 335 | return 0; |
| 6333 | 336 | } |
| 337 | ||
| 338 | int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 339 | { | |
| 340 | char *buf; | |
| 341 | ||
| 342 | if (!args) | |
| 343 | return 0; | |
| 344 | ||
| 345 | if (args[1]) | |
| 346 | buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 347 | else | |
| 348 | buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 349 | irc_send(irc, buf); | |
| 350 | g_free(buf); | |
| 351 | ||
| 352 | return 0; | |
| 353 | } | |
| 354 | ||
| 355 | int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 356 | { | |
| 357 | char *stamp; | |
| 358 | char *buf; | |
| 359 | ||
| 360 | if (args && args[0]) { | |
| 10208 | 361 | if (irc_ischannel(args[0])) |
| 6333 | 362 | return 0; |
| 363 | stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 364 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 365 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
366 | } else if (target) { |
| 6350 | 367 | stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 368 | buf = irc_format(irc, "v:", "PING", stamp); |
| 369 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
370 | } else { |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
371 | stamp = g_strdup_printf("%lu", time(NULL)); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
372 | buf = irc_format(irc, "vv", "PING", stamp); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
373 | g_free(stamp); |
| 6333 | 374 | } |
| 375 | irc_send(irc, buf); | |
| 376 | g_free(buf); | |
| 377 | ||
| 378 | return 0; | |
| 379 | } | |
| 380 | ||
| 381 | int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 382 | { | |
| 383 | const char *cur, *end; | |
| 384 | char *msg, *buf; | |
| 385 | ||
| 386 | if (!args || !args[0] || !args[1]) | |
| 387 | return 0; | |
| 388 | ||
| 389 | cur = args[1]; | |
| 390 | end = args[1]; | |
| 391 | while (*end && *cur) { | |
| 392 | end = strchr(cur, '\n'); | |
| 393 | if (!end) | |
| 394 | end = cur + strlen(cur); | |
| 395 | msg = g_strndup(cur, end - cur); | |
|
22092
52c00ca73f6f
Added /notice support for IRC. If I didn't do this properly, feel free
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
21694
diff
changeset
|
396 | |
| 22167 | 397 | if(!strcmp(cmd, "notice")) |
| 398 | buf = irc_format(irc, "vt:", "NOTICE", args[0], msg); | |
| 399 | else | |
|
22092
52c00ca73f6f
Added /notice support for IRC. If I didn't do this properly, feel free
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
21694
diff
changeset
|
400 | buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); |
|
52c00ca73f6f
Added /notice support for IRC. If I didn't do this properly, feel free
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
21694
diff
changeset
|
401 | |
| 6333 | 402 | irc_send(irc, buf); |
| 403 | g_free(msg); | |
| 404 | g_free(buf); | |
| 405 | cur = end + 1; | |
| 406 | } | |
| 407 | ||
| 408 | return 0; | |
| 409 | } | |
| 410 | ||
| 411 | int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 412 | { | |
| 413 | char *buf; | |
| 414 | ||
| 9440 | 415 | if (!irc->quitting) { |
| 11763 | 416 | /* |
| 15884 | 417 | * Use purple_account_get_string(irc->account, "quitmsg", IRC_DEFAULT_QUIT) |
| 11763 | 418 | * and uncomment the appropriate account preference in irc.c if we |
| 419 | * decide we want custom quit messages. | |
| 420 | */ | |
| 421 | buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : IRC_DEFAULT_QUIT); | |
| 9440 | 422 | irc_send(irc, buf); |
| 423 | g_free(buf); | |
| 424 | ||
| 425 | irc->quitting = TRUE; | |
|
13839
e27a7f02055c
[gaim-migrate @ 16286]
Mark Doliner <markdoliner@pidgin.im>
parents:
12669
diff
changeset
|
426 | |
|
13974
c6ff47f81057
[gaim-migrate @ 16411]
Mark Doliner <markdoliner@pidgin.im>
parents:
13943
diff
changeset
|
427 | if (!irc->account->disconnecting) |
| 15884 | 428 | purple_account_set_status(irc->account, "offline", TRUE, NULL); |
| 9440 | 429 | } |
| 6333 | 430 | |
| 431 | return 0; | |
| 432 | } | |
| 433 | ||
| 434 | int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 435 | { | |
| 436 | char *buf; | |
| 437 | ||
| 438 | if (!args || !args[0]) | |
| 439 | return 0; | |
| 440 | ||
| 441 | buf = irc_format(irc, "v", args[0]); | |
| 442 | irc_send(irc, buf); | |
| 443 | g_free(buf); | |
| 444 | ||
| 445 | return 0; | |
| 446 | } | |
| 447 | ||
| 448 | int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 449 | { | |
| 15884 | 450 | PurpleConversation *convo; |
| 451 | PurpleConnection *gc; | |
| 6333 | 452 | |
| 453 | if (!args || !args[0]) | |
| 454 | return 0; | |
| 455 | ||
| 15884 | 456 | convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, irc->account, args[0]); |
| 457 | purple_conversation_present(convo); | |
| 6333 | 458 | |
| 459 | if (args[1]) { | |
| 15884 | 460 | gc = purple_account_get_connection(irc->account); |
| 6333 | 461 | irc_cmd_privmsg(irc, cmd, target, args); |
| 15884 | 462 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
| 463 | args[1], PURPLE_MESSAGE_SEND, time(NULL)); | |
| 6333 | 464 | } |
| 465 | ||
| 466 | return 0; | |
| 467 | } | |
| 468 | ||
| 469 | int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 470 | { | |
| 471 | char *buf; | |
| 472 | ||
| 473 | if (!args || !args[0]) | |
| 474 | return 0; | |
| 475 | ||
| 10208 | 476 | if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 477 | return 0; |
| 478 | ||
| 479 | if (args[1]) | |
| 480 | buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 481 | else | |
| 482 | buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 483 | irc_send(irc, buf); | |
| 484 | g_free(buf); | |
| 485 | ||
| 486 | return 0; | |
| 487 | } | |
| 488 | ||
| 12013 | 489 | int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 490 | { | |
| 491 | char *capital_cmd, *buf; | |
| 492 | ||
| 493 | if (!args || !args[0]) | |
| 494 | return 0; | |
| 495 | ||
| 496 | /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 497 | capital_cmd = g_ascii_strup(cmd, -1); | |
| 498 | buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 499 | irc_send(irc, buf); | |
| 500 | g_free(capital_cmd); | |
| 501 | g_free(buf); | |
| 502 | ||
| 503 | return 0; | |
| 504 | } | |
| 505 | ||
| 10564 | 506 | int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 507 | { | |
| 508 | char *buf; | |
| 509 | ||
| 510 | buf = irc_format(irc, "v", "TIME"); | |
| 511 | irc_send(irc, buf); | |
| 512 | g_free(buf); | |
| 513 | ||
| 514 | return 0; | |
| 515 | } | |
| 516 | ||
| 6333 | 517 | int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 518 | { | |
| 519 | char *buf; | |
| 520 | const char *topic; | |
| 15884 | 521 | PurpleConversation *convo; |
| 6333 | 522 | |
| 523 | if (!args) | |
| 524 | return 0; | |
| 525 | ||
| 15884 | 526 | 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
|
527 | if (!convo) |
| 6350 | 528 | return 0; |
| 6333 | 529 | |
| 530 | if (!args[0]) { | |
| 15884 | 531 | topic = purple_conv_chat_get_topic (PURPLE_CONV_CHAT(convo)); |
| 6333 | 532 | |
| 8504 | 533 | if (topic) { |
| 9762 | 534 | char *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10609
diff
changeset
|
535 | tmp = g_markup_escape_text(topic, -1); |
| 15884 | 536 | tmp2 = purple_markup_linkify(tmp); |
| 9762 | 537 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); |
| 8504 | 538 | g_free(tmp); |
| 9762 | 539 | g_free(tmp2); |
| 8504 | 540 | } else |
| 6333 | 541 | buf = g_strdup(_("No topic is set")); |
| 15884 | 542 | purple_conv_chat_write(PURPLE_CONV_CHAT(convo), target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 543 | g_free(buf); |
| 544 | ||
| 545 | return 0; | |
| 546 | } | |
| 547 | ||
| 548 | buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 549 | irc_send(irc, buf); | |
| 550 | g_free(buf); | |
| 551 | ||
| 552 | return 0; | |
| 553 | } | |
| 554 | ||
| 555 | int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 556 | { | |
| 557 | char *buf; | |
| 558 | ||
| 559 | if (!args || !args[0]) | |
| 6350 | 560 | return 0; |
| 6333 | 561 | |
| 562 | if (!strcmp(cmd, "wallops")) | |
| 563 | buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 564 | else if (!strcmp(cmd, "operwall")) | |
| 565 | buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 566 | else |
| 567 | return 0; | |
| 6333 | 568 | |
| 569 | irc_send(irc, buf); | |
| 570 | g_free(buf); | |
| 571 | ||
| 572 | return 0; | |
| 573 | } | |
| 574 | ||
| 575 | int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 576 | { | |
| 577 | char *buf; | |
| 578 | ||
| 579 | if (!args || !args[0]) | |
| 580 | return 0; | |
| 581 | ||
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
582 | if (args[1]) { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
583 | buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
584 | irc->whois.nick = g_strdup(args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
585 | } else { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
586 | buf = irc_format(irc, "vn", "WHOIS", args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
587 | irc->whois.nick = g_strdup(args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
588 | } |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
589 | |
| 6333 | 590 | irc_send(irc, buf); |
| 591 | g_free(buf); | |
| 592 | ||
| 593 | return 0; | |
| 594 | } | |
| 595 | ||
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
596 | int irc_cmd_whowas(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
597 | { |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
598 | char *buf; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
599 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
600 | if (!args || !args[0]) |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
601 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
602 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
603 | buf = irc_format(irc, "vn", "WHOWAS", args[0]); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
604 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
605 | irc->whois.nick = g_strdup(args[0]); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
606 | irc_send(irc, buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
607 | g_free(buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
608 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
609 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
610 | } |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
611 | |
| 6333 | 612 | static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) |
| 613 | { | |
| 614 | char *buf, mode[5]; | |
| 615 | int i = 0; | |
| 616 | ||
| 617 | if (!sign) | |
| 618 | return; | |
| 619 | ||
| 620 | while (ops[i]) { | |
| 621 | if (ops[i + 2] && ops[i + 4]) { | |
| 622 | g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 623 | ops[i], ops[i + 2], ops[i + 4]); | |
| 624 | buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 625 | ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 626 | i += 6; | |
| 627 | } else if (ops[i + 2]) { | |
| 628 | g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 629 | sign, ops[i], ops[i + 2]); | |
| 630 | buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 631 | ops[i + 1], ops[i + 3]); | |
| 632 | i += 4; | |
| 633 | } else { | |
| 634 | g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 635 | buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 636 | i += 2; | |
| 637 | } | |
| 638 | irc_send(irc, buf); | |
| 639 | g_free(buf); | |
| 640 | } | |
| 6350 | 641 | |
| 642 | return; | |
| 6333 | 643 | } |