コード例 #1
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 Names"); /* backward compatibility */

    if (numparams==0) {
        t_elem const * curr;

        LIST_TRAVERSE_CONST(channellist(),curr)
        {
            t_channel const * channel = (const t_channel*)elem_get_data(curr);
            char const * tempname;
            char * topic = channel_get_topic(channel_get_name(channel));

            tempname = irc_convert_channel(channel,conn);

            /* FIXME: AARON: only list channels like in /channels command */
            if (topic) {
                if (std::strlen(tempname)+1+20+1+1+std::strlen(topic)<MAX_IRC_MESSAGE_LEN)
                    snprintf(temp, sizeof(temp), "%s %u :%s",tempname,channel_get_length(channel),topic);
                else
                    eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");
            }
            else {
                if (std::strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN)
                    snprintf(temp, sizeof(temp), "%s %u :",tempname,channel_get_length(channel));
                else
                    eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");
            }
            irc_send(conn,RPL_LIST,temp);
        }
コード例 #2
0
ファイル: irc.c プロジェクト: 91D2/pvpgn
static int irc_who_connection(t_connection * dest, t_connection * c)
{
    t_account * a;
    char const * tempuser;
    char const * tempowner;
    char const * tempname;
    char const * tempip;
    char const * tempflags = "@"; /* FIXME: that's dumb */
    char temp[MAX_IRC_MESSAGE_LEN];
    char const * tempchannel;
    
    if (!dest) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL destination");
	return -1;
    }
    if (!c) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    a = conn_get_account(c);
    if (!(tempuser = clienttag_uint_to_str(conn_get_clienttag(c))))
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL clienttag (tempuser)");
	return -1;
    }
    if (!(tempowner = account_get_ll_owner(a)))
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ll_owner (tempowner)");
	return -1;
    }
    if (!(tempname = conn_get_username(c)))
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL username (tempname)");
	return -1;
    }
    if (!(tempip = addr_num_to_ip_str(conn_get_addr(c))))
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL addr (tempip)");
	return -1;
    }
    if (!(tempchannel = irc_convert_channel(conn_get_channel(c))))
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel (tempchannel)");
	return -1;
    }
    if ((strlen(tempchannel)+1+strlen(tempuser)+1+strlen(tempip)+1+strlen(server_get_hostname())+1+strlen(tempname)+1+1+strlen(tempflags)+4+strlen(tempowner)+1)>MAX_IRC_MESSAGE_LEN) {
	eventlog(eventlog_level_info,__FUNCTION__,"WHO reply too long - skip");
	return -1;
    } else
        sprintf(temp,"%s %s %s %s %s %c%s :0 %s",tempchannel,tempuser,tempip,server_get_hostname(),tempname,'H',tempflags,tempowner);
    irc_send(dest,RPL_WHOREPLY,temp);
    return 0;
}
コード例 #3
0
ファイル: irc.c プロジェクト: 91D2/pvpgn
extern int irc_send_rpl_namreply(t_connection * c, t_channel const * channel)
{
    char temp[MAX_IRC_MESSAGE_LEN];
    char const * ircname;
    int first = 1;
    t_connection * m;

    if (!c) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    if (!channel) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel");
	return -1;
    }
    memset(temp,0,sizeof(temp));
    ircname = irc_convert_channel(channel);
    if (!ircname) {
	eventlog(eventlog_level_error,__FUNCTION__,"channel has NULL ircname");
	return -1;
    }
    /* '@' = secret; '*' = private; '=' = public */
    if ((1+1+strlen(ircname)+2+1)<=MAX_IRC_MESSAGE_LEN) {
	sprintf(temp,"%c %s :",((channel_get_permanent(channel))?('='):('*')),ircname);
    } else {
	eventlog(eventlog_level_warn,__FUNCTION__,"maximum message length exceeded");
	return -1;
    }
    /* FIXME: Add per user flags (@(op) and +(voice))*/
    for (m = channel_get_first(channel);m;m = channel_get_next()) {
	char const * name = conn_get_chatname(m);
	char flg[5] = "";
	unsigned int flags;
	
	if (!name)
	    continue;
	flags = conn_get_flags(m);
	if (flags & MF_BLIZZARD)
		strcat(flg,"@");
	else if ((flags & MF_BNET) || (flags & MF_GAVEL))
		strcat(flg,"%"); 
	else if (flags & MF_VOICE)
		strcat(flg,"+"); 
	if ((strlen(temp)+((!first)?(1):(0))+strlen(flg)+strlen(name)+1)<=sizeof(temp)) {
	    if (!first) strcat(temp," ");

    	    if((conn_get_wol(c) == 1))
    	    {
                if ((channel_wol_get_game_owner(channel) != NULL) && (strcmp(channel_wol_get_game_owner(channel),name) == 0)) {
                            strcat(temp,"@");
                    }
                sprintf(temp,"%s%s,0,%u",temp,name,conn_get_addr(m));
    	    }
    	    else
    	    {
	    strcat(temp,flg);
	    strcat(temp,name);
    	    }

	    first = 0;
	}
	conn_unget_chatname(m,name);
    } 
    irc_send(c,RPL_NAMREPLY,temp);
    return 0;
}
コード例 #4
0
ファイル: irc.c プロジェクト: 91D2/pvpgn
extern int irc_message_format(t_packet * packet, t_message_type type, t_connection * me, t_connection * dst, char const * text, unsigned int dstflags)
{
    char * msg;
    char const * ctag;
    t_irc_message_from from;
    
    if (!packet)
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL packet");
	return -1;
    }

    msg = NULL;
    if (me)
        ctag = clienttag_uint_to_str(conn_get_clienttag(me));
    else
	    ctag = clienttag_uint_to_str(CLIENTTAG_IIRC_UINT);
        
    switch (type)
    {
    /* case message_type_adduser: this is sent manually in handle_irc */
	case message_type_adduser:
		/* when we do it somewhere else, then we can also make sure to not get our logs spammed */
		break;
    case message_type_join:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));

	    if((conn_get_wol(me) == 1))
	    {
        	char temp[MAX_IRC_MESSAGE_LEN];
    		memset(temp,0,sizeof(temp));
    		
    		/**
            *  For WOL the channel JOIN output must be like the following:
    		*   user!WWOL@hostname JOIN :clanID,longIP channelName
    		*/
    		sprintf(temp,":0,%u",conn_get_addr(me));
    		msg = irc_message_preformat(&from,"JOIN",temp,irc_convert_channel(conn_get_channel(me)));
	    }
	    else
    	msg = irc_message_preformat(&from,"JOIN","\r",irc_convert_channel(conn_get_channel(me)));
    	conn_unget_chatname(me,from.nick);
    	break;
    case message_type_part:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));
    	msg = irc_message_preformat(&from,"PART","\r",irc_convert_channel(conn_get_channel(me)));
    	conn_unget_chatname(me,from.nick);
    	break;
    case message_type_talk:
    case message_type_whisper:
    	{
    	    char const * dest;
	    char temp[MAX_IRC_MESSAGE_LEN];

	    if (me)
	    {
    	        from.nick = conn_get_chatname(me);
    	        from.host = addr_num_to_ip_str(conn_get_addr(me));
	    }
	    else
	    {
		from.nick = server_get_hostname();
		from.host = server_get_hostname();
	    }
	    
            from.user = ctag;
	    
    	    if (type==message_type_talk)
    	    	dest = irc_convert_channel(conn_get_channel(me)); /* FIXME: support more channels and choose right one! */
	    else
	        dest = ""; /* will be replaced with username in postformat */
	    sprintf(temp,":%s",text);
    	    msg = irc_message_preformat(&from,"PRIVMSG",dest,temp);
	    if (me)
    	        conn_unget_chatname(me,from.nick);
    	}
        break;
    case message_type_emote:
    	{
    	    char const * dest;
	    char temp[MAX_IRC_MESSAGE_LEN];

    	    /* "\001ACTION " + text + "\001" + \0 */
	    if ((8+strlen(text)+1+1)<=MAX_IRC_MESSAGE_LEN) {
		sprintf(temp,":\001ACTION %s\001",text);
	    } else {
		sprintf(temp,":\001ACTION (maximum message length exceeded)\001");
	    }
    	    from.nick = conn_get_chatname(me);
            from.user = ctag;
    	    from.host = addr_num_to_ip_str(conn_get_addr(me));
    	    /* FIXME: also supports whisper emotes? */
    	    dest = irc_convert_channel(conn_get_channel(me)); /* FIXME: support more channels and choose right one! */
	    msg = irc_message_preformat(&from,"PRIVMSG",dest,temp);
    	    conn_unget_chatname(me,from.nick);
    	}
        break;
    case message_type_broadcast:
    case message_type_info:
    case message_type_error:
	{
	    char temp[MAX_IRC_MESSAGE_LEN];
	    sprintf(temp,":%s",text);
	    msg = irc_message_preformat(NULL,"NOTICE",NULL,temp);
	}
	break;
    case message_type_channel:
    	/* ignore it */
	break;
    case message_type_mode:
	from.nick = conn_get_chatname(me);
	from.user = ctag;
	from.host = addr_num_to_ip_str(conn_get_addr(me));
	msg = irc_message_preformat(&from,"MODE","\r",text);
	conn_unget_chatname(me,from.nick);
	break;
   	/**
   	*  Westwood Online Extensions
   	*/
    case message_wol_joingame:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));
    	msg = irc_message_preformat(&from,"JOINGAME",text,"\r");
    	conn_unget_chatname(me,from.nick);
    	break;
    case message_wol_gameopt_owner:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));
    	msg = irc_message_preformat(&from,"GAMEOPT",irc_convert_channel(conn_get_channel(me)),text);
    	conn_unget_chatname(me,from.nick);
    	break;
    case message_wol_gameopt_join:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));
    	msg = irc_message_preformat(&from,"GAMEOPT",channel_wol_get_game_owner(conn_get_channel(me)),text);
    	conn_unget_chatname(me,from.nick);
    	break;
    case message_wol_start_game:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));
    	msg = irc_message_preformat(&from,"STARTG","u",text);
    	conn_unget_chatname(me,from.nick);
    	break;
    case message_wol_page:
    	from.nick = conn_get_chatname(me);
    	from.user = ctag;
    	from.host = addr_num_to_ip_str(conn_get_addr(me));
    	msg = irc_message_preformat(&from,"PAGE","u",text);
    	conn_unget_chatname(me,from.nick);
    	break;
    default:
    	eventlog(eventlog_level_warn,__FUNCTION__,"%d not yet implemented",type);
	return -1;
    }

    if (msg) {
	packet_append_string(packet,msg);
	xfree(msg);
        return 0;
    }
    return -1;
}