daily pastebin goal
72%
SHARE
TWEET

Badwordsystem v1.0

Leon1337 Sep 30th, 2018 (edited) 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Badword System von LeonMrBonnie
  2. //Erstellt am 30.9.2018 für das Breadfish Forum.
  3.  
  4. #define FILTERSCRIPT
  5.  
  6. //Includes
  7. #include <a_samp>
  8. #include <zcmd>
  9. #include <a_mysql>
  10.  
  11. // ************  EINSTELLUNGEN:  ************** //
  12. #define MYSQL_HOST         "127.0.0.1"           //IP Adresse des MySQL Servers
  13. #define MYSQL_USER         "root"                //Benutzername der angemeldet wird
  14. #define MYSQL_PASS         "root"                //Passwort des Benutzers
  15. #define MYSQL_DBSE         "samp"                //Name der Datenbank
  16. #define MYSQL_TABLENAME    "server_badwords"     //Tabellenname für die Badwords
  17.  
  18. #define MAX_BADWORDS     100      //Maximale Anzahl an Badwords
  19.  
  20. //Dialoge
  21. #define DIALOG_BADWORD       30000
  22. #define DIALOG_BADWORDLIST   30001
  23. #define DIALOG_BADWORDADD    30002
  24. #define DIALOG_BADWORDREMOVE 30003
  25.  
  26. //Farben
  27. #define COLOR_LIGHTBLUE 0x33CCFFAA
  28. #define HTML_WHITE     "{FFFFFF}"
  29. #define HTML_RED       "{f44242}"
  30.  
  31. //Enum
  32. enum BadwordEnum
  33. {
  34.     Badword[32],
  35.     CreatedBy[MAX_PLAYER_NAME],
  36.     Exists
  37. };
  38.  
  39. //Variablen
  40. new MySQL:badword_handle;
  41. new BadwordInfo[MAX_BADWORDS][BadwordEnum];
  42. new badwords;
  43.  
  44. //----------------------------------------------------------------------------------------------//
  45. //***** Publics *****
  46. public OnFilterScriptInit()
  47. {
  48.     print("\n-----------------------------------");
  49.     print(" Badword System von LeonMrBonnie geladen");
  50.     print("-----------------------------------\n");
  51.  
  52.     DatabaseConnect();
  53.     return 1;
  54. }
  55.  
  56. public OnFilterScriptExit()
  57. {
  58.     mysql_close(badword_handle);
  59.     return 1;
  60. }
  61.  
  62. public OnPlayerText(playerid, text[])
  63. {
  64.     if(ContainsBadword(text))
  65.     {
  66.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "BADWORDS: Deine Nachricht hat ein Badword enthalten. Die Nachricht wurde nicht versendet.");
  67.         return 0;
  68.     }
  69.     return 1;
  70. }
  71.  
  72. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  73. {
  74.     switch(dialogid)
  75.     {
  76.         case DIALOG_BADWORD:
  77.         {
  78.             if(response)
  79.             {
  80.                 switch(listitem)
  81.                 {
  82.                     case 0: //Badwords auflisten
  83.                     {
  84.                         if(badwords == 0) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "BADWORDS: Es sind keine Badwords vorhanden.");
  85.                         new dialogstring[2048],string[64];
  86.                         dialogstring = "Badword\tHinzugefügt von\n";
  87.                         for(new i; i<badwords+1; i++)
  88.                         {
  89.                             if(BadwordInfo[i][Exists] == 0) continue;
  90.                             format(string,sizeof(string),"%s\t%s\n",BadwordInfo[i][Badword],BadwordInfo[i][CreatedBy]);
  91.                             strcat(dialogstring, string);
  92.                         }
  93.                         ShowPlayerDialog(playerid, DIALOG_BADWORDLIST, DIALOG_STYLE_TABLIST_HEADERS, "Badwords: "HTML_RED"Badwords auflisten", dialogstring, "Zurück", "");
  94.                     }
  95.                     case 1: //Badword hinzufügen
  96.                     {
  97.                         ShowPlayerDialog(playerid, DIALOG_BADWORDADD, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword hinzufügen", ""HTML_WHITE"Gib unten das Badword ein, welches du hinzufügen möchtest:","Bestätigen","Zurück");
  98.                     }
  99.                     case 2: //Badword entfernen
  100.                     {
  101.                         ShowPlayerDialog(playerid, DIALOG_BADWORDREMOVE, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword entfernen", ""HTML_WHITE"Gib unten das Badword ein, welches du entfernen möchtest:","Bestätigen","Zurück");
  102.                     }
  103.                 }
  104.             }
  105.         }
  106.         case DIALOG_BADWORDLIST:
  107.         {
  108.             if(response)
  109.             {
  110.                 ShowPlayerDialog(playerid, DIALOG_BADWORD, DIALOG_STYLE_LIST, "Badwords: "HTML_RED"Verwaltung", "Alle Badwords anzeigen\nBadword hinzufügen\nBadword entfernen", "Auswählen", "Schliessen");
  111.             }
  112.         }
  113.         case DIALOG_BADWORDADD:
  114.         {
  115.             if(response)
  116.             {
  117.                 if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_BADWORDADD, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword hinzufügen", ""HTML_RED"Das Eingabefeld ist leer.\n"HTML_WHITE"Gib unten das Badword ein, welches du hinzufügen möchtest:","Bestätigen","Zurück");
  118.                 if(strlen(inputtext) > 32) return ShowPlayerDialog(playerid, DIALOG_BADWORDADD, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword hinzufügen", ""HTML_RED"Ein Badword darf nur 32 Zeichen lang sein.\n"HTML_WHITE"Gib unten das Badword ein, welches du hinzufügen möchtest:","Bestätigen","Zurück");
  119.                 if(BadwordExists(inputtext)) return ShowPlayerDialog(playerid, DIALOG_BADWORDADD, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword hinzufügen", ""HTML_RED"Dieses Badword gibt es bereits.\n"HTML_WHITE"Gib unten das Badword ein, welches du hinzufügen möchtest:","Bestätigen","Zurück");
  120.                 if(badwords >= MAX_BADWORDS) return ShowPlayerDialog(playerid, DIALOG_BADWORDADD, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword hinzufügen", ""HTML_RED"Die maximale Anzahl an Badwords wurde bereits erreicht.\n"HTML_WHITE"Gib unten das Badword ein, welches du hinzufügen möchtest:","Bestätigen","Zurück");
  121.  
  122.                 AddBadword(playerid, inputtext);
  123.             }
  124.             else
  125.             {
  126.                 ShowPlayerDialog(playerid, DIALOG_BADWORD, DIALOG_STYLE_LIST, "Badwords: "HTML_RED"Verwaltung", "Alle Badwords anzeigen\nBadword hinzufügen\nBadword entfernen", "Auswählen", "Schliessen");
  127.             }
  128.         }
  129.         case DIALOG_BADWORDREMOVE:
  130.         {
  131.             if(response)
  132.             {
  133.                 if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_BADWORDREMOVE, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword entfernen", ""HTML_RED"Das Eingabefeld ist leer.\n"HTML_WHITE"Gib unten das Badword ein, welches du entfernen möchtest:","Bestätigen","Zurück");
  134.                 if(!BadwordExists(inputtext)) return ShowPlayerDialog(playerid, DIALOG_BADWORDREMOVE, DIALOG_STYLE_INPUT, "Badwords: "HTML_RED"Badword entfernen", ""HTML_RED"Dieses Badword gibt es nicht.\n"HTML_WHITE"Gib unten das Badword ein, welches du entfernen möchtest:","Bestätigen","Zurück");
  135.  
  136.                 RemoveBadword(playerid, inputtext);
  137.             }
  138.             else
  139.             {
  140.                 ShowPlayerDialog(playerid, DIALOG_BADWORD, DIALOG_STYLE_LIST, "Badwords: "HTML_RED"Verwaltung", "Alle Badwords anzeigen\nBadword hinzufügen\nBadword entfernen", "Auswählen", "Schliessen");
  141.             }
  142.         }
  143.     }
  144.     return 0;
  145. }
  146.  
  147. forward OnBadwordsLoad();
  148. public OnBadwordsLoad() //Badwords werden aus der Datenbank geladen
  149. {
  150.     new rows;
  151.     cache_get_row_count(rows);
  152.     if(rows == 0)
  153.     {  
  154.         print("[BADWORDS]: Es wurden 0 Badwords aus der Datenbank geladen.");
  155.         return 1;
  156.     }
  157.     else
  158.     {
  159.         for(new i; i<rows; i++)
  160.         {
  161.             cache_get_value_name(i, "Badword",BadwordInfo[i][Badword],32);
  162.             cache_get_value_name(i, "CreatedBy",BadwordInfo[i][CreatedBy],24);
  163.             BadwordInfo[i][Exists] = 1;
  164.             badwords++;
  165.         }
  166.         printf("[BADWORDS]: Es wurden %d Badwords aus der Datenbank geladen.",rows);
  167.     }
  168.     return 1;
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------------//
  172. //***** Befehle *****
  173. CMD:badwords(playerid)
  174. {
  175.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Du bist kein Admin.");
  176.  
  177.     ShowPlayerDialog(playerid, DIALOG_BADWORD, DIALOG_STYLE_LIST, "Badwords: "HTML_RED"Verwaltung", "Alle Badwords anzeigen\nBadword hinzufügen\nBadword entfernen", "Auswählen", "Schliessen");
  178.  
  179.     return 1;
  180. }
  181.  
  182. CMD:addbadword(playerid,params[])
  183. {
  184.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Du bist kein Admin.");
  185.     if(isnull(params)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "/addbadword [Badword]");
  186.     if(BadwordExists(params)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Dieses Badword existiert bereits.");
  187.     if(badwords >= MAX_BADWORDS) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Die maximale Anzahl an Badwords wurde bereits erreicht.");
  188.  
  189.     AddBadword(playerid, params);
  190.  
  191.     return 1;
  192. }
  193.  
  194. CMD:removebadword(playerid,params[])
  195. {
  196.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Du bist kein Admin.");
  197.     if(isnull(params)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "/removebadword [Badword]");
  198.     if(!BadwordExists(params)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Dieses Badword existiert nicht.");
  199.  
  200.     RemoveBadword(playerid, params);
  201.  
  202.     return 1;
  203. }
  204.  
  205. CMD:listbadwords(playerid)
  206. {
  207.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Du bist kein Admin.");
  208.     if(badwords == 0) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "BADWORDS: Es sind keine Badwords vorhanden.");
  209.  
  210.     new dialogstring[2048],string[64];
  211.     dialogstring = "Badword\tHinzugefügt von\n";
  212.  
  213.     for(new i; i<badwords+1; i++)
  214.     {
  215.         if(BadwordInfo[i][Exists] == 0) continue;
  216.         format(string,sizeof(string),"%s\t%s\n",BadwordInfo[i][Badword],BadwordInfo[i][CreatedBy]);
  217.         strcat(dialogstring, string);
  218.     }
  219.  
  220.     ShowPlayerDialog(playerid, DIALOG_BADWORDLIST, DIALOG_STYLE_TABLIST_HEADERS, "Badwords: "HTML_RED"Badwords auflisten", dialogstring, "Zurück", "");
  221.  
  222.     return 1;
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------------//
  226. //***** Funktionen/Stocks *****
  227. stock DatabaseConnect(versuch = 3) //Verbindung zur Datenbank herstellen
  228. {
  229.     mysql_log();
  230.     badword_handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DBSE);
  231.    
  232.     if(mysql_errno(badword_handle) != 0)
  233.     {
  234.         if(versuch > 1)
  235.         {
  236.             print("[BADWORDS]: Es konnte keine Verbindung zur Datenbank hergestellt werden.");
  237.             printf("[BADWORDS]: Starte neuen Verbindungsversuch (Versuch: %d).", versuch-1);
  238.             return DatabaseConnect(versuch-1);
  239.         }
  240.         else
  241.         {
  242.             print("[BADWORDS]: Es konnte keine Verbindung zur Datenbank hergestellt werden.");
  243.             print("[BADWORDS]: Bitte prüfen Sie die Verbindungsdaten.");
  244.             print("[BADWORDS]: Der Server wird heruntergefahren.");
  245.             return SendRconCommand("exit");
  246.         }
  247.     }
  248.     printf("[BADWORDS]: Die Verbindung zur Datenbank wurde erfolgreich hergestellt! Handle: %d", _:badword_handle);
  249.     mysql_query(badword_handle,"CREATE TABLE IF NOT EXISTS `"MYSQL_TABLENAME"` (`ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,`Badword` varchar(32) NOT NULL,`CreatedBy` varchar(24) NOT NULL DEFAULT 'System')");
  250.     mysql_tquery(badword_handle, "SELECT * FROM `"MYSQL_TABLENAME"`","OnBadwordsLoad");
  251.     return 1;
  252. }
  253.  
  254. AddBadword(playerid, badword[])
  255. {
  256.     new Query[96],message[96];
  257.     mysql_format(badword_handle,Query,sizeof(Query),"INSERT INTO `"MYSQL_TABLENAME"` (Badword, CreatedBy) VALUES ('%e', '%e')",badword,GetName(playerid));
  258.     mysql_tquery(badword_handle,Query);
  259.  
  260.     badwords++;
  261.     format(BadwordInfo[badwords][Badword],32,"%s",badword);
  262.     format(BadwordInfo[badwords][CreatedBy],24,"%s",GetName(playerid));
  263.     BadwordInfo[badwords][Exists] = 1;
  264.  
  265.     format(message,sizeof(message),"BADWORDS: %s hat das Badword '%s' hinzugefügt.",GetName(playerid),badword);
  266.     SendClientMessageToAll(COLOR_LIGHTBLUE, message);
  267.  
  268.     printf("[BADWORDS]: Badword '%s' von %s hinzugefügt",badword,GetName(playerid));
  269.  
  270.     return 1;
  271. }
  272.  
  273. RemoveBadword(playerid, badword[])
  274. {
  275.     new Query[96],message[96],enumid;
  276.     mysql_format(badword_handle,Query,sizeof(Query),"DELETE FROM `"MYSQL_TABLENAME"` WHERE `Badword`='%e'",badword);
  277.     mysql_tquery(badword_handle,Query);
  278.  
  279.     for(new i; i<badwords+1; i++)
  280.     {
  281.         if(!strcmp(BadwordInfo[i][Badword], badword)) enumid = i;
  282.     }
  283.     badwords--;
  284.     format(BadwordInfo[enumid][Badword],32,"");
  285.     format(BadwordInfo[enumid][CreatedBy],24,"");
  286.     BadwordInfo[enumid][Exists] = 0;
  287.  
  288.     format(message,sizeof(message),"BADWORDS: %s hat das Badword '%s' entfernt.",GetName(playerid),badword);
  289.     SendClientMessageToAll(COLOR_LIGHTBLUE, message);
  290.  
  291.     printf("[BADWORDS]: Badword '%s' von %s entfernt",badword,GetName(playerid));
  292.  
  293.     return 1;
  294. }
  295.  
  296. BadwordExists(badword[])
  297. {
  298.     for(new i; i<badwords+1; i++)
  299.     {
  300.         if(BadwordInfo[i][Exists] == 0) continue;
  301.         if(!strcmp(badword, BadwordInfo[i][Badword], true)) return true;
  302.     }
  303.     return false;
  304. }
  305.  
  306. ContainsBadword(text[])
  307. {
  308.     for(new i; i<badwords+1; i++)
  309.     {
  310.         if(BadwordInfo[i][Exists] == 0) continue;
  311.         if(strfind(text, BadwordInfo[i][Badword], true) != -1) return true;
  312.     }
  313.     return false;
  314. }
  315.  
  316. GetName(playerid)
  317. {
  318.     new PlayerName[MAX_PLAYER_NAME];
  319.     GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
  320.     return PlayerName;
  321. }
  322.  
  323. #if !defined isnull
  324.     #define isnull(%1) \
  325.                 ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  326. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top