Advertisement
proSeryoga

Untitled

Feb 11th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.86 KB | None | 0 0
  1.  
  2.  
  3. #include <a_samp>
  4. #include <sscanf>
  5.  
  6. #define DIALOG_BANLIST 500 // Ваш ID диалога банлиста
  7. #define DIALOG_UNBAN 501 // Ваш ID диалога разбана
  8.  
  9. new DB:ServerDB,
  10.     year, month, day,
  11.     UBDay, UBHour, UBMin, UBSec, UBMSec, bool:plban[MAX_PLAYERS],
  12.     sendername[32], giveplayer[32], str[255],
  13.     player[MAX_PLAYERS];
  14.  
  15. public OnFilterScriptInit()
  16. {
  17.     if(fexist("bans.db")) ServerDB = db_open("bans.db");
  18.     else
  19.     {
  20.         ServerDB = db_open("bans.db");
  21.         db_query(ServerDB, "CREATE TABLE bans (name varchar, ip varchar, bandate varchar, time int, unbandate int, reason varchar)");
  22.     }
  23.     SetTimer("CheckBans", 1000, 1);
  24.     return true;
  25. }
  26.  
  27. public OnPlayerConnect(playerid)
  28. {
  29.     CheckBanList(playerid);
  30.     return true;
  31. }
  32.  
  33. public OnPlayerDisconnect(playerid)
  34. {
  35.     plban[playerid] = false;
  36.     player[playerid] = 0;
  37.     return true;
  38. }
  39.  
  40. public OnPlayerCommandText(playerid, cmdtext[])
  41. {
  42.     new cmd[32], params[128];
  43.     sscanf(cmdtext, "s[32]s[128]", cmd, params);
  44.    
  45.     if(!strcmp(cmd, "/ban", true))
  46.     {
  47.         if(!IsPlayerAdmin(playerid)) return true;
  48.         new giveplayerid, days, text[255], ip[32], date[32], unbandate;
  49.         if(sscanf(params, "uds", giveplayerid, days, text)) return SendClientMessage(playerid, 0xFF0000AA, "{FFFF00}*Подсказка*: {FFFFFF}/ban [ID игрока] [Кол-во дней] [Причина]");
  50.         if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "{FFFF00}*Внимание*: {FFFFFF}данный игрок не в сети");
  51.         GetPlayerName(playerid, sendername, 32);
  52.         GetPlayerName(giveplayerid, giveplayer, 32);
  53.         GetPlayerIp(giveplayerid, ip, 32);
  54.         format(str, sizeof(str), "{FFFF00}* {%06x}%s(%d) {00FF00}забанен администрацией сервера. {BF00FF}Срок бана в днях: {FFFFFF}%d. {BF00FF}Причина: {FFFFFF}%s {FFFF00}*", GetPlayerColor(giveplayerid) >>> 8, giveplayer, giveplayerid, days, text);
  55.         SendClientMessageToAll(0xFF0000AA, str);
  56.         plban[giveplayerid] = true;
  57.         unbandate = gettime() + days*86400;
  58.         format(date, 32, "%02d.%02d.%04d", day, month, year);
  59.         format(str, sizeof(str), "INSERT INTO bans (name, ip, bandate, time, unbandate, reason) VALUES ('%s', '%s', '%s', %d, %d, '%s')", giveplayer, ip, date, days, unbandate, text);
  60.         db_query(ServerDB, str);
  61.         return true;
  62.     }
  63.  
  64.     if(!strcmp(cmd, "/unban", true))
  65.     {
  66.         if(!IsPlayerAdmin(playerid)) return true;
  67.         new text[32], DBResult:answer;
  68.         if(sscanf(params, "s", text)) return SendClientMessage(playerid, 0xFF0000AA, "{FFFF00}*Подсказка*: {FFFFFF}/unban [ID игрока]");
  69.         format(str, sizeof(str), "SELECT * FROM bans WHERE name = '%s'", text);
  70.         answer = db_query(ServerDB, str);
  71.         if(!db_num_rows(answer)) return SendClientMessage(playerid, 0xFF0000AA, "{FFFF00}*Внимание*: {FFFFFF}Данного игрока нет в бан листе!");
  72.         format(str, sizeof(str), "DELETE FROM bans WHERE name = '%s'", text);
  73.         db_query(ServerDB, str);
  74.         format(str, sizeof(str), "{00FF00}Вы разбанили {FFFFFF}%s", text);
  75.         SendClientMessage(playerid, 0xFF0000AA, str);
  76.         db_free_result(answer);
  77.         return true;
  78.     }
  79.  
  80.     if(!strcmp(cmd, "/banlist", true))
  81.     {
  82.         if(!IsPlayerAdmin(playerid)) return true;
  83.         new DBResult:answer, rows, banlist[1000];
  84.         new name[32], ip[32];
  85.         answer = db_query(ServerDB, "SELECT name, ip FROM bans");
  86.         rows = db_num_rows(answer);
  87.         for(new i; i<rows; i++)
  88.         {
  89.             db_get_field(answer, 0, name, 32);
  90.             db_get_field(answer, 1, ip, 32);
  91.             format(str, sizeof(str), "{FF0000}%s {FFFF00}(%s)\n", name, ip);
  92.             strcat(banlist, str);
  93.             db_next_row(answer);
  94.         }
  95.         ShowPlayerDialog(playerid, DIALOG_BANLIST, DIALOG_STYLE_LIST, "БанЛист", banlist, "Выбрать", "Закрыть");
  96.         db_free_result(answer);
  97.         return true;
  98.     }
  99.  
  100.     if(!strcmp(cmd, "/cbanlist", true))
  101.     {
  102.         if(!IsPlayerAdmin(playerid)) return true;
  103.         format(str, sizeof(str), "DELETE FROM bans WHERE unbandate < %d", getdate());
  104.         db_query(ServerDB, str);
  105.         SendClientMessage(playerid, 0xFF0000AA, "Чистка выполнена");
  106.         return true;
  107.     }
  108.     return 0;
  109. }
  110.  
  111. stock convert(time, &min, &sec, &msec)
  112. {
  113.     new Float:fTime = floatdiv(time, 60000);
  114.     min = floatround(fTime, floatround_tozero);
  115.     sec = floatround(floatmul(fTime - min, 60), floatround_tozero);
  116.     msec = floatround(floatmul(floatmul(fTime - min, 60) - sec, 1000), floatround_tozero);
  117. }
  118.  
  119. stock CheckBanList(playerid)
  120. {
  121.     new DBResult:answer, var[32], unbandate, bool:ban, ip[32];
  122.     GetPlayerName(playerid, sendername, 32);
  123.     GetPlayerIp(playerid, ip, 32);
  124.     format(str, sizeof(str), "SELECT * FROM bans WHERE name = '%s'", sendername);
  125.     answer = db_query(ServerDB, str);
  126.     if(db_num_rows(answer))
  127.     {
  128.         db_get_field(answer, 4, var, 32);
  129.         unbandate = strval(var);
  130.         if(unbandate - gettime() > 0) ban = true;
  131.     }
  132.    
  133.     if(!ban)
  134.     {
  135.         format(str, sizeof(str), "SELECT * FROM bans WHERE ip = '%s'", ip);
  136.         answer = db_query(ServerDB, str);
  137.         if(db_num_rows(answer))
  138.         {
  139.             db_get_field(answer, 4, var, 32);
  140.             unbandate = strval(var);
  141.             if(unbandate - gettime() > 0) ban = true;
  142.         }
  143.     }
  144.    
  145.     if(ban)
  146.     {
  147.         convert((unbandate-gettime())*1000,UBMin,UBSec,UBMSec);
  148.         UBHour = UBMin/60;
  149.         UBMin = UBMin%60;
  150.         UBDay = UBHour/24;
  151.         UBHour = UBHour%24;
  152.         format(str, sizeof(str), "{FF0000}Ваш аккаунт заблокирован! {FFFF00}До разбана осталось {FFFFFF}%d дней %d часов %d минут {FFFF00}и {FFFFFF}%d секунд", UBDay, UBHour, UBMin, UBSec);
  153.         SendClientMessage(playerid, 0xFF0000FF, str);
  154.         Kick(playerid);
  155.     }
  156.     return true;
  157. }
  158.  
  159. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  160. {
  161.     if(dialogid == DIALOG_BANLIST && response)
  162.     {
  163.         new dialog[500], DBResult:answer,
  164.             name[32], ip[32], bandate[32], time, unbandate, reason[255], var[32];
  165.         answer = db_query(ServerDB, "SELECT * FROM bans");
  166.         for(new i; i<listitem; i++) db_next_row(answer);
  167.         db_get_field(answer, 0, name, 32);
  168.         db_get_field(answer, 1, ip, 32);
  169.         db_get_field(answer, 2, bandate, 32);
  170.         db_get_field(answer, 3, var, 32); time = strval(var);
  171.         db_get_field(answer, 4, var, 32); unbandate = strval(var);
  172.         db_get_field(answer, 5, reason, 255);
  173.         player[playerid] = listitem;
  174.         convert((unbandate-gettime())*1000,UBMin,UBSec,UBMSec);
  175.         UBHour = UBMin/60;
  176.         UBMin = UBMin%60;
  177.         UBDay = UBHour/24;
  178.         UBHour = UBHour%24;
  179.         format(str, sizeof(str), "{FFFF00}Ник: {FFFFFF}%s. {FFFF00}IP: {FFFFFF}%s\n", name, ip);
  180.         strcat(dialog, str);
  181.         format(str, sizeof(str), "{FFFF00}Дата бана: {FFFFFF}%s\n", bandate);
  182.         strcat(dialog, str);
  183.         format(str, sizeof(str), "{FFFF00}Срок бана: {FFFFFF}%d\n", time);
  184.         strcat(dialog, str);
  185.         format(str, sizeof(str), "{FFFF00}Разбан через: {FFFFFF}%d дней и %d часов\n", UBDay, UBHour);
  186.         strcat(dialog, str);
  187.         format(str, sizeof(str), "{FFFF00}Причина бана: {FFFFFF}%s", reason);
  188.         strcat(dialog, str);
  189.         ShowPlayerDialog(playerid, DIALOG_UNBAN, DIALOG_STYLE_MSGBOX, "БанЛист", dialog, "Закрыть", "Разбанить");
  190.         db_free_result(answer);
  191.         return true;
  192.     }
  193.     if(dialogid == DIALOG_UNBAN && !response)
  194.     {
  195.         new DBResult:answer, name[32];
  196.         answer = db_query(ServerDB, "SELECT name FROM bans");
  197.         for(new i; i<player[playerid]; i++) db_next_row(answer);
  198.         db_get_field(answer, 0, name, 32);
  199.         format(str, sizeof(str), "DELETE FROM bans WHERE name = '%s'", name);
  200.         db_query(ServerDB, str);
  201.         SendClientMessage(playerid, 0xFF0000AA, "Аккаунт разблокирован!");
  202.         db_free_result(answer);
  203.         return true;
  204.     }
  205.     return false;
  206. }
  207.  
  208. forward CheckBans();
  209. public CheckBans()
  210. {
  211.     for(new i; i<GetMaxPlayers(); i++)
  212.     {
  213.         if(IsPlayerConnected(i) && plban[i] == true) Kick(i);
  214.     }
  215.     return true;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement