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

📄 handle_irc.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 4 页
字号:
            							eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");						}					}					irc_send(conn,RPL_GAME_CHANNEL,temp);				}			}		}	        	irc_send(conn,RPL_LISTEND,":End of LIST command");    	return 0;	}	if (numparams==0) { 	    t_elem const * curr; 	       	    LIST_TRAVERSE_CONST(channellist(),curr) 			{    	    t_channel const * channel = elem_get_data(curr);	        char const * tempname;			char * topic = channel_get_topic(channel_get_name(channel));	        tempname = irc_convert_channel(channel);			/* FIXME: AARON: only list channels like in /channels command */			if (topic) {	        	if (strlen(tempname)+1+20+1+1+strlen(topic)<MAX_IRC_MESSAGE_LEN)		    		sprintf(temp,"%s %u :%s",tempname,channel_get_length(channel),topic);	        	else	            	eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");			}			else {	        	if (strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN)		    		sprintf(temp,"%s %u :",tempname,channel_get_length(channel));	        		else	            			eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");			}	        	irc_send(conn,RPL_LIST,temp);    	}    }	else if (numparams>=1) {        int i;        char ** e; 	e = irc_get_listelems(params[0]);		/* FIXME: support wildcards! */		for (i=0;((e)&&(e[i]));i++) {		t_channel const * channel;		char const * verytemp; /* another good example for creative naming conventions :) */	       	char const * tempname;		char * topic;				verytemp = irc_convert_ircname(e[i]);		if (!verytemp)			continue; /* something is wrong with the name ... */		channel = channellist_find_channel_by_name(verytemp,NULL,NULL);		if (!channel)			continue; /* channel doesn't exist */						topic = channel_get_topic(channel_get_name(channel));	       	tempname = irc_convert_channel(channel);					if (topic) {	       		if (strlen(tempname)+1+20+1+1+strlen(topic)<MAX_IRC_MESSAGE_LEN)	    			sprintf(temp,"%s %u :%s",tempname,channel_get_length(channel),topic);	       		else	       			eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");		}			else {	       		if (strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN)	    			sprintf(temp,"%s %u :",tempname,channel_get_length(channel));	       		else	       			eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");		}	       	irc_send(conn,RPL_LIST,temp);	}        if (e)		irc_unget_listelems(e);    }    irc_send(conn,RPL_LISTEND,":End of LIST command");	return 0;}static int _handle_topic_command(t_connection * conn, int numparams, char ** params, char * text){	char ** e = NULL;		if((conn_get_wol(conn) == 1)) {	    t_channel * channel = conn_get_channel(conn);	    channel_set_topic(channel_get_name(channel),text,NO_SAVE_TOPIC);	}	if (params!=NULL) e = irc_get_listelems(params[0]);	if ((e)&&(e[0])) {		t_channel *channel = conn_get_channel(conn);				if (channel) {				char * topic;			char temp[MAX_IRC_MESSAGE_LEN];			char const * ircname = irc_convert_ircname(e[0]);			if ((ircname) && (strcasecmp(channel_get_name(channel),ircname)==0)) {				if ((topic = channel_get_topic(channel_get_name(channel)))) { 			  		sprintf(temp,"%s :%s",ircname,topic);			    		irc_send(conn,RPL_TOPIC,temp);				}				else			    		irc_send(conn,RPL_NOTOPIC,":No topic is set");			}			else				irc_send(conn,ERR_NOTONCHANNEL,":You are not on that channel");		}		else {			irc_send(conn,ERR_NOTONCHANNEL,":You're not on a channel");		}		irc_unget_listelems(e);	}	else		irc_send(conn,ERR_NEEDMOREPARAMS,":too few arguments to TOPIC");	return 0;}static int _handle_join_command(t_connection * conn, int numparams, char ** params, char * text){	if (numparams>=1) {	    char ** e;	    e = irc_get_listelems(params[0]);	    if ((e)&&(e[0])) {	    		char const * ircname = irc_convert_ircname(e[0]);	    		char * old_channel_name = NULL;	   	 	t_channel * old_channel = conn_get_channel(conn);			if (old_channel)			  old_channel_name = xstrdup(irc_convert_channel(old_channel));						if ((!(ircname)) || (conn_set_channel(conn,ircname)<0)) {				irc_send(conn,ERR_NOSUCHCHANNEL,":JOIN failed"); /* FIXME: be more precise; what is the real error code for that? */			} 			else {    			char temp[MAX_IRC_MESSAGE_LEN];				t_channel * channel;				channel = conn_get_channel(conn);			    if ((conn_get_wol(conn) == 1)) {					channel_set_userflags(conn);					message_send_text(conn,message_type_join,conn,NULL); /* we have to send the JOIN acknowledgement */					ircname=irc_convert_channel(channel);	    				irc_send_rpl_namreply(conn,channel);					if ((strlen(ircname)+1+strlen(":End of NAMES list")+1)<MAX_IRC_MESSAGE_LEN) {						sprintf(temp,"%s :End of NAMES list",ircname);						irc_send(conn,RPL_ENDOFNAMES,temp);					}			    }			    else {			    					if (channel!=old_channel) {					char * topic;					channel_set_userflags(conn);					message_send_text(conn,message_type_join,conn,NULL); /* we have to send the JOIN acknowledgement */					ircname=irc_convert_channel(channel);						if ((topic = channel_get_topic(channel_get_name(channel)))) {							if ((strlen(ircname)+1+1+strlen(topic)+1)<MAX_IRC_MESSAGE_LEN) {							sprintf(temp,"%s :%s",ircname,topic);							irc_send(conn,RPL_TOPIC,temp);						}							if ((strlen(ircname)+1+strlen("FIXME 0")+1)<MAX_IRC_MESSAGE_LEN) {							sprintf(temp,"%s FIXME 0",ircname);							irc_send(conn,RPL_TOPICWHOTIME,temp); /* FIXME: this in an undernet extension but other servers support it too */						}					}					else						irc_send(conn,RPL_NOTOPIC,":No topic is set");					irc_send_rpl_namreply(conn,channel);					irc_send(conn,RPL_ENDOFNAMES,":End of NAMES list");						if (old_channel_name) {						irc_send_cmd2(conn,conn_get_loggeduser(conn),"PART",old_channel_name,"only one channel at once");					}		    		}			}			}			if (old_channel_name) xfree((void *)old_channel_name);		}    		if (e)			irc_unget_listelems(e);	} 	else 	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to JOIN");	return 0;}static int _handle_names_command(t_connection * conn, int numparams, char ** params, char * text){	t_channel * channel;          if (numparams>=1) {		char ** e;		char const * ircname;		char const * verytemp;		char temp[MAX_IRC_MESSAGE_LEN];		int i;		e = irc_get_listelems(params[0]);		for (i=0;((e)&&(e[i]));i++) {						verytemp = irc_convert_ircname(e[i]);						if (!verytemp)				continue; /* something is wrong with the name ... */			channel = channellist_find_channel_by_name(verytemp,NULL,NULL);			if (!channel)				continue; /* channel doesn't exist */			irc_send_rpl_namreply(conn,channel);			ircname=irc_convert_channel(channel);			if ((strlen(ircname)+1+strlen(":End of NAMES list")+1)<MAX_IRC_MESSAGE_LEN) {				sprintf(temp,"%s :End of NAMES list",ircname);				irc_send(conn,RPL_ENDOFNAMES,temp);			} 			else 				irc_send(conn,RPL_ENDOFNAMES,":End of NAMES list");		}		if (e)		irc_unget_listelems(e);    } 	else if (numparams==0) {		t_elem const * curr;		LIST_TRAVERSE_CONST(channellist(),curr) 		{			channel = elem_get_data(curr);			irc_send_rpl_namreply(conn,channel);		}		irc_send(conn,RPL_ENDOFNAMES,"* :End of NAMES list");		    }	return 0;}static int _handle_mode_command(t_connection * conn, int numparams, char ** params, char * text){	/* FIXME: Not yet implemented */	return 0;}static int _handle_userhost_command(t_connection * conn, int numparams, char ** params, char * text){	/* FIXME: Send RPL_USERHOST */	return 0;}static int _handle_quit_command(t_connection * conn, int numparams, char ** params, char * text){	conn_set_channel(conn, NULL);	conn_set_state(conn, conn_state_destroy);	return 0;}static int _handle_ison_command(t_connection * conn, int numparams, char ** params, char * text){	char temp[MAX_IRC_MESSAGE_LEN];	char first = 1;		if (numparams>=1) {	    int i;	    temp[0]='\0';	    for (i=0; (i<numparams && (params) && (params[i]));i++) {    	  if (connlist_find_connection_by_accountname(params[i])) {		    if (first)		        strcat(temp,":");		    else 		        strcat(temp," ");		    strcat(temp,params[i]);		    first = 0;		  }	    }	    irc_send(conn,RPL_ISON,temp);	} 	else 	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to ISON");	return 0;}static int _handle_whois_command(t_connection * conn, int numparams, char ** params, char * text){	char temp[MAX_IRC_MESSAGE_LEN];	char temp2[MAX_IRC_MESSAGE_LEN];	if (numparams>=1) {	    int i;	    char ** e;	    t_connection * c;	    t_channel * chan;	    temp[0]='\0';	    temp2[0]='\0';	    e = irc_get_listelems(params[0]);	    for (i=0; ((e)&&(e[i]));i++) {    	  if ((c = connlist_find_connection_by_accountname(e[i]))) {		    if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(conn)) & command_get_group("/admin-addr")))		      sprintf(temp,"%s %s hidden * :%s",e[i],clienttag_uint_to_str(conn_get_clienttag(c)),"PvPGN user");		    else		      sprintf(temp,"%s %s %s * :%s",e[i],clienttag_uint_to_str(conn_get_clienttag(c)),addr_num_to_ip_str(conn_get_addr(c)),"PvPGN user");		    irc_send(conn,RPL_WHOISUSER,temp);		    		    if ((chan=conn_get_channel(conn))) {			char flg;			unsigned int flags;						flags = conn_get_flags(c);				            	if (flags & MF_BLIZZARD)		            flg='@';	            	else if ((flags & MF_BNET) || (flags & MF_GAVEL))		            flg='%'; 	            	else if (flags & MF_VOICE)		            flg='+';		        else flg = ' ';			sprintf(temp2,"%s :%c%s",e[i],flg,irc_convert_channel(chan));			irc_send(conn,RPL_WHOISCHANNELS,temp2);		    }		    		  }		  else		    irc_send(conn,ERR_NOSUCHNICK,":No such nick/channel");		  	    }	    irc_send(conn,RPL_ENDOFWHOIS,":End of /WHOIS list");        if (e)			irc_unget_listelems(e);	} 	else 	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to WHOIS");	return 0;}static int _handle_part_command(t_connection * conn, int numparams, char ** params, char * text){    if ((conn_get_wol(conn) == 1))		if ((conn_wol_get_ingame(conn) == 1))			conn_wol_set_ingame(conn,0);    message_send_text(conn,message_type_part,conn,NULL);    return 0;}    /***  Westwood Online Extensions*/static int _handle_cvers_command(t_connection * conn, int numparams, char ** params, char * text){	// Ignore command	return 0;}static int _handle_verchk_command(t_connection * conn, int numparams, char ** params, char * text){	// Ignore command	return 0; }static int _handle_lobcount_command(t_connection * conn, int numparams, char ** params, char * text){    // Ignore command but, return 1		irc_send(conn,RPL_LOBCOUNT,"1");	return 0;}static int _handle_whereto_command(t_connection * conn, int numparams, char ** params, char * text){	// Ignore command, but output proper server information...	char temp[MAX_IRC_MESSAGE_LEN];	// Casted to avoid warnings	const char * ircip = addr_num_to_ip_str(conn_get_real_local_addr(conn));	const char * ircname = prefs_get_servername();	const char * irctimezone = prefs_get_wol_timezone();	const char * irclong = prefs_get_wol_longitude();	const char * irclat = prefs_get_wol_latitude();	sprintf(temp,":%s %d '0:%s' %s %s %s",ircip,BNETD_WOL_PORT,ircname,irctimezone,irclong,irclat);	irc_send(conn,RPL_IRCSERV,temp);	sprintf(temp,":%s %d 'Live chat server' %s %s %s",ircip,BNETD_IRC_PORT,irctimezone,irclong,irclat);	irc_send(conn,RPL_IRCSERV,temp);	sprintf(temp,":%s %d 'Gameres server' %s %s %s",ircip,BNETD_WOL_PORT,irctimezone,irclong,irclat);	irc_send(conn,RPL_GAMERESSERV,temp);	sprintf(temp,":%s %d 'Ladder server' %s %s %s",ircip,BNETD_WOL_PORT,irctimezone,irclong,irclat);	irc_send(conn,RPL_LADDERSERV,temp);	irc_send(conn,RPL_ENDSERVLIST,"");	return 0;}static int _handle_apgar_command(t_connection * conn, int numparams, char ** params, char * text){	char * apgar = NULL;		if((numparams>=1)&&params[0]) {	    apgar = params[0];	    conn_wol_set_apgar(conn,apgar);	}		return 0;}

⌨️ 快捷键说明

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