comparison plugins/irc.c @ 1958:b71494004378

[gaim-migrate @ 1968] The IRC plugin can view/set topic now. Fixed a typo in CREDITS committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Mon, 04 Jun 2001 19:12:26 +0000
parents a02584b98823
children ffae8228d63a
comparison
equal deleted inserted replaced
1957:bfb0331abdd7 1958:b71494004378
296 296
297 /* If we didnt find one, return NULL */ 297 /* If we didnt find one, return NULL */
298 return NULL; 298 return NULL;
299 } 299 }
300 300
301 static struct conversation *find_chat(struct gaim_connection *gc, char *name)
302 {
303 GSList *bcs = gc->buddy_chats;
304 struct conversation *b = NULL;
305 char *chat = g_strdup(normalize(name));
306
307 while (bcs) {
308 b = bcs->data;
309 if (!strcasecmp(normalize(b->name), chat))
310 break;
311 b = NULL;
312 bcs = bcs->next;
313 }
314
315 g_free(chat);
316 return b;
317 }
318
301 static void irc_chat_leave(struct gaim_connection *gc, int id); 319 static void irc_chat_leave(struct gaim_connection *gc, int id);
302 static void irc_chat_send(struct gaim_connection *gc, int id, char *message) 320 static void irc_chat_send(struct gaim_connection *gc, int id, char *message)
303 { 321 {
304 322
305 struct irc_data *idata = (struct irc_data *)gc->proto_data; 323 struct irc_data *idata = (struct irc_data *)gc->proto_data;
386 irc_get_info(gc, temp); 404 irc_get_info(gc, temp);
387 g_free(temp); 405 g_free(temp);
388 is_command = TRUE; 406 is_command = TRUE;
389 407
390 } 408 }
409
410 else if (!g_strncasecmp(message, "/topic ", 7) && (strlen(message) > 7))
411 {
412 gchar *temp = (gchar *)g_malloc(IRC_BUF_LEN + 1);
413 strcpy(temp, message + 7);
414
415 /* Send the chat topic change request */
416 serv_chat_set_topic(gc, id, temp);
417
418 g_free(temp);
419 is_command = TRUE;
420 }
391 421
392 else if (!g_strncasecmp(message, "/part", 5) && (strlen(message) == 5)) { 422 else if (!g_strncasecmp(message, "/part", 5) && (strlen(message) == 5)) {
393 423
394 /* If I'm not mistaken, the chat_leave command was coded under the 424 /* If I'm not mistaken, the chat_leave command was coded under the
395 * pretense that it would only occur when someone closed the window. 425 * pretense that it would only occur when someone closed the window.
980 1010
981 /* Go Home! */ 1011 /* Go Home! */
982 return; 1012 return;
983 } 1013 }
984 1014
1015 if ((strstr(buf, " TOPIC ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
1016
1017 gchar u_channel[128];
1018 gchar u_nick[128];
1019 gchar u_topic[128];
1020 int j;
1021 struct conversation *chatroom = NULL;
1022
1023 for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
1024 u_nick[j] = buf[i];
1025 }
1026 u_nick[j] = 0; i++;
1027
1028 for (j = 0; buf[i] != '#'; j++, i++) {
1029 }
1030 i++;
1031
1032 for (j = 0; buf[i] != ' '; j++, i++) {
1033 if (buf[i] == '\0')
1034 break;
1035
1036 u_channel[j] = buf[i];
1037 }
1038
1039 for (j = 0; buf[i] != ':'; j++, i++) {
1040 }
1041 i++;
1042
1043 strcpy(u_topic, buf + i);
1044 g_strchomp(u_topic);
1045
1046 chatroom = find_chat(gc, u_channel);
1047
1048 if (!chatroom)
1049 return;
1050
1051 chat_set_topic(chatroom, u_nick, u_topic);
1052
1053 return;
1054 }
1055
985 1056
986 if ((strstr(buf, " JOIN ")) && (strstr(buf, "!")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { 1057 if ((strstr(buf, " JOIN ")) && (strstr(buf, "!")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
987 1058
988 gchar u_channel[128]; 1059 gchar u_channel[128];
989 gchar u_nick[128]; 1060 gchar u_nick[128];
2000 /* Heh, there is no buddy list. We fake it. 2071 /* Heh, there is no buddy list. We fake it.
2001 * I just need this here so the add and remove buttons will 2072 * I just need this here so the add and remove buttons will
2002 * show up */ 2073 * show up */
2003 } 2074 }
2004 2075
2005 2076 static void irc_chat_set_topic(struct gaim_connection *gc, int id, char *topic)
2077 {
2078 struct irc_channel *ic = NULL;
2079 struct irc_data *idata = (struct irc_data *)gc->proto_data;
2080 char buf[BUF_LEN];
2081
2082 ic = find_channel_by_id(gc, id);
2083
2084 /* If we ain't in no channel, foo, gets outta da kitchen beeyotch */
2085 if (!ic)
2086 return;
2087
2088 /* Prepare our command */
2089 g_snprintf(buf, BUF_LEN, "TOPIC #%s :%s\n", ic->name, topic);
2090
2091 /* And send it */
2092 write(idata->fd, buf, strlen(buf));
2093 }
2006 2094
2007 static struct prpl *my_protocol = NULL; 2095 static struct prpl *my_protocol = NULL;
2008 2096
2009 static void irc_init(struct prpl *ret) 2097 static void irc_init(struct prpl *ret)
2010 { 2098 {
2011 ret->protocol = PROTO_IRC; 2099 ret->protocol = PROTO_IRC;
2100 ret->options = OPT_PROTO_CHAT_TOPIC;
2012 ret->name = irc_name; 2101 ret->name = irc_name;
2013 ret->list_icon = irc_list_icon; 2102 ret->list_icon = irc_list_icon;
2014 ret->buddy_menu = irc_buddy_menu; 2103 ret->buddy_menu = irc_buddy_menu;
2015 ret->user_opts = irc_user_opts; 2104 ret->user_opts = irc_user_opts;
2016 ret->login = irc_login; 2105 ret->login = irc_login;
2021 ret->chat_send = irc_chat_send; 2110 ret->chat_send = irc_chat_send;
2022 ret->get_info = irc_get_info; 2111 ret->get_info = irc_get_info;
2023 ret->set_away = irc_set_away; 2112 ret->set_away = irc_set_away;
2024 ret->add_buddy = irc_fake_buddy; 2113 ret->add_buddy = irc_fake_buddy;
2025 ret->remove_buddy = irc_fake_buddy; 2114 ret->remove_buddy = irc_fake_buddy;
2026 2115 ret->chat_set_topic = irc_chat_set_topic;
2027 my_protocol = ret; 2116 my_protocol = ret;
2028 } 2117 }
2029 2118
2030 char *gaim_plugin_init(GModule * handle) 2119 char *gaim_plugin_init(GModule * handle)
2031 { 2120 {