LUA 237
V2+ Unique ID 2.0 By xdedeone on 26th February 2019 05:23:03 PM
  1. --[[
  2.         Creator: AelitePrime
  3.         Script Name: Unique ID Script
  4.         Website: http://phasorscripts.wordpress.com/
  5.         Xfire: eliteprime14789x
  6.         Version: 2.0
  7.        
  8.         Reason for Update:
  9.                 - Phasor Update
  10. ]]
  11. -- Modify
  12.  
  13. max_history = 25
  14.  
  15. -- Do not Modify
  16.  
  17. history = {}
  18. players = 0
  19. history_count = 0
  20. player_ids = {}
  21. unique_ids = {}
  22.  
  23. function GetRequiredVersion()
  24.         return 200
  25. end
  26.  
  27. function OnScriptLoad(process, game, persistent)
  28.         profilepath = getprofilepath()
  29.         local file = io.open(profilepath .. "//data//uniqueids.data","r")
  30.         if file then
  31.                 for line in file:lines() do
  32.                         if line ~= nil then
  33.                                 local words = tokenizestring(line, ",")
  34.                                 settable(words[1], words[2], words[3], words[5], words[6], tonumber(words[4]))
  35.                                 players = tonumber(words[4])
  36.                         end
  37.                 end
  38.                 players = players + 1
  39.                 file:close()
  40.         end
  41.         for player=0,15 do
  42.                 if getplayer(player) then
  43.                         local name = getname(player)
  44.                         local hash = gethash(player)
  45.                         local ip = getip(player)
  46.                         player_ids[player] = players
  47.                         local bool = true
  48.                         for i=0,#unique_ids do
  49.                                 if unique_ids[i] then
  50.                                         local words = tokenizestring(unique_ids[i].ip, ".")
  51.                                         unique_ids[i].ip2 =  words[1] .."."..words[2]
  52.                                         local ip2 = string.sub(ip, 0, string.len(unique_ids[i].ip2))
  53.                                         if unique_ids[i].ip == ip or unique_ids[i].name == name or unique_ids[i].hash == hash or unique_ids[i].ip2 == ip2 then
  54.                                                 if unique_ids[i].ip == ip then
  55.                                                         player_ids[player] = i
  56.                                                         bool = false
  57.                                                         break
  58.                                                 elseif unique_ids[i].name == name and unique_ids[i].hash == hash then
  59.                                                         player_ids[player] = i
  60.                                                         bool = false
  61.                                                         break
  62.                                                 elseif ip2 == unique_ids[i].ip2 and hash == unique_ids[i].hash or name == unique_ids[i].name then
  63.                                                         player_ids[player] = i
  64.                                                         bool = false
  65.                                                         break
  66.                                                 end
  67.                                         end
  68.                                 end
  69.                         end
  70.                         playerid = player_ids[player]
  71.                         if bool then
  72.                                 settable(name, hash, ip, "false", 0, playerid)
  73.                                 players = players + 1
  74.                         else
  75.                                 if unique_ids[playerid].banned == "true" then
  76.                                         settable(name, hash, ip, "true", unique_ids[playerid].time, playerid)
  77.                                         IDban(player)
  78.                                 else
  79.                                         settable(name, hash, ip, "false", 0, playerid)
  80.                                 end
  81.                         end
  82.                 end
  83.         end
  84.         timer = registertimer(990, "Timer")
  85. end
  86.  
  87. function OnScriptUnload()
  88.         local file = io.open(profilepath .. "//data//uniqueids.data","w")
  89.         for i = 0,#unique_ids do
  90.                 if unique_ids[i] then
  91.                         file:write(unique_ids[i].name.. "," .. unique_ids[i].hash .. "," .. unique_ids[i].ip .. "," .. unique_ids[i].id .. "," .. unique_ids[i].banned .. "," .. unique_ids[i].time .."\n")
  92.                 end
  93.         end
  94. end
  95.  
  96. function OnGameEnd(stage)
  97.         if stage == 1 and timer then
  98.                 removetimer(timer)
  99.                 timer = nil
  100.         end
  101. end
  102.  
  103. function OnServerCommand(player, command)
  104.         local response = nil
  105.         local t = tokenizecmdstring(command)
  106.         local count = #t
  107.         t[1] = string.lower(t[1])
  108.         if t[1] == "sv_banid" then
  109.                 response = false
  110.                 Command_UniqueIDBan(player, t[1], t[2], t[3], count)
  111.         elseif t[1] == "sv_playersids" then
  112.                 response = false
  113.                 Command_UniqudIDPlayersList(player, t[1], count)
  114.         elseif t[1] == "sv_search" then
  115.                 response = false
  116.                 Command_Search(player, t[1], t[2], count)
  117.         elseif t[1] == "sv_history" then
  118.                 response = false
  119.                 Command_History(player, t[1], count)
  120.         elseif t[1] == "sv_idbanlist" then
  121.                 response = false
  122.                 Command_UniqueIDBanlist(player, t[1], count)
  123.         elseif t[1] == "sv_unbanid" then
  124.                 response = false
  125.                 Command_UniqueIDunban(player, t[1], t[2], count)
  126.         elseif t[1] == "sv_cmds" then
  127.                 response = false
  128.                 sendresponse("sv_banid  |  sv_unbanid  |  sv_playersids\nsv_idbanlist  |  sv_search  |  sv_history", player)
  129.         end
  130.         return response
  131. end
  132.  
  133. function OnPlayerJoin(player)
  134.         local name = getname(player)
  135.         local hash = gethash(player)
  136.         local ip = getip(player)
  137.         player_ids[player] = players
  138.         local bool = true
  139.         for i=0,#unique_ids do
  140.                 if unique_ids[i] then
  141.                         local words = tokenizestring(unique_ids[i].ip, ".")
  142.                         unique_ids[i].ip2 =  words[1] .."."..words[2]
  143.                         local ip2 = string.sub(ip, 0, string.len(unique_ids[i].ip2))
  144.                         if unique_ids[i].ip == ip or unique_ids[i].name == name or unique_ids[i].hash == hash or unique_ids[i].ip2 == ip2 then
  145.                                 if unique_ids[i].ip == ip then
  146.                                         player_ids[player] = i
  147.                                         bool = false
  148.                                         break
  149.                                 elseif unique_ids[i].name == name and unique_ids[i].hash == hash then
  150.                                         player_ids[player] = i
  151.                                         bool = false
  152.                                         break
  153.                                 elseif ip2 == unique_ids[i].ip2 and hash == unique_ids[i].hash or name == unique_ids[i].name then
  154.                                         player_ids[player] = i
  155.                                         bool = false
  156.                                         break
  157.                                 end
  158.                         end
  159.                 end
  160.         end
  161.         playerid = player_ids[player]
  162.         if bool then
  163.                 settable(name, hash, ip, "false", 0, playerid)
  164.                 players = players + 1
  165.         else
  166.                 if unique_ids[playerid].banned == "true" then
  167.                         settable(name, hash, ip, "true", unique_ids[playerid].time, playerid)
  168.                         IDban(player)
  169.                 else
  170.                         settable(name, hash, ip, "false", 0, playerid)
  171.                 end
  172.         end
  173. end
  174.  
  175. function OnPlayerLeave(player)
  176.         if unique_ids[player_ids[player]].banned == "false" then
  177.                 if history_count >= max_history then
  178.                         history_count = 0
  179.                 end
  180.                 history[history_count] = {}
  181.                 history[history_count].name = getname(player)
  182.                 history[history_count].hash = gethash(player)
  183.                 history[history_count].ip = getip(player)
  184.                 history[history_count].id = player_ids[player]
  185.                 history_count = history_count + 1
  186.         end
  187.         player_ids[player] = nil
  188. end
  189.  
  190. function IDban(player)
  191.         local hash = gethash(player)
  192.         svcmd("sv_ban " .. resolveplayer(player))
  193.         local file = io.open(profilepath .. "\\banned.txt", "r")
  194.         if file then
  195.                 local Lines = 0
  196.                 for line in file:lines() do
  197.                         Lines = Lines + 1
  198.                         if line and line ~= "" then
  199.                                 if string.find(line, hash) then
  200.                                         svcmd("sv_unban " .. Lines - 2)
  201.                                 end
  202.                         end
  203.                 end
  204.         end
  205. end
  206.  
  207. function Command_History(executor, command, count)
  208.         if count == 1 then
  209.                 local response = "ID  |  Name\n"
  210.                 for i=0,max_history do
  211.                         if history[i] then
  212.                                 response = response .. "" .. history[i].id .. "  |  " .. history[i].name .. "\n"
  213.                         end
  214.                 end
  215.                 sendresponse(response, executor)
  216.         else
  217.                 sendresponse("Invalid Syntax " .. command, executor)
  218.         end
  219. end
  220.  
  221. function Command_Search(executor, command, value, count)
  222.         if count == 2 then
  223.                 local response = "ID  |  Name\n"
  224.                 local bool = true
  225.                 for i=0,players-1 do
  226.                         if unique_ids[i] then
  227.                                 if string.len(value) == 32 then
  228.                                         if unique_ids[i].hash == value then
  229.                                                 response = response .. "\n" .. i .. "  |  " .. unique_ids[i].name  .. "  |  " .. unique_ids[i].ip
  230.                                                 bool = false
  231.                                         end
  232.                                 else
  233.                                         if unique_ids[i].name == value then
  234.                                                 response = response .. "\n" .. i .. "  |  " .. unique_ids[i].name  .. "  |  " .. unique_ids[i].hash
  235.                                                 bool = false
  236.                                         end
  237.                                 end
  238.                         end
  239.                 end
  240.                 if bool then
  241.                         response = "No Results found!"
  242.                 end
  243.                 sendresponse(response, executor)
  244.         else
  245.                 sendresponse("Invalid Syntax " .. command .." [name or hash] ", executor)
  246.         end
  247. end
  248.  
  249. function Command_UniqueIDBan(executor, command, id, time, count)
  250.         if count == 2 or time then
  251.                 id = tonumber(id)
  252.                 if id and id <= players-1 then
  253.                         local bool = true
  254.                         if unique_ids[id] then
  255.                                 if unique_ids[id].banned == "false" then
  256.                                         local player = playeridtoplayer(id)
  257.                                         unique_ids[id].banned = "true"
  258.                                         time = wordtotime(time) or -1
  259.                                         unique_ids[id].time = time
  260.                                         IDban(player)
  261.                                 else
  262.                                         bool = false
  263.                                 end
  264.                                 if bool then
  265.                                         if time == -1 then
  266.                                                 sendresponse(unique_ids[id].name .. " has been banned indefinitely!", executor)
  267.                                         else
  268.                                                 sendresponse(unique_ids[id].name .. " has been banned for " .. timetoword(time) .. "!", executor)
  269.                                         end
  270.                                 else
  271.                                         sendresponse("That ID has already been banned!", executor)
  272.                                 end
  273.                         else
  274.                                 sendresponse("That ID is not in use.", executor)
  275.                         end
  276.                 else
  277.                         sendresponse("Invalid Unique ID!", executor)
  278.                 end
  279.         else
  280.                 sendresponse("Invalid Syntax " .. command .." [ID] {time} ", executor)
  281.         end
  282. end
  283.  
  284. function Command_UniqueIDunban(executor, command, ID, count)
  285.         if count == 2 then
  286.                 ID = tonumber(ID)
  287.                 if ID and ID <= players-1 then
  288.                         if unique_ids[ID] then
  289.                                 if unique_ids[ID].banned == "true" then
  290.                                         unique_ids[ID].banned = "false"
  291.                                         unique_ids[ID].time = 0
  292.                                         sendresponse(unique_ids[ID].name .. " is now unbanned.", executor)
  293.                                 else
  294.                                         sendresponse(unique_ids[ID].name .. " is not banned.", executor)
  295.                                 end
  296.                         else
  297.                                 sendresponse("That ID is not in use.", executor)
  298.                         end
  299.                 else
  300.                         sendresponse("Invalid Unique ID!", executor)
  301.                 end
  302.         else
  303.                 sendresponse("Invalid Syntax " .. command .." [ID] ", executor)
  304.         end
  305. end
  306.  
  307. function Command_UniqueIDBanlist(executor, command, count)
  308.         if count == 1 then
  309.                 local response = "ID  |  Name  |  Time\n"
  310.                 for i=0,players-1 do
  311.                         if unique_ids[i] then
  312.                                 if unique_ids[i].banned == "true" then
  313.                                         response = response .. i .. "  |  " .. unique_ids[i].name .. "  |  " .. timetoword(unique_ids[i].time) .."\n"
  314.                                 end
  315.                         end
  316.                 end
  317.                 sendresponse(response, executor)
  318.         else
  319.                 sendresponse("Invalid Syntax " .. command, executor)
  320.         end
  321. end
  322.  
  323. function Command_UniqudIDPlayersList(executor, command, count)
  324.         if count == 1 then
  325.                 local response = "ID  |  Name\n"
  326.                 for i= 0,15 do
  327.                         if getplayer(i) then
  328.                                 local name = getname(i)
  329.                                 response = response .. "" .. player_ids[i] .. "  |  " .. name .. "\n"
  330.                         end
  331.                 end
  332.                 sendresponse(response, executor)
  333.         else
  334.                 sendresponse("Invalid Syntax " .. command, executor)
  335.         end
  336. end
  337.  
  338. function playeridtoplayer(playerid)
  339.         for i=0,15 do
  340.                 if getplayer(i) then
  341.                         if playerid == player_ids[i] then
  342.                                 return i
  343.                         end
  344.                 end
  345.         end
  346. end
  347.  
  348. function sendresponse(message, player)
  349.         if message == "" then
  350.                 return
  351.         end
  352.         player = tonumber(player)
  353.         if tonumber(player) and player ~= nil and player ~= -1 and player >= 0 and player < 16 then
  354.                 sendconsoletext(player, message)
  355.         else
  356.                 hprintf(message)
  357.         end
  358. end
  359.  
  360. function settable(name, hash, ip, boolean, time, id)
  361.         unique_ids[id] = {}
  362.         unique_ids[id].name = name
  363.         unique_ids[id].hash = hash
  364.         unique_ids[id].ip = ip
  365.         unique_ids[id].banned = boolean
  366.         unique_ids[id].time = tonumber(time)
  367.         unique_ids[id].id = id
  368. end
  369.  
  370. function Timer(id, count)
  371.         for i=0,players-1 do
  372.                 if unique_ids[i] then
  373.                         if unique_ids[i].banned == "true" and unique_ids[i].time > 0 then
  374.                                 unique_ids[i].time = unique_ids[i].time - 1
  375.                                 if unique_ids[i].time == 0 then
  376.                                         unique_ids[i].banned = "false"
  377.                                 end
  378.                         end
  379.                 end
  380.         end
  381.         return true
  382. end
  383.  
  384. function timetoword(time)
  385.         if time == -1 or time == "-1" then
  386.                 return -1
  387.         elseif tonumber(time) then
  388.                 local returntime = ""
  389.                 local seconds = tonumber(time)
  390.                 local days = math.floor(seconds/86400)
  391.                 seconds = seconds - days*86400
  392.                 local hours = math.floor(seconds/3600)
  393.                 seconds = seconds - hours*3600
  394.                 local minutes = math.floor(seconds/60)
  395.                 seconds = seconds - minutes*60
  396.                 if seconds ~= 0 then
  397.                         returntime = seconds .. "s"
  398.                 end
  399.                 if minutes ~= 0 then
  400.                         if returntime == "" then
  401.                                 returntime = minutes .. "m"
  402.                         else
  403.                                 returntime = minutes .. "m " .. returntime
  404.                         end
  405.                 end
  406.                 if hours ~= 0 then
  407.                         if returntime == "" then
  408.                                 returntime = hours .. "h"
  409.                         else
  410.                                 returntime = hours .. "h " .. returntime
  411.                         end
  412.                 end
  413.                 if days ~= 0 then
  414.                         if returntime == "" then
  415.                                 returntime = days .. "d"
  416.                         else
  417.                                 returntime = days .. "d " .. returntime
  418.                         end
  419.                 end
  420.                 if returntime == "" then
  421.                         returntime = "0s"
  422.                 end
  423.                 return returntime
  424.         end
  425. end
  426.  
  427. function wordtotime(time) -- Function Originally created by Nuggets, modified to work for this script.
  428.         if time then
  429.                 if tonumber(time) then
  430.                         return tonumber(time)
  431.                 else
  432.                         local timeban = 0
  433.                         local num = ""
  434.                         for i = 1, string.len(time) do
  435.                                 local char = string.sub(time, i, i)
  436.                                 if tonumber(char) then
  437.                                         num = num .. char
  438.                                 else
  439.                                         local holder = 0
  440.                                         if char == "s" then
  441.                                                 holder = tonumber(num)
  442.                                         elseif char == "m" then
  443.                                                 holder = tonumber(num) * 60
  444.                                         elseif char == "h" then
  445.                                                 holder = tonumber(num) * 60 * 60
  446.                                         elseif char == "d" then
  447.                                                 holder = tonumber(num) * 60 * 60 * 24
  448.                                         end
  449.                                         timeban = timeban + holder
  450.                                         num = ""
  451.                                 end
  452.                         end
  453.                         if timeban > 0 then
  454.                                 return tonumber(timeban)
  455.                         end
  456.                 end
  457.         else
  458.                 return -1
  459.         end
  460. end

HaloNet.Net is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.