Advertisement
Jigsaw_

JigBan

Jun 3rd, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.93 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <zcmd>
  4. #include <sscanf2>
  5.  
  6. #define UNBAN_TYPE_ACCOUNT (1)
  7. #define UNBAN_TYPE_IP (2)
  8.  
  9. new
  10.     jDB,
  11.     jString[200],
  12.     jData[MAX_PLAYERS][2][24],
  13.     bool:jBlock[MAX_PLAYERS]
  14. ;
  15.  
  16. forward @banPlayer(playerid, adminname[], reason[]);
  17. forward @checkBan(playerid);
  18. forward @checkForUnban(playerid, type, value[]);
  19. forward @submitUnban(playerid, type, value[]);
  20.  
  21. public OnFilterScriptInit() {
  22.     jDB = mysql_connect("localhost", "root", "jigBanSystem", "");
  23.     if(mysql_ping(jDB) < 1)
  24.         return SendRconCommand("unloadfs jigBan");
  25.  
  26.     print("\n------------------------------");
  27.     print("        Ban System");
  28.     print(" Copyright (c) 2012 Jigsaw`");
  29.     print("------------------------------\n");
  30.     return 1;
  31. }
  32.  
  33. public OnFilterScriptExit() {
  34.     mysql_close(jDB);
  35.     return 1;
  36. }
  37.  
  38. public OnPlayerConnect(playerid) {
  39.     GetPlayerName(playerid, jData[playerid][0], 24);
  40.     GetPlayerIp(playerid, jData[playerid][1], 24);
  41.    
  42.     checkBan(playerid);
  43.     return 1;
  44. }
  45.  
  46. public OnPlayerSpawn(playerid) {
  47.     if(jBlock[playerid])
  48.         return Kick(playerid);
  49.        
  50.     return 1;
  51. }
  52.  
  53. stock banPlayer(playerid, adminname[], reason[]) {
  54.     if(strlen(reason) > 64)
  55.         return 0;
  56.  
  57.     getdate(jString[2], jString[1], jString[0]);
  58.     gettime(jString[3], jString[4], jString[5]);
  59.     format(jString, 32, "%02d/%02d/%d - %02d:%02d:%02d", jString[0], jString[1], jString[2], jString[3], jString[4], jString[5]);
  60.  
  61.     mysql_format(jDB, jString, "INSERT INTO `jigBan` (`Name`,`Admin`,`Reason`,`DateAndHour`,`IP`) VALUES ('%s','%s','%s','%s','%s')",
  62.         jData[playerid][0],
  63.         adminname,
  64.         reason,
  65.         jString,
  66.         jData[playerid][1]
  67.     );
  68.     mysql_function_query(jDB, jString, false, "@banPlayer", "iss", playerid, adminname, reason);
  69.     return 1;
  70. }
  71.  
  72. public @banPlayer(playerid, adminname[], reason[]) {
  73.     format(jString, sizeof jString, "%s{FFFFFF} foi banido por {1E90FF}%s {E31919}(%s)", jData[playerid][0], adminname, reason);
  74.     SendClientMessageToAll(0x1E90FFFF, jString);
  75.     Kick(playerid);
  76.     return 1;
  77. }
  78.  
  79. stock checkBan(playerid) {
  80.     mysql_format(jDB, jString, "SELECT * FROM `jigBan` WHERE `Name` = '%s' OR `IP` = '%s'", jData[playerid][0], jData[playerid][1]);
  81.     mysql_function_query(jDB, jString, true, "@checkBan", "i", playerid);
  82.     return 1;
  83. }
  84.  
  85. public @checkBan(playerid) {
  86.     new
  87.         jRows,
  88.         jFields
  89.     ;
  90.        
  91.     cache_get_data(jRows, jFields, jDB);
  92.    
  93.     if(!jRows)
  94.         return 1;
  95.    
  96.     SendClientMessage(playerid, 0xE31919FF, "(!) Você possui registros de banimento!");
  97.    
  98.     cache_get_field_content(0, "Name", jString, jDB);
  99.     format(jString, sizeof jString, "Conta: {1E90FF}%s", jString);
  100.     SendClientMessage(playerid, 0xFFFFFFFF, jString);
  101.  
  102.     cache_get_field_content(0, "Admin", jString, jDB);
  103.     format(jString, sizeof jString, "Admin: {1E90FF}%s", jString);
  104.     SendClientMessage(playerid, 0xFFFFFFFF, jString);
  105.  
  106.     cache_get_field_content(0, "Reason", jString, jDB);
  107.     format(jString, sizeof jString, "Motivo: {1E90FF}%s", jString);
  108.     SendClientMessage(playerid, 0xFFFFFFFF, jString);
  109.  
  110.     cache_get_field_content(0, "DateAndHour", jString, jDB);
  111.     format(jString, sizeof jString, "Data - Hora: {1E90FF}%s", jString);
  112.     SendClientMessage(playerid, 0xFFFFFFFF, jString);
  113.  
  114.     cache_get_field_content(0, "IP", jString, jDB);
  115.     format(jString, sizeof jString, "IP: {1E90FF}%s", jString);
  116.     SendClientMessage(playerid, 0xFFFFFFFF, jString);
  117.  
  118.     jBlock[playerid] = true;
  119.     return 1;
  120. }
  121.  
  122. stock checkForUnban(playerid, type, value[]) {
  123.     switch(type) {
  124.         case UNBAN_TYPE_ACCOUNT: {
  125.             mysql_format(jDB, jString, "SELECT * FROM `jigBan` WHERE `Name` = '%s'", value);
  126.             mysql_function_query(jDB, jString, true, "@checkForUnban", "iis", playerid, type, value);
  127.         }
  128.         case UNBAN_TYPE_IP: {
  129.             mysql_format(jDB, jString, "SELECT * FROM `jigBan` WHERE `IP` = '%s'", value);
  130.             mysql_function_query(jDB, jString, true, "@checkForUnban", "iis", playerid, type, value);
  131.         }
  132.     }
  133.     return 1;
  134. }
  135.  
  136. public @checkForUnban(playerid, type, value[]) {
  137.     new
  138.         jRows,
  139.         jFields
  140.     ;
  141.    
  142.     cache_get_data(jRows, jFields, jDB);
  143.     if(jRows > 0) {
  144.         mysql_format(jDB, jString, "DELETE FROM `jigBan` WHERE `%s` = '%s'", (type == 1) ? ("Name") : ("IP"), value);
  145.         mysql_function_query(jDB, jString, false, "@submitUnban", "iis", playerid, type, value);
  146.         return 1;
  147.     }
  148.     SendClientMessage(playerid, 0xF6F600FF, "(!) Nenhum registro de banimento encontrado.");
  149.     return 1;
  150. }
  151.  
  152. public @submitUnban(playerid, type, value[]) {
  153.     format(jString, sizeof(jString), "O %s {1E90FF}%s{FFFFFF} foi desbanido por {1E90FF}%s.", (type == 1) ? ("jogador") : ("ip"), value, jData[playerid][0]);
  154.     SendClientMessageToAll(0xFFFFFFFF, jString);
  155.     return 1;
  156. }
  157.  
  158. // Comandos
  159.  
  160. CMD:ban(playerid, params[]) {
  161.     if(!IsPlayerAdmin(playerid))
  162.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Somente admins rcon.");
  163.        
  164.     new
  165.         jBanID,
  166.         jBanReason[64]
  167.     ;
  168.    
  169.     if(sscanf(params, "us[64]", jBanID, jBanReason))
  170.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Use /ban <ID/Nome> <Motivo>");
  171.     if(!IsPlayerConnected(jBanID) || jBanID == INVALID_PLAYER_ID)
  172.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Jogador inativo.");
  173.     if(isnull(jBanReason))
  174.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Por favor especifique o motivo pelo qual está banindo este jogador.");
  175.        
  176.     banPlayer(jBanID, jData[playerid][0], jBanReason);
  177.     return 1;
  178. }
  179.  
  180. CMD:desban(playerid, params[]) {
  181.     if(!IsPlayerAdmin(playerid))
  182.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Somente admins rcon.");
  183.  
  184.     new
  185.         jBanType,
  186.         jBanValue[24]
  187.     ;
  188.    
  189.     if(sscanf(params, "is[24]", jBanType, jBanValue))
  190.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Use /desban <Tipo [1 = Conta] [2 = IP]> <Nome ~ IP>");
  191.     if(UNBAN_TYPE_ACCOUNT < jBanType > UNBAN_TYPE_IP)
  192.         return 1;
  193.     if(isnull(jBanValue))
  194.         return SendClientMessage(playerid, 0xFFFFFFFF, "(!) Especifique o Nome/IP");
  195.        
  196.     checkForUnban(playerid, jBanType, jBanValue);
  197.     return 1;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement