Mercurial > pidgin
comparison plugins/irc.c @ 1742:34369ed4e212
[gaim-migrate @ 1752]
IRC changes.
committer: Tailor Script <tailor@pidgin.im>
| author | Rob Flynn <gaim@robflynn.com> |
|---|---|
| date | Mon, 23 Apr 2001 17:37:44 +0000 |
| parents | 1573a65fd0cd |
| children | 1e0613d9526b |
comparison
equal
deleted
inserted
replaced
| 1741:7506587a394d | 1742:34369ed4e212 |
|---|---|
| 87 struct irc_data *idata = (struct irc_data *)gc->proto_data; | 87 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
| 88 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | 88 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
| 89 | 89 |
| 90 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); | 90 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); |
| 91 write(idata->fd, buf, strlen(buf)); | 91 write(idata->fd, buf, strlen(buf)); |
| 92 write(idata->fd, buf, strlen(buf)); | |
| 92 | 93 |
| 93 g_free(buf); | 94 g_free(buf); |
| 94 } | 95 } |
| 95 | 96 |
| 96 static void irc_update_user(struct gaim_connection *gc, char *name, int status) | 97 static void irc_update_user(struct gaim_connection *gc, char *name, int status) |
| 168 | 169 |
| 169 | 170 |
| 170 static void irc_send_im(struct gaim_connection *gc, char *who, char *message, int away) | 171 static void irc_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
| 171 { | 172 { |
| 172 | 173 |
| 173 struct irc_data *idata = (struct irc_data *)gc->proto_data; | 174 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
| 174 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | 175 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
| 175 | 176 |
| 176 /* Before we actually send this, we should check to see if they're trying | 177 /* Before we actually send this, we should check to see if they're trying |
| 177 * To issue a command and handle it properly. */ | 178 * To issue a command and handle it properly. */ |
| 178 | 179 |
| 286 } | 287 } |
| 287 | 288 |
| 288 static void irc_chat_send(struct gaim_connection *gc, int id, char *message) | 289 static void irc_chat_send(struct gaim_connection *gc, int id, char *message) |
| 289 { | 290 { |
| 290 | 291 |
| 291 struct irc_data *idata = (struct irc_data *)gc->proto_data; | 292 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
| 292 struct irc_channel *channel = NULL; | 293 struct irc_channel *channel = NULL; |
| 293 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | 294 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
| 294 | 295 char **kick; |
| 296 gboolean is_command = FALSE; | |
| 295 /* First lets get our current channel */ | 297 /* First lets get our current channel */ |
| 296 channel = find_channel_by_id(gc, id); | 298 channel = find_channel_by_id(gc, id); |
| 297 | 299 |
| 298 | 300 |
| 299 if (!channel) { | 301 if (!channel) { |
| 305 | 307 |
| 306 /* Before we actually send this, we should check to see if they're trying | 308 /* Before we actually send this, we should check to see if they're trying |
| 307 * To issue a command and handle it properly. */ | 309 * To issue a command and handle it properly. */ |
| 308 | 310 |
| 309 if (message[0] == '/') | 311 if (message[0] == '/') |
| 310 { | 312 { |
| 311 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | 313 |
| 312 /* We have /me!! We have /me!! :-) */ | 314 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { |
| 313 | 315 /* We have /me!! We have /me!! :-) */ |
| 314 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | 316 |
| 315 strcpy(temp, message + 4); | 317 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
| 316 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, '\001', temp, | 318 strcpy(temp, message + 4); |
| 317 '\001'); | 319 |
| 318 g_free(temp); | 320 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, '\001', temp, |
| 319 } | 321 '\001'); |
| 320 else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | 322 g_free(temp); |
| 321 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | 323 } |
| 322 | 324 else if ((g_strncasecmp(message, "/op ", 4) == 0) && (strlen(message) > 4)) { |
| 323 strcpy(temp, message + 7); | 325 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
| 324 irc_get_info(gc, temp); | 326 strcpy(temp, message + 4); |
| 325 g_free(temp); | 327 |
| 326 | 328 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +o %s\n", channel->name, temp); |
| 327 return; | 329 |
| 328 } | 330 g_free(temp); |
| 329 } | 331 is_command = TRUE; |
| 332 | |
| 333 } | |
| 334 else if ((g_strncasecmp(message, "/deop ", 6) == 0) && (strlen(message) > 6)) { | |
| 335 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 336 strcpy(temp, message + 6); | |
| 337 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -o %s\n", channel->name, temp); | |
| 338 | |
| 339 g_free(temp); | |
| 340 is_command = TRUE; | |
| 341 } | |
| 342 | |
| 343 else if ((g_strncasecmp(message, "/voice ", 7) == 0) && (strlen(message) > 7)) { | |
| 344 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 345 strcpy(temp, message + 7); | |
| 346 | |
| 347 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +v %s\n", channel->name, temp); | |
| 348 | |
| 349 g_free(temp); | |
| 350 is_command = TRUE; | |
| 351 | |
| 352 } | |
| 353 else if ((g_strncasecmp(message, "/devoice ", 9) == 0) && (strlen(message) > 9)) { | |
| 354 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 355 strcpy(temp, message + 6); | |
| 356 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -v %s\n", channel->name, temp); | |
| 357 | |
| 358 g_free(temp); | |
| 359 is_command = TRUE; | |
| 360 } | |
| 361 else if ((g_strncasecmp(message, "/mode ", 6) == 0) && (strlen(message) > 6)) { | |
| 362 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 363 strcpy(temp, message + 6); | |
| 364 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s %s\n", channel->name, temp); | |
| 365 g_free(temp); | |
| 366 is_command = TRUE; | |
| 367 } | |
| 368 | |
| 369 else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | |
| 370 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 371 | |
| 372 strcpy(temp, message + 7); | |
| 373 irc_get_info(gc, temp); | |
| 374 g_free(temp); | |
| 375 | |
| 376 | |
| 377 } | |
| 378 | |
| 379 else if (!g_strncasecmp(message, "/raw ", 5) && (strlen(message) > 5)){ | |
| 380 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 381 strcpy(temp, message + 5); | |
| 382 g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
| 383 g_free(temp); | |
| 384 is_command = TRUE; | |
| 385 } | |
| 386 | |
| 387 else if (!g_strncasecmp(message, "/quote ", 7) && (strlen(message) >7)) { | |
| 388 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 389 strcpy(temp, message + 7); | |
| 390 g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
| 391 g_free(temp); | |
| 392 is_command = TRUE; | |
| 393 } | |
| 394 | |
| 395 else if (!g_strncasecmp(message, "/kick ", 6) && (strlen(message) > 6)) { | |
| 396 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 397 strcpy(temp, message + 6); | |
| 398 kick = g_strsplit(temp, " ", 2); | |
| 399 g_snprintf(buf, IRC_BUF_LEN, "KICK #%s %s :%s\r\n", channel->name, kick[0], kick[1]); | |
| 400 g_free(temp); | |
| 401 is_command = TRUE; | |
| 402 } | |
| 403 | |
| 404 /* FIXME: I'll go back in and grab this later. -- Rob */ | |
| 405 /* | |
| 406 I THOUGHT THIS WOULD WORK, BUT I WAS WRONG. WOULD SOMEONE KINDLY FIX IT? | |
| 407 | |
| 408 | |
| 409 else if (!g_strncasecmp(message, "/help", 5)) { | |
| 410 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 411 strcpy(temp, message + 5); | |
| 412 if (temp == "") { | |
| 413 | |
| 414 serv_got_chat_in(gc, id, "gAIM", 0, "Available Commands:"); | |
| 415 serv_got_chat_in(gc, id, "gAIM", 0, " "); | |
| 416 serv_got_chat_in(gc, id, "gAIM", 0, "<b>op voice kick </b>"); | |
| 417 serv_got_chat_in(gc, id, "gAIM", 0, "<b>deop devoice whois</b>"); | |
| 418 serv_got_chat_in(gc, id, "gAIM", 0, "<b>me raw quote</b>"); | |
| 419 serv_got_chat_in(gc, id, "gAIM", 0, "<b>mode</b>"); | |
| 420 } | |
| 421 else { | |
| 422 serv_got_chat_in(gc, id, "gAIM", 0, "Usage: "); | |
| 423 if (temp == "op") | |
| 424 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/op <nick></b> - Gives operator status to user."); | |
| 425 else if (temp == "deop") | |
| 426 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/deop <nick></b> - Removes operator status from user."); | |
| 427 else if (temp == "me") | |
| 428 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/me <action></b> - Sends an action to the channel."); | |
| 429 else if (temp == "mode") | |
| 430 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/mode {[+|-}|o|p|s|i|t|n|b|v} [<limit][<nick>][<ban mask]</b> - Changes channel and user modes."); | |
| 431 else if (temp == "voice") | |
| 432 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/voice <nick></b> - Gives voice status to user."); | |
| 433 else if (temp == "devoice") | |
| 434 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/devoice <nick></b> - Removes voice status from user."); | |
| 435 else if (temp == "raw") | |
| 436 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
| 437 else if (temp == "kick") | |
| 438 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/kick [<comment>]</b> - Kicks a user out of the channel."); | |
| 439 else if (temp == "whois") | |
| 440 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/whois <nick></b> - Gets information about user."); | |
| 441 else if (temp == "quote") | |
| 442 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
| 443 else | |
| 444 serv_got_chat_in(gc, id, "gAIM", 0, "No such command."); | |
| 445 } | |
| 446 | |
| 447 g_free(temp); | |
| 448 is_command = TRUE; | |
| 449 } | |
| 450 */ | |
| 451 | |
| 452 } | |
| 453 | |
| 330 else { | 454 else { |
| 331 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message); | 455 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message); |
| 332 } | 456 |
| 333 | 457 } |
| 458 | |
| 459 | |
| 334 write(idata->fd, buf, strlen(buf)); | 460 write(idata->fd, buf, strlen(buf)); |
| 335 | 461 |
| 336 /* Since AIM expects us to receive the message we send, we gotta fake it */ | 462 /* Since AIM expects us to receive the message we send, we gotta fake it */ |
| 337 serv_got_chat_in(gc, id, gc->username, 0, message); | 463 if (is_command==FALSE) |
| 338 | 464 serv_got_chat_in(gc, id, gc->username, 0, message); |
| 465 | |
| 339 g_free(buf); | 466 g_free(buf); |
| 340 } | 467 |
| 341 | 468 |
| 469 } | |
| 342 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) | 470 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) |
| 343 { | 471 { |
| 344 struct irc_data *idata = (struct irc_data *)gc->proto_data; | 472 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
| 345 GSList *bc = gc->buddy_chats; | 473 GSList *bc = gc->buddy_chats; |
| 346 struct conversation *b = NULL; | 474 struct conversation *b = NULL; |
| 392 struct gaim_connection *gc = data; | 520 struct gaim_connection *gc = data; |
| 393 int i = 0; | 521 int i = 0; |
| 394 gchar buf[4096]; | 522 gchar buf[4096]; |
| 395 gchar **buf2; | 523 gchar **buf2; |
| 396 struct irc_data *idata; | 524 struct irc_data *idata; |
| 397 | 525 |
| 398 idata = (struct irc_data *)gc->proto_data; | 526 idata = (struct irc_data *)gc->proto_data; |
| 527 | |
| 399 | 528 |
| 400 do { | 529 do { |
| 401 if (read(idata->fd, buf + i, 1) < 0) { | 530 if (read(idata->fd, buf + i, 1) < 0) { |
| 402 hide_login_progress(gc, "Read error"); | 531 hide_login_progress(gc, "Read error"); |
| 403 signoff(gc); | 532 signoff(gc); |
