Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. local handler = mysql_connect("185.180.230.29", "geoip", "WTAqquYRMTQmNKvK", "geoip");
  2. local Player = {};
  3.  
  4. function OnFilterscriptInit()
  5.     MySQLInit();
  6.     test(0);
  7. end
  8.  
  9. function MySQLInit()
  10.     if not(handler) then
  11.         LogString("Logs_MySQL","Unable connect to database");
  12.     else
  13.         LogString("Logs_MySQL","Connected: ", handler);
  14.     end
  15. end
  16.  
  17. function checkMySQLConnection()
  18.     if (mysql_ping(handler) == false) then
  19.         return false;
  20.     end
  21.     return true;
  22. end
  23.  
  24. function reconnectMySQL()
  25.     LogString("Logs_MySQL","Lost connection to database. Reconnecting...");
  26.     mysql_close(handler);
  27.     handler = mysql_connect("185.180.230.29", "geoip", "WTAqquYRMTQmNKvK", "geoip");
  28. end
  29.  
  30. function OnPlayerConnect(playerid)
  31.     if IsNPC(playerid) == 0 then
  32.         if checkMySQLConnection() == true then
  33.             if IsPlayerConnected(playerid) == 1 then
  34.                 --ั…ะตั…
  35.             end
  36.         else
  37.             reconnectMySQL();
  38.         end
  39.     end
  40. end
  41.  
  42.  
  43. function test(playerid)
  44. local Player = {};
  45. Player.Row = nil;
  46.  
  47. local _ip = "70.25.96.9";
  48. local ip1,ip2,ip3,ip4 = string.match(_ip, "(%d+).(%d+).(%d+).(%d+)"); --1.0.1.0  70.25.96.95
  49.  
  50. local table_amount = "SELECT COUNT(*) FROM  `mytable` WHERE `IP1` LIKE '"..ip1..".%' AND `IP1` LIKE '%."..ip2..".%' OR `IP2` LIKE '"..ip1..".%' AND `IP2` LIKE '%."..ip2..".%'"; --70.25.96.80 - 70.25.96.95
  51.  
  52.             local result = mysql_query(handler, table_amount);
  53.             if not(result) then
  54.             else
  55.                 local rows = {};
  56.                 local amount = mysql_fetch_row(result);
  57.                 mysql_free_result(result);
  58.                 result = mysql_query ( handler, "SELECT * FROM  `mytable` WHERE `IP1` LIKE '"..ip1..".%' AND `IP1` LIKE '%."..ip2..".%' OR `IP2` LIKE '"..ip1..".%' AND `IP2` LIKE '%."..ip2..".%'");
  59.                 for i = 1, amount[1] do
  60.                     local row = mysql_fetch_assoc(result);
  61.                     table.insert(rows, row);
  62.                         for key,value in pairs(rows) do
  63.                             local q1,q2,q3,q4 = string.match(rows[key]["IP1"], "(%d+).(%d+).(%d+).(%d+)");
  64.                             local s1,s2,s3,s4 = string.match(rows[key]["IP2"], "(%d+).(%d+).(%d+).(%d+)");
  65.                             if ((ip1 >= q1 and ip1 <= s1) and (ip2 >= q2 and ip2 <= s2) and (ip3 >= q3 and ip3 <= s3) and (ip4 >= q4 and ip4 <= s4)) then
  66.                                 LogString("GeoIP_Log","IP ".._ip.." founded. It belongs to "..rows[key]["country_name"]..".");
  67.                             else
  68.                                 LogString("GeoIP_Log","IP ".._ip.." not founded.");
  69.                             end
  70.                                
  71.                         end
  72.                        
  73.                 end
  74.                 mysql_free_result(result);
  75.             end
  76.        
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement