SHOW:
|
|
- or go back to the newest paste.
| 1 | /* | |
| 2 | 74 | |
| 3 | SA-MP FloodControl Include | |
| 4 | Copyright © 2012 RyDeR`, JernejL | |
| 5 | */ | |
| 6 | ||
| 7 | #if !defined MAX_JOIN_LOGS | |
| 8 | #define MAX_JOIN_LOGS (30) | |
| 9 | #endif | |
| 10 | ||
| 11 | #if !defined MAX_THRESHOLD | |
| 12 | #define MAX_THRESHOLD (8000) // The amount of time in which all joins are valid and counted | |
| 13 | #endif | |
| 14 | ||
| 15 | enum e_JoinLog {
| |
| 16 | e_iIP, | |
| 17 | e_iTimeStamp | |
| 18 | }; | |
| 19 | ||
| 20 | static stock | |
| 21 | g_eaJoinLog[MAX_JOIN_LOGS][e_JoinLog] | |
| 22 | ; | |
| 23 | ||
| 24 | public OnPlayerConnect(playerid) {
| |
| 25 | static | |
| 26 | s_iJoinSeq, | |
| 27 | s_szIP[16] | |
| 28 | ; | |
| 29 | GetPlayerIp(playerid, s_szIP, sizeof(s_szIP)); | |
| 30 | ||
| 31 | g_eaJoinLog[s_iJoinSeq][e_iIP] = s_szIP[0] = IpToInt(s_szIP); | |
| 32 | g_eaJoinLog[s_iJoinSeq][e_iTimeStamp] = GetTickCount(); | |
| 33 | ||
| 34 | s_iJoinSeq = ++s_iJoinSeq % MAX_JOIN_LOGS; | |
| 35 | ||
| 36 | s_szIP[1] = s_szIP[2] = 0; | |
| 37 | ||
| 38 | for(new i = 0; i < (MAX_JOIN_LOGS - 1); ++i) {
| |
| 39 | if(g_eaJoinLog[i][e_iIP] != s_szIP[0]) {
| |
| 40 | continue; | |
| 41 | } | |
| 42 | s_szIP[3] = GetTickCount(); | |
| 43 | ||
| 44 | if(floatround(floatabs(s_szIP[3] - g_eaJoinLog[i][e_iTimeStamp])) < MAX_THRESHOLD) {
| |
| 45 | if(floatround(floatabs(s_szIP[3] - g_eaJoinLog[i + 1][e_iTimeStamp])) < MAX_THRESHOLD) {
| |
| 46 | s_szIP[2] += floatround(floatabs(g_eaJoinLog[i][e_iTimeStamp] - g_eaJoinLog[i + 1][e_iTimeStamp])); | |
| 47 | s_szIP[1] += 1; | |
| 48 | } | |
| 49 | } | |
| 50 | } | |
| 51 | // Eventually initialize and call if exists | |
| 52 | static | |
| 53 | bool: s_bInit, | |
| 54 | ||
| 55 | s_iHasOPFC = -1, | |
| 56 | s_iHasOPC = -1 | |
| 57 | ; | |
| 58 | if(!s_bInit) {
| |
| 59 | s_iHasOPFC = funcidx("OnPlayerFloodControl");
| |
| 60 | s_iHasOPC = funcidx("FC_OnPlayerConnect");
| |
| 61 | ||
| 62 | s_bInit = !s_bInit; | |
| 63 | } | |
| 64 | if(s_bInit) {
| |
| 65 | if(s_iHasOPFC != -1) {
| |
| 66 | CallRemoteFunction("OnPlayerFloodControl", "iii", playerid, s_szIP[1], s_szIP[2]);
| |
| 67 | } | |
| 68 | if(s_iHasOPC != -1) {
| |
| 69 | return CallLocalFunction("FC_OnPlayerConnect", "i", playerid);
| |
| 70 | } | |
| 71 | } | |
| 72 | return 1; | |
| 73 | } | |
| 74 | ||
| 75 | #if defined _ALS_OnPlayerConnect | |
| 76 | #undef OnPlayerConnect | |
| 77 | #else | |
| 78 | #define _ALS_OnPlayerConnect | |
| 79 | #endif | |
| 80 | ||
| 81 | #define OnPlayerConnect FC_OnPlayerConnect | |
| 82 | ||
| 83 | static stock IpToInt(const s_szIP[]) {
| |
| 84 | new | |
| 85 | aiBytes[1], | |
| 86 | iPos = 0 | |
| 87 | ; | |
| 88 | aiBytes{0} = strval(s_szIP[iPos]);
| |
| 89 | while(iPos < 15 && s_szIP[iPos++] != '.') {}
| |
| 90 | aiBytes{1} = strval(s_szIP[iPos]);
| |
| 91 | while(iPos < 15 && s_szIP[iPos++] != '.') {}
| |
| 92 | aiBytes{2} = strval(s_szIP[iPos]);
| |
| 93 | while(iPos < 15 && s_szIP[iPos++] != '.') {}
| |
| 94 | aiBytes{3} = strval(s_szIP[iPos]);
| |
| 95 | ||
| 96 | return aiBytes[0]; | |
| 97 | } | |
| 98 | ||
| 99 | forward OnPlayerConnect(playerid); | |
| 100 | forward OnPlayerFloodControl(playerid, iCount, iTimeSpan); |