Exemple #1
0
Fichier : irc.c Projet : 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;
}
Exemple #2
0
static void mail_func_send(t_connection * c, const char * str) {
   int i;
   char *dest;
   char const *p,*myname;   
   t_account * recv;
   t_mailbox * mailbox;
   
   if (c==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
      return;
   }
   if (str==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL command string");
      return;
   }
   for(i=0;str[i]==' ';i++); /* skip any spaces */
   if (str[i]=='\0') { /* the %mail send command has no receiver */
      message_send_text(c,message_type_error,c,"You must specify the receiver");
      message_send_text(c,message_type_error,c,"Syntax: /mail send <receiver> <message>");
      return;
   }
   p=str+i; /* set ip at the start of receiver string */
   for(i=1;p[i]!=' ' && p[i]!='\0';i++); /* skip the receiver string */
   if (p[i]=='\0') { /* it seems user forgot to write any message */
      message_send_text(c,message_type_error,c,"Your message is empty!");
      message_send_text(c,message_type_error,c,"Syntax: /mail send <receiver> <message>");
      return;
   }
   dest=xmalloc(i+1);
   memmove(dest,p,i); dest[i]='\0'; /* copy receiver in his separate string */
   if ((recv=accountlist_find_account(dest))==NULL) { /* is dest a valid account on this server ? */
      message_send_text(c,message_type_error,c,"Receiver UNKNOWN!");
      xfree(dest);
      return;
   }
   xfree(dest); /* free dest here, the sooner the better */
   if ((mailbox=mailbox_open(recv, mbox_mode_write))==NULL) {
      message_send_text(c,message_type_error,c,"There was an error completing your request!");
      return;
   }
   if (get_mail_quota(recv)<=mailbox_count(mailbox)) { /* check quota */
      message_send_text(c,message_type_error,c,"Receiver has reached his mail quota. Your message will NOT be sent.");
      mailbox_close(mailbox);
      return;
   }
   myname=conn_get_username(c); /* who am i ? */
   if (mailbox_deliver(mailbox,myname,p+i+1)<0)
     message_send_text(c,message_type_error,c,"There was an error completing your request!");
   else 
     message_send_text(c,message_type_info,c,"Your mail has been sent successfully.");
   mailbox_close(mailbox);
}
Exemple #3
0
		static void mail_func_send(t_connection * c, std::istream& istr)
		{
			if (!c) {
				ERROR0("got NULL connection");
				return;
			}

			std::string dest;
			istr >> dest;
			if (dest.empty()) {
				message_send_text(c, message_type_error, c, "You must specify the receiver");
				message_send_text(c, message_type_error, c, "Syntax: /mail send <receiver> <message>");
				return;
			}

			std::string message;
			std::getline(istr, message);
			std::string::size_type pos(message.find_first_not_of(" \t"));
			if (pos == std::string::npos) {
				message_send_text(c, message_type_error, c, "Your message is empty!");
				message_send_text(c, message_type_error, c, "Syntax: /mail send <receiver> <message>");
				return;
			}

			t_account * recv = accountlist_find_account(dest.c_str());
			if (!recv) {
				message_send_text(c, message_type_error, c, "Receiver UNKNOWN!");
				return;
			}

			Mailbox mbox(account_get_uid(recv));
			if (get_mail_quota(recv) <= mbox.size()) {
				message_send_text(c, message_type_error, c, "Receiver has reached his mail quota. Your message will NOT be sent.");
				return;
			}

			try {
				mbox.deliver(conn_get_username(c), message.substr(pos));
				message_send_text(c, message_type_info, c, "Your mail has been sent successfully.");
			}
			catch (const Mailbox::DeliverError&) {
				message_send_text(c, message_type_error, c, "There was an error completing your request!");
			}
		}
		/* Choose icon by user from profile > portrait */
		static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet)
		{
			//BlacKDicK 04/20/2003
			// Modified by aancw 16/12/2014
			unsigned int desired_icon;
			char user_icon[5];
			t_account * account;

			// disable with custom icons
			if (prefs_get_custom_icons() == 1)
			{
				return 0;
			}

			/*FIXME: In this case we do not get a 'count' but insted of it we get the icon
			that the client wants to set.'W3H2' for an example. For now it is ok, since they share
			the same position	on the packet*/
			desired_icon = bn_int_get(packet->u.client_findanongame.count);
			//user_icon[4]=0;
			if (desired_icon == 0){
				std::strcpy(user_icon, "1O3W"); // 103W is equal to Default Icon
				eventlog(eventlog_level_info, __FUNCTION__, "[%d] Set icon packet to DEFAULT ICON [%4.4s]", conn_get_socket(c), user_icon);
			}
			else{
				std::memcpy(user_icon, &desired_icon, 4);
				eventlog(eventlog_level_info, __FUNCTION__, "[%d] Set icon packet to ICON [%s]", conn_get_socket(c), user_icon);
			}

			account = conn_get_account(c);
			
			// ICON SWITCH HACK PROTECTION
			if (check_user_icon(account, user_icon) == 0)
			{
				std::strcpy(user_icon, "1O3W"); // set icon to default
				eventlog(eventlog_level_info, __FUNCTION__, "[%s] \"%s\" ICON SWITCH hack attempt, icon set to default ", conn_get_username(c), user_icon);
				//conn_set_state(c,conn_state_destroy); // dont kill user session
			}

			account_set_user_icon(conn_get_account(c), conn_get_clienttag(c), user_icon);
			//FIXME: Still need a way to 'refresh the user/channel'
			//_handle_rejoin_command(conn_get_account(c),"");
			/* ??? channel_update_userflags() */
			conn_update_w3_playerinfo(c);

			channel_rejoin(c);
			return 0;
		}
Exemple #5
0
static int on_d2cs_accountloginreq(t_connection * c, t_packet const * packet)
{
	unsigned int	sessionkey;
	unsigned int	sessionnum;
	unsigned int	salt;
	char const *	account;
	char const *	tname;
	t_connection	* client;
	int		reply;
	t_packet	* rpacket;
	struct
	{
		bn_int   salt;
		bn_int   sessionkey;
		bn_int   sessionnum;
		bn_int   secret;
		bn_int	 passhash[5];
	} temp;
	t_hash       secret_hash;
	char const * pass_str;
	t_hash	     passhash;
	t_hash	     try_hash;

	if (packet_get_size(packet)<sizeof(t_d2cs_bnetd_accountloginreq)) {
		eventlog(eventlog_level_error,"on_d2cs_accountloginreq","got bad packet size");
		return -1;
	}
	if (!(account=packet_get_str_const(packet,sizeof(t_d2cs_bnetd_accountloginreq),USER_NAME_MAX))) {
		eventlog(eventlog_level_error,"on_d2cs_accountloginreq","got bad account name");
		return -1;
	}
	sessionkey=bn_int_get(packet->u.d2cs_bnetd_accountloginreq.sessionkey);
	sessionnum=bn_int_get(packet->u.d2cs_bnetd_accountloginreq.sessionnum);
	salt=bn_int_get(packet->u.d2cs_bnetd_accountloginreq.seqno);
	if (!(client=connlist_find_connection_by_sessionnum(sessionnum))) {
		eventlog(eventlog_level_error,"on_d2cs_accountloginreq","sessionnum %d not found",sessionnum);
		reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED;
	} else if (sessionkey!=conn_get_sessionkey(client)) {
		eventlog(eventlog_level_error,"on_d2cs_accountloginreq","sessionkey %d not match",sessionkey);
		reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED;
	} else if (!(tname=conn_get_username(client))) {
		eventlog(eventlog_level_error,"on_d2cs_accountloginreq","got NULL username");
		reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED;
	} else if (strcasecmp(account,tname)) {
		eventlog(eventlog_level_error,"on_d2cs_accountloginreq","username %s not match",account);
		conn_unget_username(client,tname);
		reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED;
	} else {
		conn_unget_username(client,tname);
		bn_int_set(&temp.salt,salt);
		bn_int_set(&temp.sessionkey,sessionkey);
		bn_int_set(&temp.sessionnum,sessionnum);
		bn_int_set(&temp.secret,conn_get_secret(client));
		pass_str=account_get_pass(conn_get_account(client));
		if (hash_set_str(&passhash,pass_str)<0) {
			reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED;
		} else {
			hash_to_bnhash((t_hash const *)&passhash,temp.passhash);
			bnet_hash(&secret_hash,sizeof(temp),&temp);
			bnhash_to_hash(packet->u.d2cs_bnetd_accountloginreq.secret_hash,&try_hash);
			if (hash_eq(try_hash,secret_hash)==1) {
				eventlog(eventlog_level_debug,"on_d2cs_accountloginreq","user %s loggedin on d2cs",\
					account);
				reply=BNETD_D2CS_ACCOUNTLOGINREPLY_SUCCEED;
			} else {
				eventlog(eventlog_level_error,"on_d2cs_accountloginreq","user %s hash not match",\
					account);
				reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED;
			}
		}
		account_unget_pass(pass_str);
	}
	if ((rpacket=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(rpacket,sizeof(t_bnetd_d2cs_accountloginreply));
		packet_set_type(rpacket,BNETD_D2CS_ACCOUNTLOGINREPLY);
		bn_int_set(&rpacket->u.bnetd_d2cs_accountloginreply.h.seqno,\
			bn_int_get(packet->u.d2cs_bnetd_accountloginreq.h.seqno));
		bn_int_set(&rpacket->u.bnetd_d2cs_accountloginreply.reply,reply);
		queue_push_packet(conn_get_out_queue(c),rpacket);
		packet_del_ref(rpacket);
	}
	return 0;
}
Exemple #6
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);
				}