Sat, 23 Apr 2022 05:05:54 -0500
Use the leaky bucket algorithm to rate limit irc messages.
The default values were suggested by an operator of libera.
We don't rate limit the login process, nor parts and quits. However, if you
paste a bunch of text and then part a channel, you will be spammed with a
bunch of "no such nick/channel" error dialogs. I tried to work around this,
but the alternative just makes irc unresponsive until all the pasted messages
are sent. That said, other messages are still delayed while these errors
dialogs are slowly popping up.
Testing Done:
Lots
Bugs closed: PIDGIN-11089
Reviewed at https://reviews.imfreedom.org/r/524/
| 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 | |
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
57 | if (args[0] && !purple_strequal(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; |
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
101 | char *msg; |
| 15884 | 102 | PurpleConversation *convo; |
| 6333 | 103 | |
| 104 | if (!args || !args[0] || !gc) | |
| 105 | return 0; | |
| 106 | ||
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
107 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
108 | target, irc->account); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
109 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
110 | msg = g_strdup_printf("/me %s", args[0]); |
| 6333 | 111 | |
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
112 | /* XXX: we'd prefer to keep this in conversation.c */ |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
113 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_IM) { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
114 | purple_signal_emit(purple_conversations_get_handle(), |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
115 | "sending-im-msg", irc->account, |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
116 | purple_conversation_get_name(convo), &msg); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
117 | } else { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
118 | purple_signal_emit(purple_conversations_get_handle(), |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
119 | "sending-chat-msg", irc->account, &msg, |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
120 | purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo))); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
121 | } |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
122 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
123 | if (!msg || !msg[0]) { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
124 | g_free(msg); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
125 | return 0; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
126 | } |
| 6333 | 127 | |
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
128 | if (strncmp(msg, "/me ", 4) != 0) { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
129 | newargs = g_new0(char *, 2); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
130 | newargs[0] = g_strdup(target); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
131 | newargs[1] = msg; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
132 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
133 | irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
134 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
135 | g_free(newargs[0]); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
136 | g_free(newargs); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
137 | } else { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
138 | action = g_malloc(strlen(&msg[4]) + 10); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
139 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
140 | sprintf(action, "\001ACTION "); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
141 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
142 | src = &msg[4]; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
143 | dst = action + 8; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
144 | while (*src) { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
145 | if (*src == '\n') { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
146 | if (*(src + 1) == '\0') { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
147 | break; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
148 | } else { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
149 | *dst++ = ' '; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
150 | src++; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
151 | continue; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
152 | } |
| 6333 | 153 | } |
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
154 | *dst++ = *src++; |
| 6333 | 155 | } |
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
156 | *dst++ = '\001'; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
157 | *dst = '\0'; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
158 | |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
159 | newargs = g_new0(char *, 2); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
160 | newargs[0] = g_strdup(target); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
161 | newargs[1] = action; |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
162 | irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
163 | g_free(newargs[0]); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
164 | g_free(newargs); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
165 | g_free(action); |
| 6333 | 166 | } |
| 167 | ||
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
168 | /* XXX: we'd prefer to keep this in conversation.c */ |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
169 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_IM) { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
170 | purple_signal_emit(purple_conversations_get_handle(), |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
171 | "sent-im-msg", irc->account, |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
172 | purple_conversation_get_name(convo), msg); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
173 | } else { |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
174 | purple_signal_emit(purple_conversations_get_handle(), |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
175 | "sent-chat-msg", irc->account, msg, |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
176 | purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo))); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
177 | } |
| 6333 | 178 | |
|
35925
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
179 | g_free(msg); |
|
3edc70bf4e09
Emit sending/sent signals when doing /me irc command. Fixes #15750
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
180 | |
| 9130 | 181 | if (convo) { |
|
10933
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
182 | escaped = g_markup_escape_text(args[0], -1); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
183 | action = g_strdup_printf("/me %s", escaped); |
|
ba1a5024f03a
[gaim-migrate @ 12716]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
184 | g_free(escaped); |
| 6333 | 185 | if (action[strlen(action) - 1] == '\n') |
| 186 | action[strlen(action) - 1] = '\0'; | |
| 15884 | 187 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_CHAT) |
| 188 | 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
|
189 | 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
|
190 | PURPLE_MESSAGE_SEND, action, time(NULL)); |
| 9130 | 191 | else |
| 15884 | 192 | 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
|
193 | action, PURPLE_MESSAGE_SEND, time(NULL)); |
| 6333 | 194 | g_free(action); |
| 195 | } | |
| 196 | ||
| 197 | return 1; | |
| 198 | } | |
| 199 | ||
| 13943 | 200 | int irc_cmd_ctcp_version(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 201 | { | |
| 202 | char *buf; | |
| 203 | ||
| 204 | if (!args || !args[0]) | |
| 205 | return 0; | |
| 206 | ||
| 207 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], "\001VERSION\001"); | |
| 208 | irc_send(irc, buf); | |
| 209 | g_free(buf); | |
| 210 | ||
| 211 | return 0; | |
| 212 | } | |
| 213 | ||
| 6333 | 214 | int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 215 | { | |
| 216 | char *buf; | |
| 217 | ||
| 218 | if (!args || !args[0] || !(args[1] || target)) | |
| 219 | return 0; | |
| 220 | ||
| 221 | buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 222 | irc_send(irc, buf); | |
| 223 | g_free(buf); | |
| 224 | ||
| 225 | return 0; | |
| 226 | } | |
| 227 | ||
| 228 | int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 229 | { | |
| 230 | char *buf; | |
| 231 | ||
| 232 | if (!args || !args[0]) | |
| 233 | return 0; | |
| 234 | ||
| 235 | if (args[1]) | |
| 236 | buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 237 | else | |
| 238 | buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 239 | irc_send(irc, buf); | |
| 240 | g_free(buf); | |
| 241 | ||
| 242 | return 0; | |
| 243 | } | |
| 244 | ||
| 245 | int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 246 | { | |
| 247 | char *buf; | |
| 15884 | 248 | PurpleConversation *convo; |
| 6333 | 249 | |
| 250 | if (!args || !args[0]) | |
| 251 | return 0; | |
| 252 | ||
| 15884 | 253 | 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
|
254 | if (!convo) |
| 6350 | 255 | return 0; |
| 6333 | 256 | |
| 257 | if (args[1]) | |
| 258 | buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 259 | else | |
| 260 | buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 261 | irc_send(irc, buf); | |
| 262 | g_free(buf); | |
| 263 | ||
| 264 | return 0; | |
| 265 | } | |
| 266 | ||
| 8114 | 267 | int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 268 | { | |
| 15884 | 269 | purple_roomlist_show_with_account(irc->account); |
| 8114 | 270 | |
| 271 | return 0; | |
| 272 | } | |
| 273 | ||
| 6333 | 274 | int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 275 | { | |
| 15884 | 276 | PurpleConnection *gc; |
| 6333 | 277 | char *buf; |
| 278 | ||
| 279 | if (!args) | |
| 280 | return 0; | |
| 281 | ||
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
282 | if (purple_strequal(cmd, "mode")) { |
| 10208 | 283 | if (!args[0] && irc_ischannel(target)) |
| 6333 | 284 | buf = irc_format(irc, "vc", "MODE", target); |
| 285 | 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
|
286 | buf = irc_format(irc, "vcn", "MODE", target, args[0]); |
| 6333 | 287 | 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
|
288 | buf = irc_format(irc, "vn", "MODE", args[0]); |
| 6333 | 289 | else |
| 6350 | 290 | return 0; |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
291 | } else if (purple_strequal(cmd, "umode")) { |
| 6333 | 292 | if (!args[0]) |
| 6350 | 293 | return 0; |
| 15884 | 294 | 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
|
295 | buf = irc_format(irc, "vnc", "MODE", purple_connection_get_display_name(gc), args[0]); |
| 6365 | 296 | } else { |
| 297 | return 0; | |
| 6333 | 298 | } |
| 6365 | 299 | |
| 6333 | 300 | irc_send(irc, buf); |
| 301 | g_free(buf); | |
| 302 | ||
| 303 | return 0; | |
| 304 | } | |
| 305 | ||
| 306 | int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 307 | { | |
| 308 | char *buf; | |
| 309 | ||
| 10208 | 310 | if (!args || (!args[0] && !irc_ischannel(target))) |
| 6333 | 311 | return 0; |
| 312 | ||
| 313 | buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 314 | irc_send(irc, buf); | |
| 315 | g_free(buf); | |
| 316 | ||
| 317 | return 0; | |
| 318 | } | |
| 319 | ||
| 320 | int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 321 | { | |
| 322 | char *buf; | |
| 323 | ||
| 324 | if (!args || !args[0]) | |
| 325 | return 0; | |
| 326 | ||
| 327 | 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
|
328 | 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
|
329 | 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
|
330 | irc->nickused = FALSE; |
| 6333 | 331 | irc_send(irc, buf); |
| 332 | g_free(buf); | |
| 333 | ||
| 334 | return 0; | |
| 335 | } | |
| 336 | ||
| 337 | int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 338 | { | |
| 339 | char **nicks, **ops, *sign, *mode; | |
| 340 | int i = 0, used = 0; | |
| 341 | ||
| 342 | if (!args || !args[0] || !*args[0]) | |
| 343 | return 0; | |
| 344 | ||
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
345 | if (purple_strequal(cmd, "op")) { |
| 6333 | 346 | sign = "+"; |
| 347 | mode = "o"; | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
348 | } else if (purple_strequal(cmd, "deop")) { |
| 6333 | 349 | sign = "-"; |
| 350 | mode = "o"; | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
351 | } else if (purple_strequal(cmd, "voice")) { |
| 6333 | 352 | sign = "+"; |
| 353 | mode = "v"; | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
354 | } else if (purple_strequal(cmd, "devoice")) { |
| 6333 | 355 | sign = "-"; |
| 356 | mode = "v"; | |
| 357 | } else { | |
| 15884 | 358 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); |
| 6333 | 359 | return 0; |
| 360 | } | |
| 361 | ||
| 362 | nicks = g_strsplit(args[0], " ", -1); | |
| 363 | ||
| 364 | for (i = 0; nicks[i]; i++) | |
| 365 | /* nothing */; | |
| 366 | ops = g_new0(char *, i * 2 + 1); | |
| 367 | ||
| 368 | for (i = 0; nicks[i]; i++) { | |
| 22521 | 369 | if (*nicks[i]) { |
| 370 | ops[used++] = mode; | |
| 371 | ops[used++] = nicks[i]; | |
|
21694
ac3973a88b24
Plug a tiny little leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
372 | } |
| 6333 | 373 | } |
| 374 | ||
| 375 | irc_do_mode(irc, target, sign, ops); | |
| 376 | g_free(ops); | |
| 22521 | 377 | g_strfreev(nicks); |
| 6333 | 378 | |
| 6350 | 379 | return 0; |
| 6333 | 380 | } |
| 381 | ||
| 382 | int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 383 | { | |
| 384 | char *buf; | |
| 385 | ||
| 386 | if (!args) | |
| 387 | return 0; | |
| 388 | ||
| 389 | if (args[1]) | |
| 390 | buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 391 | else | |
| 392 | buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
|
41335
c49dcf00bee6
Use the leaky bucket algorithm to rate limit irc messages.
Gary Kramlich <grim@reaperworld.com>
parents:
38259
diff
changeset
|
393 | irc_priority_send(irc, buf); |
| 6333 | 394 | g_free(buf); |
| 395 | ||
| 396 | return 0; | |
| 397 | } | |
| 398 | ||
| 399 | int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 400 | { | |
| 401 | char *stamp; | |
| 402 | char *buf; | |
| 403 | ||
| 404 | if (args && args[0]) { | |
| 10208 | 405 | if (irc_ischannel(args[0])) |
| 6333 | 406 | return 0; |
| 407 | stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 408 | buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 409 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
410 | } else if (target) { |
| 6350 | 411 | stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 412 | buf = irc_format(irc, "v:", "PING", stamp); |
| 413 | g_free(stamp); | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
414 | } else { |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
415 | stamp = g_strdup_printf("%lu", time(NULL)); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
416 | buf = irc_format(irc, "vv", "PING", stamp); |
|
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
417 | g_free(stamp); |
| 6333 | 418 | } |
| 419 | irc_send(irc, buf); | |
| 420 | g_free(buf); | |
| 421 | ||
| 422 | return 0; | |
| 423 | } | |
| 424 | ||
| 425 | int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 426 | { | |
|
37954
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
427 | int max_privmsg_arg_len; |
| 6333 | 428 | const char *cur, *end; |
|
37954
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
429 | gchar *salvaged; |
| 6333 | 430 | char *msg, *buf; |
| 431 | ||
| 432 | if (!args || !args[0] || !args[1]) | |
| 433 | return 0; | |
| 434 | ||
|
37954
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
435 | max_privmsg_arg_len = IRC_MAX_MSG_SIZE - strlen(args[0]) - 64; |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
436 | salvaged = purple_utf8_salvage(args[1]); |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
437 | cur = salvaged; |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
438 | end = salvaged; |
| 6333 | 439 | while (*end && *cur) { |
| 440 | end = strchr(cur, '\n'); | |
| 441 | if (!end) | |
| 442 | end = cur + strlen(cur); | |
|
37954
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
443 | if (end - cur > max_privmsg_arg_len) { |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
444 | /* this call is used to find the last valid character position in the first |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
445 | * max_privmsg_arg_len bytes of the utf-8 message |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
446 | */ |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
447 | g_utf8_validate(cur, max_privmsg_arg_len, &end); |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
448 | } |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
449 | |
| 6333 | 450 | 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
|
451 | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
452 | if(purple_strequal(cmd, "notice")) |
| 22167 | 453 | buf = irc_format(irc, "vt:", "NOTICE", args[0], msg); |
| 454 | 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
|
455 | 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
|
456 | |
| 6333 | 457 | irc_send(irc, buf); |
| 458 | g_free(msg); | |
| 459 | g_free(buf); | |
|
37954
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
460 | cur = end; |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
461 | if(*cur == '\n') { |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
462 | cur++; |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
463 | } |
| 6333 | 464 | } |
| 465 | ||
|
37954
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
466 | g_free(salvaged); |
|
b76dd48063d6
Fix issue #4753 with IRC message truncation
Senya <senya@riseup.net>
parents:
35925
diff
changeset
|
467 | |
| 6333 | 468 | return 0; |
| 469 | } | |
| 470 | ||
| 471 | int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 472 | { | |
| 473 | char *buf; | |
| 474 | ||
| 9440 | 475 | if (!irc->quitting) { |
| 11763 | 476 | /* |
| 15884 | 477 | * Use purple_account_get_string(irc->account, "quitmsg", IRC_DEFAULT_QUIT) |
| 11763 | 478 | * and uncomment the appropriate account preference in irc.c if we |
| 479 | * decide we want custom quit messages. | |
| 480 | */ | |
| 481 | buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : IRC_DEFAULT_QUIT); | |
|
41335
c49dcf00bee6
Use the leaky bucket algorithm to rate limit irc messages.
Gary Kramlich <grim@reaperworld.com>
parents:
38259
diff
changeset
|
482 | irc_priority_send(irc, buf); |
| 9440 | 483 | g_free(buf); |
| 484 | ||
| 485 | irc->quitting = TRUE; | |
|
13839
e27a7f02055c
[gaim-migrate @ 16286]
Mark Doliner <markdoliner@pidgin.im>
parents:
12669
diff
changeset
|
486 | |
|
13974
c6ff47f81057
[gaim-migrate @ 16411]
Mark Doliner <markdoliner@pidgin.im>
parents:
13943
diff
changeset
|
487 | if (!irc->account->disconnecting) |
| 15884 | 488 | purple_account_set_status(irc->account, "offline", TRUE, NULL); |
| 9440 | 489 | } |
| 6333 | 490 | |
| 491 | return 0; | |
| 492 | } | |
| 493 | ||
| 494 | int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 495 | { | |
| 496 | char *buf; | |
| 497 | ||
| 498 | if (!args || !args[0]) | |
| 499 | return 0; | |
| 500 | ||
|
30469
7f787c107093
Fixes non-ASCII arguments to /mode, /umode, etc. Thanks to Max
Max Ulidtko <ulidtko@gmail.com>
parents:
27185
diff
changeset
|
501 | buf = irc_format(irc, "n", args[0]); |
| 6333 | 502 | irc_send(irc, buf); |
| 503 | g_free(buf); | |
| 504 | ||
| 505 | return 0; | |
| 506 | } | |
| 507 | ||
| 508 | int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 509 | { | |
| 15884 | 510 | PurpleConversation *convo; |
| 511 | PurpleConnection *gc; | |
| 6333 | 512 | |
| 513 | if (!args || !args[0]) | |
| 514 | return 0; | |
| 515 | ||
| 15884 | 516 | convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, irc->account, args[0]); |
| 517 | purple_conversation_present(convo); | |
| 6333 | 518 | |
| 519 | if (args[1]) { | |
| 15884 | 520 | gc = purple_account_get_connection(irc->account); |
| 6333 | 521 | irc_cmd_privmsg(irc, cmd, target, args); |
| 15884 | 522 | purple_conv_im_write(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc), |
| 523 | args[1], PURPLE_MESSAGE_SEND, time(NULL)); | |
| 6333 | 524 | } |
| 525 | ||
| 526 | return 0; | |
| 527 | } | |
| 528 | ||
| 529 | int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 530 | { | |
| 531 | char *buf; | |
| 532 | ||
| 533 | if (!args || !args[0]) | |
| 534 | return 0; | |
| 535 | ||
| 10208 | 536 | if (!irc_ischannel(target)) /* not a channel, punt */ |
| 6333 | 537 | return 0; |
| 538 | ||
| 539 | if (args[1]) | |
| 540 | buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 541 | else | |
| 542 | buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 543 | irc_send(irc, buf); | |
| 544 | g_free(buf); | |
| 545 | ||
| 546 | return 0; | |
| 547 | } | |
| 548 | ||
| 12013 | 549 | int irc_cmd_service(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 550 | { | |
| 551 | char *capital_cmd, *buf; | |
| 552 | ||
| 553 | if (!args || !args[0]) | |
| 554 | return 0; | |
| 555 | ||
| 556 | /* cmd will be one of nickserv, chanserv, memoserv or operserv */ | |
| 557 | capital_cmd = g_ascii_strup(cmd, -1); | |
| 558 | buf = irc_format(irc, "v:", capital_cmd, args[0]); | |
| 559 | irc_send(irc, buf); | |
| 560 | g_free(capital_cmd); | |
| 561 | g_free(buf); | |
| 562 | ||
| 563 | return 0; | |
| 564 | } | |
| 565 | ||
| 10564 | 566 | int irc_cmd_time(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 567 | { | |
| 568 | char *buf; | |
| 569 | ||
| 570 | buf = irc_format(irc, "v", "TIME"); | |
| 571 | irc_send(irc, buf); | |
| 572 | g_free(buf); | |
| 573 | ||
| 574 | return 0; | |
| 575 | } | |
| 576 | ||
| 6333 | 577 | int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 578 | { | |
| 579 | char *buf; | |
| 580 | const char *topic; | |
| 15884 | 581 | PurpleConversation *convo; |
| 6333 | 582 | |
| 583 | if (!args) | |
| 584 | return 0; | |
| 585 | ||
| 15884 | 586 | 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
|
587 | if (!convo) |
| 6350 | 588 | return 0; |
| 6333 | 589 | |
| 590 | if (!args[0]) { | |
| 15884 | 591 | topic = purple_conv_chat_get_topic (PURPLE_CONV_CHAT(convo)); |
| 6333 | 592 | |
| 8504 | 593 | if (topic) { |
| 9762 | 594 | char *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10609
diff
changeset
|
595 | tmp = g_markup_escape_text(topic, -1); |
| 15884 | 596 | tmp2 = purple_markup_linkify(tmp); |
| 9762 | 597 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); |
| 8504 | 598 | g_free(tmp); |
| 9762 | 599 | g_free(tmp2); |
| 8504 | 600 | } else |
| 6333 | 601 | buf = g_strdup(_("No topic is set")); |
| 15884 | 602 | purple_conv_chat_write(PURPLE_CONV_CHAT(convo), target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 603 | g_free(buf); |
| 604 | ||
| 605 | return 0; | |
| 606 | } | |
| 607 | ||
| 608 | buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 609 | irc_send(irc, buf); | |
| 610 | g_free(buf); | |
| 611 | ||
| 612 | return 0; | |
| 613 | } | |
| 614 | ||
| 615 | int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 616 | { | |
| 617 | char *buf; | |
| 618 | ||
| 619 | if (!args || !args[0]) | |
| 6350 | 620 | return 0; |
| 6333 | 621 | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
622 | if (purple_strequal(cmd, "wallops")) |
| 6333 | 623 | buf = irc_format(irc, "v:", "WALLOPS", args[0]); |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
37954
diff
changeset
|
624 | else if (purple_strequal(cmd, "operwall")) |
| 6333 | 625 | buf = irc_format(irc, "v:", "OPERWALL", args[0]); |
| 6365 | 626 | else |
| 627 | return 0; | |
| 6333 | 628 | |
| 629 | irc_send(irc, buf); | |
| 630 | g_free(buf); | |
| 631 | ||
| 632 | return 0; | |
| 633 | } | |
| 634 | ||
| 635 | int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 636 | { | |
| 637 | char *buf; | |
| 638 | ||
| 639 | if (!args || !args[0]) | |
| 640 | return 0; | |
| 641 | ||
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
642 | if (args[1]) { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
643 | buf = irc_format(irc, "vvn", "WHOIS", args[0], args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
644 | irc->whois.nick = g_strdup(args[1]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
645 | } else { |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
646 | buf = irc_format(irc, "vn", "WHOIS", args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
647 | irc->whois.nick = g_strdup(args[0]); |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
648 | } |
|
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
649 | |
| 6333 | 650 | irc_send(irc, buf); |
| 651 | g_free(buf); | |
| 652 | ||
| 653 | return 0; | |
| 654 | } | |
| 655 | ||
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
656 | 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
|
657 | { |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
658 | char *buf; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
659 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
660 | if (!args || !args[0]) |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
661 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
662 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
663 | buf = irc_format(irc, "vn", "WHOWAS", args[0]); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30469
diff
changeset
|
664 | |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
665 | irc->whois.nick = g_strdup(args[0]); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
666 | irc_send(irc, buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
667 | g_free(buf); |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
668 | |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
669 | return 0; |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
670 | } |
|
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
671 | |
| 6333 | 672 | static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) |
| 673 | { | |
| 674 | char *buf, mode[5]; | |
| 675 | int i = 0; | |
| 676 | ||
| 677 | if (!sign) | |
| 678 | return; | |
| 679 | ||
| 680 | while (ops[i]) { | |
| 681 | if (ops[i + 2] && ops[i + 4]) { | |
| 682 | g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 683 | ops[i], ops[i + 2], ops[i + 4]); | |
| 684 | buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 685 | ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 686 | i += 6; | |
| 687 | } else if (ops[i + 2]) { | |
| 688 | g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 689 | sign, ops[i], ops[i + 2]); | |
| 690 | buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 691 | ops[i + 1], ops[i + 3]); | |
| 692 | i += 4; | |
| 693 | } else { | |
| 694 | g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 695 | buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 696 | i += 2; | |
| 697 | } | |
| 698 | irc_send(irc, buf); | |
| 699 | g_free(buf); | |
| 700 | } | |
| 6350 | 701 | |
| 702 | return; | |
| 6333 | 703 | } |