namespace AntiServerFullAttackProcessor { const size_t TIME_BEFORE_KICK = 3333;//ms std::map<int, unsigned long long> PlayersConnecting; std::map<unsigned long, char> IncommingConnectionCount; boost::asio::ip::address_v4 ipv4addr; bool AreWeUnderAttack = false; unsigned long long LastConnectionTime = 0; unsigned long long SuspectAttackStartTime = 0; int AttackSuspectCount = 0; void PerformCleanup(int timerid, void* param) { if (PlayersConnecting.size()) { unsigned long long TimeNow = Functions::GetTime(); for (auto i = PlayersConnecting.begin(); i != PlayersConnecting.end(); ) { if (i->second < TimeNow) { if (i->first != gMySpecialNPCWhichFucksUp) Kick(i->first); i = PlayersConnecting.erase(i); } else ++i; } } } class CAntiServerFullAttackProcessor : public Extension::Base { public: bool OnGameModeInit() { //SendRconCommand("minconnectiontime 50"); sampgdk_SetTimer(TIME_BEFORE_KICK / 2, true, PerformCleanup, 0); return true; } bool OnIncomingConnection(int playerid, std::string ip_address, int port) { unsigned long long TimeNow = Functions::GetTime(); if ((TimeNow - LastConnectionTime) < 50) { SuspectAttackStartTime = TimeNow; if (++AttackSuspectCount == 100) { AreWeUnderAttack = true; } } else if ((TimeNow - SuspectAttackStartTime) > 10000) { AttackSuspectCount = 0; SuspectAttackStartTime = 0; AreWeUnderAttack = false; IncommingConnectionCount.clear(); } LastConnectionTime = TimeNow; if (AreWeUnderAttack) { ipv4addr = ipv4addr.from_string(ip_address); if (++IncommingConnectionCount[ipv4addr.to_ulong()] < 2) { Kick(playerid); } } if (IncommingConnectionCount.size() > 2000) { IncommingConnectionCount.clear();//meh... } PlayersConnecting.insert(std::pair<int, unsigned long long>(playerid, Functions::GetTime() + TIME_BEFORE_KICK));//GetTime == get current milliseconds uptime return true; } bool OnPlayerConnect(int playerid) { //onplayerconnect can still execute for "kicked" players in OnIncommingConnection!!!!!!! auto found = PlayersConnecting.find(playerid); if (found != PlayersConnecting.end())//so we need to find the element and UNDER ANY CIRCUMSTANCES DO NOT ASSUME THE PLAYERID IS STILL IN THE MAP PlayersConnecting.erase(found);//(or this WILL crash your server, but thanks to the if a crash is being prevented) return true; } } _CAntiServerFullAttackProcessor; }
Standard input is empty
prog.cpp:3:8: error: ‘size_t’ does not name a type const size_t TIME_BEFORE_KICK = 3333;//ms ^ prog.cpp:4:2: error: ‘map’ in namespace ‘std’ does not name a type std::map<int, unsigned long long> PlayersConnecting; ^ prog.cpp:5:2: error: ‘map’ in namespace ‘std’ does not name a type std::map<unsigned long, char> IncommingConnectionCount; ^ prog.cpp:6:2: error: ‘boost’ does not name a type boost::asio::ip::address_v4 ipv4addr; ^ prog.cpp: In function ‘void AntiServerFullAttackProcessor::PerformCleanup(int, void*)’: prog.cpp:15:7: error: ‘PlayersConnecting’ was not declared in this scope if (PlayersConnecting.size()) ^ prog.cpp:17:33: error: ‘Functions’ has not been declared unsigned long long TimeNow = Functions::GetTime(); ^ prog.cpp:22:22: error: ‘gMySpecialNPCWhichFucksUp’ was not declared in this scope if (i->first != gMySpecialNPCWhichFucksUp) ^ prog.cpp:23:20: error: ‘Kick’ was not declared in this scope Kick(i->first); ^ prog.cpp: At global scope: prog.cpp:31:48: error: ‘Extension’ has not been declared class CAntiServerFullAttackProcessor : public Extension::Base ^ prog.cpp:31:59: error: expected ‘{’ before ‘Base’ class CAntiServerFullAttackProcessor : public Extension::Base ^ prog.cpp:32:2: error: invalid type in declaration before ‘{’ token { ^ prog.cpp:33:2: error: expected primary-expression before ‘public’ public: ^ prog.cpp:33:2: error: expected ‘}’ before ‘public’ prog.cpp:33:2: error: expected ‘,’ or ‘;’ before ‘public’ prog.cpp:40:48: error: ‘std::string’ has not been declared bool OnIncomingConnection(int playerid, std::string ip_address, int port) ^ prog.cpp: In function ‘bool AntiServerFullAttackProcessor::OnIncomingConnection(int, int, int)’: prog.cpp:42:33: error: ‘Functions’ has not been declared unsigned long long TimeNow = Functions::GetTime(); ^ prog.cpp:56:5: error: ‘IncommingConnectionCount’ was not declared in this scope IncommingConnectionCount.clear(); ^ prog.cpp:61:5: error: ‘ipv4addr’ was not declared in this scope ipv4addr = ipv4addr.from_string(ip_address); ^ prog.cpp:62:11: error: ‘IncommingConnectionCount’ was not declared in this scope if (++IncommingConnectionCount[ipv4addr.to_ulong()] < 2) ^ prog.cpp:64:19: error: ‘Kick’ was not declared in this scope Kick(playerid); ^ prog.cpp:67:8: error: ‘IncommingConnectionCount’ was not declared in this scope if (IncommingConnectionCount.size() > 2000) ^ prog.cpp:72:4: error: ‘PlayersConnecting’ was not declared in this scope PlayersConnecting.insert(std::pair<int, unsigned long long>(playerid, Functions::GetTime() + TIME_BEFORE_KICK));//GetTime == get current milliseconds uptime ^ prog.cpp:72:29: error: ‘pair’ is not a member of ‘std’ PlayersConnecting.insert(std::pair<int, unsigned long long>(playerid, Functions::GetTime() + TIME_BEFORE_KICK));//GetTime == get current milliseconds uptime ^ prog.cpp:72:39: error: expected primary-expression before ‘int’ PlayersConnecting.insert(std::pair<int, unsigned long long>(playerid, Functions::GetTime() + TIME_BEFORE_KICK));//GetTime == get current milliseconds uptime ^ prog.cpp:72:44: error: expected primary-expression before ‘unsigned’ PlayersConnecting.insert(std::pair<int, unsigned long long>(playerid, Functions::GetTime() + TIME_BEFORE_KICK));//GetTime == get current milliseconds uptime ^ prog.cpp: In function ‘bool AntiServerFullAttackProcessor::OnPlayerConnect(int)’: prog.cpp:78:17: error: ‘PlayersConnecting’ was not declared in this scope auto found = PlayersConnecting.find(playerid); ^ prog.cpp: At global scope: prog.cpp:83:4: error: ‘_CAntiServerFullAttackProcessor’ does not name a type } _CAntiServerFullAttackProcessor; ^ prog.cpp:84:1: error: expected declaration before ‘}’ token } ^
Standard output is empty