Код
--[[
HideShare 2.2 LUA 5.1x [Strict] [API 2]
By Mutor 07/30/08
A share hider script. Nothing new but the code method.
Imperfect because MyINFO is not blockable, nor should it be.
I never liked any such script that resends MyINFO, but I try
not to force my opinions on others. :P
- Hides user shares per profile
- Shares restored on script exit
+Changes from 2.0 08/14/08
+ Added hideprof and hidenick commands. Request by kalle370
+ Added command permission per profile
+ Added context menus [right click]
+ Added configuration saved to file for hub/script restarts
+ Added script is restated if profile settings are changed
+Changes from 2.01 03/04/10
+ Added CTM/RCTM block for hidden users
+ Added Search block for hidden users
]]
--[[ Start User Settings ]]--
-- "Botname" ["" = hub bot]
local Bot = "[RequestChat]"
-- "Command Menu" ["" = hub name]
local Menu = ""
-- "Command SubMenu" ["" = script name]
local SubMenu = ""
-- File to save configuration to. "Filename.ext"
local File = "HideShare.dat"
-- Delay [in ms] to delay resend of MyINFO
local Delay = 250
-- Always send script replies in private message?
local OnlyPm = true
-- Default profile settings
HsCfg = {
-- Set your profiles / permissions here.
-- [#] = true/false, (true = Hide Share / false = Show Share)
Profiles = {
[-1] = false, -- Unregistered User
[0] = true, -- Master
[1] = false, -- Operator
[2] = false, -- Vip
[3] = false, -- Reg
},
-- Hide these nicks
-- ["Nick"] = true/false,
Exclude = {
["Mutor"] = true,
},
}
--[[ End User Settings ]]--
local Tmr,Temp,Path,Scp = 0,{},Core.GetPtokaXPath().."scripts/","HideShare 2.2"
OnStartup = function()
if Bot == "" then Bot = SetMan.GetString(21) end
if Menu == "" then Menu = SetMan.GetString(0) end
if SubMenu == "" then SubMenu = Scp end
if not File:find("^"..Path,1,true) then File = Path..File end
if loadfile(File) then dofile(File) else Save_File(File,HsCfg,"HsCfg") end
for _,user in ipairs(Core.GetOnlineUsers()) do DoInfo(user) end
Mem()
end
OnExit = function()
for _,user in ipairs(Core.GetOnlineUsers()) do local mi = Core.GetUserValue(user,1) Core.SendToAll(mi.."|") end
end
OnTimer = function(Id)
if Id == Tmr then
for i,v in pairs(Temp) do Core.SendToAll(v.."|") i = nil end
TmrMan.RemoveTimer(Tmr)
Tmr = 0
end
end
UserConnected = function(user)
DoInfo(user)
for _,user in ipairs(Core.GetOnlineUsers()) do DoInfo(user) end
local str,stp,uc,m,p = "","","$UserCommand 1 3 "..Menu.."\\"..SubMenu.."\\","$<%[mynick]> ","||"
local pfx = SetMan.GetString(29):sub(1,1)
for k,v in pairs(HsCmds) do
if v[2][user.iProfile] then local d,a = v[1]() str = str..uc..d..m..pfx..k..a..p end
end
if str:len() > 0 then Core.SendToUser(user,str) end
Mem()
end
OpConnected,RegConnected = UserConnected,UserConnected
MyINFOArrival = function(user,data) if Core.GetUserValue(user,9) then DoInfo(user) end end
ChatArrival = function(user,data)
local _,_,cmd = data:find("%b<> ["..SetMan.GetString(29).."](%a+)")
if cmd and HsCmds[cmd] and HsCmds[cmd][2][user.iProfile] then
reply = HsCmds[cmd][1](user,data,SetMan.GetString(29):sub(1,1)..cmd)
if reply then return Core.SendToUser(user,"<"..Bot.."> "..reply.."|"),true end
end
end
ToArrival = ChatArrival
ConnectToMeArrival = function(user,data)
local p,n = user.iProfile,user.sNick
local Ctms = {[1] = "^$ConnectToMe ([^ ]-) ",[2] = "^$RevConnectToMe [^ ]- (.+)",}
for i,v in ipairs(Ctms) do
local _,_,s = data:sub(1,-2):find(v)
if s and not HsCfg.Exclude[s] then
local msg1,msg2 = "You requested a file from "..s:format("%q")..", transfers from this user are blocked.|",
"Please clear "..string.format("%q",s).." from your download queue. Thank you.|"
if OnlyPm then
return Core.SendPmToUser(user,Bot,msg1),
Core.SendPmToUser(user,Bot,msg2),true
else
return Core.SendToUser(user,"<"..Bot.."> "..msg1),
Core.SendToUser(user,"<"..Bot.."> "..msg2),true
end
end
end
end
RevConnectToMeArrival = ConnectToMeArrival
SearchArrival = function (user,data)
local t = Core.GetOnlineUsers()
if next(t) then
for _,usr in ipairs(t) do
local n = usr.sNick
if not HsCfg.Exclude[n] then Core.SendToUser(usr,data) end
end
end
return true
end
DoInfo = function(user)
local bool
if not HsCfg.Exclude[user.sNick] and HsCfg.Profiles[user.iProfile] then bool = true end
if bool then
local s = tostring(Core.GetUserValue(user,16))
Temp[user.sNick] = Core.GetUserValue(user,1):gsub(s,"0")
if Tmr == 0 then Tmr = TmrMan.AddTimer(Delay) end
end
end
Mem = function() collectgarbage("collect") return string.format("%-.2f Kb.",collectgarbage("count")) end
GetProf = function(i)
local Prof = "Unregistered User"
if i ~= -1 then Prof = ProfMan.GetProfile(i).sProfileName end
return Prof
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n" )
for key, value in pairs(tTable) do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
if(type(value) == "table") then
Save_Serialize(value, sKey, hFile, sTab.."\t")
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
hFile:write(sTab.."\t"..sKey.." = "..sValue)
end
hFile:write(",\n")
end
hFile:write(sTab.."}")
end
Save_File = function(file,table, tablename )
local hFile = io.open (file , "wb")
Save_Serialize(table, tablename, hFile)
hFile:close()
Mem()
end
HsCmds = {
hideprof = {function(user,data,cmd)
if user then
local _,_,prof,val = data:find("%b<> %p%a+ ([-%d]+) ([%a]+)|$")
if prof then
if val then
local bool,valid,chg
if val:lower() == "true" then bool,valid = true,true end
if val:lower() == "false" then bool,valid = false,true end
if valid then
t = {["true"] = "enabled",["false"] = "disabled"}
prof = tonumber(prof)
if HsCfg.Profiles[prof] ~= bool then chg = true end
HsCfg.Profiles[prof] = bool
if chg then Save_File(File,HsCfg,"HsCfg") end
local restart = function()
local scp = ScriptMan.GetScript().sName
if scp then return ScriptMan.RestartScript(scp) end
end
return "Hidden share for "..GetProf(prof).."'s"..
" is now "..t[tostring(HsCfg.Profiles[prof])],restart()
else
return "Error, Invalid Value! Usage:"..cmd.." <profile> '<true/false>'"
end
else
return "Error, Value Omitted! Usage:"..cmd.." <profile> '<true/false>'"
end
else
return "Error, Profile Omitted! Usage:"..cmd.." '<profile>' <true/false>"
end
else
local s = "< -1"
for i = 0,#ProfMan.GetProfiles() do
s = s.." / "..tostring(i)
end
return "Enable / Disable Hidden Share For Profile",
" %[line:Profile Number "..s.." >] %[line:Setting <*true/false> *true = hide / false = unhide]"
end
end,
{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false,},
},
hidenick = {function(user,data,cmd)
if user then
local _,_,val = data:find("%b<> %p%a+ ([%a]+)|$")
local t = {["true"] = "disabled",["false"] = "enabled",["nil"] = "enabled"}
if val then
local bool,valid
if val:lower() == "true" then bool,valid = true,true end
if val:lower() == "false" then bool,valid = false,true end
if valid then
HsCfg.Exclude[user.sNick] = bool
Save_File(File,HsCfg,"HsCfg")
if not bool then
DoInfo(user)
else
Core.SendToAll(Core.GetUserValue(user,1).."|")
end
return "Hidden share for "..user.sNick..
" is now "..t[tostring(HsCfg.Exclude[user.sNick])]
else
return "Error, Invalid Value! Usage:"..cmd.." '<true/false>'"
end
else
return "Hidden share for "..user.sNick..
" is currently "..t[tostring(HsCfg.Exclude[user.sNick])]
end
else
return "Exclude Your Nick From Hidden Share"," %[line:Setting <true/false> (Blank for current setting))]"
end
end,
{[-1] = false,[0] = true,[1] = true,[2] = true,[3] = false,},
},
}