Ejemplo n.º 1
0
	void dns_requester::incoming_message(connection& aConnection, const message& aMessage)
	{
		if (aMessage.command() != message::NICK)
			return;
		user oldUser(aMessage.origin(), aConnection);
		user newUser(oldUser);
		if (!aMessage.parameters().empty())
			newUser.nick_name() = aMessage.parameters()[0];
		nick_change(oldUser.nick_name(), newUser.nick_name());
	}
Ejemplo n.º 2
0
	void dns_requester::whois_result(const message& aMessage)
	{
		if (aMessage.parameters().empty())
			return;

		switch(aMessage.command())
		{
		case message::RPL_WHOISUSER:
		case message::ERR_NOSUCHNICK:
			for (request_list::iterator i = iRequests.begin(); i != iRequests.end();)
			{
				if (irc::make_string(iConnection, i->first.nick_name()) == aMessage.parameters()[0])
				{
					if (aMessage.command() == message::RPL_WHOISUSER)
					{
						if (aMessage.parameters().size() >= 3)
						{
							i->first.user_name() = aMessage.parameters()[1];
							i->first.host_name() = aMessage.parameters()[2];
							iResolver.resolve(*this, i->first.host_name());
						}
						++i;
					}
					else
					{
						i->second->new_message(aMessage);
						iRequests.erase(i++);
					}
				}
				else
					++i;
			}
			break;
		default:
			break;
		}
	}
Ejemplo n.º 3
0
	void dcc_send_connection::incoming_message(irc::connection& aConnection, const message& aMessage)
	{
		if (&aConnection != iConnection)
			return;
		if (aMessage.command() != message::PRIVMSG)
			return;
		typedef std::vector<std::pair<std::string::const_iterator, std::string::const_iterator> > bits_t;
		bits_t bits;
		neolib::tokens(aMessage.content(), std::string("\001 "), bits);
		if (neolib::to_upper(neolib::to_string(bits[0])) != "DCC")
			return;
		if (iSendType == Download && neolib::to_upper(neolib::to_string(bits[1])) == "ACCEPT" && bits.size() >= 5)
		{
			if (*bits[2].first == '\"')
			{
				for (bits_t::size_type i = 3; i < bits.size(); ++i)
					if (*(bits[i].second - 1) == '\"')
					{
						bits[2].second = bits[i].second;
						bits.erase(bits.begin() + 3, bits.begin() + i + 1);
						break;
					}
			}
			std::string fileName = neolib::to_string(bits[2]);
			if (fileName == iResumeData->iFileName && 
				neolib::string_to_unsigned_integer(neolib::to_string(bits[3])) == iResumeData->iPort &&
				neolib::string_to_unsigned_integer(neolib::to_string(bits[4])) == iResumeData->iResumeFileSize)
			{
				u_long address = iResumeData->iAddress;
				u_short port = iResumeData->iPort;
				iBytesTransferred = iResumeData->iResumeFileSize;
				iLastBytesTransferred = iBytesTransferred;
				if (!connect(address, port))
				{
					close();
					return;
				}
				neolib::observable<dcc_send_connection_observer>::notify_observers(dcc_send_connection_observer::NotifyTransferStarted);
				if (!open_file())
					return;
			}
		}
		else if (iSendType == Listen && neolib::to_upper(neolib::to_string(bits[1])) == "RESUME" && bits.size() >= 5)
		{
			if (*bits[2].first == '\"')
			{
				for (bits_t::size_type i = 3; i < bits.size(); ++i)
					if (*(bits[i].second - 1) == '\"')
					{
						bits[2].second = bits[i].second;
						bits.erase(bits.begin() + 3, bits.begin() + i + 1);
						break;
					}
			}
			std::string fileName = neolib::to_string(bits[2]);
			if (fileName == iName && 
				neolib::string_to_unsigned_integer(neolib::to_string(bits[3])) == stream_server().local_port())
			{
				iResumeData = resume_data_t(0, stream_server().local_port(), name(), neolib::string_to_unsigned_integer(neolib::to_string(bits[4])));
				message newMessage(*iConnection, message::OUTGOING);
				newMessage.set_command(message::PRIVMSG);
				newMessage.parameters().push_back(iRemoteUser.nick_name());
				newMessage.parameters().push_back("\001DCC ACCEPT "); 
				newMessage.parameters().back() += iResumeData->iFileName + " ";
				newMessage.parameters().back() += neolib::unsigned_integer_to_string<char>(iResumeData->iPort) + " ";
				newMessage.parameters().back() += neolib::unsigned_integer_to_string<char>(iResumeData->iResumeFileSize) + "\001";
				iConnection->send_message(newMessage);
			}
		}
	}