Sun, 23 Jun 2013 18:34:00 +0530
Refactored gg and irc protocols to use the GObject-based PurpleConversation
| 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 | { | |
|
34625
03d62b1660fc
Refactor code to remove conversation type from some instances of purple_conversations_find_with_account()
Ankit Vani <a@nevitus.org>
parents:
34622
diff
changeset
|
37 | PurpleConversation *convo = purple_conversations_find_with_account(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); | |
|
34629
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
44 | purple_conversation_write_message(convo, "", buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 45 | g_free(buf); |
| 46 | ||
| 47 | return 1; | |
| 48 | } | |
| 49 | ||
| 50 | int irc_cmd_away(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 51 | { | |
|
12669
c15115dcfc23
[gaim-migrate @ 15012]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12013
diff
changeset
|
52 | char *buf, *message; |
| 6333 | 53 | |
| 54 | if (args[0] && strcmp(cmd, "back")) { | |
| 15884 | 55 | message = purple_markup_strip_html(args[0]); |
| 56 | purple_util_chrreplace(message, '\n', ' '); | |
| 6333 | 57 | buf = irc_format(irc, "v:", "AWAY", message); |
| 58 | g_free(message); | |
| 59 | } else { | |
| 60 | buf = irc_format(irc, "v", "AWAY"); | |
| 61 | } | |
| 62 | irc_send(irc, buf); | |
| 63 | g_free(buf); | |
| 64 | ||
| 65 | return 0; | |
| 66 | } | |
| 67 | ||
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
68 | 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
|
69 | { |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
70 | /* 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
|
71 | char *buf; |
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
72 | GString *string; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
73 | |
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
74 | /* check if we have args */ |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
75 | if (!args || !args[0] || !args[1]) |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
76 | return 0; |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
77 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
78 | /* 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
|
79 | * 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
|
80 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
81 | string = g_string_new(args[1]); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
82 | g_string_prepend_c (string,'\001'); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
83 | g_string_append_c (string,'\001'); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
84 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], string->str); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
85 | g_string_free(string,TRUE); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
86 | |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
87 | irc_send(irc, buf); |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
88 | g_free(buf); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
89 | |
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
90 | return 1; |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
91 | } |
|
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23118
diff
changeset
|
92 | |
| 6333 | 93 | int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 94 | { | |
| 15884 | 95 | PurpleConnection *gc = purple_account_get_connection(irc->account); |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
96 | char *action, *escaped, *dst, **newargs; |
| 6333 | 97 | const char *src; |
| 15884 | 98 | PurpleConversation *convo; |
| 6333 | 99 | |
| 100 | if (!args || !args[0] || !gc) | |
| 101 | return 0; | |
| 102 | ||
| 6376 | 103 | action = g_malloc(strlen(args[0]) + 10); |
| 6333 | 104 | |
| 105 | sprintf(action, "\001ACTION "); | |
| 106 | ||
| 107 | src = args[0]; | |
| 108 | dst = action + 8; | |
| 109 | while (*src) { | |
| 110 | if (*src == '\n') { | |
| 111 | if (*(src + 1) == '\0') { | |
| 112 | break; | |
| 113 | } else { | |
| 114 | *dst++ = ' '; | |
| 115 | src++; | |
| 116 | continue; | |
| 117 | } | |
| 118 | } | |
| 119 | *dst++ = *src++; | |
| 120 | } | |
| 121 | *dst++ = '\001'; | |
| 122 | *dst = '\0'; | |
| 123 | ||
| 124 | newargs = g_new0(char *, 2); | |
| 125 | newargs[0] = g_strdup(target); | |
| 126 | newargs[1] = action; | |
| 127 | irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
| 128 | g_free(newargs[0]); | |
| 129 | g_free(newargs[1]); | |
| 130 | g_free(newargs); | |
| 131 | ||
|
34625
03d62b1660fc
Refactor code to remove conversation type from some instances of purple_conversations_find_with_account()
Ankit Vani <a@nevitus.org>
parents:
34622
diff
changeset
|
132 | convo = purple_conversations_find_with_account(target, irc->account); |
| 9130 | 133 | if (convo) { |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
134 | escaped = g_markup_escape_text(args[0], -1); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
135 | action = g_strdup_printf("/me %s", escaped); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
136 | g_free(escaped); |
| 6333 | 137 | if (action[strlen(action) - 1] == '\n') |
| 138 | action[strlen(action) - 1] = '\0'; | |
|
34629
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
139 | if (PURPLE_IS_CHAT_CONVERSATION(convo)) |
|
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
140 | serv_got_chat_in(gc, purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(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
|
141 | 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
|
142 | PURPLE_MESSAGE_SEND, action, time(NULL)); |
| 9130 | 143 | else |
|
34629
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
144 | purple_conversation_write_message(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
|
145 | action, PURPLE_MESSAGE_SEND, time(NULL)); |
| 6333 | 146 | g_free(action); |
| 147 | } | |
| 148 | ||
| 149 | return 1; | |
| 150 | } | |
| 151 | ||
| 13943 | 152 | int irc_cmd_ctcp_version(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 153 | { | |
| 154 | char *buf; | |
| 155 | ||
| 156 | if (!args || !args[0]) | |
| 157 | return 0; | |
| 158 | ||
| 159 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], "\001VERSION\001"); | |
| 160 | irc_send(irc, buf); | |
| 161 | g_free(buf); | |
| 162 | ||
| 163 | return 0; | |
| 164 | } | |
| 165 | ||
| 6333 | 166 | int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 167 | { | |
| 168 | char *buf; | |
| 169 | ||
| 170 | if (!args || !args[0] || !(args[1] || target)) | |
| 171 | return 0; | |
| 172 | ||
| 173 | buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 174 | irc_send(irc, buf); | |
| 175 | g_free(buf); | |
| 176 | ||
| 177 | return 0; | |
| 178 | } | |
| 179 | ||
| 180 | int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 181 | { | |
| 182 | char *buf; | |
| 183 | ||
| 184 | if (!args || !args[0]) | |
| 185 | return 0; | |
| 186 | ||
| 187 | if (args[1]) | |
| 188 | buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 189 | else | |
| 190 | buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 191 | irc_send(irc, buf); | |
| 192 | g_free(buf); | |
| 193 | ||
| 194 | return 0; | |
| 195 | } | |
| 196 | ||
| 197 | int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 198 | { | |
| 199 | char *buf; | |
| 15884 | 200 | PurpleConversation *convo; |
| 6333 | 201 | |
| 202 | if (!args || !args[0]) | |
| 203 | return 0; | |
| 204 | ||
|
34625
03d62b1660fc
Refactor code to remove conversation type from some instances of purple_conversations_find_with_account()
Ankit Vani <a@nevitus.org>
parents:
34622
diff
changeset
|
205 | convo = purple_conversations_find_chat_with_account(target, irc->account); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10208
diff
changeset
|
206 | if (!convo) |
| 6350 | 207 | return 0; |
| 6333 | 208 | |
| 209 | if (args[1]) | |
| 210 | buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 211 | else | |
| 212 | buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 213 | irc_send(irc, buf); | |
| 214 | g_free(buf); | |
| 215 | ||
| 216 | return 0; | |
| 217 | } | |
| 218 | ||
| 8114 | 219 | int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 220 | { | |
| 15884 | 221 | purple_roomlist_show_with_account(irc->account); |
| 8114 | 222 | |
| 223 | return 0; | |
| 224 | } | |
| 225 | ||
| 6333 | 226 | int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 227 | { | |
| 15884 | 228 | PurpleConnection *gc; |
| 6333 | 229 | char *buf; |
| 230 | ||
| 231 | if (!args) | |
| 232 | return 0; | |
| 233 | ||
| 234 | if (!strcmp(cmd, "mode")) { | |
| 10208 | 235 | if (!args[0] && irc_ischannel(target)) |
| 6333 | 236 | buf = irc_format(irc, "vc", "MODE", target); |
| 237 | 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
|
238 | buf = irc_format(irc, "vcn", "MODE", target, args[0]); |
| 6333 | 239 | 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
|
240 | buf = irc_format(irc, "vn", "MODE", args[0]); |
| 6333 | 241 | else |
| 6350 | 242 | return 0; |
| 6333 | 243 | } else if (!strcmp(cmd, "umode")) { |
| 244 | if (!args[0]) | |
| 6350 | 245 | return 0; |
| 15884 | 246 | 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
|
247 | buf = irc_format(irc, "vnc", "MODE", purple_connection_get_display_name(gc), args[0]); |
| 6365 | 248 | } else { |
| 249 | return 0; | |
| 6333 | 250 | } |
| 6365 | 251 | |
| 6333 | 252 | irc_send(irc, buf); |
| 253 | g_free(buf); | |
| 254 | ||
| 255 | return 0; | |
| 256 | } | |
| 257 | ||
| 258 | int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 259 | { | |
| 260 | char *buf; | |
| 261 | ||
| 10208 | 262 | if (!args || (!args[0] && !irc_ischannel(target))) |
| 6333 | 263 | return 0; |
| 264 | ||
| 265 | buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 266 | irc_send(irc, buf); | |
| 267 | g_free(buf); | |
| 268 | ||
| 269 | return 0; | |
| 270 | } | |
| 271 | ||
| 272 | int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 273 | { | |
| 274 | char *buf; | |
| 275 | ||
| 276 | if (!args || !args[0]) | |
| 277 | return 0; | |
| 278 | ||
| 279 | 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
|
280 | 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
|
281 | 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
|
282 | irc->nickused = FALSE; |
| 6333 | 283 | irc_send(irc, buf); |
| 284 | g_free(buf); | |
| 285 | ||
| 286 | return 0; | |
| 287 | } | |
| 288 | ||
| 289 | int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 290 | { | |
| 291 | char **nicks, **ops, *sign, *mode; | |
| 292 | int i = 0, used = 0; | |
| 293 | ||
| 294 | if (!args || !args[0] || !*args[0]) | |
| 295 | return 0; | |
| 296 | ||
| 297 | if (!strcmp(cmd, "op")) { | |
| 298 | sign = "+"; | |
| 299 | mode = "o"; | |
| 300 | } else if (!strcmp(cmd, "deop")) { | |
| 301 | sign = "-"; | |
| 302 | mode = "o"; | |
| 303 | } else if (!strcmp(cmd, "voice")) { | |
| 304 | sign = "+"; | |
| 305 | mode = "v"; | |
| 306 | } else if (!strcmp(cmd, "devoice")) { | |
| 307 | sign = "-"; | |
| 308 | mode = "v"; | |
| 309 | } else { | |
| 15884 | 310 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); |
| 6333 | 311 | return 0; |
| 312 | } | |
| 313 | ||
| 314 | nicks = g_strsplit(args[0], " ", -1); | |
| 315 | ||
| 316 | for (i = 0; nicks[i]; i++) | |
| 317 | /* nothing */; | |
| 318 | ops = g_new0(char *, i * 2 + 1); | |
| 319 | ||
| 320 | for (i = 0; nicks[i]; i++) { | |
| 22521 | 321 | if (*nicks[i]) { |
| 322 | ops[used++] = mode; | |
| 323 | ops[used++] = nicks[i]; | |
|
21694
ac3973a88b24
Plug a tiny little leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
324 | } |
| 6333 | 325 | } |
| 326 | ||
| 327 | irc_do_mode(irc, target, sign, ops); | |
| 328 | g_free(ops); | |
| 22521 | 329 | g_strfreev(nicks); |
| 6333 | 330 | |
| 6350 | 331 | return 0; |
| 6333 | 332 | } |
| 333 | ||
| 334 | int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 335 | { | |
| 336 | char *buf; | |
| 337 | ||
| 338 | if (!args) | |
| 339 | return 0; | |
| 340 | ||
| 341 | if (args[1]) | |
| 342 | buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 343 | else | |
| 344 | buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 345 | irc_send(irc, buf); | |
| 346 | g_free(buf); | |
| 347 | ||
| 348 | return 0; | |
| 349 | } | |
| 350 | ||
| 351 | int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 352 | { | |
| 353 | char *stamp; | |
| 354 | char *buf; | |
| 355 | ||
| 356 | if (args && args[0]) { | |
| 10208 | 357 | if (irc_ischannel(args[0])) |
| 6333 | 358 | return 0; |
| 359 | stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 360 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 361 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
362 | } else if (target) { |
| 6350 | 363 | stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 364 | buf = irc_format(irc, "v:", "PING", stamp); |
| 365 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
366 | } else { |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
367 | stamp = g_strdup_printf("%lu", time(NULL)); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
368 | buf = irc_format(irc, "vv", "PING", stamp); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
369 | g_free(stamp); |
| 6333 | 370 | } |
| 371 | irc_send(irc, buf); | |
| 372 | g_free(buf); | |
| 373 | ||
| 374 | return 0; | |
| 375 | } | |
| 376 | ||
| 377 | int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 378 | { | |
| 379 | const char *cur, *end; | |
| 380 | char *msg, *buf; | |
| 381 | ||
| 382 | if (!args || !args[0] || !args[1]) | |
| 383 | return 0; | |
| 384 | ||
| 385 | cur = args[1]; | |
| 386 | end = args[1]; | |
| 387 | while (*end && *cur) { | |
| 388 | end = strchr(cur, '\n'); | |
| 389 | if (!end) | |
| 390 | end = cur + strlen(cur); | |
| 391 | 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
|
392 | |
| 22167 | 393 | if(!strcmp(cmd, "notice")) |
| 394 | buf = irc_format(irc, "vt:", "NOTICE", args[0], msg); | |
| 395 | 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
|
396 | 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
|
397 | |
| 6333 | 398 | irc_send(irc, buf); |
| 399 | g_free(msg); | |
| 400 | g_free(buf); | |
| 401 | cur = end + 1; | |
| 402 | } | |
| 403 | ||
| 404 | return 0; | |
| 405 | } | |
| 406 | ||
| 407 | int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 408 | { | |
| 409 | char *buf; | |
| 410 | ||
| 9440 | 411 | if (!irc->quitting) { |
| 11763 | 412 | /* |
| 15884 | 413 | * Use purple_account_get_string(irc->account, "quitmsg", IRC_DEFAULT_QUIT) |
| 11763 | 414 | * and uncomment the appropriate account preference in irc.c if we |
| 415 | * decide we want custom quit messages. | |
| 416 | */ | |
| 417 | buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : IRC_DEFAULT_QUIT); | |
| 9440 | 418 | irc_send(irc, buf); |
| 419 | g_free(buf); | |
| 420 | ||
| 421 | irc->quitting = TRUE; | |
|
13839
e27a7f02055c
[gaim-migrate @ 16286]
Mark Doliner <markdoliner@pidgin.im>
parents:
12669
diff
changeset
|
422 | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
423 | if (!purple_account_is_disconnecting(irc->account)) |
| 15884 | 424 | purple_account_set_status(irc->account, "offline", TRUE, NULL); |
| 9440 | 425 | } |
| 6333 | 426 | |
| 427 | return 0; | |
| 428 | } | |
| 429 | ||
| 430 | int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 431 | { | |
| 432 | char *buf; | |
| 433 | ||
| 434 | if (!args || !args[0]) | |
| 435 | return 0; | |
| 436 | ||
|
30469
7f787c107093
Fixes non-ASCII arguments to /mode, /umode, etc. Thanks to Max
Max Ulidtko <ulidtko@gmail.com>
parents:
27185
diff
changeset
|
437 | buf = irc_format(irc, "n", args[0]); |
| 6333 | 438 | irc_send(irc, buf); |
| 439 | g_free(buf); | |
| 440 | ||
| 441 | return 0; | |
| 442 | } | |
| 443 | ||
| 444 | int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 445 | { | |
| 15884 | 446 | PurpleConversation *convo; |
| 447 | PurpleConnection *gc; | |
| 6333 | 448 | |
| 449 | if (!args || !args[0]) | |
| 450 | return 0; | |
| 451 | ||
|
34627
08733a7475df
Replaced purple_conversation_new() with purple_[im,chat]_conversation_new()
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
452 | convo = purple_im_conversation_new(irc->account, args[0]); |
| 15884 | 453 | purple_conversation_present(convo); |
| 6333 | 454 | |
| 455 | if (args[1]) { | |
| 15884 | 456 | gc = purple_account_get_connection(irc->account); |
| 6333 | 457 | irc_cmd_privmsg(irc, cmd, target, args); |
|
34629
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
458 | purple_conversation_write_message(convo, purple_connection_get_display_name(gc), |
| 15884 | 459 | args[1], PURPLE_MESSAGE_SEND, time(NULL)); |
| 6333 | 460 | } |
| 461 | ||
| 462 | return 0; | |
| 463 | } | |
| 464 | ||
| 465 | int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 466 | { | |
| 467 | char *buf; | |
| 468 | ||
| 469 | if (!args || !args[0]) | |
| 470 | return 0; | |
| 471 | ||
| 10208 | 472 | if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 473 | return 0; |
| 474 | ||
| 475 | if (args[1]) | |
| 476 | buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 477 | else | |
| 478 | buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 479 | irc_send(irc, buf); | |
| 480 | g_free(buf); | |
| 481 | ||
| 482 | return 0; | |
| 483 | } | |
| 484 | ||
| 12013 | 485 | int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 486 | { | |
| 487 | char *capital_cmd, *buf; | |
| 488 | ||
| 489 | if (!args || !args[0]) | |
| 490 | return 0; | |
| 491 | ||
| 492 | /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 493 | capital_cmd = g_ascii_strup(cmd, -1); | |
| 494 | buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 495 | irc_send(irc, buf); | |
| 496 | g_free(capital_cmd); | |
| 497 | g_free(buf); | |
| 498 | ||
| 499 | return 0; | |
| 500 | } | |
| 501 | ||
| 10564 | 502 | int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 503 | { | |
| 504 | char *buf; | |
| 505 | ||
| 506 | buf = irc_format(irc, "v", "TIME"); | |
| 507 | irc_send(irc, buf); | |
| 508 | g_free(buf); | |
| 509 | ||
| 510 | return 0; | |
| 511 | } | |
| 512 | ||
| 6333 | 513 | int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 514 | { | |
| 515 | char *buf; | |
| 516 | const char *topic; | |
| 15884 | 517 | PurpleConversation *convo; |
| 6333 | 518 | |
| 519 | if (!args) | |
| 520 | return 0; | |
| 521 | ||
|
34625
03d62b1660fc
Refactor code to remove conversation type from some instances of purple_conversations_find_with_account()
Ankit Vani <a@nevitus.org>
parents:
34622
diff
changeset
|
522 | convo = purple_conversations_find_chat_with_account(target, irc->account); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10208
diff
changeset
|
523 | if (!convo) |
| 6350 | 524 | return 0; |
| 6333 | 525 | |
| 526 | if (!args[0]) { | |
|
34629
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
527 | topic = purple_chat_conversation_get_topic (PURPLE_CHAT_CONVERSATION(convo)); |
| 6333 | 528 | |
| 8504 | 529 | if (topic) { |
| 9762 | 530 | char *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10609
diff
changeset
|
531 | tmp = g_markup_escape_text(topic, -1); |
| 15884 | 532 | tmp2 = purple_markup_linkify(tmp); |
| 9762 | 533 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); |
| 8504 | 534 | g_free(tmp); |
| 9762 | 535 | g_free(tmp2); |
| 8504 | 536 | } else |
| 6333 | 537 | buf = g_strdup(_("No topic is set")); |
|
34629
3c3bed0fd13c
Refactored gg and irc protocols to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34627
diff
changeset
|
538 | purple_conversation_write_message(convo, target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 539 | g_free(buf); |
| 540 | ||
| 541 | return 0; | |
| 542 | } | |
| 543 | ||
| 544 | buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 545 | irc_send(irc, buf); | |
| 546 | g_free(buf); | |
| 547 | ||
| 548 | return 0; | |
| 549 | } | |
| 550 | ||
| 551 | int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 552 | { | |
| 553 | char *buf; | |
| 554 | ||
| 555 | if (!args || !args[0]) | |
| 6350 | 556 | return 0; |
| 6333 | 557 | |
| 558 | if (!strcmp(cmd, "wallops")) | |
| 559 | buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 560 | else if (!strcmp(cmd, "operwall")) | |
| 561 | buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 562 | else |
| 563 | return 0; | |
| 6333 | 564 | |
| 565 | irc_send(irc, buf); | |
| 566 | g_free(buf); | |
| 567 | ||
| 568 | return 0; | |
| 569 | } | |
| 570 | ||
| 571 | int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 572 | { | |
| 573 | char *buf; | |
| 574 | ||
| 575 | if (!args || !args[0]) | |
| 576 | return 0; | |
| 577 | ||
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
578 | if (args[1]) { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
579 | buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
580 | irc->whois.nick = g_strdup(args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
581 | } else { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
582 | buf = irc_format(irc, "vn", "WHOIS", args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
583 | irc->whois.nick = g_strdup(args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
584 | } |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
585 | |
| 6333 | 586 | irc_send(irc, buf); |
| 587 | g_free(buf); | |
| 588 | ||
| 589 | return 0; | |
| 590 | } | |
| 591 | ||
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
592 | 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
|
593 | { |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
594 | char *buf; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
595 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
596 | if (!args || !args[0]) |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
597 | return 0; |
|
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 | buf = irc_format(irc, "vn", "WHOWAS", args[0]); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
600 | |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
601 | irc->whois.nick = g_strdup(args[0]); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
602 | irc_send(irc, buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
603 | g_free(buf); |
|
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 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
606 | } |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
607 | |
| 6333 | 608 | static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) |
| 609 | { | |
| 610 | char *buf, mode[5]; | |
| 611 | int i = 0; | |
| 612 | ||
| 613 | if (!sign) | |
| 614 | return; | |
| 615 | ||
| 616 | while (ops[i]) { | |
| 617 | if (ops[i + 2] && ops[i + 4]) { | |
| 618 | g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 619 | ops[i], ops[i + 2], ops[i + 4]); | |
| 620 | buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 621 | ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 622 | i += 6; | |
| 623 | } else if (ops[i + 2]) { | |
| 624 | g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 625 | sign, ops[i], ops[i + 2]); | |
| 626 | buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 627 | ops[i + 1], ops[i + 3]); | |
| 628 | i += 4; | |
| 629 | } else { | |
| 630 | g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 631 | buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 632 | i += 2; | |
| 633 | } | |
| 634 | irc_send(irc, buf); | |
| 635 | g_free(buf); | |
| 636 | } | |
| 6350 | 637 | |
| 638 | return; | |
| 6333 | 639 | } |