I have a MAJOR problem... I really, really, REALLY need help on this one :'( so like... I have 2 scripts that I really need, they save memory about an user (Ip and stuff) but when they do that they request a lot of memory and that means lag on the hub. Could somebody make a script that will automaticly clear those 'registry' that the scripts make, after 3 days or 5 days after the hub was started ? Pleeeasee help meee :( the scripts are: 1: -- PtokaX Lua 5 version by PPK
-- vim:ts=4:sw=4:noet
-- PtokaX OpComExtra.lua 1.1 (Sedulus/20030314) tested on PtokaX 0.3.2.4 IceCube-III-fix3
-- based on OpComExtra.lua for DCH++ by Sedulus
-- created for Cop][Killer of the [TropiCo.se] network
-- no rights reserved (although it would be nice if you kept my name in here)
-- now saves to files, does some otherstuff and is DSN ready ...uwv
-- to 5.1 uwv
-- usercommands glued in & actually NOT 5.0/5.1 compatible by uw
-- this one only does !userinfo & !ipinfo
-- stripped allmost all "extra" things
-- still Nt really 5.0-5.1 compatible
-- you need to create 2 files in your scripts folder named " ntable.tbl " and " itable.tbl "
bot_name = frmHub:GetHubSecAliasName() -- botname to react to commands in PM
max_table_siz = 7 -- the maximum number of nick/times per IP and ip/times per nick stored
---- script start ----
function Main()
-- if the line below gives you a erro you are using lua 5.0.x (please comment it and this script will work fine for you.)
table.getn = table.getn or function(tbl) return #tbl end
if _VERSION == "Lua 5.1" or _VERSION == "Lua 5.2" then -- ;0)
gc = "collect"
end
IPTable = {} -- store info about IP's here
NickTable = {} -- store info about Nicks here
dofile("itable.tbl")
dofile("ntable.tbl")
end
-- Gets called upon arrival of a chat or pm message
function clientMessage(client, msg, loc)
if string.sub(msg, 1, 7) == "ipinfo " then
if client.bOperator then
local ip = string.sub(msg, 8)
if IPTable[ip] then
local str = "ipinfo on: "..ip.."\r\n"
for key, elem in pairs(IPTable[ip]) do
if key ~= "n" then str = str..elem.."\r\n" end
end
messageClient(client, loc, bot_name, str)
else
messageClient(client, loc, bot_name, "Sorry my love.., no ipinfo on: "..ip)
end
end
return 1
elseif string.sub(msg, 1, 8) == "getinfo " then
if client.bOperator then
local nick = string.sub(msg, 9 )
if NickTable[nick] then
local str = "userinfo on: "..nick.."\r\n"
for key, elem in pairs(NickTable[nick]) do
if key ~= "n" then str = str..elem.."\r\n" end
end
messageClient(client, loc, bot_name, str)
else
messageClient(client, loc, bot_name, "Sorry my dear, but i have no extra userinfo on: "..nick)
end
end
end
end
-- Gets called when a new user connects
function userConnected(client)
local nick = client.sName
local ip = client.sIP
local level = client.bOperator
if not level then level = 0 else level = 1 end
-- create tables
if not IPTable[ip] then IPTable[ip] = {} end
if not NickTable[nick] then NickTable[nick] = {} end
-- remove first so we scroll (max_table_siz/max_history_siz)
if table.getn(IPTable[ip]) == max_table_siz then table.remove(IPTable[ip], 1) end
if table.getn(NickTable[ nick ] ) == max_table_siz then table.remove(NickTable[nick], 1) end
-- add newest entry
table.insert(IPTable[ip], os.date()..": ["..level.."] "..nick )
table.insert(NickTable[nick], os.date()..": "..ip )
end
-- Checks if this is a message for us
function isMessageForMe(data)
local ret,c,msg = string.find( data, "^%b<> %p(.*)|$" )
if ret then
return msg,0
end
end
-- Send client a message
function messageClient(client, where, from, msg)
if where == 0 then
client:SendData("<"..from.."> "..msg.."|")
end
end
-- Events: arrival of data
function ChatArrival(curUser, sData)
local msg,loc = isMessageForMe(sData)
if msg then
return clientMessage(curUser, msg, loc)
end
end
-- Event: new user
function NewUserConnected(curUser)
return userConnected(curUser)
end
-- Event: new op
function OpConnected(curUser)
-- For all operators
return userConnected(curUser)
end
---------------------------------------------- the garbage collector
function Clear()
collectgarbage(gc)
io.flush()
end
function OnExit()
Save_File("itable.tbl", IPTable, "IPTable")
Save_File("ntable.tbl", NickTable, "NickTable")
end
----------------------------------------------
-- ripped (with full respect) the next 2 functions from :
--Any Table 1.0 LUA 5.1 by Mutor 10/01/05
-- Fetches table structure & data.
-- Saves tables to file
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
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 , "w")
Serialize(table, tablename, hFile);
hFile:close()
end
and 2:--[[
User Log 1.0 LUA 5.0/5.11
By Mutor 08/19/06
Requested by BoyKind
Logs user profile / connection times.
Returns log list or single entry on command
-LUA 5.02/5.1x compatible
-Provides list log command
-Builds os.date() table , use which fields you want
-Saves to file for script/hub restarts
-Provides context menu [right click]
-Responds in main when hub tab is used
-Responds in PM when user tab is used
User Log Command Help
Command Description
————————————————————————————————————————
+check Check User Log For...
+listlog Display User Log
+loghelp User Log Command Help
————————————————————————————————————————
]]
LogCfg = {
-- Botname pulled from the hub or use "Custom-Name"
Bot = frmHub:GetHubBotName(),
-- Hub Name
Hub = frmHub:GetHubName(),
-- Should bot have a key?
BotIsOp = 1,
-- Bot description
BotDesc = "User Log",
-- Bot Email address
BotMail = "user@domain.com",
-- File to save config/user log tables
File = "UserLog.txt",
-- Context Menu Title
Menu = frmHub:GetHubName(),
-- Context Submenu Title
SubMenu = "User Log",
-- Admin's Nick For Status/Error Messages
OpNick = "Mutor",
-- Adjust To Your Profiles
--[profile#] = {0/1 (0=Commands/Menus Disabled / 1=Commands/Menus Enabled),"Custom Profile Name"},
Profiles = {
[-1] = {0,"Unregistered User"},
[0] = {1,"Master"},
[1] = {1,"Operator"},
[2] = {0,"Vip"},
[3] = {0,"Registered User"},
[4] = {1,"Moderator"}, --RoboCop compatible profile
[5] = {1,"NetFounder"}, --RoboCop compatible profile
},
-- Log Table
UserLog = {},
}
Main = function()
gc,no = nil,table.getn
if _VERSION == "Lua 5.1" then
gc,no = "collect",table.maxn
end
if loadfile(LogCfg.File) then
dofile(LogCfg.File)
else
for i,v in ipairs(frmHub:GetOnlineUsers()) do
user = GetItemByName(v.sName)
Log(user)
end
Save_File(LogCfg.File,LogCfg,"LogCfg")
end
if LogCfg.Bot ~= frmHub:GetHubBotName() or
LogCfg.Bot == frmHub:GetHubBotName() and not frmHub:GetHubBot() then
frmHub:RegBot(LogCfg.Bot, LogCfg.BotIsOp, LogCfg.BotDesc, LogCfg.BotMail)
end
collectgarbage(gc)
OnError("User Log 1.0 LUA for ".._VERSION.." by Mutor has been started. Memory Used: "..gcinfo().." Kb.")
end
OnExit = function()
OnError("User Log 1.0 LUA for ".._VERSION.." by Mutor has been stopped.")
--Save_File(LogCfg.File,LogCfg,"LogCfg")
end
OnError = function(msg)
SendToNick(LogCfg.OpNick,"<"..LogCfg.Bot.."> "..msg)
end
function NewUserConnected(user, data)
Log(user)
if LogCfg.Profiles[user.iProfile] and LogCfg.Profiles[user.iProfile][1] == 1 then
SendLogCmds(user)
user:SendData(LogCfg.Bot,"Bine ai venit "..user.sName..", pe Hub-ul Volvo. Profilul tau este "..GetProfileName(user.iProfile)..
".")
end
end
OpConnected = NewUserConnected
ChatArrival = function(user, data)
data = string.sub(data,1,-2)
if LogCfg.Profiles[user.iProfile] and LogCfg.Profiles[user.iProfile][1] == 1 then
local s,e,cmd = string.find( data, "%b<>%s%p(%w+)")
local s,e,to = string.find(data,"^$To:%s(%S+)%sFrom:")
if cmd and LogCmds[cmd] then
if to and to == LogCfg.Bot then
user:SendPM(LogCfg.Bot,LogCmds[cmd](user,data))
else
user:SendData(LogCfg.Bot,LogCmds[cmd](user,data))
end
collectgarbage(gc)
return 1
end
end
end
ToArrival = ChatArrival
Log = function(user)
local nick,profile,time,exists = user.sName,GetProfileName(user.iProfile) or "Unregistered User",os.date("*t"),nil
for i,v in ipairs(LogCfg.UserLog) do
if v[1] == user.sName then
exists = true
v[2],v[3] = profile,time
break
end
end
if not exists then
local t = {nick,profile,time}
table.insert(LogCfg.UserLog,t)
end
Save_File(LogCfg.File,LogCfg,"LogCfg")
collectgarbage(gc)
end
GetLog = function(nick)
if nick then
local msg = nil
for i,v in ipairs(LogCfg.UserLog) do
if v[1] == nick then
msg = {v[1],v[2],v[3]}
break
end
end
collectgarbage(gc)
return msg
end
end
LogCmds = {
check = function(user,data)
if user then
local s,e,nick = string.find( data, "%b<>%s%p%w+%s(%S+)")
if not nick then
return "Error!, Usage: "..frmHub:GetPrefixes()[1]..
"check <nick>"
else
local msg,prof = "The user: ",GetProfileName(GetUserProfile(nick)) or "Unregistered"
local usr,on = GetItemByName(nick),"offline"
if GetLog(nick) then
local t = GetLog(nick)
if usr then
on = "online"
end
msg = msg..t[1].." last logged in at "..
t[3]["day"].."."..t[3]["month"].."."..t[3]["year"]..
" - "..string.format("%-2.2d",t[3]["hour"])..":"..
string.format("%-2.2d",t[3]["min"]).." and is currently "..on
else
msg = msg..nick.." has the profile "..prof..", does not exist in the log "..
"and is currently "..on
end
return msg
end
else
return "Check User Log For..."," %[line:Nickname]"," %[line:Nickname]"
end
end,
listlog = function(user,data)
if user then
local reply = "Listing User Log\r\n\r\n\tUser\t\t\tLast Login\t\tOnline Status\r\n"..
"\t"..string.rep("—",60).."\r\n"
for i,v in ipairs(LogCfg.UserLog) do
local usr,on = GetItemByName(v[1]),"- Offline -"
if usr then
on = "+ Online +"
end
reply = reply.."\t"..string.format("%-30s",v[1]).."\t"..
string.format("%-16s",v[3]["day"].."."..v[3]["month"].."."..v[3]["year"]..
" - "..string.format("%-2.2d",v[3]["hour"])..":"..
string.format("%-2.2d",v[3]["min"])).."\t\t"..on.."\r\n"
end
return reply.."\n\t"..string.rep("—",60).."\r\n\r\n"
else
return "Display User Log","",""
end
end,
loghelp = function(user,data)
if user then
local reply = "User Log Command Help\r\n\r\n\tCommand\t\tDescription\r\n"..
"\t"..string.rep("—",40).."\r\n"
for i,v in pairs(LogCmds) do
local desc,args = LogCmds[i]()
reply = reply.."\t+"..string.format("%-15s",i).."\t"..desc.."\r\n"
end
return reply.."\n\t"..string.rep("—",40).."\r\n\r\n"
else
return "User Log Command Help","",""
end
end,
}
SendLogCmds = function(user)
for i,v in pairs(LogCmds) do
local desc,arg1,arg2 = LogCmds[i]()
user:SendData("$UserCommand 1 1 "..LogCfg.Menu.."\\"..LogCfg.SubMenu.."\\"..
desc.."$<%[mynick]> +"..i..arg1.."|")
user:SendData("$UserCommand 1 2 "..LogCfg.Menu.."\\"..LogCfg.SubMenu.."\\"..
desc.."$$To: "..LogCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."|")
collectgarbage(gc)
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)
io.flush()
hFile:close()
collectgarbage(gc)
end
as you have notice, the no. 1 script creates the itable.tbl and ntable.tbl and script no.2 creates UserLog.txt ... can you please help me out? :( please :(
Could you explain the MaxLog for me, please? It's like 200 . The script memorizes 200 nicknames and when it reached that 200 number, the oldest log will be deleted and a newer nick will be added ?
Thank you :) Now I must wait for PPK to help me with that script also, if he is so kind :P
I don't created that script, i only changed few small things to get it working with lua 5 ... so, here will not be help with this script from me ::)
Oh, darn :( Mutor, can u help me with it, please?
Aha :D and can you do it? I just need a script that can show me all the info about an user even if he's offline and that can show me all the info about an ip. If it's possbile to refresh it's list, like you did on that script earlier :) Thanks ;)