Ejemplo n.º 1
0
		int output_standard_writer(std::FILE * fp)
		{
			t_elem const	*curr;
			t_connection	*conn;
			t_channel const	*channel;
			t_game *game;

			char const		*channel_name;
			int			number;
			char		clienttag_str[5];
			int uptime = server_get_uptime();


			if (prefs_get_XML_status_output())
			{
				int seconds;
				int minutes;
				int hours;
				int days;

				days = (uptime / (60 * 60 * 24));
				hours = (uptime / (60 * 60)) % 24;
				minutes = (uptime / 60) % 60;
				seconds = uptime % 60;

				std::fprintf(fp, "<?xml version=\"1.0\"?>\n<status>\n");
				std::fprintf(fp, "\t\t<Version>%s</Version>\n", PVPGN_VERSION);
				std::fprintf(fp, "\t\t<Uptime>\n");
				std::fprintf(fp, "\t\t\t<Days>%d</Days>\n", days);
				std::fprintf(fp, "\t\t\t<Hours>%d</Hours>\n", hours);
				std::fprintf(fp, "\t\t\t<Minutes>%d</Minutes>\n", minutes);
				std::fprintf(fp, "\t\t\t<Seconds>%d</Seconds>\n", seconds);
				std::fprintf(fp, "\t\t</Uptime>\n");
				std::fprintf(fp, "\t\t<Users>\n");
				std::fprintf(fp, "\t\t<Number>%d</Number>\n", connlist_login_get_length());

				LIST_TRAVERSE_CONST(connlist(), curr)
				{
					conn = (t_connection*)elem_get_data(curr);
					if (conn_get_account(conn))
						std::fprintf(fp, "\t\t<user><name>%s</name><clienttag>%s</clienttag><version>%s</version>", conn_get_username(conn), tag_uint_to_str(clienttag_str, conn_get_clienttag(conn)), conn_get_clientver(conn));

					if ((game = conn_get_game(conn)))
						std::fprintf(fp, "<gameid>%u</gameid>", game_get_id(game));
					std::fprintf(fp, "</user>\n");
				}

				std::fprintf(fp, "\t\t</Users>\n");
				std::fprintf(fp, "\t\t<Games>\n");
				std::fprintf(fp, "\t\t<Number>%d</Number>\n", gamelist_get_length());

				gamelist_traverse(_glist_cb_xml, fp);

				std::fprintf(fp, "\t\t</Games>\n");
				std::fprintf(fp, "\t\t<Channels>\n");
				std::fprintf(fp, "\t\t<Number>%d</Number>\n", channellist_get_length());

				LIST_TRAVERSE_CONST(channellist(), curr)
				{
					channel = (t_channel*)elem_get_data(curr);
					channel_name = channel_get_name(channel);
					std::fprintf(fp, "\t\t<channel>%s</channel>\n", channel_name);
				}
Ejemplo n.º 2
0
extern int tracker_send_report(t_addrlist const * laddrs)
{
    t_addr const *     addrl;
    t_elem const *     currl;
    t_addr const *     addrt;
    t_elem const *     currt;
    t_trackpacket      packet;
    struct utsname     utsbuf;
    struct sockaddr_in tempaddr;
    t_laddr_info *     laddr_info;
    char               tempa[64];
    char               tempb[64];

    if (addrlist_get_length(track_servers)>0)
    {
        std::memset(&packet,0,sizeof(packet));
	bn_short_nset(&packet.packet_version,(unsigned short)TRACK_VERSION);
	/* packet.port is set below */
	bn_int_nset(&packet.flags, 0);
	std::strncpy((char *)packet.server_location,
		prefs_get_location(),
		sizeof(packet.server_location));
	bn_byte_set(&packet.server_location[sizeof(packet.server_location)-1],'\0');
	std::strncpy((char *)packet.software,
		PVPGN_SOFTWARE,
		sizeof(packet.software));
	bn_byte_set(&packet.software[sizeof(packet.software)-1],'\0');
	std::strncpy((char *)packet.version,
		PVPGN_VERSION,
		sizeof(packet.version));
	bn_byte_set(&packet.version[sizeof(packet.version)-1],'\0');
	std::strncpy((char *)packet.server_desc,
		prefs_get_description(),
		sizeof(packet.server_desc));
	bn_byte_set(&packet.server_desc[sizeof(packet.server_desc)-1],'\0');
	std::strncpy((char *)packet.server_url,
		prefs_get_url(),
		sizeof(packet.server_url));
	bn_byte_set(&packet.server_url[sizeof(packet.server_url)-1],'\0');
	std::strncpy((char *)packet.contact_name,
		prefs_get_contact_name(),
		sizeof(packet.contact_name));
	bn_byte_set(&packet.contact_name[sizeof(packet.contact_name)-1],'\0');
	std::strncpy((char *)packet.contact_email,
		prefs_get_contact_email(),
		sizeof(packet.contact_email));
	bn_byte_set(&packet.contact_email[sizeof(packet.contact_email)-1],'\0');
	bn_int_nset(&packet.users,connlist_login_get_length());
	bn_int_nset(&packet.channels,channellist_get_length());
	bn_int_nset(&packet.games,gamelist_get_length());
	bn_int_nset(&packet.uptime,server_get_uptime());
	bn_int_nset(&packet.total_logins,connlist_total_logins());
	bn_int_nset(&packet.total_games,gamelist_total_games());

	if (uname(&utsbuf)<0)
	{
	    eventlog(eventlog_level_warn,__FUNCTION__,"could not get platform info (uname: %s)",pstrerror(errno));
	    std::strncpy((char *)packet.platform,"",sizeof(packet.platform));
	}
	else
	{
	    std::strncpy((char *)packet.platform,
		    utsbuf.sysname,
		    sizeof(packet.platform));
	    bn_byte_set(&packet.platform[sizeof(packet.platform)-1],'\0');
	}

	LIST_TRAVERSE_CONST(laddrs,currl)
	{
	    addrl = (t_addr*)elem_get_data(currl);

	    if (!(laddr_info = (t_laddr_info*)addr_get_data(addrl).p))
	    {
		eventlog(eventlog_level_error,__FUNCTION__,"address data is NULL");
		continue;
	    }
	    if (laddr_info->type!=laddr_type_bnet)
		continue; /* don't report IRC, telnet, and other non-game ports */

	    bn_short_nset(&packet.port,addr_get_port(addrl));

	    LIST_TRAVERSE_CONST(track_servers,currt)
	    {
		addrt = (t_addr*)elem_get_data(currt);

		std::memset(&tempaddr,0,sizeof(tempaddr));
		tempaddr.sin_family = PSOCK_AF_INET;
		tempaddr.sin_port = htons(addr_get_port(addrt));
		tempaddr.sin_addr.s_addr = htonl(addr_get_ip(addrt));

		if (!addr_get_addr_str(addrl,tempa,sizeof(tempa)))
		    std::strcpy(tempa,"x.x.x.x:x");
		if (!addr_get_addr_str(addrt,tempb,sizeof(tempb)))
		    std::strcpy(tempa,"x.x.x.x:x");
		/* eventlog(eventlog_level_debug,__FUNCTION__,"sending tracking info from %s to %s",tempa,tempb); */

		if (psock_sendto(laddr_info->usocket,&packet,sizeof(packet),0,(struct sockaddr *)&tempaddr,(psock_t_socklen)sizeof(tempaddr))<0)
		    eventlog(eventlog_level_warn,__FUNCTION__,"could not send tracking information from %s to %s (psock_sendto: %s)",tempa,tempb,pstrerror(errno));
	    }
Ejemplo n.º 3
0
extern char * message_format_line(t_connection const * c, char const * in)
{
    char *       out;
    unsigned int inpos;
    unsigned int outpos;
    unsigned int outlen=MAX_INC;
    
    if (!(out = malloc(outlen+1)))
	return NULL;
    
    out[0] = 'I';
    for (inpos=0,outpos=1; inpos<strlen(in); inpos++)
    {
        if (in[inpos]!='%')
	{
	    out[outpos] = in[inpos];
	    outpos += 1;
	}
        else
	    switch (in[++inpos])
	    {
	    case '%':
		out[outpos++] = '%';
		break;
		
	    case 'a':
		sprintf(&out[outpos],"%u",accountlist_get_length());
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'c':
		sprintf(&out[outpos],"%d",channellist_get_length());
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'g':
		sprintf(&out[outpos],"%d",gamelist_get_length());
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'h':
    		if (gethostname(&out[outpos],MAX_INC)<0)
    		{
		    eventlog(eventlog_level_error,"message_format_line","could not get hostname (gethostname: %s)",strerror(errno));
		    strcpy(&out[outpos],"localhost"); /* not much else you can do */
    		}
		outpos += strlen(&out[outpos]);
		break;

#ifndef ACCT_DYN_LOAD
           case 'i':
		sprintf(&out[outpos],UID_FORMAT,conn_get_userid(c));
		outpos += strlen(&out[outpos]);
		break;
#endif
		
	    case 'l':
	        {
		    char const * tname;
		    
		    strncpy(&out[outpos],(tname = conn_get_chatname(c)),MAX_USER_NAME-1);
		    conn_unget_chatname(c,tname);
		}
		out[outpos+MAX_USER_NAME-1] = '\0';
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'r':
		strncpy(&out[outpos],addr_num_to_ip_str(conn_get_addr(c)),MAX_INC-1);
		out[outpos+MAX_INC-1] = '\0';
		outpos += strlen(&out[outpos]);
		break;
		
	    case 't':
		sprintf(&out[outpos],"%s",conn_get_clienttag(c));
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'u':
		sprintf(&out[outpos],"%d",connlist_login_get_length());
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'v':
		strcpy(&out[outpos],BNETD_VERSION);
		outpos += strlen(&out[outpos]);
		break;
		
	    case 'C': /* simulated command */
		out[0] = 'C';
		break;
		
	    case 'B': /* BROADCAST */
		out[0] = 'B';
		break;
		
	    case 'E': /* ERROR */
		out[0] = 'E';
		break;
		
	    case 'I': /* INFO */
		out[0] = 'I';
		break;
		
	    case 'M': /* MESSAGE */
		out[0] = 'M';
		break;
		
	    case 'T': /* EMOTE */
		out[0] = 'T';
		break;
		
	    case 'W': /* INFO */
		out[0] = 'W';
		break;
		
	    default:
		eventlog(eventlog_level_warn,"message_format_line","bad formatter \"%%%c\"",in[inpos-1]);
	    }
	
	if ((outpos+MAX_INC)>=outlen)
	{
	    char * newout;
	    
	    outlen += MAX_INC;
	    if (!(newout = realloc(out,outlen)))
	    {
		free(out);
		return NULL;
	    }
	    out = newout;
	}
    }
    out[outpos] = '\0';
    
    return out;
}