- --[[
- Creator: AelitePrime
- Script Name: Unique ID Script
- Website: http://phasorscripts.wordpress.com/
- Xfire: eliteprime14789x
- Version: 2.0
- Reason for Update:
- - Phasor Update
- ]]
- -- Modify
- max_history = 25
- -- Do not Modify
- history = {}
- players = 0
- history_count = 0
- player_ids = {}
- unique_ids = {}
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(process, game, persistent)
- profilepath = getprofilepath()
- local file = io.open(profilepath .. "//data//uniqueids.data","r")
- if file then
- for line in file:lines() do
- if line ~= nil then
- local words = tokenizestring(line, ",")
- settable(words[1], words[2], words[3], words[5], words[6], tonumber(words[4]))
- players = tonumber(words[4])
- end
- end
- players = players + 1
- file:close()
- end
- for player=0,15 do
- if getplayer(player) then
- local name = getname(player)
- local hash = gethash(player)
- local ip = getip(player)
- player_ids[player] = players
- local bool = true
- for i=0,#unique_ids do
- if unique_ids[i] then
- local words = tokenizestring(unique_ids[i].ip, ".")
- unique_ids[i].ip2 = words[1] .."."..words[2]
- local ip2 = string.sub(ip, 0, string.len(unique_ids[i].ip2))
- 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
- if unique_ids[i].ip == ip then
- player_ids[player] = i
- bool = false
- break
- elseif unique_ids[i].name == name and unique_ids[i].hash == hash then
- player_ids[player] = i
- bool = false
- break
- elseif ip2 == unique_ids[i].ip2 and hash == unique_ids[i].hash or name == unique_ids[i].name then
- player_ids[player] = i
- bool = false
- break
- end
- end
- end
- end
- playerid = player_ids[player]
- if bool then
- settable(name, hash, ip, "false", 0, playerid)
- players = players + 1
- else
- if unique_ids[playerid].banned == "true" then
- settable(name, hash, ip, "true", unique_ids[playerid].time, playerid)
- IDban(player)
- else
- settable(name, hash, ip, "false", 0, playerid)
- end
- end
- end
- end
- timer = registertimer(990, "Timer")
- end
- function OnScriptUnload()
- local file = io.open(profilepath .. "//data//uniqueids.data","w")
- for i = 0,#unique_ids do
- if unique_ids[i] then
- 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")
- end
- end
- end
- function OnGameEnd(stage)
- if stage == 1 and timer then
- removetimer(timer)
- timer = nil
- end
- end
- function OnServerCommand(player, command)
- local response = nil
- local t = tokenizecmdstring(command)
- local count = #t
- t[1] = string.lower(t[1])
- if t[1] == "sv_banid" then
- response = false
- Command_UniqueIDBan(player, t[1], t[2], t[3], count)
- elseif t[1] == "sv_playersids" then
- response = false
- Command_UniqudIDPlayersList(player, t[1], count)
- elseif t[1] == "sv_search" then
- response = false
- Command_Search(player, t[1], t[2], count)
- elseif t[1] == "sv_history" then
- response = false
- Command_History(player, t[1], count)
- elseif t[1] == "sv_idbanlist" then
- response = false
- Command_UniqueIDBanlist(player, t[1], count)
- elseif t[1] == "sv_unbanid" then
- response = false
- Command_UniqueIDunban(player, t[1], t[2], count)
- elseif t[1] == "sv_cmds" then
- response = false
- sendresponse("sv_banid | sv_unbanid | sv_playersids\nsv_idbanlist | sv_search | sv_history", player)
- end
- return response
- end
- function OnPlayerJoin(player)
- local name = getname(player)
- local hash = gethash(player)
- local ip = getip(player)
- player_ids[player] = players
- local bool = true
- for i=0,#unique_ids do
- if unique_ids[i] then
- local words = tokenizestring(unique_ids[i].ip, ".")
- unique_ids[i].ip2 = words[1] .."."..words[2]
- local ip2 = string.sub(ip, 0, string.len(unique_ids[i].ip2))
- 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
- if unique_ids[i].ip == ip then
- player_ids[player] = i
- bool = false
- break
- elseif unique_ids[i].name == name and unique_ids[i].hash == hash then
- player_ids[player] = i
- bool = false
- break
- elseif ip2 == unique_ids[i].ip2 and hash == unique_ids[i].hash or name == unique_ids[i].name then
- player_ids[player] = i
- bool = false
- break
- end
- end
- end
- end
- playerid = player_ids[player]
- if bool then
- settable(name, hash, ip, "false", 0, playerid)
- players = players + 1
- else
- if unique_ids[playerid].banned == "true" then
- settable(name, hash, ip, "true", unique_ids[playerid].time, playerid)
- IDban(player)
- else
- settable(name, hash, ip, "false", 0, playerid)
- end
- end
- end
- function OnPlayerLeave(player)
- if unique_ids[player_ids[player]].banned == "false" then
- if history_count >= max_history then
- history_count = 0
- end
- history[history_count] = {}
- history[history_count].name = getname(player)
- history[history_count].hash = gethash(player)
- history[history_count].ip = getip(player)
- history[history_count].id = player_ids[player]
- history_count = history_count + 1
- end
- player_ids[player] = nil
- end
- function IDban(player)
- local hash = gethash(player)
- svcmd("sv_ban " .. resolveplayer(player))
- local file = io.open(profilepath .. "\\banned.txt", "r")
- if file then
- local Lines = 0
- for line in file:lines() do
- Lines = Lines + 1
- if line and line ~= "" then
- if string.find(line, hash) then
- svcmd("sv_unban " .. Lines - 2)
- end
- end
- end
- end
- end
- function Command_History(executor, command, count)
- if count == 1 then
- local response = "ID | Name\n"
- for i=0,max_history do
- if history[i] then
- response = response .. "" .. history[i].id .. " | " .. history[i].name .. "\n"
- end
- end
- sendresponse(response, executor)
- else
- sendresponse("Invalid Syntax " .. command, executor)
- end
- end
- function Command_Search(executor, command, value, count)
- if count == 2 then
- local response = "ID | Name\n"
- local bool = true
- for i=0,players-1 do
- if unique_ids[i] then
- if string.len(value) == 32 then
- if unique_ids[i].hash == value then
- response = response .. "\n" .. i .. " | " .. unique_ids[i].name .. " | " .. unique_ids[i].ip
- bool = false
- end
- else
- if unique_ids[i].name == value then
- response = response .. "\n" .. i .. " | " .. unique_ids[i].name .. " | " .. unique_ids[i].hash
- bool = false
- end
- end
- end
- end
- if bool then
- response = "No Results found!"
- end
- sendresponse(response, executor)
- else
- sendresponse("Invalid Syntax " .. command .." [name or hash] ", executor)
- end
- end
- function Command_UniqueIDBan(executor, command, id, time, count)
- if count == 2 or time then
- id = tonumber(id)
- if id and id <= players-1 then
- local bool = true
- if unique_ids[id] then
- if unique_ids[id].banned == "false" then
- local player = playeridtoplayer(id)
- unique_ids[id].banned = "true"
- time = wordtotime(time) or -1
- unique_ids[id].time = time
- IDban(player)
- else
- bool = false
- end
- if bool then
- if time == -1 then
- sendresponse(unique_ids[id].name .. " has been banned indefinitely!", executor)
- else
- sendresponse(unique_ids[id].name .. " has been banned for " .. timetoword(time) .. "!", executor)
- end
- else
- sendresponse("That ID has already been banned!", executor)
- end
- else
- sendresponse("That ID is not in use.", executor)
- end
- else
- sendresponse("Invalid Unique ID!", executor)
- end
- else
- sendresponse("Invalid Syntax " .. command .." [ID] {time} ", executor)
- end
- end
- function Command_UniqueIDunban(executor, command, ID, count)
- if count == 2 then
- ID = tonumber(ID)
- if ID and ID <= players-1 then
- if unique_ids[ID] then
- if unique_ids[ID].banned == "true" then
- unique_ids[ID].banned = "false"
- unique_ids[ID].time = 0
- sendresponse(unique_ids[ID].name .. " is now unbanned.", executor)
- else
- sendresponse(unique_ids[ID].name .. " is not banned.", executor)
- end
- else
- sendresponse("That ID is not in use.", executor)
- end
- else
- sendresponse("Invalid Unique ID!", executor)
- end
- else
- sendresponse("Invalid Syntax " .. command .." [ID] ", executor)
- end
- end
- function Command_UniqueIDBanlist(executor, command, count)
- if count == 1 then
- local response = "ID | Name | Time\n"
- for i=0,players-1 do
- if unique_ids[i] then
- if unique_ids[i].banned == "true" then
- response = response .. i .. " | " .. unique_ids[i].name .. " | " .. timetoword(unique_ids[i].time) .."\n"
- end
- end
- end
- sendresponse(response, executor)
- else
- sendresponse("Invalid Syntax " .. command, executor)
- end
- end
- function Command_UniqudIDPlayersList(executor, command, count)
- if count == 1 then
- local response = "ID | Name\n"
- for i= 0,15 do
- if getplayer(i) then
- local name = getname(i)
- response = response .. "" .. player_ids[i] .. " | " .. name .. "\n"
- end
- end
- sendresponse(response, executor)
- else
- sendresponse("Invalid Syntax " .. command, executor)
- end
- end
- function playeridtoplayer(playerid)
- for i=0,15 do
- if getplayer(i) then
- if playerid == player_ids[i] then
- return i
- end
- end
- end
- end
- function sendresponse(message, player)
- if message == "" then
- return
- end
- player = tonumber(player)
- if tonumber(player) and player ~= nil and player ~= -1 and player >= 0 and player < 16 then
- sendconsoletext(player, message)
- else
- hprintf(message)
- end
- end
- function settable(name, hash, ip, boolean, time, id)
- unique_ids[id] = {}
- unique_ids[id].name = name
- unique_ids[id].hash = hash
- unique_ids[id].ip = ip
- unique_ids[id].banned = boolean
- unique_ids[id].time = tonumber(time)
- unique_ids[id].id = id
- end
- function Timer(id, count)
- for i=0,players-1 do
- if unique_ids[i] then
- if unique_ids[i].banned == "true" and unique_ids[i].time > 0 then
- unique_ids[i].time = unique_ids[i].time - 1
- if unique_ids[i].time == 0 then
- unique_ids[i].banned = "false"
- end
- end
- end
- end
- return true
- end
- function timetoword(time)
- if time == -1 or time == "-1" then
- return -1
- elseif tonumber(time) then
- local returntime = ""
- local seconds = tonumber(time)
- local days = math.floor(seconds/86400)
- seconds = seconds - days*86400
- local hours = math.floor(seconds/3600)
- seconds = seconds - hours*3600
- local minutes = math.floor(seconds/60)
- seconds = seconds - minutes*60
- if seconds ~= 0 then
- returntime = seconds .. "s"
- end
- if minutes ~= 0 then
- if returntime == "" then
- returntime = minutes .. "m"
- else
- returntime = minutes .. "m " .. returntime
- end
- end
- if hours ~= 0 then
- if returntime == "" then
- returntime = hours .. "h"
- else
- returntime = hours .. "h " .. returntime
- end
- end
- if days ~= 0 then
- if returntime == "" then
- returntime = days .. "d"
- else
- returntime = days .. "d " .. returntime
- end
- end
- if returntime == "" then
- returntime = "0s"
- end
- return returntime
- end
- end
- function wordtotime(time) -- Function Originally created by Nuggets, modified to work for this script.
- if time then
- if tonumber(time) then
- return tonumber(time)
- else
- local timeban = 0
- local num = ""
- for i = 1, string.len(time) do
- local char = string.sub(time, i, i)
- if tonumber(char) then
- num = num .. char
- else
- local holder = 0
- if char == "s" then
- holder = tonumber(num)
- elseif char == "m" then
- holder = tonumber(num) * 60
- elseif char == "h" then
- holder = tonumber(num) * 60 * 60
- elseif char == "d" then
- holder = tonumber(num) * 60 * 60 * 24
- end
- timeban = timeban + holder
- num = ""
- end
- end
- if timeban > 0 then
- return tonumber(timeban)
- end
- end
- else
- return -1
- end
- end
Recent Pastes