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

📄 handle_irc.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 4 页
字号:
static int _handle_serial_command(t_connection * conn, int numparams, char ** params, char * text){    // Ignore command	return 0;}static int _handle_squadinfo_command(t_connection * conn, int numparams, char ** params, char * text){	// FIXME: Not implemented	return 0;}	    static int _handle_setopt_command(t_connection * conn, int numparams, char ** params, char * text){	// Ignore this command	return 0;}	    static int _handle_setcodepage_command(t_connection * conn, int numparams, char ** params, char * text){	char * codepage = NULL;		if((numparams>=1)&&params[0]) {	    codepage = params[0];	    conn_wol_set_codepage(conn,atoi(codepage));	}	irc_send(conn,RPL_SET_CODEPAGE,codepage);	return 0;}static int _handle_setlocale_command(t_connection * conn, int numparams, char ** params, char * text){	char * locale = NULL;		if((numparams>=1)&&params[0]) {	    locale = params[0];	    conn_wol_set_locale(conn,atoi(locale));	}	irc_send(conn,RPL_SET_LOCALE,locale);		return 0;}	    static int _handle_getcodepage_command(t_connection * conn, int numparams, char ** params, char * text){	char temp[MAX_IRC_MESSAGE_LEN];	char _temp[MAX_IRC_MESSAGE_LEN];		memset(temp,0,sizeof(temp));	memset(_temp,0,sizeof(_temp));	if((numparams>=1)) {	    int i;	    for (i=0; i<numparams; i++) {    		t_connection * user;            int codepage;    		char const * name;    		    		if((user = connlist_find_connection_by_accountname(params[i]))) {    		    codepage = conn_wol_get_codepage(user);    		    name = conn_get_chatname(user);        		    sprintf(_temp,"%s`%u",name,codepage);    		    strcat(temp,_temp);    		    if(i < numparams-1)    			     strcat(temp,"`");    		}	    }   	    irc_send(conn,RPL_GET_CODEPAGE,temp);		}	return 0;}static int _handle_getlocale_command(t_connection * conn, int numparams, char ** params, char * text){	char temp[MAX_IRC_MESSAGE_LEN];	char _temp[MAX_IRC_MESSAGE_LEN];		memset(temp,0,sizeof(temp));	memset(_temp,0,sizeof(_temp));	if((numparams>=1)) {	    int i;	    for (i=0; i<numparams; i++) {    		t_connection * user;    		int locale;    		char const * name;    		    		if((user = connlist_find_connection_by_accountname(params[i]))) {    		    locale = conn_wol_get_locale(user);    		    name = conn_get_chatname(user);        		    sprintf(_temp,"%s`%u",name,locale);    		    strcat(temp,_temp);    		    if(i < numparams-1)           			strcat(temp,"`");    		}	    }   	    irc_send(conn,RPL_GET_LOCALE,temp);		}	return 0;}	    static int _handle_joingame_command(t_connection * conn, int numparams, char ** params, char * text){	char _temp[MAX_IRC_MESSAGE_LEN];		memset(_temp,0,sizeof(_temp));	/**	*  Basically this has 2 modes, Join Game and Create Game output is pretty much	*  the same...input and output of JOINGAME is listed below. By the way, there is a	*  hack in here, for Red Alert 1, it use's JOINGAME for some reason to join a lobby channel.	*   	*   Here is the input expected:	*   JOINGAME #user's_game unknown numberOfPlayers gameType unknown unknown gameIsTournament unknown password	*	*   Heres the output expected:	*   user!WWOL@hostname JOINGAME unknown numberOfPlayers gameType unknown clanID longIP gameIsTournament :#game_channel_name	*/	if((numparams==2)) {	    char ** e;	    eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] JOINGAME: * Join * (%s, %s)",		     params[0],params[1]);	    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,":JOINGAME failed");			} 			else {				t_channel * channel;				char const * gameOptions;				int gameType;				conn_wol_set_ingame(conn,1);				channel = conn_get_channel(conn);				gameOptions = channel_wol_get_game_options(channel);				gameType = channel_wol_get_game_type(channel);								if (gameType == conn_wol_get_game_type(conn)) {				    eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] JOINGAME [Game Options] (%s) [Game Type] (%u) [Game Owner] (%s)",gameOptions,gameType,channel_wol_get_game_owner(channel));								    if (channel!=old_channel) {		    			char temp[MAX_IRC_MESSAGE_LEN];        					channel_set_userflags(conn);    					message_send_text(conn,message_wol_joingame,conn,gameOptions); /* we have to send the JOINGAME 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 {				    irc_send(conn,ERR_NOSUCHCHANNEL,":JOINGAME failed");				}			}			if (old_channel_name) xfree((void *)old_channel_name);		}    		if (e)		    irc_unget_listelems(e);    	    return 0;	}	/**	* HACK: Check for 3 params, because in that case we must be running RA1	* then just forward to _handle_join_command	*/	else if((numparams==3)) {	    _handle_join_command(conn,numparams,params,text);	}	else if((numparams>=8)) {	    char ** e;	    eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] JOINGAME: * Create * (%s, %s)",		     params[0],params[1]);		     	    sprintf(_temp,"%s %s %s %s 0 %u %s :%s",params[1],params[2],params[3],params[4],conn_get_addr(conn),params[6],params[0]);	    eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] JOINGAME [Game Options] (%s)",_temp);	    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,":JOINGAME failed"); /* FIXME: be more precise; what is the real error code for that? */			} 			else {				t_channel * channel;				channel = conn_get_channel(conn);				if (channel!=old_channel) {	    			char temp[MAX_IRC_MESSAGE_LEN];					char * topic;					channel_set_userflags(conn);					channel_wol_set_game_options(channel,_temp);					channel_wol_set_game_owner(channel,conn_get_chatname(conn));					channel_wol_set_game_ownerip(channel,conn_get_addr(conn));					channel_wol_set_game_type(channel,conn_wol_get_game_type(conn));					channel_wol_set_game_tournament(channel,atoi(params[6]));										message_send_text(conn,message_wol_joingame,conn,_temp); /* we have to send the JOINGAME 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);						}					}	    			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);					}	    		}			}			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 JOINGAME");	return 0;}	    static int _handle_gameopt_command(t_connection * conn, int numparams, char ** params, char * text){	char temp[MAX_IRC_MESSAGE_LEN]; 	/** 	*  Basically this has 2 modes, Game Owner Change and Game Joinee Change what the output 	*  on this does is pretty much unknown, we just dump this to the client to deal with... 	*    	*	Heres the output expected (from game owner): 	*	user!WWOL@hostname GAMEOPT #game_channel_name :gameOptions 	*    	*	Heres the output expected (from game joinee): 	*	user!WWOL@hostname GAMEOPT game_owner_name :gameOptions 	*/	if ((numparams>=1)&&(text)) {	    int i;	    char ** e;		    e = irc_get_listelems(params[0]);	    /* FIXME: support wildcards! */			    eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] GAMEOPT: (%s :%s)",params[0],text);	    conn_wol_set_game_options(conn,text);	    	    for (i=0;((e)&&(e[i]));i++) {    		if (e[i][0]=='#') {    		    /* game owner change */    		    t_channel * channel;        		    if ((channel = channellist_find_channel_by_name(irc_convert_ircname(params[0]),NULL,NULL))) {        			sprintf(temp,":%s",text);        			channel_message_send(channel,message_wol_gameopt_owner,conn,temp);    		    }    		    else {        			irc_send(conn,ERR_NOSUCHCHANNEL,":No such channel");    		    }    		}     		else    		{    		    /* user change */    		    t_connection * user;        		    if ((user = connlist_find_connection_by_accountname(e[i]))) {        			sprintf(temp,":%s",text);        			message_send_text(user,message_wol_gameopt_join,conn,temp);    		    }    		    else {          			irc_send(conn,ERR_NOSUCHNICK,":No such user");    		    }    		}	    }	}	else	    irc_send(conn,ERR_NEEDMOREPARAMS,":Too few arguments to GAMEOPT");	return 0;}	    static int _handle_finduserex_command(t_connection * conn, int numparams, char ** params, char * text){	char _temp[MAX_IRC_MESSAGE_LEN];	char const * ircname = NULL;		memset(_temp,0,sizeof(_temp));	if ((numparams>=1)) {	    t_connection * user;	    	    if((user = connlist_find_connection_by_accountname(params[0]))) {     		ircname = irc_convert_channel(conn_get_channel(user));	    }	    	    sprintf(_temp,"0 :%s,0",ircname);	    irc_send(conn,RPL_FIND_USER_EX,_temp);    }	return 0;}static int _handle_page_command(t_connection * conn, int numparams, char ** params, char * text){	char _temp[MAX_IRC_MESSAGE_LEN];		memset(_temp,0,sizeof(_temp));	if ((numparams>=1)&&(text)) {	    t_connection * user;	    	    sprintf(_temp,":%s",text);	    if((user = connlist_find_connection_by_accountname(params[0]))) {     		message_send_text(user,message_wol_page,conn,_temp);	    }	}	return 0;}	   static int _handle_startg_command(t_connection * conn, int numparams, char ** params, char * text){	char temp[MAX_IRC_MESSAGE_LEN];	char _temp_a[MAX_IRC_MESSAGE_LEN];	t_channel * channel;	time_t now; 	/** 	*  Heres the output expected (this can have up-to 8 entries (ie 8 players):     *  (we are assuming for this example that user1 is the game owner)    * 	*   user1!WWOL@hostname STARTG u :user1 xxx.xxx.xxx.xxx user2 xxx.xxx.xxx.xxx :gameNumber cTime 	*/	if((numparams>=1)) {	    int i;	    char ** e;		    memset(temp,0,sizeof(temp));	    memset(_temp_a,0,sizeof(_temp_a));			    e = irc_get_listelems(params[1]);	    /* FIXME: support wildcards! */			    strcat(temp,":");	    for (i=0;((e)&&(e[i]));i++) {    		t_connection * user;    		const char * addr = NULL;    		    		if((user = connlist_find_connection_by_accountname(e[i]))) {    		    addr = addr_num_to_ip_str(conn_get_addr(user));    		}    		sprintf(_temp_a,"%s %s ",e[i],addr);    		strcat(temp,_temp_a);	    }	            strcat(temp,":");        strcat(temp,"1337"); /* yes, ha ha funny, i just don't generate game numbers yet */        strcat(temp," ");                now = time(NULL);        strcat(temp,ctime(&now));	    	    eventlog(eventlog_level_debug,__FUNCTION__,"[** WOL **] STARTG: (%s)",temp);	    if ((channel = channellist_find_channel_by_name(irc_convert_ircname(params[0]),NULL,NULL))) {     		channel_message_send(channel,message_wol_start_game,conn,temp);	    }	    else {     		irc_send(conn,ERR_NOSUCHCHANNEL,":No such channel");	    }	}	       	return 0;}	    static int _handle_listsearch_command(t_connection * conn, int numparams, char ** params, char * text){	// FIXME: Not implemented	return 0;}

⌨️ 快捷键说明

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