Paste Description for S:B:R Flood Protect
S:B:R SA-MP Server Flood Protection
- S:B:R Flood Protect
- Sunday, May 27th, 2007 at 2:28:40am MDT
- /*******************************************************************************************************
- [S:B:R] Server flooding protection. Coded by Sacky, Betamaster and Ramjet.
- NO PORTION OF THIS SCRIPT IS TO BE REPRODUCED FOR COMMERCIAL USE, WITHOUT THE CREATORS CONSENT.
- THIS INCLUDES USING SCRIPT SNIPPETS IN CUSTOM BUILT GAMEMODES FOR MONEY.
- *******************************************************************************************************/
- #include <a_samp>
- #include <dprops>
- #define VERSION "1.0"
- #define LOGFILE "FloodLog.txt"
- #define dcmd(%1,%2,%3) if ((strcmp(cmdtext, "/%1", true, %2 + 1) == 0) && (((cmdtext[%2 + 1] == 0) && (%3(playerid, ""))) || ((cmdtext[%2 + 1] == 32) && (%3(playerid, cmdtext[%2 + 2]))))) return 1
- #define dcmd2(%1,%2,%3) if ((strcmp(text, "%1", true, %2) == 0) && (((text[%2] == 0) && (%3(playerid, ""))) || ((text[%2] == 32) && (%3(playerid, text[%2 + 1]))))) return 1
- #define MSG(%1) SendClientMessage(playerid, 0xFFFFFFAA, %1)
- #define MSG_INFO(%1) SendClientMessage(playerid, 0xAA3333AA, %1)
- // ============================================================================================
- new CheckActivated = true;
- new MAX_FLOODS = 10;
- enum Database {
- MiniCounter,
- MainFloodCounter,
- Banee[MAX_PLAYER_NAME],
- Banned[2]
- }
- new gPlayerAntiFlood[MAX_PLAYERS][Database];
- // ============================================================================================
- public OnFilterScriptInit(){
- print("\n----------------------------------");
- printf("S:B:R Server Flood Protection %s.", VERSION);
- print("----------------------------------");
- }
- // ============================================================================================
- public OnPlayerConnect(playerid) {
- if(!PropertyExists("SBR_AntiFlood_Timer")) {
- PropertySet("SBR_AntiFlood_Timer", "Active");
- SetTimer("AFTimer", 1000, true);
- }
- if(CheckActivated) {
- gPlayerAntiFlood[playerid][MiniCounter] = 0;
- if(gPlayerAntiFlood[playerid][MainFloodCounter] > MAX_FLOODS) {
- ReadyPlayerForBannage(playerid);
- Ban(playerid);
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid) {
- if(gPlayerAntiFlood[playerid][MiniCounter] < 3) gPlayerAntiFlood[playerid][MainFloodCounter]++;
- else gPlayerAntiFlood[playerid][MainFloodCounter] = 0;
- return 1;
- }
- public OnPlayerText(playerid, text[]) {
- if(!IsPlayerConnected(playerid)) return 0;
- return AsciiCheck(text);
- }
- // ============================================================================================
- /*
- * This section contains the administration center for RCON admins.
- */
- public OnPlayerCommandText(playerid, cmdtext[]) {
- if(!IsPlayerConnected(playerid)) return 0;
- if(AsciiCheck(cmdtext)) dcmd(fmenu, 5, AC_Menu);
- return 0;
- }
- AC_Menu(playerid, text[]) {
- if(!IsPlayerAdmin(playerid)) {
- MSG_INFO("[S:B:R] You need RCON privilages to access this menu");
- return true;
- }
- if(!strlen(text)) {
- MSG_INFO("S:B:R Administration Center.");
- MSG("/fmenu startservice - Restarts the Anti-Crash Protection.");
- MSG("/fmenu stopservice - Kills the Anti-Crash Protection.");
- MSG("/fmenu maxfloods - Changes the server's maximum flood limit. (10 Recommended).");
- MSG("/fmenu version - Shows the version of the script.");
- MSG("/fmenu credits - Shows the names that made the script possible.");
- return true;
- }
- dcmd2(startservice, 12, AC_Startservice);
- dcmd2(stopservice, 11, AC_Stopservice);
- dcmd2(maxfloods, 9, AC_Maxfloods);
- dcmd2(version, 7, AC_Version);
- dcmd2(credits, 7, AC_Credits);
- return true;
- }
- AC_Startservice(playerid, text[]) {
- #pragma unused text
- if(CheckActivated) {
- MSG_INFO("[S:B:R] The script has already been started.");
- } else {
- CheckActivated = true;
- MSG("[S:B:R] The script has been started successfully.");
- }
- return true;
- }
- AC_Stopservice(playerid, text[]) {
- #pragma unused text
- if(!CheckActivated) {
- MSG_INFO("[S:B:R] The script has already been shutdown.");
- } else {
- CheckActivated = false;
- MSG("[S:B:R] The script has been shutdown successfully.");
- }
- return true;
- }
- AC_Maxfloods(playerid, text[]) {
- if(!strlen(text)) {
- MSG("[S:B:R] Usage: /fmenu maxfloods [FloodLimit]");
- } else if(IsInputNumeric(text)) {
- new string[128], val = strval(text);
- format(string, 128, "[S:B:R] The maximum flood limit has been changed from %d to %d.", MAX_FLOODS, val);
- MSG(string);
- MAX_FLOODS = val;
- } else {
- MSG_INFO("[S:B:R] The value must be numeric.");
- }
- return true;
- }
- AC_Version(playerid, text[]) {
- #pragma unused text
- new string[128];
- format(string, 128, "[S:B:R] Version %s is currently being used on this server.", VERSION);
- MSG(string);
- return true;
- }
- AC_Credits(playerid, text[]) {
- #pragma unused text
- MSG_INFO("S:B:R Anti Server Flood Protection.");
- MSG("Sacky - Coding a basic protection system.");
- MSG("Betamaster - Improving the detection system.");
- MSG("Ramjet - Improving the detection system, and other Misc features.");
- return true;
- }
- // ============================================================================================
- /*
- * This function increments the MiniCounter variable so it will detect floods. The function will also
- * send a message to all players if a player has been banned for flood attacks.
- * This function is a constantly running timer.
- */
- public AFTimer() {
- static count = 0;
- count++, count %= 60;
- for(new i = 0; i < MAX_PLAYERS; i++) {
- if(gPlayerAntiFlood[i][Banned][0] == 1) { // banned
- new tmpstr[128];
- format(tmpstr, 128, "[S:B:R] Banned: %s for flood hack.", gPlayerAntiFlood[i][Banee]);
- print(tmpstr);
- SendClientMessageToAll(0xFF0000AA, tmpstr);
- if(fexist(LOGFILE)) {
- new File:fhandle, date[3], time[3], temp[64];
- gettime(time[0], time[1], time[2]);
- getdate(date[0], date[1], date[2]);
- fhandle = fopen(LOGFILE,io_append);
- format(temp,sizeof(temp),"\n[%d/%d/%d] Server Flood Prevented (Time: %d:%d:%d)",date[0], date[1], date[2], time[0], time[1], time[2]);
- fwrite(fhandle,temp);
- fclose(fhandle);
- }
- gPlayerAntiFlood[i][Banned][0] = false;
- gPlayerAntiFlood[i][Banned][1] = 0;
- } else {
- if(count == 0) gPlayerAntiFlood[i][MiniCounter] = gPlayerAntiFlood[i][MainFloodCounter] = 0;
- else gPlayerAntiFlood[i][MiniCounter]++;
- }
- }
- }
- // ============================================================================================
- // Sets a few variables to ready a flooder for bannage.
- ReadyPlayerForBannage(playerid) {
- gPlayerAntiFlood[playerid][MainFloodCounter] = 0;
- GetPlayerName(playerid, gPlayerAntiFlood[playerid][Banee], MAX_PLAYER_NAME);
- gPlayerAntiFlood[playerid][Banned][0] = true;
- }
- // ============================================================================================
- // Checks if a string is numeric. This is used for the MAX_FLOODS changer command.
- IsInputNumeric(string[]) {
- if(strlen(string) > 50 || ((string[0] > '9' || string[0] < '0') && (string[0] != '-'))) return 0;
- for(new i = 1, j = strlen(string); i < j; i++) {
- if(string[i] > '9' || string[i] < '0') return 0;
- }
- return 1;
- }
- // ============================================================================================
- // Check string for invalid SA-MP characters
- AsciiCheck(string[]) {
- new i, c;
- while ((c = string[i++])) if (c < 0x20 || c > 0x7E) return 0;
- return 1; //ok
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.