Help with Nick Watchdog 1.0
 

Help with Nick Watchdog 1.0

Started by rEALx, 09 July, 2008, 10:47:19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rEALx

Hi,

Need help with Nick Watchdog 1.0 LUA 5.0/5.1 By Mutor

I tried to convert this script using PtokaX LUA API Converter.
The functions are working I am using Ptokax 0.4.1.1, but i am getting this error.

QuoteC:\Servers\040API2\scripts\NickWatchdog.lua:66: attempt to call global 'GetItemByName' (a nil value)

Also if not much trouble plz incorporate removal of nick/ip entries from the saved log file from a RC menu.

rEALx

[[
	Nick Watchdog 1.0 LUA 5.0/5.1
	By Mutor	02/13/07
	
	Requested by tom_cruise4g
	
	Logs user nick names and IP addresses
	-Disconnect users with changed nick names.
	-Reports status/errors to OpNick
	-Saves to file for script/hub restart
	
]]

Cfg = {
-- Botname pulled from the hub or use "CustomName"
Bot = SetMan.GetString(21),
-- Bot description
Desc = "I watch for changes in user nicknames",
-- Bot email address
Mail = "realx@gmx.com",
-- Admins nick for status / error messages
OpNick = "Hurricane",
--Filename for user data
File="NickWatchdog.dat",
--//--Set your profiles permissions here.
--profile_idx, Check this Profiles IP [0=no 1=yes], "Profile Name"
Profiles = {
	[-1] = 1,
	[0] = 0,
	[1] = 1,
	[2] = 1,
	[3] = 1,
	[4] = 1,
	[5] = 1,
	[6] = 1,
	},
Exclude = {
	["Hurricane"] = 1,
    ["COOL"] = 1,
	},
}

OnStartup = function()
	if Cfg.Bot ~= SetMan.GetString(21) or (SetMan.GetBool(17) and 1 or 0)== 0 then
		Core.RegBot(Cfg.Bot,Cfg.Desc.." PtokaX ".._VERSION,Cfg.Mail,true)
	end
	local LuaVer = string.sub(_VERSION,1,7)
	if LuaVer == "Lua 5.1" then
		Cfg.Gc,Cfg.Mem = "collect",collectgarbage("count")
	elseif LuaVer == "Lua 5.0" then
		Cfg.Gc,Cfg.Mem = nil,collectgarbage(count)
	else
		OnError("This script is incompatible with ".._VERSION)
	end
	if loadfile(Cfg.File) then
		dofile(Cfg.File)
	else
		Cfg.IPs = {}
		Save_File(Cfg.File,Cfg.IPs,"Cfg.IPs")
	end
	for a,b in ipairs(Core.GetOnlineUsers(true)) do
		local user = GetItemByName(b.sNick)
		if user then
			CheckIP(user)
		end
	end
	Cfg.Mem = string.format("%-.2f Kb.",Cfg.Mem)
	OnError("Nick Watchdog 1.0 for ".._VERSION.." by Mutor has been started, using "..Cfg.Mem.." of memory.")
	
end

OnExit = function()
	OnError("Nick Watchdog 1.0 for ".._VERSION.." by Mutor has been stopped, freeing "..Cfg.Mem.." of memory.")
end

OnError = function(msg)
	Core.SendToNick(Cfg.OpNick,"<"..Cfg.Bot.."> "..msg)
end

function UserConnected(user)
	Core.GetUserAllData(user)
	CheckIP(user)
end
OpConnected = UserConnected

CheckIP = function(user)
	if Cfg.Profiles[user.iProfile] and Cfg.Profiles[user.iProfile] == 1 then
		if Cfg.IPs[user.sIP] then
			if not Cfg.Exclude[user.sNick] or Cfg.Exclude[user.sNick] ~= 1 then
				if Cfg.IPs[user.sIP] ~= user.sNick then
					local profile = (ProfMan.GetProfile(user.iProfile) and ProfMan.GetProfile(user.iProfile).sProfileName) or "Unregistered User"
					local msg = "Sorry "..user.sNick.." you may not change your nickname. "..
					"You are disconnected from the hub. You may return with the nick "..
					Cfg.IPs[user.sIP].." after "..SetMan.GetNumber(16)..
					" minute(s) has elapsed.If you did not change your NickName then, chances are you are using another users IP"
					local reason = "Nick/IP changed from "..Cfg.IPs[user.sIP].." to "..user.sNick
					Core.SendToNick(user.sNick,"<"..Cfg.Bot.."> "..msg)
					Core.SendPmToNick(user.sNick,Cfg.Bot,msg)
					Core.Kick(user,Cfg.Bot,reason)
					return true
				end
			end
		else
			Cfg.IPs[user.sIP] = user.sNick
			Save_File(Cfg.File,Cfg.IPs,"Cfg.IPs")
		end
	end
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()
	collectgarbage(Cfg.Gc)
end
RegConnected = UserConnected



rEALx


Thx Mutor for your great scripts..

This one works great...

Thx

rEALx

SMF spam blocked by CleanTalk