void DCCChatConnection::process()
{
	std::vector<Message> received_messages;
	std::unique_lock<std::mutex> lock(mutex);
	received_messages.swap(receive_queue);
	lock.unlock();

	for (size_t i = 0; i < received_messages.size(); i++)
	{
		switch (received_messages[i].type)
		{
		case Message::type_system:
			sig_system_text(received_messages[i].text);
			break;
		case Message::type_text:
			{
				IRCRawString text = received_messages[i].text;
				if (text.length() >= 2 && text.substr(text.length() - 2, 2) == "\r\n")
					text = text.substr(0, text.length() - 2);
				else if (text.length() >= 1 && text[text.length() - 1] == '\n')
					text = text.substr(0, text.length() - 1);
				sig_text_line(IRCText::from_raw(text));
			}
			break;
		case Message::type_disconnect:
			sig_disconnected(received_messages[i].text);
			break;
		}
	}
}
void IRCSession::extract_ctcp_command(const IRCText &ctcp_data, IRCRawString &command, IRCRawString &data)
{
	command = ctcp_data.to_raw();
	data = ctcp_data.to_raw();
	IRCRawString::size_type pos = command.find(" ");
	if (pos != IRCRawString::npos)
	{
		command = command.substr(0, pos);
		data = data.substr(pos+1);
	}
	else
	{
		data.clear();
	}
}
void IRCSession::on_unknown_message(const IRCMessage &message)
{
	IRCRawString s = IRCMessage::create_line(message.get_prefix().to_raw(), message.get_command(), message.get_params());
	cb_system_text(IRCText::from_raw(s.substr(0, s.length()-2)));
}