⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgs.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/** * @file msgs.c * * purple * * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "internal.h"#include "conversation.h"#include "blist.h"#include "notify.h"#include "util.h"#include "debug.h"#include "irc.h"#include <stdio.h>static char *irc_mask_nick(const char *mask);static char *irc_mask_userhost(const char *mask);static void irc_chat_remove_buddy(PurpleConversation *convo, char *data[2]);static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc);static void irc_connected(struct irc_conn *irc, const char *nick);static void irc_msg_handle_privmsg(struct irc_conn *irc, const char *name,                                   const char *from, const char *to,                                   const char *rawmsg, gboolean notice);static char *irc_mask_nick(const char *mask){	char *end, *buf;	end = strchr(mask, '!');	if (!end)		buf = g_strdup(mask);	else		buf = g_strndup(mask, end - mask);	return buf;}static char *irc_mask_userhost(const char *mask){	return g_strdup(strchr(mask, '!') + 1);}static void irc_chat_remove_buddy(PurpleConversation *convo, char *data[2]){	char *message;	message = g_strdup_printf("quit: %s", data[1]);	if (purple_conv_chat_find_user(PURPLE_CONV_CHAT(convo), data[0]))		purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), data[0], message);	g_free(message);}static void irc_connected(struct irc_conn *irc, const char *nick){	PurpleConnection *gc;	PurpleStatus *status;	PurpleBlistNode *gnode, *cnode, *bnode;	if ((gc = purple_account_get_connection(irc->account)) == NULL	    || PURPLE_CONNECTION_IS_CONNECTED(gc))		return;	purple_connection_set_display_name(gc, nick);	purple_connection_set_state(gc, PURPLE_CONNECTED);	/* If we're away then set our away message */	status = purple_account_get_active_status(irc->account);	if (!purple_status_get_type(status) != PURPLE_STATUS_AVAILABLE) {		PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);		prpl_info->set_status(irc->account, status);	}	/* this used to be in the core, but it's not now */	for (gnode = purple_get_blist()->root; gnode; gnode = gnode->next) {		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))			continue;		for(cnode = gnode->child; cnode; cnode = cnode->next) {			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))				continue;			for(bnode = cnode->child; bnode; bnode = bnode->next) {				PurpleBuddy *b;				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))					continue;				b = (PurpleBuddy *)bnode;				if(b->account == gc->account) {					struct irc_buddy *ib = g_new0(struct irc_buddy, 1);					ib->name = g_strdup(b->name);					g_hash_table_insert(irc->buddies, ib->name, ib);				}			}		}	}	irc_blist_timeout(irc);	if (!irc->timer)		irc->timer = purple_timeout_add(45000, (GSourceFunc)irc_blist_timeout, (gpointer)irc);}void irc_msg_default(struct irc_conn *irc, const char *name, const char *from, char **args){	purple_debug(PURPLE_DEBUG_INFO, "irc", "Unrecognized message: %s\n", args[0]);}void irc_msg_features(struct irc_conn *irc, const char *name, const char *from, char **args){	gchar **features;	int i;	if (!args || !args[0] || !args[1])		return;	features = g_strsplit(args[1], " ", -1);	for (i = 0; features[i]; i++) {		char *val;		if (!strncmp(features[i], "PREFIX=", 7)) {			if ((val = strchr(features[i] + 7, ')')) != NULL)				irc->mode_chars = g_strdup(val + 1);		}	}}void irc_msg_luser(struct irc_conn *irc, const char *name, const char *from, char **args){	if (!args || !args[0])		return;	if (!strcmp(name, "251")) {		/* 251 is required, so we pluck our nick from here and		 * finalize connection */		irc_connected(irc, args[0]);		/* Some IRC servers seem to not send a 255 numeric, so		 * I guess we can't require it; 251 will do. */	/* } else if (!strcmp(name, "255")) { */	}}void irc_msg_away(struct irc_conn *irc, const char *name, const char *from, char **args){	PurpleConnection *gc;	char *msg;	if (!args || !args[1])		return;	if (irc->whois.nick && !purple_utf8_strcasecmp(irc->whois.nick, args[1])) {		/* We're doing a whois, show this in the whois dialog */		irc_msg_whois(irc, name, from, args);		return;	}	gc = purple_account_get_connection(irc->account);	if (gc) {		msg = g_markup_escape_text(args[2], -1);		serv_got_im(gc, args[1], msg, PURPLE_MESSAGE_AUTO_RESP, time(NULL));		g_free(msg);	}}void irc_msg_badmode(struct irc_conn *irc, const char *name, const char *from, char **args){	PurpleConnection *gc = purple_account_get_connection(irc->account);	if (!args || !args[1] || !gc)		return;	purple_notify_error(gc, NULL, _("Bad mode"), args[1]);}void irc_msg_banned(struct irc_conn *irc, const char *name, const char *from, char **args){	PurpleConnection *gc = purple_account_get_connection(irc->account);	char *buf;	if (!args || !args[1] || !gc)		return;	buf = g_strdup_printf(_("You are banned from %s."), args[1]);	purple_notify_error(gc, _("Banned"), _("Banned"), buf);	g_free(buf);}void irc_msg_banfull(struct irc_conn *irc, const char *name, const char *from, char **args){	PurpleConversation *convo;	char *buf, *nick;	if (!args || !args[0] || !args[1] || !args[2])		return;	convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[1], irc->account);	if (!convo)		return;	nick = g_markup_escape_text(args[2], -1);	buf = g_strdup_printf(_("Cannot ban %s: banlist is full"), nick);	g_free(nick);	purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "", buf,			     PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG,			     time(NULL));	g_free(buf);}void irc_msg_chanmode(struct irc_conn *irc, const char *name, const char *from, char **args){	PurpleConversation *convo;	char *buf, *escaped;	if (!args || !args[1] || !args[2])		return;	convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[1], irc->account);	if (!convo)	/* XXX punt on channels we are not in for now */		return;	escaped = (args[3] != NULL) ? g_markup_escape_text(args[3], -1) : NULL;	buf = g_strdup_printf("mode for %s: %s %s", args[1], args[2], escaped ? escaped : "");	purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "", buf, PURPLE_MESSAGE_SYSTEM, time(NULL));	g_free(escaped);	g_free(buf);	return;}void irc_msg_whois(struct irc_conn *irc, const char *name, const char *from, char **args){	if (!irc->whois.nick) {		purple_debug(PURPLE_DEBUG_WARNING, "irc", "Unexpected %s reply for %s\n", !strcmp(name, "314") ? "WHOWAS" : "WHOIS"											   , args[1]);		return;	}	if (purple_utf8_strcasecmp(irc->whois.nick, args[1])) {		purple_debug(PURPLE_DEBUG_WARNING, "irc", "Got %s reply for %s while waiting for %s\n", !strcmp(name, "314") ? "WHOWAS" : "WHOIS"												      , args[1], irc->whois.nick);		return;	}	if (!strcmp(name, "301")) {		irc->whois.away = g_strdup(args[2]);	} else if (!strcmp(name, "311") || !strcmp(name, "314")) {		irc->whois.userhost = g_strdup_printf("%s@%s", args[2], args[3]);		irc->whois.name = g_strdup(args[5]);	} else if (!strcmp(name, "312")) {		irc->whois.server = g_strdup(args[2]);		irc->whois.serverinfo = g_strdup(args[3]);	} else if (!strcmp(name, "313")) {		irc->whois.ircop = 1;	} else if (!strcmp(name, "317")) {		irc->whois.idle = atoi(args[2]);		if (args[3])			irc->whois.signon = (time_t)atoi(args[3]);	} else if (!strcmp(name, "319")) {		irc->whois.channels = g_strdup(args[2]);	} else if (!strcmp(name, "320")) {		irc->whois.identified = 1;	}}void irc_msg_endwhois(struct irc_conn *irc, const char *name, const char *from, char **args){	PurpleConnection *gc;	char *tmp, *tmp2;	PurpleNotifyUserInfo *user_info;	if (!irc->whois.nick) {		purple_debug(PURPLE_DEBUG_WARNING, "irc", "Unexpected End of %s for %s\n", !strcmp(name, "369") ? "WHOWAS" : "WHOIS" 											     , args[1]);		return;	}	if (purple_utf8_strcasecmp(irc->whois.nick, args[1])) {		purple_debug(PURPLE_DEBUG_WARNING, "irc", "Received end of %s for %s, expecting %s\n", !strcmp(name, "369") ? "WHOWAS" : "WHOIS" 													 , args[1], irc->whois.nick);		return;	}	user_info = purple_notify_user_info_new();	tmp2 = g_markup_escape_text(args[1], -1);	tmp = g_strdup_printf("%s%s%s", tmp2,				(irc->whois.ircop ? _(" <i>(ircop)</i>") : ""),				(irc->whois.identified ? _(" <i>(identified)</i>") : ""));	purple_notify_user_info_add_pair(user_info, _("Nick"), tmp);	g_free(tmp2);	g_free(tmp);	if (irc->whois.away) {		tmp = g_markup_escape_text(irc->whois.away, strlen(irc->whois.away));		g_free(irc->whois.away);		purple_notify_user_info_add_pair(user_info, _("Away"), tmp);		g_free(tmp);	}	if (irc->whois.userhost) {		tmp = g_markup_escape_text(irc->whois.name, strlen(irc->whois.name));		g_free(irc->whois.name);		purple_notify_user_info_add_pair(user_info, _("Username"), irc->whois.userhost);		purple_notify_user_info_add_pair(user_info, _("Real name"), tmp);		g_free(irc->whois.userhost);		g_free(tmp);	}	if (irc->whois.server) {		tmp = g_strdup_printf("%s (%s)", irc->whois.server, irc->whois.serverinfo);		purple_notify_user_info_add_pair(user_info, _("Server"), tmp);		g_free(tmp);		g_free(irc->whois.server);		g_free(irc->whois.serverinfo);	}	if (irc->whois.channels) {		purple_notify_user_info_add_pair(user_info, _("Currently on"), irc->whois.channels);		g_free(irc->whois.channels);	}	if (irc->whois.idle) {		gchar *timex = purple_str_seconds_to_string(irc->whois.idle);		purple_notify_user_info_add_pair(user_info, _("Idle for"), timex);		g_free(timex);		purple_notify_user_info_add_pair(user_info,														_("Online since"), purple_date_format_full(localtime(&irc->whois.signon)));	}	if (!strcmp(irc->whois.nick, "Paco-Paco")) {		purple_notify_user_info_add_pair(user_info,																   _("<b>Defining adjective:</b>"), _("Glorious"));	}	gc = purple_account_get_connection(irc->account);	purple_notify_userinfo(gc, irc->whois.nick, user_info, NULL, NULL);	purple_notify_user_info_destroy(user_info);	g_free(irc->whois.nick);	memset(&irc->whois, 0, sizeof(irc->whois));}void irc_msg_list(struct irc_conn *irc, const char *name, const char *from, char **args){	if (!irc->roomlist)		return;	if (!strcmp(name, "321")) {		purple_roomlist_set_in_progress(irc->roomlist, TRUE);		return;	}	if (!strcmp(name, "323")) {		purple_roomlist_set_in_progress(irc->roomlist, FALSE);		purple_roomlist_unref(irc->roomlist);		irc->roomlist = NULL;		return;	}	if (!strcmp(name, "322")) {		PurpleRoomlistRoom *room;		char *topic;		if (!args[0] || !args[1] || !args[2] || !args[3])			return;		room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, args[1], NULL);		purple_roomlist_room_add_field(irc->roomlist, room, args[1]);		purple_roomlist_room_add_field(irc->roomlist, room, GINT_TO_POINTER(strtol(args[2], NULL, 10)));		topic = irc_mirc2txt(args[3]);		purple_roomlist_room_add_field(irc->roomlist, room, topic);		g_free(topic);		purple_roomlist_room_add(irc->roomlist, room);	}}void irc_msg_topic(struct irc_conn *irc, const char *name, const char *from, char **args){	char *chan, *topic, *msg, *nick, *tmp, *tmp2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -