Mercurial > pidgin
annotate src/protocols/irc/cmds.c @ 9234:f18eb3f22733
[gaim-migrate @ 10030]
This appears to be somewhat hacky, but due to the lack of a timer in
blist.c, we need a core place to emit buddy-idle-updated. server.c now
maintains a list of idle buddies and emits the signal when appropriate. We
really need a better way to do this, which I'll attempt to incorporate into
the status rewrite, but perhaps the best way would involve the blist update
timer being in blist.c. Anyhow, this works for now.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Tue, 08 Jun 2004 02:02:25 +0000 |
| parents | 933a19e3a6b3 |
| children | 6430b09ccc71 |
| rev | line source |
|---|---|
| 6333 | 1 /** |
| 2 * @file cmds.c | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> | |
| 7 * | |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 */ | |
| 22 | |
| 23 #include "internal.h" | |
| 24 | |
| 25 #include "conversation.h" | |
| 8504 | 26 #include "debug.h" |
| 6333 | 27 #include "notify.h" |
| 8624 | 28 #include "util.h" |
| 8504 | 29 |
| 6333 | 30 #include "irc.h" |
| 31 | |
| 32 | |
| 33 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops); | |
| 34 | |
| 35 int irc_cmd_default(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 36 { | |
| 37 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); | |
| 38 char *buf; | |
| 39 | |
| 40 if (!convo) | |
| 6350 | 41 return 1; |
| 6333 | 42 |
| 43 buf = g_strdup_printf(_("Unknown command: %s"), cmd); | |
| 44 if (gaim_conversation_get_type(convo) == GAIM_CONV_IM) | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
45 gaim_conv_im_write(GAIM_CONV_IM(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 46 else |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
47 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_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 { | |
| 55 char *buf, *message, *cur; | |
| 56 | |
| 57 if (args[0] && strcmp(cmd, "back")) { | |
| 58 message = strdup(args[0]); | |
| 59 for (cur = message; *cur; cur++) { | |
| 60 if (*cur == '\n') | |
| 61 *cur = ' '; | |
| 62 } | |
| 63 buf = irc_format(irc, "v:", "AWAY", message); | |
| 64 g_free(message); | |
| 65 } else { | |
| 66 buf = irc_format(irc, "v", "AWAY"); | |
| 67 } | |
| 68 irc_send(irc, buf); | |
| 69 g_free(buf); | |
| 70 | |
| 71 return 0; | |
| 72 } | |
| 73 | |
| 74 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 75 { | |
| 76 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
| 77 char *action, *dst, **newargs; | |
| 78 const char *src; | |
| 79 GaimConversation *convo; | |
| 80 | |
| 81 if (!args || !args[0] || !gc) | |
| 82 return 0; | |
| 83 | |
| 6376 | 84 action = g_malloc(strlen(args[0]) + 10); |
| 6333 | 85 |
| 86 sprintf(action, "\001ACTION "); | |
| 87 | |
| 88 src = args[0]; | |
| 89 dst = action + 8; | |
| 90 while (*src) { | |
| 91 if (*src == '\n') { | |
| 92 if (*(src + 1) == '\0') { | |
| 93 break; | |
| 94 } else { | |
| 95 *dst++ = ' '; | |
| 96 src++; | |
| 97 continue; | |
| 98 } | |
| 99 } | |
| 100 *dst++ = *src++; | |
| 101 } | |
| 102 *dst++ = '\001'; | |
| 103 *dst = '\0'; | |
| 104 | |
| 105 newargs = g_new0(char *, 2); | |
| 106 newargs[0] = g_strdup(target); | |
| 107 newargs[1] = action; | |
| 108 irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
| 109 g_free(newargs[0]); | |
| 110 g_free(newargs[1]); | |
| 111 g_free(newargs); | |
| 112 | |
| 113 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 9130 | 114 if (convo) { |
| 6333 | 115 action = g_strdup_printf("/me %s", args[0]); |
| 116 if (action[strlen(action) - 1] == '\n') | |
| 117 action[strlen(action) - 1] = '\0'; | |
| 9130 | 118 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) |
| 119 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), | |
| 120 gaim_connection_get_display_name(gc), | |
| 121 0, action, time(NULL)); | |
| 122 else | |
| 123 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), | |
| 124 action, 0, time(NULL)); | |
| 6333 | 125 g_free(action); |
| 126 } | |
| 127 | |
| 128 return 1; | |
| 129 } | |
| 130 | |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
131 int irc_cmd_help(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
132 { |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
133 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
134 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
135 /* XXX we should eventually have per-command help */ |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
136 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
137 if (!convo) |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
138 return 0; |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
139 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
140 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) { |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
141 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", _("<B>Supported IRC Commands:</B><BR>" |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
142 "AWAY INVITE JOIN KICK<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
143 "ME MODE MSG NAMES<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
144 "NICK OP DEOP OPERWALL<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
145 "PART PING QUERY QUIT<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
146 "QUOTE REMOVE TOPIC UMODE<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
147 "VOICE DEVOICE WALLOPS WHOIS<BR>"), |
| 6621 | 148 GAIM_MESSAGE_NO_LOG, time(NULL)); |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
149 } else { |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
150 gaim_conv_im_write(GAIM_CONV_IM(convo), "", _("<B>Supported IRC Commands:</B><BR>" |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
151 "AWAY JOIN ME MODE<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
152 "MSG NICK OPERWALL PING<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
153 "QUERY QUIT QUOTE UMODE<BR>" |
| 6982 | 154 "WALLOPS WHOIS"), GAIM_MESSAGE_NO_LOG, time(NULL)); |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
155 } |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
156 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
157 return 0; |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
158 } |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
159 |
| 6333 | 160 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 161 { | |
| 162 char *buf; | |
| 163 | |
| 164 if (!args || !args[0] || !(args[1] || target)) | |
| 165 return 0; | |
| 166 | |
| 167 buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 168 irc_send(irc, buf); | |
| 169 g_free(buf); | |
| 170 | |
| 171 return 0; | |
| 172 } | |
| 173 | |
| 174 int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 175 { | |
| 176 char *buf; | |
| 177 | |
| 178 if (!args || !args[0]) | |
| 179 return 0; | |
| 180 | |
| 181 if (args[1]) | |
| 182 buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 183 else | |
| 184 buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 185 irc_send(irc, buf); | |
| 186 g_free(buf); | |
| 187 | |
| 188 return 0; | |
| 189 } | |
| 190 | |
| 191 int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 192 { | |
| 193 char *buf; | |
| 194 GaimConversation *convo; | |
| 195 | |
| 196 if (!args || !args[0]) | |
| 197 return 0; | |
| 198 | |
| 199 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 200 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
| 6350 | 201 return 0; |
| 6333 | 202 |
| 203 if (args[1]) | |
| 204 buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 205 else | |
| 206 buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 207 irc_send(irc, buf); | |
| 208 g_free(buf); | |
| 209 | |
| 210 return 0; | |
| 211 } | |
| 212 | |
| 8114 | 213 int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 214 { | |
| 8352 | 215 gaim_roomlist_show_with_account(irc->account); |
| 8114 | 216 |
| 217 return 0; | |
| 218 } | |
| 219 | |
| 6333 | 220 int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 221 { | |
| 222 GaimConnection *gc; | |
| 223 char *buf; | |
| 224 | |
| 225 if (!args) | |
| 226 return 0; | |
| 227 | |
| 228 if (!strcmp(cmd, "mode")) { | |
| 229 if (!args[0] && (*target == '#' || *target == '&')) | |
| 230 buf = irc_format(irc, "vc", "MODE", target); | |
| 231 else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
| 232 buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
| 233 else if (args[0]) | |
| 234 buf = irc_format(irc, "vv", "MODE", args[0]); | |
| 235 else | |
| 6350 | 236 return 0; |
| 6333 | 237 } else if (!strcmp(cmd, "umode")) { |
| 238 if (!args[0]) | |
| 6350 | 239 return 0; |
| 6333 | 240 gc = gaim_account_get_connection(irc->account); |
| 241 buf = irc_format(irc, "vnv", "MODE", gaim_connection_get_display_name(gc), args[0]); | |
| 6365 | 242 } else { |
| 243 return 0; | |
| 6333 | 244 } |
| 6365 | 245 |
| 6333 | 246 irc_send(irc, buf); |
| 247 g_free(buf); | |
| 248 | |
| 249 return 0; | |
| 250 } | |
| 251 | |
| 252 int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 253 { | |
| 254 char *buf; | |
| 255 | |
| 256 if (!args) | |
| 257 return 0; | |
| 258 | |
| 259 buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 260 irc_send(irc, buf); | |
| 261 g_free(buf); | |
| 262 | |
| 263 irc->nameconv = g_strdup(target); | |
| 264 | |
| 265 return 0; | |
| 266 } | |
| 267 | |
| 268 int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 269 { | |
| 270 char *buf; | |
| 271 | |
| 272 if (!args || !args[0]) | |
| 273 return 0; | |
| 274 | |
| 275 buf = irc_format(irc, "v:", "NICK", args[0]); | |
| 276 irc_send(irc, buf); | |
| 277 g_free(buf); | |
| 278 | |
| 279 return 0; | |
| 280 } | |
| 281 | |
| 282 int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 283 { | |
| 284 char **nicks, **ops, *sign, *mode; | |
| 285 int i = 0, used = 0; | |
| 286 | |
| 287 if (!args || !args[0] || !*args[0]) | |
| 288 return 0; | |
| 289 | |
| 290 if (!strcmp(cmd, "op")) { | |
| 291 sign = "+"; | |
| 292 mode = "o"; | |
| 293 } else if (!strcmp(cmd, "deop")) { | |
| 294 sign = "-"; | |
| 295 mode = "o"; | |
| 296 } else if (!strcmp(cmd, "voice")) { | |
| 297 sign = "+"; | |
| 298 mode = "v"; | |
| 299 } else if (!strcmp(cmd, "devoice")) { | |
| 300 sign = "-"; | |
| 301 mode = "v"; | |
| 302 } else { | |
| 303 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); | |
| 304 return 0; | |
| 305 } | |
| 306 | |
| 307 nicks = g_strsplit(args[0], " ", -1); | |
| 308 | |
| 309 for (i = 0; nicks[i]; i++) | |
| 310 /* nothing */; | |
| 311 ops = g_new0(char *, i * 2 + 1); | |
| 312 | |
| 313 for (i = 0; nicks[i]; i++) { | |
| 314 if (!*nicks[i]) | |
| 315 continue; | |
| 316 ops[used++] = mode; | |
| 317 ops[used++] = nicks[i]; | |
| 318 } | |
| 319 | |
| 320 irc_do_mode(irc, target, sign, ops); | |
| 321 g_free(ops); | |
| 322 | |
| 6350 | 323 return 0; |
| 6333 | 324 } |
| 325 | |
| 326 int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 327 { | |
| 328 char *buf; | |
| 329 | |
| 330 if (!args) | |
| 331 return 0; | |
| 332 | |
| 333 if (args[1]) | |
| 334 buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 335 else | |
| 336 buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 337 irc_send(irc, buf); | |
| 338 g_free(buf); | |
| 339 | |
| 340 return 0; | |
| 341 } | |
| 342 | |
| 343 int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 344 { | |
| 345 char *stamp; | |
| 346 char *buf; | |
| 347 | |
| 348 if (args && args[0]) { | |
| 349 if (*args[0] == '#' || *args[0] == '&') | |
| 350 return 0; | |
| 351 stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 352 buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 353 g_free(stamp); | |
| 354 } else { | |
| 6350 | 355 stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 356 buf = irc_format(irc, "v:", "PING", stamp); |
| 357 g_free(stamp); | |
| 358 } | |
| 359 irc_send(irc, buf); | |
| 360 g_free(buf); | |
| 361 | |
| 362 return 0; | |
| 363 } | |
| 364 | |
| 365 int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 366 { | |
| 367 const char *cur, *end; | |
| 368 char *msg, *buf; | |
| 369 | |
| 370 if (!args || !args[0] || !args[1]) | |
| 371 return 0; | |
| 372 | |
| 373 cur = args[1]; | |
| 374 end = args[1]; | |
| 375 while (*end && *cur) { | |
| 376 end = strchr(cur, '\n'); | |
| 377 if (!end) | |
| 378 end = cur + strlen(cur); | |
| 379 msg = g_strndup(cur, end - cur); | |
| 380 buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
| 381 irc_send(irc, buf); | |
| 382 g_free(msg); | |
| 383 g_free(buf); | |
| 384 cur = end + 1; | |
| 385 } | |
| 386 | |
| 387 return 0; | |
| 388 } | |
| 389 | |
| 390 int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 391 { | |
| 392 char *buf; | |
| 393 | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6365
diff
changeset
|
394 buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : "Download Gaim: " GAIM_WEBSITE); |
| 6333 | 395 irc_send(irc, buf); |
| 396 g_free(buf); | |
| 397 | |
| 398 return 0; | |
| 399 } | |
| 400 | |
| 401 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 402 { | |
| 403 char *buf; | |
| 404 | |
| 405 if (!args || !args[0]) | |
| 406 return 0; | |
| 407 | |
| 408 buf = irc_format(irc, "v", args[0]); | |
| 409 irc_send(irc, buf); | |
| 410 g_free(buf); | |
| 411 | |
| 412 return 0; | |
| 413 } | |
| 414 | |
| 415 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 416 { | |
| 417 GaimConversation *convo; | |
| 418 GaimConnection *gc; | |
| 419 | |
| 420 if (!args || !args[0]) | |
| 421 return 0; | |
| 422 | |
| 423 convo = gaim_conversation_new(GAIM_CONV_IM, irc->account, args[0]); | |
| 424 | |
| 425 if (args[1]) { | |
| 426 gc = gaim_account_get_connection(irc->account); | |
| 427 irc_cmd_privmsg(irc, cmd, target, args); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
428 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), |
| 6982 | 429 args[1], GAIM_MESSAGE_SEND, time(NULL)); |
| 6333 | 430 } |
| 431 | |
| 432 return 0; | |
| 433 } | |
| 434 | |
| 435 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 436 { | |
| 437 char *buf; | |
| 438 | |
| 439 if (!args || !args[0]) | |
| 440 return 0; | |
| 441 | |
| 442 if (*target != '#' && *target != '&') /* not a channel, punt */ | |
| 443 return 0; | |
| 444 | |
| 445 if (args[1]) | |
| 446 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 447 else | |
| 448 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 449 irc_send(irc, buf); | |
| 450 g_free(buf); | |
| 451 | |
| 452 return 0; | |
| 453 } | |
| 454 | |
| 455 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 456 { | |
| 457 char *buf; | |
| 458 const char *topic; | |
| 459 GaimConversation *convo; | |
| 460 | |
| 461 if (!args) | |
| 462 return 0; | |
| 463 | |
| 464 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 465 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
| 6350 | 466 return 0; |
| 6333 | 467 |
| 468 if (!args[0]) { | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
469 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(convo)); |
| 6333 | 470 |
| 8504 | 471 if (topic) { |
| 472 char *tmp = gaim_escape_html(topic); | |
| 473 buf = g_strdup_printf(_("current topic is: %s"), tmp); | |
| 474 g_free(tmp); | |
| 475 } else | |
| 6333 | 476 buf = g_strdup(_("No topic is set")); |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
477 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), target, buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 478 g_free(buf); |
| 479 | |
| 480 return 0; | |
| 481 } | |
| 482 | |
| 483 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 484 irc_send(irc, buf); | |
| 485 g_free(buf); | |
| 486 | |
| 487 return 0; | |
| 488 } | |
| 489 | |
| 490 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 491 { | |
| 492 char *buf; | |
| 493 | |
| 494 if (!args || !args[0]) | |
| 6350 | 495 return 0; |
| 6333 | 496 |
| 497 if (!strcmp(cmd, "wallops")) | |
| 498 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 499 else if (!strcmp(cmd, "operwall")) | |
| 500 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 501 else |
| 502 return 0; | |
| 6333 | 503 |
| 504 irc_send(irc, buf); | |
| 505 g_free(buf); | |
| 506 | |
| 507 return 0; | |
| 508 } | |
| 509 | |
| 510 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 511 { | |
| 512 char *buf; | |
| 513 | |
| 514 if (!args || !args[0]) | |
| 515 return 0; | |
| 516 | |
| 517 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
| 518 irc_send(irc, buf); | |
| 519 g_free(buf); | |
| 520 irc->whois.nick = g_strdup(args[0]); | |
| 521 | |
| 522 return 0; | |
| 523 } | |
| 524 | |
| 525 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
| 526 { | |
| 527 char *buf, mode[5]; | |
| 528 int i = 0; | |
| 529 | |
| 530 if (!sign) | |
| 531 return; | |
| 532 | |
| 533 while (ops[i]) { | |
| 534 if (ops[i + 2] && ops[i + 4]) { | |
| 535 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 536 ops[i], ops[i + 2], ops[i + 4]); | |
| 537 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 538 ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 539 i += 6; | |
| 540 } else if (ops[i + 2]) { | |
| 541 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 542 sign, ops[i], ops[i + 2]); | |
| 543 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 544 ops[i + 1], ops[i + 3]); | |
| 545 i += 4; | |
| 546 } else { | |
| 547 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 548 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 549 i += 2; | |
| 550 } | |
| 551 irc_send(irc, buf); | |
| 552 g_free(buf); | |
| 553 } | |
| 6350 | 554 |
| 555 return; | |
| 6333 | 556 } |
