Sun, 06 Nov 2011 20:31:14 +0000
Add purple_account_is_disconnecting() accessor function.
| 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 */ |
|
24763
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23896
diff
changeset
|
74 | char *buf; |
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
75 | GString *string; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
76 | |
|
23895
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); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
92 | |
|
23895
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)), | |
|
24763
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23896
diff
changeset
|
144 | purple_connection_get_display_name(gc), |
|
27185
47b88eabc980
Fix outgoing IRC /mes to be printed to the conversation window as sent
Florian Quèze <florian@instantbird.org>
parents:
24763
diff
changeset
|
145 | PURPLE_MESSAGE_SEND, action, time(NULL)); |
| 9130 | 146 | else |
| 15884 | 147 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
|
27185
47b88eabc980
Fix outgoing IRC /mes to be printed to the conversation window as sent
Florian Quèze <florian@instantbird.org>
parents:
24763
diff
changeset
|
148 | action, PURPLE_MESSAGE_SEND, 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 | if (!args || !args[0]) | |
| 160 | return 0; | |
| 161 | ||
| 162 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], "\001VERSION\001"); | |
| 163 | irc_send(irc, buf); | |
| 164 | g_free(buf); | |
| 165 | ||
| 166 | return 0; | |
| 167 | } | |
| 168 | ||
| 6333 | 169 | int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 170 | { | |
| 171 | char *buf; | |
| 172 | ||
| 173 | if (!args || !args[0] || !(args[1] || target)) | |
| 174 | return 0; | |
| 175 | ||
| 176 | buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 177 | irc_send(irc, buf); | |
| 178 | g_free(buf); | |
| 179 | ||
| 180 | return 0; | |
| 181 | } | |
| 182 | ||
| 183 | int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 184 | { | |
| 185 | char *buf; | |
| 186 | ||
| 187 | if (!args || !args[0]) | |
| 188 | return 0; | |
| 189 | ||
| 190 | if (args[1]) | |
| 191 | buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 192 | else | |
| 193 | buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 194 | irc_send(irc, buf); | |
| 195 | g_free(buf); | |
| 196 | ||
| 197 | return 0; | |
| 198 | } | |
| 199 | ||
| 200 | int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 201 | { | |
| 202 | char *buf; | |
| 15884 | 203 | PurpleConversation *convo; |
| 6333 | 204 | |
| 205 | if (!args || !args[0]) | |
| 206 | return 0; | |
| 207 | ||
| 15884 | 208 | 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
|
209 | if (!convo) |
| 6350 | 210 | return 0; |
| 6333 | 211 | |
| 212 | if (args[1]) | |
| 213 | buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 214 | else | |
| 215 | buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 216 | irc_send(irc, buf); | |
| 217 | g_free(buf); | |
| 218 | ||
| 219 | return 0; | |
| 220 | } | |
| 221 | ||
| 8114 | 222 | int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 223 | { | |
| 15884 | 224 | purple_roomlist_show_with_account(irc->account); |
| 8114 | 225 | |
| 226 | return 0; | |
| 227 | } | |
| 228 | ||
| 6333 | 229 | int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 230 | { | |
| 15884 | 231 | PurpleConnection *gc; |
| 6333 | 232 | char *buf; |
| 233 | ||
| 234 | if (!args) | |
| 235 | return 0; | |
| 236 | ||
| 237 | if (!strcmp(cmd, "mode")) { | |
| 10208 | 238 | if (!args[0] && irc_ischannel(target)) |
| 6333 | 239 | buf = irc_format(irc, "vc", "MODE", target); |
| 240 | else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
|
30469
7f787c107093
Fixes non-ASCII arguments to /mode, /umode, etc. Thanks to Max
Max Ulidtko <ulidtko@gmail.com>
parents:
27185
diff
changeset
|
241 | buf = irc_format(irc, "vcn", "MODE", target, args[0]); |
| 6333 | 242 | else if (args[0]) |
|
30469
7f787c107093
Fixes non-ASCII arguments to /mode, /umode, etc. Thanks to Max
Max Ulidtko <ulidtko@gmail.com>
parents:
27185
diff
changeset
|
243 | buf = irc_format(irc, "vn", "MODE", args[0]); |
| 6333 | 244 | else |
| 6350 | 245 | return 0; |
| 6333 | 246 | } else if (!strcmp(cmd, "umode")) { |
| 247 | if (!args[0]) | |
| 6350 | 248 | return 0; |
| 15884 | 249 | gc = purple_account_get_connection(irc->account); |
|
30469
7f787c107093
Fixes non-ASCII arguments to /mode, /umode, etc. Thanks to Max
Max Ulidtko <ulidtko@gmail.com>
parents:
27185
diff
changeset
|
250 | buf = irc_format(irc, "vnc", "MODE", purple_connection_get_display_name(gc), args[0]); |
| 6365 | 251 | } else { |
| 252 | return 0; | |
| 6333 | 253 | } |
| 6365 | 254 | |
| 6333 | 255 | irc_send(irc, buf); |
| 256 | g_free(buf); | |
| 257 | ||
| 258 | return 0; | |
| 259 | } | |
| 260 | ||
| 261 | int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 262 | { | |
| 263 | char *buf; | |
| 264 | ||
| 10208 | 265 | if (!args || (!args[0] && !irc_ischannel(target))) |
| 6333 | 266 | return 0; |
| 267 | ||
| 268 | buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 269 | irc_send(irc, buf); | |
| 270 | g_free(buf); | |
| 271 | ||
| 272 | return 0; | |
| 273 | } | |
| 274 | ||
| 275 | int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 276 | { | |
| 277 | char *buf; | |
| 278 | ||
| 279 | if (!args || !args[0]) | |
| 280 | return 0; | |
| 281 | ||
| 282 | 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
|
283 | 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
|
284 | 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
|
285 | irc->nickused = FALSE; |
| 6333 | 286 | irc_send(irc, buf); |
| 287 | g_free(buf); | |
| 288 | ||
| 289 | return 0; | |
| 290 | } | |
| 291 | ||
| 292 | int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 293 | { | |
| 294 | char **nicks, **ops, *sign, *mode; | |
| 295 | int i = 0, used = 0; | |
| 296 | ||
| 297 | if (!args || !args[0] || !*args[0]) | |
| 298 | return 0; | |
| 299 | ||
| 300 | if (!strcmp(cmd, "op")) { | |
| 301 | sign = "+"; | |
| 302 | mode = "o"; | |
| 303 | } else if (!strcmp(cmd, "deop")) { | |
| 304 | sign = "-"; | |
| 305 | mode = "o"; | |
| 306 | } else if (!strcmp(cmd, "voice")) { | |
| 307 | sign = "+"; | |
| 308 | mode = "v"; | |
| 309 | } else if (!strcmp(cmd, "devoice")) { | |
| 310 | sign = "-"; | |
| 311 | mode = "v"; | |
| 312 | } else { | |
| 15884 | 313 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); |
| 6333 | 314 | return 0; |
| 315 | } | |
| 316 | ||
| 317 | nicks = g_strsplit(args[0], " ", -1); | |
| 318 | ||
| 319 | for (i = 0; nicks[i]; i++) | |
| 320 | /* nothing */; | |
| 321 | ops = g_new0(char *, i * 2 + 1); | |
| 322 | ||
| 323 | for (i = 0; nicks[i]; i++) { | |
| 22521 | 324 | if (*nicks[i]) { |
| 325 | ops[used++] = mode; | |
| 326 | ops[used++] = nicks[i]; | |
|
21694
ac3973a88b24
Plug a tiny little leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
327 | } |
| 6333 | 328 | } |
| 329 | ||
| 330 | irc_do_mode(irc, target, sign, ops); | |
| 331 | g_free(ops); | |
| 22521 | 332 | g_strfreev(nicks); |
| 6333 | 333 | |
| 6350 | 334 | return 0; |
| 6333 | 335 | } |
| 336 | ||
| 337 | int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 338 | { | |
| 339 | char *buf; | |
| 340 | ||
| 341 | if (!args) | |
| 342 | return 0; | |
| 343 | ||
| 344 | if (args[1]) | |
| 345 | buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 346 | else | |
| 347 | buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 348 | irc_send(irc, buf); | |
| 349 | g_free(buf); | |
| 350 | ||
| 351 | return 0; | |
| 352 | } | |
| 353 | ||
| 354 | int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 355 | { | |
| 356 | char *stamp; | |
| 357 | char *buf; | |
| 358 | ||
| 359 | if (args && args[0]) { | |
| 10208 | 360 | if (irc_ischannel(args[0])) |
| 6333 | 361 | return 0; |
| 362 | stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 363 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 364 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
365 | } else if (target) { |
| 6350 | 366 | stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 367 | buf = irc_format(irc, "v:", "PING", stamp); |
| 368 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
369 | } else { |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
370 | stamp = g_strdup_printf("%lu", time(NULL)); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
371 | buf = irc_format(irc, "vv", "PING", stamp); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
372 | g_free(stamp); |
| 6333 | 373 | } |
| 374 | irc_send(irc, buf); | |
| 375 | g_free(buf); | |
| 376 | ||
| 377 | return 0; | |
| 378 | } | |
| 379 | ||
| 380 | int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 381 | { | |
| 382 | const char *cur, *end; | |
| 383 | char *msg, *buf; | |
| 384 | ||
| 385 | if (!args || !args[0] || !args[1]) | |
| 386 | return 0; | |
| 387 | ||
| 388 | cur = args[1]; | |
| 389 | end = args[1]; | |
| 390 | while (*end && *cur) { | |
| 391 | end = strchr(cur, '\n'); | |
| 392 | if (!end) | |
| 393 | end = cur + strlen(cur); | |
| 394 | 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
|
395 | |
| 22167 | 396 | if(!strcmp(cmd, "notice")) |
| 397 | buf = irc_format(irc, "vt:", "NOTICE", args[0], msg); | |
| 398 | 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
|
399 | 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
|
400 | |
| 6333 | 401 | irc_send(irc, buf); |
| 402 | g_free(msg); | |
| 403 | g_free(buf); | |
| 404 | cur = end + 1; | |
| 405 | } | |
| 406 | ||
| 407 | return 0; | |
| 408 | } | |
| 409 | ||
| 410 | int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 411 | { | |
| 412 | char *buf; | |
| 413 | ||
| 9440 | 414 | if (!irc->quitting) { |
| 11763 | 415 | /* |
| 15884 | 416 | * Use purple_account_get_string(irc->account, "quitmsg", IRC_DEFAULT_QUIT) |
| 11763 | 417 | * and uncomment the appropriate account preference in irc.c if we |
| 418 | * decide we want custom quit messages. | |
| 419 | */ | |
| 420 | buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : IRC_DEFAULT_QUIT); | |
| 9440 | 421 | irc_send(irc, buf); |
| 422 | g_free(buf); | |
| 423 | ||
| 424 | irc->quitting = TRUE; | |
|
13839
e27a7f02055c
[gaim-migrate @ 16286]
Mark Doliner <markdoliner@pidgin.im>
parents:
12669
diff
changeset
|
425 | |
|
32722
50ed95d90d55
Add purple_account_is_disconnecting() accessor function.
Andrew Victor <andrew.victor@mxit.com>
parents:
31294
diff
changeset
|
426 | if (!purple_account_is_disconnecting(irc->account)) |
| 15884 | 427 | purple_account_set_status(irc->account, "offline", TRUE, NULL); |
| 9440 | 428 | } |
| 6333 | 429 | |
| 430 | return 0; | |
| 431 | } | |
| 432 | ||
| 433 | int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 434 | { | |
| 435 | char *buf; | |
| 436 | ||
| 437 | if (!args || !args[0]) | |
| 438 | return 0; | |
| 439 | ||
|
30469
7f787c107093
Fixes non-ASCII arguments to /mode, /umode, etc. Thanks to Max
Max Ulidtko <ulidtko@gmail.com>
parents:
27185
diff
changeset
|
440 | buf = irc_format(irc, "n", args[0]); |
| 6333 | 441 | irc_send(irc, buf); |
| 442 | g_free(buf); | |
| 443 | ||
| 444 | return 0; | |
| 445 | } | |
| 446 | ||
| 447 | int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 448 | { | |
| 15884 | 449 | PurpleConversation *convo; |
| 450 | PurpleConnection *gc; | |
| 6333 | 451 | |
| 452 | if (!args || !args[0]) | |
| 453 | return 0; | |
| 454 | ||
| 15884 | 455 | convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, irc->account, args[0]); |
| 456 | purple_conversation_present(convo); | |
| 6333 | 457 | |
| 458 | if (args[1]) { | |
| 15884 | 459 | gc = purple_account_get_connection(irc->account); |
| 6333 | 460 | irc_cmd_privmsg(irc, cmd, target, args); |
| 15884 | 461 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
| 462 | args[1], PURPLE_MESSAGE_SEND, time(NULL)); | |
| 6333 | 463 | } |
| 464 | ||
| 465 | return 0; | |
| 466 | } | |
| 467 | ||
| 468 | int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 469 | { | |
| 470 | char *buf; | |
| 471 | ||
| 472 | if (!args || !args[0]) | |
| 473 | return 0; | |
| 474 | ||
| 10208 | 475 | if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 476 | return 0; |
| 477 | ||
| 478 | if (args[1]) | |
| 479 | buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 480 | else | |
| 481 | buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 482 | irc_send(irc, buf); | |
| 483 | g_free(buf); | |
| 484 | ||
| 485 | return 0; | |
| 486 | } | |
| 487 | ||
| 12013 | 488 | int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 489 | { | |
| 490 | char *capital_cmd, *buf; | |
| 491 | ||
| 492 | if (!args || !args[0]) | |
| 493 | return 0; | |
| 494 | ||
| 495 | /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 496 | capital_cmd = g_ascii_strup(cmd, -1); | |
| 497 | buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 498 | irc_send(irc, buf); | |
| 499 | g_free(capital_cmd); | |
| 500 | g_free(buf); | |
| 501 | ||
| 502 | return 0; | |
| 503 | } | |
| 504 | ||
| 10564 | 505 | int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 506 | { | |
| 507 | char *buf; | |
| 508 | ||
| 509 | buf = irc_format(irc, "v", "TIME"); | |
| 510 | irc_send(irc, buf); | |
| 511 | g_free(buf); | |
| 512 | ||
| 513 | return 0; | |
| 514 | } | |
| 515 | ||
| 6333 | 516 | int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 517 | { | |
| 518 | char *buf; | |
| 519 | const char *topic; | |
| 15884 | 520 | PurpleConversation *convo; |
| 6333 | 521 | |
| 522 | if (!args) | |
| 523 | return 0; | |
| 524 | ||
| 15884 | 525 | 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
|
526 | if (!convo) |
| 6350 | 527 | return 0; |
| 6333 | 528 | |
| 529 | if (!args[0]) { | |
| 15884 | 530 | topic = purple_conv_chat_get_topic (PURPLE_CONV_CHAT(convo)); |
| 6333 | 531 | |
| 8504 | 532 | if (topic) { |
| 9762 | 533 | char *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10609
diff
changeset
|
534 | tmp = g_markup_escape_text(topic, -1); |
| 15884 | 535 | tmp2 = purple_markup_linkify(tmp); |
| 9762 | 536 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); |
| 8504 | 537 | g_free(tmp); |
| 9762 | 538 | g_free(tmp2); |
| 8504 | 539 | } else |
| 6333 | 540 | buf = g_strdup(_("No topic is set")); |
| 15884 | 541 | purple_conv_chat_write(PURPLE_CONV_CHAT(convo), target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 542 | g_free(buf); |
| 543 | ||
| 544 | return 0; | |
| 545 | } | |
| 546 | ||
| 547 | buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 548 | irc_send(irc, buf); | |
| 549 | g_free(buf); | |
| 550 | ||
| 551 | return 0; | |
| 552 | } | |
| 553 | ||
| 554 | int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 555 | { | |
| 556 | char *buf; | |
| 557 | ||
| 558 | if (!args || !args[0]) | |
| 6350 | 559 | return 0; |
| 6333 | 560 | |
| 561 | if (!strcmp(cmd, "wallops")) | |
| 562 | buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 563 | else if (!strcmp(cmd, "operwall")) | |
| 564 | buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 565 | else |
| 566 | return 0; | |
| 6333 | 567 | |
| 568 | irc_send(irc, buf); | |
| 569 | g_free(buf); | |
| 570 | ||
| 571 | return 0; | |
| 572 | } | |
| 573 | ||
| 574 | int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 575 | { | |
| 576 | char *buf; | |
| 577 | ||
| 578 | if (!args || !args[0]) | |
| 579 | return 0; | |
| 580 | ||
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
581 | if (args[1]) { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
582 | buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
583 | irc->whois.nick = g_strdup(args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
584 | } else { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
585 | buf = irc_format(irc, "vn", "WHOIS", args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
586 | irc->whois.nick = g_strdup(args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
587 | } |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
588 | |
| 6333 | 589 | irc_send(irc, buf); |
| 590 | g_free(buf); | |
| 591 | ||
| 592 | return 0; | |
| 593 | } | |
| 594 | ||
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
595 | 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
|
596 | { |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
597 | char *buf; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
598 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
599 | if (!args || !args[0]) |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
600 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
601 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
602 | buf = irc_format(irc, "vn", "WHOWAS", args[0]); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
603 | |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
604 | irc->whois.nick = g_strdup(args[0]); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
605 | irc_send(irc, buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
606 | g_free(buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
607 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
608 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
609 | } |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
610 | |
| 6333 | 611 | static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) |
| 612 | { | |
| 613 | char *buf, mode[5]; | |
| 614 | int i = 0; | |
| 615 | ||
| 616 | if (!sign) | |
| 617 | return; | |
| 618 | ||
| 619 | while (ops[i]) { | |
| 620 | if (ops[i + 2] && ops[i + 4]) { | |
| 621 | g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 622 | ops[i], ops[i + 2], ops[i + 4]); | |
| 623 | buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 624 | ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 625 | i += 6; | |
| 626 | } else if (ops[i + 2]) { | |
| 627 | g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 628 | sign, ops[i], ops[i + 2]); | |
| 629 | buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 630 | ops[i + 1], ops[i + 3]); | |
| 631 | i += 4; | |
| 632 | } else { | |
| 633 | g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 634 | buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 635 | i += 2; | |
| 636 | } | |
| 637 | irc_send(irc, buf); | |
| 638 | g_free(buf); | |
| 639 | } | |
| 6350 | 640 | |
| 641 | return; | |
| 6333 | 642 | } |