Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- We got A-Spam/Forbidden Words
- _____________________________________________
- Config the Spam Settings in setspam.ini.
- Add words in forbwords.ini
- Located in: scriptfiles/wgasfw/
- Credits to:
- Romel
- Zeex
- DracoBlue
- Y_Less
- */
- #include <a_samp>
- #include <dini>
- #include <YSI\y_ini> //Only used for isnumeric
- #include <zcmd>
- new word = 0;
- new ForbiddenWords[100][100];
- new playerwarn[MAX_PLAYERS] = 0;
- enum settings
- {
- spam,
- swarn,
- sms,
- forbidword
- };
- new set2[settings];
- #define ConfigPath "wgasfw/"
- #define SettingsSpam "setspam.ini"
- #define SettingsWords "forbwords.ini"
- #define cset 550
- #define cwarn 551
- #define cword 552
- #define csms 553
- #define cfw 554
- #if defined FILTERSCRIPT
- #else
- //==============================================================================
- public OnFilterScriptInit()
- {
- print("\n");
- print("[FS] Loaded");
- print("We got A-Spam/Forbidden Words");
- print("Config the Settings of Spam/Forbidden Words");
- print("\n");
- LoadSettings();
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n");
- print("[FS] Unloaded");
- print("We got A-Spam/Forbidden Words");
- print("Config the Settings of Spam/Forbidden Words");
- print("\n");
- SaveSettings();
- set2[spam] = 0;
- set2[forbidword] = 0;
- set2[swarn] = 3;
- set2[sms] = 4000;
- return 1;
- }
- #endif
- public OnPlayerConnect(playerid)
- {
- playerwarn[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- playerwarn[playerid] = 0;
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- new str[128];
- if(set2[spam] == 1)
- {
- if((GetTickCount() - GetPVarInt(playerid, "spwait")) < set2[sms])
- {
- playerwarn[playerid] += 1;
- format(str, sizeof(str), "ANTI-SPAM: %s(%d) has been warned by Anti-Spam - Warns: %d/%d", pName(playerid), playerid, playerwarn[playerid], set2[swarn]);
- SendClientMessageToAll(0xFFFF00FF, str);
- format(str, sizeof(str), "ANTI-SPAM: You should wait till the Spam Wait Time is finished, Warnings: %d/%d", playerwarn[playerid], set2[swarn]);
- SendClientMessage(playerid, 0xFF0000FF, str);
- if(playerwarn[playerid] == set2[swarn])
- {
- format(str, sizeof(str), "ANTI-SPAM: %s(%d) has been kicked by Anti-Spam for Spamming", pName(playerid), playerid);
- SendClientMessageToAll(0xFF0000FF, str);
- SendClientMessage(playerid, -1, "You've been kicked for Spamming!");
- return 0;
- }
- return 0;
- }
- SetPVarInt(playerid, "spwait", GetTickCount());
- }
- if(set2[forbidword] == 1)
- {
- for(new s = 0; s < word; s++)
- {
- new pos;
- while((pos = strfind(text, ForbiddenWords[s], true)) != -1) for(new i = pos, j = pos + strlen(ForbiddenWords[s]); i < j; i++) text[i] = '*';
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new str[128];
- if(dialogid == cset)
- {
- if(!response) return 1;
- switch(listitem)
- {
- case 0:
- {
- if(set2[spam] == 0)
- {
- format(str, sizeof(str), "RCON %s(%d) has enable the Anti-Spam", pName(playerid), playerid);
- SendClientMessageToAll(0xFFFF00FF, str);
- set2[spam] = 1;
- }
- else if(set2[spam] == 1)
- {
- format(str, sizeof(str), "RCON %s(%d) has disable the Anti-Spam", pName(playerid), playerid);
- SendClientMessageToAll(0xFFFF00FF, str);
- set2[spam] = 0;
- }
- }
- case 1:
- {
- if(set2[forbidword] == 0)
- {
- format(str, sizeof(str), "RCON %s(%d) has enable the Anti-Forbid Word", pName(playerid), playerid);
- SendClientMessageToAll(0xFFFF00FF, str);
- set2[forbidword] = 1;
- }
- else if(set2[spam] == 1)
- {
- format(str, sizeof(str), "RCON %s(%d) has disable the Anti-Forbid Word", pName(playerid), playerid);
- SendClientMessageToAll(0xFFFF00FF, str);
- set2[forbidword] = 0;
- }
- }
- case 2:
- {
- ShowPlayerDialog(playerid, cwarn, DIALOG_STYLE_INPUT, "{FFFFFF}Config the Warnings", "{FFFFFF}Function: Put the warnings you like to set when player get's warned\nInput the value not string", "Input", "Back");
- }
- case 3:
- {
- ShowPlayerDialog(playerid, csms, DIALOG_STYLE_INPUT, "{FFFFFF}Config the Wait Time", "{FFFFFF}Function: When player chat, We will store the wait time in variable\nThen when player talks when the wait time is not finish he gets warn\nInput the value (Mileseconds) not string", "Input", "Back");
- }
- case 4:
- {
- ShowPlayerDialog(playerid, cfw, DIALOG_STYLE_INPUT, "{FFFFFF}Add the Words", "{FFFFFF}Function: Type the string that you want to be forbidden word\nInput the string not the value", "Input", "Back");
- }
- case 5:
- {
- new str2[956];
- format(str2, sizeof(str2), "Anti-Spam [On/Off]\nAnti-ForbidWord [On/Off]\nSpam Warnings [%d]\nSpam Wait [%d]\nForbid Words [%d]", set2[swarn], set2[sms], word);
- ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
- }
- }
- return 1;
- }
- if(dialogid == cwarn)
- {
- if(!response)
- {
- new str2[956];
- format(str2, sizeof(str2), "Anti-Spam [On/Off]\nAnti-ForbidWord [On/Off]\nSpam Warnings [%d]\nSpam Wait [%d]\nAdd Forbid Words\nForbid Words [%d]", set2[swarn], set2[sms], word);
- ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
- return 1;
- }
- if(!strlen(inputtext))
- {
- ShowPlayerDialog(playerid, cwarn, DIALOG_STYLE_INPUT, "{FFFFFF}Config the Warnings", "{FFFFFF}Function: Put the warnings you like to set when player get's warned\nInput the value not string\nINVALID: Your field is empty!", "Input", "Back");
- return 1;
- }
- if(!isnumeric(inputtext))
- {
- ShowPlayerDialog(playerid, cwarn, DIALOG_STYLE_INPUT, "{FFFFFF}Config the Warnings", "{FFFFFF}Function: Put the warnings you like to set when player get's warned\nInput the value not string\nINVALID: That's string not value", "Input", "Back");
- return 1;
- }
- set2[swarn] = strval(inputtext);
- format(str, sizeof(str), "RCON %s(%d) set the Spam Warnings to %d", pName(playerid), playerid, strval(inputtext));
- SendClientMessageToAll(0xFFFF00FF, str);
- }
- if(dialogid == csms)
- {
- if(!response)
- {
- new str2[956];
- format(str2, sizeof(str2), "Anti-Spam [On/Off]\nAnti-ForbidWord [On/Off]\nSpam Warnings [%d]\nSpam Wait [%d]\nAdd Forbid Words\nForbid Words [%d]", set2[swarn], set2[sms], word);
- ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
- return 1;
- }
- if(!strlen(inputtext))
- {
- ShowPlayerDialog(playerid, csms, DIALOG_STYLE_INPUT, "{FFFFFF}Config the Wait Time", "{FFFFFF}Function: When player chat, We will store the wait time in variable\nThen when player talks when the wait time is not finish he gets warn\nInput the value (Mileseconds) not string\nINVALID: Your field is empty!", "Input", "Back");
- return 1;
- }
- if(!isnumeric(inputtext))
- {
- ShowPlayerDialog(playerid, csms, DIALOG_STYLE_INPUT, "{FFFFFF}Config the Wait Time", "{FFFFFF}Function: When player chat, We will store the wait time in variable\nThen when player talks when the wait time is not finish he gets warn\nInput the value (Mileseconds) not string\nINVALID: That's string not value", "Input", "Back");
- return 1;
- }
- set2[sms] = strval(inputtext);
- format(str, sizeof(str), "RCON %s(%d) set the Spam Wait Time to %d (ms)", pName(playerid), playerid, strval(inputtext));
- SendClientMessageToAll(0xFFFF00FF, str);
- }
- if(dialogid == cfw)
- {
- if(!response)
- {
- new str2[956];
- format(str2, sizeof(str2), "Anti-Spam [On/Off]\nAnti-ForbidWord [On/Off]\nSpam Warnings [%d]\nSpam Wait [%d]\nAdd Forbid Words\nForbid Words [%d]", set2[swarn], set2[sms], word);
- ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
- return 1;
- }
- if(!strlen(inputtext))
- {
- ShowPlayerDialog(playerid, cfw, DIALOG_STYLE_INPUT, "{FFFFFF}Add the Words", "{FFFFFF}Function: Type the string that you want to be forbidden word\nInput the string not the value\nINVALID: Your field is empty!", "Input", "Back");
- return 1;
- }
- if(isnumeric(inputtext))
- {
- ShowPlayerDialog(playerid, cfw, DIALOG_STYLE_INPUT, "{FFFFFF}Add the Words", "{FFFFFF}Function: Type the string that you want to be forbidden word\nInput the string not the value\nINVALID: That's value not a string", "Input", "Back");
- return 1;
- }
- new File:file, string2[256];
- format(string2, 256, "%s/%s", ConfigPath, SettingsWords);
- file = fopen(string2, io_append);
- format(string2, sizeof(string2), "%s\r\n", inputtext);
- fwrite(file, string2);
- fclose(file);
- new File:file2, file3[256], string[100];
- format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsWords);
- word = 0;
- if((file2 = fopen(file3, io_read)))
- {
- while(fread(file2, string))
- {
- for(new i = 0, j = strlen(string); i < j; i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
- ForbiddenWords[word] = string;
- word++;
- }
- fclose(file2);
- printf("[FS]: Forbidden Words has been reloaded - %d Forbidden Words", word);
- }
- format(str, sizeof(str), "RCON %s(%d) has add the word ''%s'' as Forbidden Word", pName(playerid), playerid, inputtext);
- SendClientMessageToAll(0xFFFF00FF, str);
- }
- return 1;
- }
- //==============================================================================
- command(csettings, playerid, params[])
- {
- new str[956];
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "INVALID: You're not rcon admin!");
- format(str, sizeof(str), "Anti-Spam [On/Off]\nAnti-ForbidWord [On/Off]\nSpam Warnings [%d]\nSpam Wait [%d]\nAdd Forbid Words\nForbid Words [%d]", set2[swarn], set2[sms], word);
- ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str, "Edit", "Close");
- return 1;
- }
- //==============================================================================
- stock SaveSettings()
- {
- new file[256];
- format(file, sizeof(file), "%s/%s", ConfigPath, SettingsSpam);
- dini_IntSet(file, "ASpam", set2[spam]);
- dini_IntSet(file, "SpamWarn", set2[swarn]);
- dini_IntSet(file, "SpamWait", set2[sms]);
- dini_IntSet(file, "ForbidWord", set2[forbidword]);
- print("[FS]: Now saving the config base on the store results from the variables");
- return 1;
- }
- stock pName(playerid)
- {
- new getname[24];
- GetPlayerName(playerid, getname, 24);
- return getname;
- }
- stock LoadSettings()
- {
- new file[256], File:file2, file3[256], string[100],
- File:file4;
- format(file, sizeof(file), ConfigPath);
- word = 0;
- format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsSpam);
- if(!dini_Exists(file3))
- {
- print("[FS]: You don't have the configuration, We created it automatically for you");
- print("[FS]: Note the config that we created are in default mode");
- dini_Create(file3);
- set2[spam] = 1;
- set2[forbidword] = 1;
- set2[swarn] = 3;
- set2[sms] = 4000;
- dini_IntSet(file3, "ASpam", set2[spam]);
- dini_IntSet(file3, "SpamWarn", set2[swarn]);
- dini_IntSet(file3, "SpamWait", set2[sms]);
- dini_IntSet(file3, "ForbidWord", set2[forbidword]);
- format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsWords);
- file4 = fopen(file3, io_append);
- fwrite(file4, " ");
- fclose(file4);
- }
- format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsSpam);
- if(dini_Exists(file3))
- {
- print("[FS]: You've the configuration, Our system has now scanned the result from the config");
- print("[FS]: Now storing the results in variables, And will use it later for needs");
- set2[spam] = dini_Int(file3, "ASpam");
- set2[swarn] = dini_Int(file3, "SpamWarn");
- set2[sms] = dini_Int(file3, "SpamWait");
- set2[forbidword] = dini_Int(file3, "ForbidWord");
- }
- format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsWords);
- if((file2 = fopen(file3, io_read)))
- {
- while(fread(file2, string))
- {
- for(new i = 0, j = strlen(string); i < j; i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
- ForbiddenWords[word] = string;
- word++;
- }
- fclose(file2);
- printf("[FS]: %i Forbidden Words - Stored in our folder database", word);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment