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

📄 handle_irc.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 4 页
字号:
			irc_welcome(conn); /* only send the welcome if we have USER and NICK */	}	return 0;}static int _handle_user_command(t_connection * conn, int numparams, char ** params, char * text){	/* RFC 2812 says: */	/* <user> <mode> <unused> :<realname>*/	/* ircII and X-Chat say: */	/* mz SHODAN localhost :Marco Ziech */	/* BitchX says: */	/* mz +iws mz :Marco Ziech */	/* Don't bother with, params 1 and 2 anymore they don't contain what they should. */	char * user = NULL;	char * realname = NULL;	t_account * a;	if ((numparams>=3)&&(params[0])&&(text)) {	    user = params[0];	    realname = text;		if (conn_get_wol(conn) == 1) {			user = (char *)conn_get_loggeduser(conn);			realname = (char *)conn_get_loggeduser(conn);			        	if (conn_get_user(conn)) {		irc_send(conn,ERR_ALREADYREGISTRED,":You are already registred");        } 			else {				eventlog(eventlog_level_debug,__FUNCTION__,"[%d][** WOL **] got USER: user=\"%s\"",conn_get_socket(conn),user);                a = accountlist_find_account(user);                if (!a) {                   if((conn_get_wol(conn) == 1)) {                        t_account * tempacct;                        t_hash pass_hash;                        char * pass = "supersecret";                        int j;                        			for (j=0; j<strlen(pass); j++)            				if (isupper((int)pass[j])) pass[j] = tolower((int)pass[j]);                        			bnet_hash(&pass_hash,strlen(pass),pass);                        			tempacct = accountlist_create_account(user,hash_get_str(pass_hash));            			if (!tempacct) {                            return 0;            			}                   }                }			conn_set_user(conn,user);			conn_set_owner(conn,realname);			if (conn_get_loggeduser(conn))				irc_welcome(conn); /* only send the welcome if we have USER and NICK */	    	}    	} 		else {			if (conn_get_user(conn)) {				irc_send(conn,ERR_ALREADYREGISTRED,":You are already registred");			} 			else {				eventlog(eventlog_level_debug,__FUNCTION__,"[%d] got USER: user=\"%s\" realname=\"%s\"",conn_get_socket(conn),user,realname);				conn_set_user(conn,user);				conn_set_owner(conn,realname);				if (conn_get_loggeduser(conn))					irc_welcome(conn); /* only send the welcome if we have USER and NICK */    		}		}   	} 	else {	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to USER");    	}	return 0;}static int _handle_ping_command(t_connection * conn, int numparams, char ** params, char * text){	if((conn_get_wol(conn) == 1))	    return 0;	/* Dizzy: just ignore this because RFC says we should not reply client PINGs	 * NOTE: RFC2812 doesn't seem to be very expressive about this ... */	if (numparams)	    irc_send_pong(conn,params[0]);	else	    irc_send_pong(conn,text);	return 0;}static int _handle_pong_command(t_connection * conn, int numparams, char ** params, char * text){	if((conn_get_wol(conn) == 1))	    return 0;		/* NOTE: RFC2812 doesn't seem to be very expressive about this ... */	if (conn_get_ircping(conn)==0) {	    eventlog(eventlog_level_warn,__FUNCTION__,"[%d] PONG without PING",conn_get_socket(conn));	} 	else {	    unsigned int val = 0;	    char * sname;	    if (numparams>=1) {  	        val = strtoul(params[0],NULL,10);		sname = params[0];	    }	    else if (text) {	    	val = strtoul(text,NULL,10);		sname = text;	    }	    else {		val = 0;		sname = 0;	    }	    if (conn_get_ircping(conn) != val) {	    	if ((!(sname)) || (strcmp(sname,server_get_hostname())!=0)) {			/* Actually the servername should not be always accepted but we aren't that pedantic :) */			eventlog(eventlog_level_warn,__FUNCTION__,"[%d] got bad PONG (%u!=%u && %s!=%s)",conn_get_socket(conn),val,conn_get_ircping(conn),sname,server_get_hostname());			return -1;		}	    }	    conn_set_latency(conn,get_ticks()-conn_get_ircping(conn));	    eventlog(eventlog_level_debug,__FUNCTION__,"[%d] latency is now %d (%u-%u)",conn_get_socket(conn),get_ticks()-conn_get_ircping(conn),get_ticks(),conn_get_ircping(conn));	    conn_set_ircping(conn,0);	}	return 0;}static int _handle_pass_command(t_connection * conn, int numparams, char ** params, char * text){	if ((!conn_get_ircpass(conn))&&(conn_get_state(conn)==conn_state_bot_username)) {		t_hash h;	    if (numparams>=1) {			bnet_hash(&h,strlen(params[0]),params[0]);			conn_set_ircpass(conn,hash_get_str(h));	    } 		else			irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to PASS");    } 	else {	    eventlog(eventlog_level_warn,__FUNCTION__,"[%d] client tried to set password twice with PASS",conn_get_socket(conn));    }	return 0;}static int _handle_privmsg_command(t_connection * conn, int numparams, char ** params, char * text){	if ((numparams>=1)&&(text)) 	{	    int i;	    char ** e;		    e = irc_get_listelems(params[0]);	    /* FIXME: support wildcards! */				/* start amadeo: code was sent by some unkown fellow of pvpgn (maybe u wanna give us your name 		   for any credits), it adds nick-registration, i changed some things here and there... */	    for (i=0;((e)&&(e[i]));i++) {    		if (strcasecmp(e[i],"NICKSERV")==0) { 				char * pass;				char * p;			 				pass = strchr(text,' '); 				if (pass) 		    		*pass++ = '\0';				if (strcasecmp(text,"identify")==0) {				    switch (conn_get_state(conn)) {					case conn_state_bot_password:					{							if (pass) { 		    				t_hash h; 						for (p = pass; *p; p++)						    if (isupper((int)*p)) *p = tolower(*p); 		    				bnet_hash(&h,strlen(pass),pass); 		    				irc_authenticate(conn,hash_get_str(h)); 					    }							else {								irc_send_cmd(conn,"NOTICE",":Syntax: IDENTIFY <password> (max 16 characters)");					    }					    break;					}					case conn_state_loggedin:					{					    irc_send_cmd(conn,"NOTICE",":You don't need to IDENTIFY");					    break;					}					default: ;					    eventlog(eventlog_level_trace,__FUNCTION__,"got /msg in unexpected connection state (%s)",conn_state_get_str(conn_get_state(conn)));				    }				} 				else if (strcasecmp(text,"register")==0) {					unsigned int j;					t_hash       passhash;					t_account  * temp;					char         msgtemp[MAX_MESSAGE_LEN];					char       * username=(char *)conn_get_loggeduser(conn);																if (account_check_name(username)<0) {						message_send_text(conn,message_type_error,conn,"Account name contains invalid symbol!");						break;					}					if (!pass || pass[0]=='\0' || (strlen(pass)>16) ) {						message_send_text(conn,message_type_error,conn,":Syntax: REGISTER <password> (max 16 characters)");						break;					}											for (j=0; j<strlen(pass); j++)						if (isupper((int)pass[j])) pass[j] = tolower((int)pass[j]);						bnet_hash(&passhash,strlen(pass),pass);						sprintf(msgtemp,"Trying to create account \"%s\" with password \"%s\"",username,pass);					message_send_text(conn,message_type_info,conn,msgtemp);										temp = accountlist_create_account(username,hash_get_str(passhash));					if (!temp) {						message_send_text(conn,message_type_error,conn,"Failed to create account!");						eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" not created (failed)",conn_get_socket(conn),username);						conn_unget_chatname(conn,username);						break;					}					sprintf(msgtemp,"Account "UID_FORMAT" created.",account_get_uid(temp));					message_send_text(conn,message_type_info,conn,msgtemp);					eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" created",conn_get_socket(conn),username);					conn_unget_chatname(conn,username);				}				else {					char tmp[MAX_IRC_MESSAGE_LEN+1];					 					irc_send_cmd(conn,"NOTICE",":Invalid arguments for NICKSERV");					sprintf(tmp,":Unrecognized command \"%s\"",text);					irc_send_cmd(conn,"NOTICE",tmp); 				} 	        } 			else if (conn_get_state(conn)==conn_state_loggedin) {				if (e[i][0]=='#') {					/* channel message */					t_channel * channel;					if ((channel = channellist_find_channel_by_name(irc_convert_ircname(e[i]),NULL,NULL))) {						if ((strlen(text)>=9)&&(strncmp(text,"\001ACTION ",8)==0)&&(text[strlen(text)-1]=='\001')) { 							/* at least "\001ACTION \001" */							/* it's a CTCP ACTION message */							text = text + 8;							text[strlen(text)-1] = '\0';							channel_message_send(channel,message_type_emote,conn,text);						} 						else							channel_message_send(channel,message_type_talk,conn,text);					}					else {						irc_send(conn,ERR_NOSUCHCHANNEL,":No such channel");					}					    	    } 				else {					/* whisper */					t_connection * user;					if ((user = connlist_find_connection_by_accountname(e[i]))) 					{						message_send_text(user,message_type_whisper,conn,text);					}					else 					{						irc_send(conn,ERR_NOSUCHNICK,":No such user");					}	    	    }	        }	    }	    if (e)	         irc_unget_listelems(e);	} 	else	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to PRIVMSG");	return 0;}static int _handle_notice_command(t_connection * conn, int numparams, char ** params, char * text){	if ((numparams>=1)&&(text)) {	    int i;	    char ** e;		    e = irc_get_listelems(params[0]);	    /* FIXME: support wildcards! */			    for (i=0;((e)&&(e[i]));i++) {			if (conn_get_state(conn)==conn_state_loggedin) {				t_connection * user;				if ((user = connlist_find_connection_by_accountname(e[i]))) {					irc_send_cmd2(user,conn_get_loggeduser(conn),"NOTICE",conn_get_loggeduser(user),text);				}				else {					irc_send(conn,ERR_NOSUCHNICK,":No such user");				}	        	}	    	}	    	if (e)	        irc_unget_listelems(e);	} 	else	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to PRIVMSG");	return 0;}static int _handle_who_command(t_connection * conn, int numparams, char ** params, char * text){	if (numparams>=1) {	    int i;	    char ** e;	    e = irc_get_listelems(params[0]);	    for (i=0; ((e)&&(e[i]));i++) {	    	irc_who(conn,e[i]);	    }	    irc_send(conn,RPL_ENDOFWHO,":End of WHO list"); /* RFC2812 only requires this to be sent if a list of names was given. Undernet seems to always send it, so do we :) */        if (e)			irc_unget_listelems(e);	} 	else 	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to WHO");	return 0;}static int _handle_list_command(t_connection * conn, int numparams, char ** params, char * text){    char temp[MAX_IRC_MESSAGE_LEN];	irc_send(conn,RPL_LISTSTART,"Channel :Users  Name"); /* backward compatibility */	if((conn_get_wol(conn) == 1)) { 	    t_elem const * curr; 	    	    if(strcmp(params[0], "0") == 0) {			/* HACK: Currently, this is the best way to set the game type... */			conn_wol_set_game_type(conn,atoi(params[1]));			    			eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] LIST [Channel]");   	    LIST_TRAVERSE_CONST(channellist(),curr) 		{    	    		t_channel const * channel = elem_get_data(curr);	        	char const * tempname;	        	tempname = irc_convert_channel(channel);				if(strstr(tempname,"Lob") != NULL) {					eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] LIST [Channel: \"Lob\"] (%s)",tempname);					if (strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN)						sprintf(temp,"%s %u 0 388",tempname,channel_get_length(channel));   					else   						eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");					irc_send(conn,RPL_CHANNEL,temp);				}    		}	    }	    /**        *  18 = Tiberian Sun game channels, 21 = Red alert 1 channels, 		*  33 = Red alert 2 channels, 41 = Yuri's Revenge		*/	    else if((strcmp(params[0], "18") == 0) ||				(strcmp(params[0], "21") == 0) ||				(strcmp(params[0], "33") == 0) ||				(strcmp(params[0], "41"))) {    		eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] LIST [Game]");   			LIST_TRAVERSE_CONST(channellist(),curr) 			{    		    t_channel const * channel = elem_get_data(curr);			    t_connection * m;        	    char const * tempname;				char * topic = channel_get_topic(channel_get_name(channel));        	    tempname = irc_convert_channel(channel);				if(strstr(tempname,"_game") != NULL) {					m = channel_get_first(channel);					if(channel_wol_get_game_type(channel) == conn_wol_get_game_type(conn)) {						eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] List [Channel: \"_game\"] (%s)",tempname);						if (topic) {	    						eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] List [Channel: \"_game\"] %s %u 0 %u %u 0 %u 128::%s",tempname,										 channel_get_length(channel),channel_wol_get_game_type(channel),channel_wol_get_game_tournament(channel),										 channel_wol_get_game_ownerip(channel),topic);								/**								*  The layout of the game list entry is something like this:                                *								*   #game_channel_name users unknown gameType gameIsTournment unknown longIP 128::topic								*/	        		if (strlen(tempname)+1+20+1+1+strlen(topic)<MAX_IRC_MESSAGE_LEN)	    							sprintf(temp,"%s %u 0 %u %u 0 %u 128::%s",tempname,											channel_get_length(channel),channel_wol_get_game_type(channel),channel_wol_get_game_tournament(channel),											channel_wol_get_game_ownerip(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 0 %u %u 0 %u 128::",tempname,channel_get_length(channel),channel_wol_get_game_type(channel),											channel_wol_get_game_tournament(channel),channel_wol_get_game_ownerip(channel));			else

⌨️ 快捷键说明

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