SHOROOP

JaSNF (Just a Small Name Filter)

Aug 22nd, 2013 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.94 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #define db_name "WrongNicks.db"
  3.  
  4. #include <a_samp>
  5. #include <a_sampdb>
  6.  
  7. new DB:NicksDB;
  8. new DBResult:Result;
  9.  
  10. public OnFilterScriptInit()
  11. {
  12.     NicksDB = db_open(db_name);
  13.     db_query(NicksDB,"CREATE TABLE IF NOT EXISTS Nicks (NICK varchar)");
  14.     return 1;
  15. }
  16.  
  17. public OnFilterScriptExit ()
  18. {
  19.     db_close(NicksDB);
  20.     return 1;
  21. }
  22.  
  23. public OnPlayerConnect (playerid)
  24. {
  25.     new Nick[MAX_PLAYER_NAME];
  26.     GetPlayerName (playerid, Nick, MAX_PLAYER_NAME);
  27.     new Name[2][24];
  28.     split (Nick, Name, '_');
  29.     new query [512];
  30.     format (query, sizeof(query), "SELECT * FROM Nicks WHERE NICK LIKE '%s'", Name[0]);
  31.     Result = db_query (NicksDB, query);
  32.     if (db_num_rows(Result))
  33.     {
  34.         new Response[144];
  35.         SendClientMessage (playerid, 0xdc143cFF, "Вы были кикнуты сервером. Причина: В нике указано неполное имя.");
  36.         Kick(playerid);
  37.         format (Response, sizeof(Response), "Игрок %s кикнут сервером. Причина: В нике указано неполное имя.", Nick);
  38.         SendClientMessageToAll (0xdc143cFF, Response);
  39.     }
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerCommandText (playerid, cmdtext[])
  44. {
  45.     new cmd[256], tmp[256], idx;
  46.     cmd = strtok(cmdtext, idx);
  47.     if (!strcmp ("/addnick", cmd, true))
  48.     {
  49.         if (!IsPlayerAdmin(playerid))
  50.         {
  51.             SendClientMessage (playerid, 0xdc143cFF, "Вы не обладаете необходимыми правами доступа.");
  52.             return 1;
  53.         }
  54.         tmp = strtok(cmdtext, idx);
  55.         if (!strlen(tmp))
  56.         {
  57.             SendClientMessage (playerid, 0xdc143cFF, "Синтаксис команды: /addnick [Имя]");
  58.             return 1;
  59.         }
  60.         new query[512];
  61.         format (query, sizeof(query), "INSERT INTO Nicks (NICK) VALUES ('%s')", tmp);
  62.         db_query (NicksDB, query);
  63.         SendClientMessage (playerid, 0xdc143cFF, "Ник добавлен в базу данных.");
  64.         new TempNick[MAX_PLAYER_NAME];
  65.         for (new pid=0; pid<MAX_PLAYERS; pid++)
  66.         {
  67.             if (IsPlayerConnected(pid))
  68.             {
  69.                 GetPlayerName (pid, TempNick, MAX_PLAYER_NAME);
  70.                 new NickCheck[MAX_PLAYER_NAME];
  71.                 format (NickCheck, sizeof(NickCheck), "%s_", tmp);
  72.                 if (!strcmp (TempNick, NickCheck, true, strlen(NickCheck)))
  73.                 {
  74.                     new Response[144];
  75.                     SendClientMessage (pid, 0xdc143cFF, "Вы были кикнуты сервером. Причина: В нике указано неполное имя.");
  76.                     Kick(pid);
  77.                     format (Response, sizeof(Response), "Игрок %s кикнут сервером. Причина: В нике указано неполное имя.", TempNick);
  78.                     SendClientMessageToAll (0xdc143cFF, Response);
  79.                 }
  80.             }
  81.         }      
  82.         return 1;
  83.     }
  84.     if (!strcmp ("/removenick", cmd, true))
  85.     {
  86.         if (!IsPlayerAdmin(playerid))
  87.         {
  88.             SendClientMessage (playerid, 0xdc143cFF, "Вы не обладаете необходимыми правами доступа.");
  89.             return 1;
  90.         }
  91.         tmp = strtok(cmdtext, idx);
  92.         if (!strlen(tmp))
  93.         {
  94.             SendClientMessage (playerid, 0xdc143cFF, "Синтаксис команды: /removenick [Имя]");
  95.             return 1;
  96.         }
  97.         new query[512];
  98.         format (query, sizeof(query), "DELETE FROM Nicks WHERE NICK LIKE '%s'", tmp);
  99.         db_query (NicksDB, query);
  100.         SendClientMessage (playerid, 0xdc143cFF, "Ник удален из базы данных.");
  101.         return 1;
  102.     }
  103.     if (!strcmp ("/checknick", cmd, true))
  104.     {
  105.         if (!IsPlayerAdmin(playerid))
  106.         {
  107.             SendClientMessage (playerid, 0xdc143cFF, "Вы не обладаете необходимыми правами доступа.");
  108.             return 1;
  109.         }
  110.         tmp = strtok(cmdtext, idx);
  111.         if (!strlen(tmp))
  112.         {
  113.             SendClientMessage (playerid, 0xdc143cFF, "Синтаксис команды: /checknick [Имя]");
  114.             return 1;
  115.         }
  116.         new query[512];
  117.         format (query, sizeof(query), "SELECT * FROM Nicks WHERE NICK LIKE '%s'", tmp);
  118.         Result = db_query (NicksDB, query);
  119.         if (db_num_rows(Result)) SendClientMessage (playerid, 0xdc143cFF, "Данное имя есть в базе данных запрещенных имен.");
  120.         else SendClientMessage (playerid, 0xdc143cFF, "Данного имени в базе запрещенных имен нет.");
  121.         return 1;
  122.     }
  123.     return 0;
  124. }
  125.  
  126. //Разделение
  127. stock split(const strsrc[], strdest[][], delimiter)
  128. {
  129.     new i, li;
  130.     new aNum;
  131.     new len;
  132.     while(i <= strlen(strsrc))
  133.     {
  134.         if(strsrc[i] == delimiter || i == strlen(strsrc))
  135.         {
  136.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  137.             strdest[aNum][len] = 0;
  138.             li = i+1;
  139.             aNum++;
  140.         }
  141.         i++;
  142.     }
  143.     return 1;
  144. }
  145.  
  146. strtok(const string[], &index)
  147. {
  148.     new length = strlen(string);
  149.     while ((index < length) && (string[index] <= ' '))
  150.     {
  151.         index++;
  152.     }
  153.  
  154.     new offset = index;
  155.     new result[20];
  156.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  157.     {
  158.         result[index - offset] = string[index];
  159.         index++;
  160.     }
  161.     result[index - offset] = EOS;
  162.     return result;
  163. }
Add Comment
Please, Sign In to add comment