Guest User

We got A-Spam/Forbid Word v1.0

a guest
Feb 4th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.17 KB | None | 0 0
  1. /*
  2.  
  3. We got A-Spam/Forbidden Words
  4. _____________________________________________
  5.  
  6. Config the Spam Settings in setspam.ini.
  7. Add words in forbwords.ini
  8.  
  9. Located in: scriptfiles/wgasfw/
  10.  
  11. Credits to:
  12. Romel
  13. Zeex
  14. DracoBlue
  15. Y_Less
  16.  
  17. */
  18.  
  19. #include <a_samp>
  20. #include <dini>
  21. #include <YSI\y_ini> //Only used for isnumeric
  22. #include <zcmd>
  23.  
  24. new word = 0;
  25. new ForbiddenWords[100][100];
  26. new playerwarn[MAX_PLAYERS] = 0;
  27.  
  28. enum settings
  29. {
  30. spam,
  31. swarn,
  32. sms,
  33. forbidword
  34. };
  35. new set2[settings];
  36.  
  37. #define ConfigPath "wgasfw/"
  38. #define SettingsSpam "setspam.ini"
  39. #define SettingsWords "forbwords.ini"
  40. #define cset 550
  41. #define cwarn 551
  42. #define cword 552
  43. #define csms 553
  44. #define cfw 554
  45.  
  46. #if defined FILTERSCRIPT
  47. #else
  48.  
  49. //==============================================================================
  50.  
  51. public OnFilterScriptInit()
  52. {
  53. print("\n");
  54. print("[FS] Loaded");
  55. print("We got A-Spam/Forbidden Words");
  56. print("Config the Settings of Spam/Forbidden Words");
  57. print("\n");
  58. LoadSettings();
  59. return 1;
  60. }
  61.  
  62. public OnFilterScriptExit()
  63. {
  64. print("\n");
  65. print("[FS] Unloaded");
  66. print("We got A-Spam/Forbidden Words");
  67. print("Config the Settings of Spam/Forbidden Words");
  68. print("\n");
  69. SaveSettings();
  70. set2[spam] = 0;
  71. set2[forbidword] = 0;
  72. set2[swarn] = 3;
  73. set2[sms] = 4000;
  74. return 1;
  75. }
  76.  
  77. #endif
  78.  
  79. public OnPlayerConnect(playerid)
  80. {
  81. playerwarn[playerid] = 0;
  82. return 1;
  83. }
  84.  
  85. public OnPlayerDisconnect(playerid, reason)
  86. {
  87. playerwarn[playerid] = 0;
  88. return 1;
  89. }
  90.  
  91. public OnPlayerText(playerid, text[])
  92. {
  93. new str[128];
  94. if(set2[spam] == 1)
  95. {
  96. if((GetTickCount() - GetPVarInt(playerid, "spwait")) < set2[sms])
  97. {
  98. playerwarn[playerid] += 1;
  99. format(str, sizeof(str), "ANTI-SPAM: %s(%d) has been warned by Anti-Spam - Warns: %d/%d", pName(playerid), playerid, playerwarn[playerid], set2[swarn]);
  100. SendClientMessageToAll(0xFFFF00FF, str);
  101. format(str, sizeof(str), "ANTI-SPAM: You should wait till the Spam Wait Time is finished, Warnings: %d/%d", playerwarn[playerid], set2[swarn]);
  102. SendClientMessage(playerid, 0xFF0000FF, str);
  103. return 0;
  104. }
  105. SetPVarInt(playerid, "spwait", GetTickCount());
  106. }
  107. if(set2[forbidword] == 1)
  108. {
  109. for(new s = 0; s < word; s++)
  110. {
  111. new pos;
  112. while((pos = strfind(text, ForbiddenWords[s], true)) != -1) for(new i = pos, j = pos + strlen(ForbiddenWords[s]); i < j; i++) text[i] = '*';
  113. }
  114. }
  115. return 1;
  116. }
  117.  
  118. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  119. {
  120. new str[128];
  121. if(dialogid == cset)
  122. {
  123. if(!response) return 1;
  124. switch(listitem)
  125. {
  126. case 0:
  127. {
  128. if(set2[spam] == 0)
  129. {
  130. format(str, sizeof(str), "RCON %s(%d) has enable the Anti-Spam", pName(playerid), playerid);
  131. SendClientMessageToAll(0xFFFF00FF, str);
  132. set2[spam] = 1;
  133. }
  134. else if(set2[spam] == 1)
  135. {
  136. format(str, sizeof(str), "RCON %s(%d) has disable the Anti-Spam", pName(playerid), playerid);
  137. SendClientMessageToAll(0xFFFF00FF, str);
  138. set2[spam] = 0;
  139. }
  140. }
  141. case 1:
  142. {
  143. if(set2[forbidword] == 0)
  144. {
  145. format(str, sizeof(str), "RCON %s(%d) has enable the Anti-Forbid Word", pName(playerid), playerid);
  146. SendClientMessageToAll(0xFFFF00FF, str);
  147. set2[forbidword] = 1;
  148. }
  149. else if(set2[spam] == 1)
  150. {
  151. format(str, sizeof(str), "RCON %s(%d) has disable the Anti-Forbid Word", pName(playerid), playerid);
  152. SendClientMessageToAll(0xFFFF00FF, str);
  153. set2[forbidword] = 0;
  154. }
  155. }
  156. case 2:
  157. {
  158. 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");
  159. }
  160. case 3:
  161. {
  162. 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");
  163. }
  164. case 4:
  165. {
  166. 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");
  167. }
  168. case 5:
  169. {
  170. new str2[956];
  171. 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);
  172. ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
  173. }
  174. }
  175. return 1;
  176. }
  177. if(dialogid == cwarn)
  178. {
  179. if(!response)
  180. {
  181. new str2[956];
  182. 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);
  183. ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
  184. return 1;
  185. }
  186. if(!strlen(inputtext))
  187. {
  188. 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");
  189. return 1;
  190. }
  191. if(!isnumeric(inputtext))
  192. {
  193. 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");
  194. return 1;
  195. }
  196. set2[swarn] = strval(inputtext);
  197. format(str, sizeof(str), "RCON %s(%d) set the Spam Warnings to %d", pName(playerid), playerid, strval(inputtext));
  198. SendClientMessageToAll(0xFFFF00FF, str);
  199. }
  200. if(dialogid == csms)
  201. {
  202. if(!response)
  203. {
  204. new str2[956];
  205. 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);
  206. ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
  207. return 1;
  208. }
  209. if(!strlen(inputtext))
  210. {
  211. 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");
  212. return 1;
  213. }
  214. if(!isnumeric(inputtext))
  215. {
  216. 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");
  217. return 1;
  218. }
  219. set2[sms] = strval(inputtext);
  220. format(str, sizeof(str), "RCON %s(%d) set the Spam Wait Time to %d (ms)", pName(playerid), playerid, strval(inputtext));
  221. SendClientMessageToAll(0xFFFF00FF, str);
  222. }
  223. if(dialogid == cfw)
  224. {
  225. if(!response)
  226. {
  227. new str2[956];
  228. 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);
  229. ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str2, "Edit", "Close");
  230. return 1;
  231. }
  232. if(!strlen(inputtext))
  233. {
  234. 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");
  235. return 1;
  236. }
  237. if(isnumeric(inputtext))
  238. {
  239. 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");
  240. return 1;
  241. }
  242. new File:file, string2[256];
  243. format(string2, 256, "%s/%s", ConfigPath, SettingsWords);
  244. file = fopen(string2, io_append);
  245. format(string2, sizeof(string2), "%s\r\n", inputtext);
  246. fwrite(file, string2);
  247. fclose(file);
  248. new File:file2, file3[256], string[100];
  249. format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsWords);
  250. word = 0;
  251. if((file2 = fopen(file3, io_read)))
  252. {
  253. while(fread(file2, string))
  254. {
  255. for(new i = 0, j = strlen(string); i < j; i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
  256. ForbiddenWords[word] = string;
  257. word++;
  258. }
  259. fclose(file2);
  260. printf("[FS]: Forbidden Words has been reloaded - %d Forbidden Words", word);
  261. }
  262. format(str, sizeof(str), "RCON %s(%d) has add the word ''%s'' as Forbidden Word", pName(playerid), playerid, inputtext);
  263. SendClientMessageToAll(0xFFFF00FF, str);
  264. }
  265. return 1;
  266. }
  267.  
  268. //==============================================================================
  269.  
  270. command(csettings, playerid, params[])
  271. {
  272. new str[956];
  273. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "INVALID: You're not rcon admin!");
  274. 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);
  275. ShowPlayerDialog(playerid, cset, DIALOG_STYLE_LIST, "{FFFFFF}Configuration", str, "Edit", "Close");
  276. return 1;
  277. }
  278.  
  279. //==============================================================================
  280.  
  281. stock SaveSettings()
  282. {
  283. new file[256];
  284. format(file, sizeof(file), "%s/%s", ConfigPath, SettingsSpam);
  285. dini_IntSet(file, "ASpam", set2[spam]);
  286. dini_IntSet(file, "SpamWarn", set2[swarn]);
  287. dini_IntSet(file, "SpamWait", set2[sms]);
  288. dini_IntSet(file, "ForbidWord", set2[forbidword]);
  289. print("[FS]: Now saving the config base on the store results from the variables");
  290. return 1;
  291. }
  292.  
  293. stock pName(playerid)
  294. {
  295. new getname[24];
  296. GetPlayerName(playerid, getname, 24);
  297. return getname;
  298. }
  299.  
  300. stock LoadSettings()
  301. {
  302. new file[256], File:file2, file3[256], string[100],
  303. File:file4;
  304. format(file, sizeof(file), ConfigPath);
  305. word = 0;
  306. format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsSpam);
  307. if(!dini_Exists(file3))
  308. {
  309. print("[FS]: You don't have the configuration, We created it automatically for you");
  310. print("[FS]: Note the config that we created are in default mode");
  311. dini_Create(file3);
  312. set2[spam] = 1;
  313. set2[forbidword] = 1;
  314. set2[swarn] = 3;
  315. set2[sms] = 4000;
  316. dini_IntSet(file3, "ASpam", set2[spam]);
  317. dini_IntSet(file3, "SpamWarn", set2[swarn]);
  318. dini_IntSet(file3, "SpamWait", set2[sms]);
  319. dini_IntSet(file3, "ForbidWord", set2[forbidword]);
  320. format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsWords);
  321. file4 = fopen(file3, io_append);
  322. fwrite(file4, " ");
  323. fclose(file4);
  324. }
  325. format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsSpam);
  326. if(dini_Exists(file3))
  327. {
  328. print("[FS]: You've the configuration, Our system has now scanned the result from the config");
  329. print("[FS]: Now storing the results in variables, And will use it later for needs");
  330. set2[spam] = dini_Int(file3, "ASpam");
  331. set2[swarn] = dini_Int(file3, "SpamWarn");
  332. set2[sms] = dini_Int(file3, "SpamWait");
  333. set2[forbidword] = dini_Int(file3, "ForbidWord");
  334. }
  335. format(file3, sizeof(file3), "%s/%s", ConfigPath, SettingsWords);
  336. if((file2 = fopen(file3, io_read)))
  337. {
  338. while(fread(file2, string))
  339. {
  340. for(new i = 0, j = strlen(string); i < j; i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
  341. ForbiddenWords[word] = string;
  342. word++;
  343. }
  344. fclose(file2);
  345. printf("[FS]: %i Forbidden Words - Stored in our folder database", word);
  346. }
  347. return 1;
  348. }
Advertisement
Add Comment
Please, Sign In to add comment