fork download
  1. namespace AntiServerFullAttackProcessor
  2. {
  3. const size_t TIME_BEFORE_KICK = 3333;//ms
  4. std::map<int, unsigned long long> PlayersConnecting;
  5. std::map<unsigned long, char> IncommingConnectionCount;
  6. boost::asio::ip::address_v4 ipv4addr;
  7.  
  8. bool AreWeUnderAttack = false;
  9. unsigned long long LastConnectionTime = 0;
  10. unsigned long long SuspectAttackStartTime = 0;
  11. int AttackSuspectCount = 0;
  12.  
  13. void PerformCleanup(int timerid, void* param)
  14. {
  15. if (PlayersConnecting.size())
  16. {
  17. unsigned long long TimeNow = Functions::GetTime();
  18. for (auto i = PlayersConnecting.begin(); i != PlayersConnecting.end(); )
  19. {
  20. if (i->second < TimeNow)
  21. {
  22. if (i->first != gMySpecialNPCWhichFucksUp)
  23. Kick(i->first);
  24. i = PlayersConnecting.erase(i);
  25. }
  26. else ++i;
  27. }
  28. }
  29. }
  30.  
  31. class CAntiServerFullAttackProcessor : public Extension::Base
  32. {
  33. public:
  34. bool OnGameModeInit()
  35. {
  36. //SendRconCommand("minconnectiontime 50");
  37. sampgdk_SetTimer(TIME_BEFORE_KICK / 2, true, PerformCleanup, 0);
  38. return true;
  39. }
  40. bool OnIncomingConnection(int playerid, std::string ip_address, int port)
  41. {
  42. unsigned long long TimeNow = Functions::GetTime();
  43. if ((TimeNow - LastConnectionTime) < 50)
  44. {
  45. SuspectAttackStartTime = TimeNow;
  46. if (++AttackSuspectCount == 100)
  47. {
  48. AreWeUnderAttack = true;
  49. }
  50. }
  51. else if ((TimeNow - SuspectAttackStartTime) > 10000)
  52. {
  53. AttackSuspectCount = 0;
  54. SuspectAttackStartTime = 0;
  55. AreWeUnderAttack = false;
  56. IncommingConnectionCount.clear();
  57. }
  58. LastConnectionTime = TimeNow;
  59. if (AreWeUnderAttack)
  60. {
  61. ipv4addr = ipv4addr.from_string(ip_address);
  62. if (++IncommingConnectionCount[ipv4addr.to_ulong()] < 2)
  63. {
  64. Kick(playerid);
  65. }
  66. }
  67. if (IncommingConnectionCount.size() > 2000)
  68. {
  69. IncommingConnectionCount.clear();//meh...
  70. }
  71.  
  72. PlayersConnecting.insert(std::pair<int, unsigned long long>(playerid, Functions::GetTime() + TIME_BEFORE_KICK));//GetTime == get current milliseconds uptime
  73. return true;
  74. }
  75. bool OnPlayerConnect(int playerid)
  76. {
  77. //onplayerconnect can still execute for "kicked" players in OnIncommingConnection!!!!!!!
  78. auto found = PlayersConnecting.find(playerid);
  79. 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
  80. PlayersConnecting.erase(found);//(or this WILL crash your server, but thanks to the if a crash is being prevented)
  81. return true;
  82. }
  83. } _CAntiServerFullAttackProcessor;
  84. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
 }
 ^
stdout
Standard output is empty