Mercurial > pidgin
annotate src/protocols/irc/cmds.c @ 8352:77baefe979c6
[gaim-migrate @ 9076]
this compiles, and I don't think it breaks anything, so here's
/list support, again from our patient friend marv
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Fri, 27 Feb 2004 01:48:11 +0000 |
| parents | 7a6e30eb7aad |
| children | 534b479692d0 |
| 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" | |
| 26 #include "notify.h" | |
| 27 #include "debug.h" | |
| 28 #include "irc.h" | |
| 29 | |
| 30 | |
| 31 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops); | |
| 32 | |
| 33 int irc_cmd_default(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 34 { | |
| 35 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); | |
| 36 char *buf; | |
| 37 | |
| 38 if (!convo) | |
| 6350 | 39 return 1; |
| 6333 | 40 |
| 41 buf = g_strdup_printf(_("Unknown command: %s"), cmd); | |
| 42 if (gaim_conversation_get_type(convo) == GAIM_CONV_IM) | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
43 gaim_conv_im_write(GAIM_CONV_IM(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 44 else |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
45 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 46 g_free(buf); |
| 47 | |
| 48 return 1; | |
| 49 } | |
| 50 | |
| 51 int irc_cmd_away(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 52 { | |
| 53 char *buf, *message, *cur; | |
| 54 | |
| 55 if (args[0] && strcmp(cmd, "back")) { | |
| 56 message = strdup(args[0]); | |
| 57 for (cur = message; *cur; cur++) { | |
| 58 if (*cur == '\n') | |
| 59 *cur = ' '; | |
| 60 } | |
| 61 buf = irc_format(irc, "v:", "AWAY", message); | |
| 62 g_free(message); | |
| 63 } else { | |
| 64 buf = irc_format(irc, "v", "AWAY"); | |
| 65 } | |
| 66 irc_send(irc, buf); | |
| 67 g_free(buf); | |
| 68 | |
| 69 return 0; | |
| 70 } | |
| 71 | |
| 72 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 73 { | |
| 74 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
| 75 char *action, *dst, **newargs; | |
| 76 const char *src; | |
| 77 GaimConversation *convo; | |
| 78 | |
| 79 if (!args || !args[0] || !gc) | |
| 80 return 0; | |
| 81 | |
| 6376 | 82 action = g_malloc(strlen(args[0]) + 10); |
| 6333 | 83 |
| 84 sprintf(action, "\001ACTION "); | |
| 85 | |
| 86 src = args[0]; | |
| 87 dst = action + 8; | |
| 88 while (*src) { | |
| 89 if (*src == '\n') { | |
| 90 if (*(src + 1) == '\0') { | |
| 91 break; | |
| 92 } else { | |
| 93 *dst++ = ' '; | |
| 94 src++; | |
| 95 continue; | |
| 96 } | |
| 97 } | |
| 98 *dst++ = *src++; | |
| 99 } | |
| 100 *dst++ = '\001'; | |
| 101 *dst = '\0'; | |
| 102 | |
| 103 newargs = g_new0(char *, 2); | |
| 104 newargs[0] = g_strdup(target); | |
| 105 newargs[1] = action; | |
| 106 irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
| 107 g_free(newargs[0]); | |
| 108 g_free(newargs[1]); | |
| 109 g_free(newargs); | |
| 110 | |
| 111 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 112 if (convo && gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) { | |
| 113 action = g_strdup_printf("/me %s", args[0]); | |
| 114 if (action[strlen(action) - 1] == '\n') | |
| 115 action[strlen(action) - 1] = '\0'; | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
116 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), |
| 6333 | 117 gaim_connection_get_display_name(gc), |
| 118 0, action, time(NULL)); | |
| 119 g_free(action); | |
| 120 } | |
| 121 | |
| 122 return 1; | |
| 123 } | |
| 124 | |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
125 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
|
126 { |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
127 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
128 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
129 /* XXX we should eventually have per-command help */ |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
130 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
131 if (!convo) |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
132 return 0; |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
133 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
134 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) { |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
135 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
|
136 "AWAY INVITE JOIN KICK<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
137 "ME MODE MSG NAMES<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
138 "NICK OP DEOP OPERWALL<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
139 "PART PING QUERY QUIT<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
140 "QUOTE REMOVE TOPIC UMODE<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
141 "VOICE DEVOICE WALLOPS WHOIS<BR>"), |
| 6621 | 142 GAIM_MESSAGE_NO_LOG, time(NULL)); |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
143 } else { |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
144 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
|
145 "AWAY JOIN ME MODE<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
146 "MSG NICK OPERWALL PING<BR>" |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
147 "QUERY QUIT QUOTE UMODE<BR>" |
| 6982 | 148 "WALLOPS WHOIS"), GAIM_MESSAGE_NO_LOG, time(NULL)); |
|
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
149 } |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
150 |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
151 return 0; |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
152 } |
|
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
153 |
| 6333 | 154 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 155 { | |
| 156 char *buf; | |
| 157 | |
| 158 if (!args || !args[0] || !(args[1] || target)) | |
| 159 return 0; | |
| 160 | |
| 161 buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
| 162 irc_send(irc, buf); | |
| 163 g_free(buf); | |
| 164 | |
| 165 return 0; | |
| 166 } | |
| 167 | |
| 168 int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 169 { | |
| 170 char *buf; | |
| 171 | |
| 172 if (!args || !args[0]) | |
| 173 return 0; | |
| 174 | |
| 175 if (args[1]) | |
| 176 buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
| 177 else | |
| 178 buf = irc_format(irc, "vc", "JOIN", args[0]); | |
| 179 irc_send(irc, buf); | |
| 180 g_free(buf); | |
| 181 | |
| 182 return 0; | |
| 183 } | |
| 184 | |
| 185 int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 186 { | |
| 187 char *buf; | |
| 188 GaimConversation *convo; | |
| 189 | |
| 190 if (!args || !args[0]) | |
| 191 return 0; | |
| 192 | |
| 193 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 194 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
| 6350 | 195 return 0; |
| 6333 | 196 |
| 197 if (args[1]) | |
| 198 buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
| 199 else | |
| 200 buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
| 201 irc_send(irc, buf); | |
| 202 g_free(buf); | |
| 203 | |
| 204 return 0; | |
| 205 } | |
| 206 | |
| 8114 | 207 int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 208 { | |
| 8352 | 209 gaim_roomlist_show_with_account(irc->account); |
| 8114 | 210 |
| 211 return 0; | |
| 212 } | |
| 213 | |
| 6333 | 214 int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
| 215 { | |
| 216 GaimConnection *gc; | |
| 217 char *buf; | |
| 218 | |
| 219 if (!args) | |
| 220 return 0; | |
| 221 | |
| 222 if (!strcmp(cmd, "mode")) { | |
| 223 if (!args[0] && (*target == '#' || *target == '&')) | |
| 224 buf = irc_format(irc, "vc", "MODE", target); | |
| 225 else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
| 226 buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
| 227 else if (args[0]) | |
| 228 buf = irc_format(irc, "vv", "MODE", args[0]); | |
| 229 else | |
| 6350 | 230 return 0; |
| 6333 | 231 } else if (!strcmp(cmd, "umode")) { |
| 232 if (!args[0]) | |
| 6350 | 233 return 0; |
| 6333 | 234 gc = gaim_account_get_connection(irc->account); |
| 235 buf = irc_format(irc, "vnv", "MODE", gaim_connection_get_display_name(gc), args[0]); | |
| 6365 | 236 } else { |
| 237 return 0; | |
| 6333 | 238 } |
| 6365 | 239 |
| 6333 | 240 irc_send(irc, buf); |
| 241 g_free(buf); | |
| 242 | |
| 243 return 0; | |
| 244 } | |
| 245 | |
| 246 int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 247 { | |
| 248 char *buf; | |
| 249 | |
| 250 if (!args) | |
| 251 return 0; | |
| 252 | |
| 253 buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
| 254 irc_send(irc, buf); | |
| 255 g_free(buf); | |
| 256 | |
| 257 irc->nameconv = g_strdup(target); | |
| 258 | |
| 259 return 0; | |
| 260 } | |
| 261 | |
| 262 int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 263 { | |
| 264 char *buf; | |
| 265 | |
| 266 if (!args || !args[0]) | |
| 267 return 0; | |
| 268 | |
| 269 buf = irc_format(irc, "v:", "NICK", args[0]); | |
| 270 irc_send(irc, buf); | |
| 271 g_free(buf); | |
| 272 | |
| 273 return 0; | |
| 274 } | |
| 275 | |
| 276 int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 277 { | |
| 278 char **nicks, **ops, *sign, *mode; | |
| 279 int i = 0, used = 0; | |
| 280 | |
| 281 if (!args || !args[0] || !*args[0]) | |
| 282 return 0; | |
| 283 | |
| 284 if (!strcmp(cmd, "op")) { | |
| 285 sign = "+"; | |
| 286 mode = "o"; | |
| 287 } else if (!strcmp(cmd, "deop")) { | |
| 288 sign = "-"; | |
| 289 mode = "o"; | |
| 290 } else if (!strcmp(cmd, "voice")) { | |
| 291 sign = "+"; | |
| 292 mode = "v"; | |
| 293 } else if (!strcmp(cmd, "devoice")) { | |
| 294 sign = "-"; | |
| 295 mode = "v"; | |
| 296 } else { | |
| 297 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); | |
| 298 return 0; | |
| 299 } | |
| 300 | |
| 301 nicks = g_strsplit(args[0], " ", -1); | |
| 302 | |
| 303 for (i = 0; nicks[i]; i++) | |
| 304 /* nothing */; | |
| 305 ops = g_new0(char *, i * 2 + 1); | |
| 306 | |
| 307 for (i = 0; nicks[i]; i++) { | |
| 308 if (!*nicks[i]) | |
| 309 continue; | |
| 310 ops[used++] = mode; | |
| 311 ops[used++] = nicks[i]; | |
| 312 } | |
| 313 | |
| 314 irc_do_mode(irc, target, sign, ops); | |
| 315 g_free(ops); | |
| 316 | |
| 6350 | 317 return 0; |
| 6333 | 318 } |
| 319 | |
| 320 int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 321 { | |
| 322 char *buf; | |
| 323 | |
| 324 if (!args) | |
| 325 return 0; | |
| 326 | |
| 327 if (args[1]) | |
| 328 buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
| 329 else | |
| 330 buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
| 331 irc_send(irc, buf); | |
| 332 g_free(buf); | |
| 333 | |
| 334 return 0; | |
| 335 } | |
| 336 | |
| 337 int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 338 { | |
| 339 char *stamp; | |
| 340 char *buf; | |
| 341 | |
| 342 if (args && args[0]) { | |
| 343 if (*args[0] == '#' || *args[0] == '&') | |
| 344 return 0; | |
| 345 stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
| 346 buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
| 347 g_free(stamp); | |
| 348 } else { | |
| 6350 | 349 stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
| 6333 | 350 buf = irc_format(irc, "v:", "PING", stamp); |
| 351 g_free(stamp); | |
| 352 } | |
| 353 irc_send(irc, buf); | |
| 354 g_free(buf); | |
| 355 | |
| 356 return 0; | |
| 357 } | |
| 358 | |
| 359 int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 360 { | |
| 361 const char *cur, *end; | |
| 362 char *msg, *buf; | |
| 363 | |
| 364 if (!args || !args[0] || !args[1]) | |
| 365 return 0; | |
| 366 | |
| 367 cur = args[1]; | |
| 368 end = args[1]; | |
| 369 while (*end && *cur) { | |
| 370 end = strchr(cur, '\n'); | |
| 371 if (!end) | |
| 372 end = cur + strlen(cur); | |
| 373 msg = g_strndup(cur, end - cur); | |
| 374 buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
| 375 irc_send(irc, buf); | |
| 376 g_free(msg); | |
| 377 g_free(buf); | |
| 378 cur = end + 1; | |
| 379 } | |
| 380 | |
| 381 return 0; | |
| 382 } | |
| 383 | |
| 384 int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 385 { | |
| 386 char *buf; | |
| 387 | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6365
diff
changeset
|
388 buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : "Download Gaim: " GAIM_WEBSITE); |
| 6333 | 389 irc_send(irc, buf); |
| 390 g_free(buf); | |
| 391 | |
| 392 return 0; | |
| 393 } | |
| 394 | |
| 395 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 396 { | |
| 397 char *buf; | |
| 398 | |
| 399 if (!args || !args[0]) | |
| 400 return 0; | |
| 401 | |
| 402 buf = irc_format(irc, "v", args[0]); | |
| 403 irc_send(irc, buf); | |
| 404 g_free(buf); | |
| 405 | |
| 406 return 0; | |
| 407 } | |
| 408 | |
| 409 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 410 { | |
| 411 GaimConversation *convo; | |
| 412 GaimConnection *gc; | |
| 413 | |
| 414 if (!args || !args[0]) | |
| 415 return 0; | |
| 416 | |
| 417 convo = gaim_conversation_new(GAIM_CONV_IM, irc->account, args[0]); | |
| 418 | |
| 419 if (args[1]) { | |
| 420 gc = gaim_account_get_connection(irc->account); | |
| 421 irc_cmd_privmsg(irc, cmd, target, args); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
422 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), |
| 6982 | 423 args[1], GAIM_MESSAGE_SEND, time(NULL)); |
| 6333 | 424 } |
| 425 | |
| 426 return 0; | |
| 427 } | |
| 428 | |
| 429 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 430 { | |
| 431 char *buf; | |
| 432 | |
| 433 if (!args || !args[0]) | |
| 434 return 0; | |
| 435 | |
| 436 if (*target != '#' && *target != '&') /* not a channel, punt */ | |
| 437 return 0; | |
| 438 | |
| 439 if (args[1]) | |
| 440 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
| 441 else | |
| 442 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
| 443 irc_send(irc, buf); | |
| 444 g_free(buf); | |
| 445 | |
| 446 return 0; | |
| 447 } | |
| 448 | |
| 449 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 450 { | |
| 451 char *buf; | |
| 452 const char *topic; | |
| 453 GaimConversation *convo; | |
| 454 | |
| 455 if (!args) | |
| 456 return 0; | |
| 457 | |
| 458 convo = gaim_find_conversation_with_account(target, irc->account); | |
| 459 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
| 6350 | 460 return 0; |
| 6333 | 461 |
| 462 if (!args[0]) { | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
463 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(convo)); |
| 6333 | 464 |
| 465 if (topic) | |
| 6350 | 466 buf = g_strdup_printf(_("current topic is: %s"), topic); |
| 6333 | 467 else |
| 468 buf = g_strdup(_("No topic is set")); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
469 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), target, buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| 6333 | 470 g_free(buf); |
| 471 | |
| 472 return 0; | |
| 473 } | |
| 474 | |
| 475 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
| 476 irc_send(irc, buf); | |
| 477 g_free(buf); | |
| 478 | |
| 479 return 0; | |
| 480 } | |
| 481 | |
| 482 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 483 { | |
| 484 char *buf; | |
| 485 | |
| 486 if (!args || !args[0]) | |
| 6350 | 487 return 0; |
| 6333 | 488 |
| 489 if (!strcmp(cmd, "wallops")) | |
| 490 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
| 491 else if (!strcmp(cmd, "operwall")) | |
| 492 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
| 6365 | 493 else |
| 494 return 0; | |
| 6333 | 495 |
| 496 irc_send(irc, buf); | |
| 497 g_free(buf); | |
| 498 | |
| 499 return 0; | |
| 500 } | |
| 501 | |
| 502 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
| 503 { | |
| 504 char *buf; | |
| 505 | |
| 506 if (!args || !args[0]) | |
| 507 return 0; | |
| 508 | |
| 509 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
| 510 irc_send(irc, buf); | |
| 511 g_free(buf); | |
| 512 irc->whois.nick = g_strdup(args[0]); | |
| 513 | |
| 514 return 0; | |
| 515 } | |
| 516 | |
| 517 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
| 518 { | |
| 519 char *buf, mode[5]; | |
| 520 int i = 0; | |
| 521 | |
| 522 if (!sign) | |
| 523 return; | |
| 524 | |
| 525 while (ops[i]) { | |
| 526 if (ops[i + 2] && ops[i + 4]) { | |
| 527 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
| 528 ops[i], ops[i + 2], ops[i + 4]); | |
| 529 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
| 530 ops[i + 1], ops[i + 3], ops[i + 5]); | |
| 531 i += 6; | |
| 532 } else if (ops[i + 2]) { | |
| 533 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
| 534 sign, ops[i], ops[i + 2]); | |
| 535 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
| 536 ops[i + 1], ops[i + 3]); | |
| 537 i += 4; | |
| 538 } else { | |
| 539 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
| 540 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
| 541 i += 2; | |
| 542 } | |
| 543 irc_send(irc, buf); | |
| 544 g_free(buf); | |
| 545 } | |
| 6350 | 546 |
| 547 return; | |
| 6333 | 548 } |
