#include "SecurityFeatures.h"
#include "Utils/TimeUtils.h"

#include "Client.h"

auto SecurityFeatures::onPacketReceive(Packet* packet, bool* cancel) -> void {
	long long now = Utils::Time::getMs();
	static long long start = now;

	if (packet->getID() == PacketID::Text) {
		auto text = reinterpret_cast<TextPacket*>(packet);

		std::string msg = text->getMessage();
		TextPacket::Type type = text->getType();
		
		static std::string lastmsg = _("");
		if (now - start < 100.f && msg == lastmsg && type == TextPacket::Type::Chat) {
			*cancel = true;
			Client::notifications.push_back({ _("Information"), Datas::Language::get().module.other.securityfeatures.patched_message_1, 2.5f });
		}
		else {
			lastmsg = msg;
			start = now;
		}
	}
}

auto SecurityFeatures::onClient4() -> void {
	name = Datas::Language::get().module.other.securityfeatures.name;
	description = Datas::Language::get().module.other.securityfeatures.description;
}
