PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: nEgativE on 30 March, 2005, 12:15:39

Title: Onjoin Info [L5]
Post by: nEgativE on 30 March, 2005, 12:15:39
Hi friends, please help me with my favorite script :(
The problem is in the reading of RegisteredUsers.xml
I get this line empty --> user:SendData("   -?--- Usu?rios Registrados: "..tmp2.." - OP's: "..tmp.." - ViP's: "..LEVELSTOT["2"].." - R/OP's: "..LEVELSTOT["4"].." - Total: "..tmp5.." ---?-")

function OpenRegisterdUsersFile()

local handle = io.open("../cfg/RegisteredUsers.xml","r")
for a,b in LEVELSTOT do
LEVELSTOT[a]=0
end
while 1 do
local line = handle:read()
local level
if line == nil then
handle:flush()
handle:close()
break
end
s,e,level = string.find(line,".+|.+|(.+)")
if LEVELSTOT[level] then
LEVELSTOT[level] = LEVELSTOT[level] +1
end
end  
end
The Script
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
--> Made by plop
--> Functions by nErBoS
--> Functions by [BR]Carlos
--> Convertion LUA 5 by Jelf
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Bot = frmHub:GetHubBotName()
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
sec = 1000
min = 60 * sec
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
LEVELSTOT = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["4"]=0, ["5"]=0}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Path = "Data"
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Stattxt = "Data/CLP.Stat.dat"
Stat = {
logins = 0,
share = 0,
users = 0,
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
os.execute("mkdir ".."\""..string.gsub(Path, "/", "\\").."\"")
commands = {["!addreguser"]=1, ["!delreguser"]=1}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function rightSize(tam)

tam = tonumber( tam )
local count = 0
local tamStr = ""
local tamTmp = tam
if  tam < 0 then
tamTmp = tamTmp * -1
end
while tamTmp > 1024 do
tamTmp = tamTmp / 1024
count = count + 1
end
tamTmp = string.format("%0.2f", tamTmp)
if count == 0 then
tamStr = "Bytes" -- Bytes
elseif count == 1 then
tamStr = "KiB" -- kilobytes
elseif count == 2 then
tamStr = "MiB" -- megabytes
elseif count == 3 then
tamStr = "GiB" -- gigabytes
elseif count == 4 then
tamStr = "TiB" -- terabytes
elseif count == 5 then
tamStr = "PiB" -- petabytes
elseif count == 6 then
tamStr = "EiB" -- exabytes
elseif count == 7 then
tamStr = "ZiB" -- zettabytes
else
tamStr = "YiB" -- yottabytes
end
if tam < 0 then
tamTmp = tamTmp * -1
end
return tamTmp.." "..tamStr
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function Message(user)

local _,_,share = string.find(user.sMyInfoString, "$(%d+)%$")
if share == nil then
share = 0
end
local SC=os.clock()
local hubshare = frmHub:GetCurrentShareAmount()
local ttshare = tonumber(Stat.share)
local tmp = LEVELSTOT["1"] + LEVELSTOT["0"]  --- total ops  (adding masters 2 ops)
local tmp1 = (LEVELSTOT["2"] - LEVELS["2"]) if tmp1 < 0 then tmp1 = 0 end --- offline vips (total - online)
local tmp2 = (LEVELSTOT["3"]) if tmp2 < 0 then tmp2 = 0 end --- offline regs (total - online)
local tmp3 = LEVELS["1"] + LEVELS["0"] -- online ops (adding masters 2 the ops)
local tmp4 = LEVELS["4"]
local tmp5 = LEVELSTOT["3"] + LEVELSTOT["1"] + LEVELSTOT["0"] + LEVELSTOT["2"] + LEVELSTOT["4"]
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..user.sName.."")
user:SendData("     -?--- Compartilhamento: "..rightSize( share ).." - Status: "..(GetProfileName(user.iProfile) or "N?o Registrado").." - Senha: "..(frmHub:GetUserPassword(user.sName) or "(???)").." ---?-")
user:SendData("     -?--- Conectado: "..(user.iHubs or "0").." Hub's - Com registro: "..(user.iRegHubs or "0").." - Como Operador: "..(user.iOpHubs or "0").." ---?-")
user:SendData("     -?--- Cliente: "..VersionChecker(user).." - Vers?o: "..(user.sClientVersion or "Indispon?vel").." - Modo: "..ModeChecker(user).." - Slot's: "..(user.iSlots or "0").." ---?-")
user:SendData("     -?--- Endere?o IP: "..user.sIP.." - Conex?o: "..(user.sConnection or "Indispon?vel").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..frmHub:GetHubName().."")
user:SendData("     -?--- Comunidade de Lingua Portuguesa --?-- Compartilhamento: "..rightSize( hubshare ) .." ---?-")
user:SendData("     -?--- Usu?rios Online: "..(frmHub:GetUsersCount() + "5").." - OP's: "..tmp3.." - ViP's: "..LEVELS["2"].." - NetOP's: "..tmp4.." - M?ximo: "..frmHub:GetMaxUsers().." ---?-")
user:SendData("     -?--- Usu?rios Registrados: "..tmp2.." - OP's: "..tmp.." - ViP's: "..LEVELSTOT["2"].." - NetOP's: "..LEVELSTOT["4"].." - Total: "..tmp5.." ---?-")
user:SendData("     -?--- Uptime: " ..math.floor(SC/86400).." dia's "..math.floor(math.mod(SC/3600,24)).." hora's e "..math.floor(math.mod(SC/60,60)).." minuto's --?-- "..GetTime().." ---?-")
user:SendData("     -?--- Peak --?-- Conex?es: "..Stat.logins.." - Compartilhamento: "..rightSize( ttshare ).." - Usu?rios: "..Stat.users.." ---?-")
user:SendData("     -?--- Lista de Comandos - Regras - Ajuda - Informa??o: !ajuda - !help ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData("     -?--- T?pico: "..frmHub:GetHubTopic().." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData(" ")
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function GetTime()

--s = os.date("%S")
h = os.date("%H")
m = os.date("%M")
d = os.date("%d")
mm = os.date("%m")
y = os.date("%y")
Date = "Hora local: "..h..":"..m.." - "..d.."/"..mm.."/20"..y..""
return Date
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
ALLUSERS={}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function NewUserConnected(user)

local s,e,usrshare = string.find(user.sMyInfoString, "%$%s*(%d+)%$")
if (io.open(Stattxt) == nil) then
if (Stat.users < frmHub:GetUsersCount()) then
Stat.users = frmHub:GetUsersCount()
else
end
if Stat.share < frmHub:GetCurrentShareAmount() then
Stat.share = frmHub:GetCurrentShareAmount()
end
Stat.logins = Stat.logins + 1
SaveToFile(Stattxt , Stat , "Stat")
else
LoadFromFile (Stattxt)
local logins = Stat["logins"]
local share = Stat["share"]
local users = Stat["users"]
if (users < frmHub:GetUsersCount() + 5) then
Stat.users = frmHub:GetUsersCount() + 5
else
Stat.users = users
end
if share < frmHub:GetCurrentShareAmount() then
Stat.share = frmHub:GetCurrentShareAmount()
else
Stat.share = share
end
Stat.logins = logins + 1
SaveToFile(Stattxt , Stat , "Stat")
end
if ALLUSERS[user.sName]==nil then
ALLUSERS[user.sName]=1
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
end
if (VersionChecker(user) == "Desconhe?ido") then
end
Message(user)
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
OpConnected = NewUserConnected
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function ChatArrival(user, data)

if ALLUSERS[user.sName]==nil then
ALLUSERS[user.sName]=1
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
end
s,e,cmd= string.find(data, "%b<>%s+(%S+)")
if cmd ~= nil and commands[cmd] then
SetTimer(5 * 1000)
StartTimer()
end
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function OnTimer()

StopTimer()
OpenRegisterdUsersFile()
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function UserDisconnected(user)

if ALLUSERS[user.sName] then
ALLUSERS[user.sName]=nil
if LEVELS[tostring(user.iProfile)] > 0 then
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
end
end
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function OpDisconnected(user)

if ALLUSERS[user.sName] then
ALLUSERS[user.sName]=nil
if LEVELS[tostring(user.iProfile)] > 0 then
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
end
end
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function Main()

OpenRegisterdUsersFile()
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function OpenRegisterdUsersFile()

local handle = io.open("../cfg/RegisteredUsers.xml","r")
for a,b in LEVELSTOT do
LEVELSTOT[a]=0
end
while 1 do
local line = handle:read()
local level
if line == nil then
handle:flush()
handle:close()
break
end
s,e,level = string.find(line,".+|.+|(.+)")
if LEVELSTOT[level] then
LEVELSTOT[level] = LEVELSTOT[level] +1
end
end  
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function Serialize(tTable, sTableName, sTab)

assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
                if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function SaveToFile(file , table , tablename)

local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function LoadFromFile(file)

local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function VersionChecker(user)

local tmp = ""
if (string.find(user.sMyInfoString, "oDC")) then
tmp = "oDC++"
elseif string.find(user.sMyInfoString,"DCGUI") then
tmp = "NMDC - DCGUI"
elseif string.find(user.sMyInfoString,"DC:PRO") then
tmp = "DC:PRO"
elseif string.find(user.sMyInfoString,"LDC++") then
tmp = "LDC++"
elseif string.find(user.sMyInfoString,"<.P>") then
tmp = "PhantomDC++"
elseif string.find(user.sMyInfoString,"ptDC") then
tmp = "PTDC++"
elseif string.find(user.sMyInfoString,"R2++") then
tmp = "R2++"
elseif string.find(user.sMyInfoString,"iDC") then
tmp = "iDC++"
elseif string.find(user.sMyInfoString,"rmDC") then
tmp = "RMDC++"
elseif string.find(user.sMyInfoString,"UKC++") then
tmp = "UKC++"
elseif string.find(user.sMyInfoString,"zDC") then
tmp = "zDC++"
elseif string.find(user.sMyInfoString,"Z++") then
tmp = "Zion++"
elseif string.find(user.sMyInfoString,"QuickDC") then
tmp = "QuickDC++"
elseif string.find(user.sMyInfoString,"RevConnect") then
tmp = "RevConnect"
elseif string.find(user.sMyInfoString,"McDC") then
tmp = "MCDC++"
elseif string.find(user.sMyInfoString,"DCDM") then
tmp = "DCDM++"
elseif string.find(user.sMyInfoString,"BoolDC++") then
tmp = "BoolDC++"
elseif string.find(user.sMyInfoString,"<++") then
tmp = "DC++"
elseif (string.find(user.sMyInfoString, "StrgDC")) then
tmp = "StrongDC++"
else
tmp = "Desconhe?ido"
end
return tmp
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function ModeChecker(user)

local tmp = ""
if (string.find(user.sMyInfoString, "M:P")) then
tmp = "Passivo"
else
tmp = "Ativo"
end
return tmp
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

Please ! :|
Title:
Post by: jiten on 02 May, 2005, 15:20:27
Here you go (slightly tested)
---------------------------------------------------------------
-- Heavily optimized by jiten (LUA 5)

--> Made by plop
--> Functions by nErBoS
--> Functions by [BR]Carlos
--> Convertion LUA 5 by Jelf
---------------------------------------------------------------
Bot = frmHub:GetHubBotName()
ALLUSERS={}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}
Stat = {
logins = 0,
share = 0,
users = 0,
}
sec = 1000
min = 60*sec
os.execute("mkdir ".."\""..string.gsub("Data", "/", "\\").."\"")

function ChatArrival(user, data)
if ALLUSERS[user.sName]==nil then ALLUSERS[user.sName]=1 LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1 end
s,e,cmd= string.find(data, "%b<>%s+(%S+)")
local commands = {
["!addreguser"]=1,
["!delreguser"]=1
}
if cmd ~= nil and commands[cmd] then SetTimer(5*1000) StartTimer() end
end

function NewUserConnected(user)
local usrshare = user.iShareSize
if loadfile("Data/CLP.Stat.dat") then
dofile("Data/CLP.Stat.dat")
local logins,share,users = Stat["logins"],Stat["share"],Stat["users"]
if (users < frmHub:GetUsersCount()) then Stat.users = frmHub:GetUsersCount() else Stat.users = users end
if share < frmHub:GetCurrentShareAmount() then Stat.share = frmHub:GetCurrentShareAmount() else Stat.share = share end
Stat.logins = logins + 1
SaveToFile("Data/CLP.Stat.dat" , Stat , "Stat")
else
if (Stat.users < frmHub:GetUsersCount()) then Stat.users = frmHub:GetUsersCount() end
if Stat.share < frmHub:GetCurrentShareAmount() then Stat.share = frmHub:GetCurrentShareAmount() end
Stat.logins = Stat.logins + 1
SaveToFile("Data/CLP.Stat.dat" , Stat , "Stat")
end
if ALLUSERS[user.sName]==nil then ALLUSERS[user.sName]=1 LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1 end
Message(user)
end

OpConnected = NewUserConnected

function UserDisconnected(user)
if ALLUSERS[user.sName] then
ALLUSERS[user.sName]=nil
if LEVELS[tostring(user.iProfile)] > 0 then
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
end
end
end

OpDisconnected = UserDisconnected

function OnTimer()
StopTimer()
end

function Message(user)
local tmp,share,SC,hubshare,ttshare = "",user.iShareSize,os.clock(),frmHub:GetCurrentShareAmount(),tonumber(Stat.share)
if share == nil then share = 0 end
if user.sMode == "A" then tmp = "Activo" else tmp = "Passivo" end
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..user.sName.."")
user:SendData("     -?--- Compartilhamento: "..rightSize( tonumber(share) ).." - Status: "..(GetProfileName(user.iProfile) or "N?o Registrado").." - Senha: "..(frmHub:GetUserPassword(user.sName) or "(???)").." ---?-")
user:SendData("     -?--- Conectado: "..(user.iHubs or "0").." Hub's - Com registro: "..(user.iRegHubs or "0").." - Como Operador: "..(user.iOpHubs or "0").." ---?-")
user:SendData("     -?--- Cliente: "..(user.sClient or "Desconhecido").." - Vers?o: "..(user.sClientVersion or "Indispon?vel").." - Modo: "..tmp.." - Slot's: "..(user.iSlots or "0").." ---?-")
user:SendData("     -?--- Endere?o IP: "..user.sIP.." - Conex?o: "..(user.sConnection or "Indispon?vel").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..frmHub:GetHubName().."")
user:SendData("     -?--- Comunidade de Lingua Portuguesa --?-- Compartilhamento: "..rightSize( tonumber(hubshare) ) .." ---?-")
user:SendData("     -?--- Usu?rios Online: "..getOn(3).." - OP's: "..getOn(1).." - ViP's: "..getOn(2).." - NetOP's: "..getOn(5).." - M?ximo: "..frmHub:GetMaxUsers().." ---?-")
user:SendData("     -?--- Usu?rios Registrados: "..getAll(3).." - OP's: "..getAll(0) + getAll(1).." - ViP's: "..getAll(2).." - NetOP's: "..getAll(0).." - Total: "..table.getn(frmHub:GetRegisteredUsers()).." ---?-")
user:SendData("     -?--- Uptime: " ..math.floor(SC/86400).." dia's "..math.floor(math.mod(SC/3600,24)).." hora's e "..math.floor(math.mod(SC/60,60)).." minuto's --?-- "..os.date().." ---?-")
user:SendData("     -?--- Peak --?-- Conex?es: "..Stat.logins.." - Compartilhamento: "..rightSize( tonumber(ttshare) ).." - Usu?rios: "..Stat.users.." ---?-")
user:SendData("     -?--- Lista de Comandos - Regras - Ajuda - Informa??o: !ajuda - !help ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData("     -?--- T?pico: "..(frmHub:GetHubTopic() or "Desconhecido").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData(" ")
end

function getOn(p)
local r,t = frmHub:GetOnlineRegUsers(),0
for i,nick in r do
if nick.iProfile == p then
t = t + 1
end
end
return t
end

function getAll(p)
local r = table.getn(GetUsersByProfile(GetProfileName(p)))
return r
end

function rightSize(intSize) --- Thanks to kepp and NotRambitWombat
if intSize ~= 0 then
local tUnits = { "Bytes", "KB", "MB", "GB", "TB" }
intSize = tonumber(intSize);
local sUnits;
for index = 1, table.getn(tUnits) do
if(intSize < 1024) then
sUnits = tUnits[index];
break;
else  
intSize = intSize / 1024;
end
end
return string.format("%0.1f %s",intSize, sUnits);
else
return "nothing"
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
                if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
Cheers
Title:
Post by: nEgativE on 02 May, 2005, 16:40:55
QuoteOriginally posted by jiten
Here you go (slightly tested)
---------------------------------------------------------------
-- Heavily optimized by jiten (LUA 5)

--> Made by plop
--> Functions by nErBoS
--> Functions by [BR]Carlos
--> Convertion LUA 5 by Jelf
---------------------------------------------------------------
Bot = frmHub:GetHubBotName()
ALLUSERS={}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}
Stat = {
logins = 0,
share = 0,
users = 0,
}
sec = 1000
min = 60*sec
os.execute("mkdir ".."\""..string.gsub("Data", "/", "\\").."\"")

function ChatArrival(user, data)
if ALLUSERS[user.sName]==nil then ALLUSERS[user.sName]=1 LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1 end
s,e,cmd= string.find(data, "%b<>%s+(%S+)")
local commands = {
["!addreguser"]=1,
["!delreguser"]=1
}
if cmd ~= nil and commands[cmd] then SetTimer(5*1000) StartTimer() end
end

function NewUserConnected(user)
local usrshare = user.iShareSize
if loadfile("Data/CLP.Stat.dat") then
dofile("Data/CLP.Stat.dat")
local logins,share,users = Stat["logins"],Stat["share"],Stat["users"]
if (users < frmHub:GetUsersCount()) then Stat.users = frmHub:GetUsersCount() else Stat.users = users end
if share < frmHub:GetCurrentShareAmount() then Stat.share = frmHub:GetCurrentShareAmount() else Stat.share = share end
Stat.logins = logins + 1
SaveToFile("Data/CLP.Stat.dat" , Stat , "Stat")
else
if (Stat.users < frmHub:GetUsersCount()) then Stat.users = frmHub:GetUsersCount() end
if Stat.share < frmHub:GetCurrentShareAmount() then Stat.share = frmHub:GetCurrentShareAmount() end
Stat.logins = Stat.logins + 1
SaveToFile("Data/CLP.Stat.dat" , Stat , "Stat")
end
if ALLUSERS[user.sName]==nil then ALLUSERS[user.sName]=1 LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1 end
Message(user)
end

OpConnected = NewUserConnected

function UserDisconnected(user)
if ALLUSERS[user.sName] then
ALLUSERS[user.sName]=nil
if LEVELS[tostring(user.iProfile)] > 0 then
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
end
end
end

OpDisconnected = UserDisconnected

function OnTimer()
StopTimer()
end

function Message(user)
local tmp,share,SC,hubshare,ttshare = "",user.iShareSize,os.clock(),frmHub:GetCurrentShareAmount(),tonumber(Stat.share)
if share == nil then share = 0 end
if user.sMode == "A" then tmp = "Activo" else tmp = "Passivo" end
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..user.sName.."")
user:SendData("     -?--- Compartilhamento: "..rightSize( tonumber(share) ).." - Status: "..(GetProfileName(user.iProfile) or "N?o Registrado").." - Senha: "..(frmHub:GetUserPassword(user.sName) or "(???)").." ---?-")
user:SendData("     -?--- Conectado: "..(user.iHubs or "0").." Hub's - Com registro: "..(user.iRegHubs or "0").." - Como Operador: "..(user.iOpHubs or "0").." ---?-")
user:SendData("     -?--- Cliente: "..(user.sClient or "Desconhecido").." - Vers?o: "..(user.sClientVersion or "Indispon?vel").." - Modo: "..tmp.." - Slot's: "..(user.iSlots or "0").." ---?-")
user:SendData("     -?--- Endere?o IP: "..user.sIP.." - Conex?o: "..(user.sConnection or "Indispon?vel").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..frmHub:GetHubName().."")
user:SendData("     -?--- Comunidade de Lingua Portuguesa --?-- Compartilhamento: "..rightSize( tonumber(hubshare) ) .." ---?-")
user:SendData("     -?--- Usu?rios Online: "..getOn(3).." - OP's: "..getOn(1).." - ViP's: "..getOn(2).." - NetOP's: "..getOn(5).." - M?ximo: "..frmHub:GetMaxUsers().." ---?-")
user:SendData("     -?--- Usu?rios Registrados: "..getAll(3).." - OP's: "..getAll(0) + getAll(1).." - ViP's: "..getAll(2).." - NetOP's: "..getAll(0).." - Total: "..table.getn(frmHub:GetRegisteredUsers()).." ---?-")
user:SendData("     -?--- Uptime: " ..math.floor(SC/86400).." dia's "..math.floor(math.mod(SC/3600,24)).." hora's e "..math.floor(math.mod(SC/60,60)).." minuto's --?-- "..os.date().." ---?-")
user:SendData("     -?--- Peak --?-- Conex?es: "..Stat.logins.." - Compartilhamento: "..rightSize( tonumber(ttshare) ).." - Usu?rios: "..Stat.users.." ---?-")
user:SendData("     -?--- Lista de Comandos - Regras - Ajuda - Informa??o: !ajuda - !help ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData("     -?--- T?pico: "..(frmHub:GetHubTopic() or "Desconhecido").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData(" ")
end

function getOn(p)
local r,t = frmHub:GetOnlineRegUsers(),0
for i,nick in r do
if nick.iProfile == p then
t = t + 1
end
end
return t
end

function getAll(p)
local r = table.getn(GetUsersByProfile(GetProfileName(p)))
return r
end

function rightSize(intSize) --- Thanks to kepp and NotRambitWombat
if intSize ~= 0 then
local tUnits = { "Bytes", "KB", "MB", "GB", "TB" }
intSize = tonumber(intSize);
local sUnits;
for index = 1, table.getn(tUnits) do
if(intSize < 1024) then
sUnits = tUnits[index];
break;
else  
intSize = intSize / 1024;
end
end
return string.format("%0.1f %s",intSize, sUnits);
else
return "nothing"
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
                if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
Cheers

oW.. Heavily optimized in did, i'll try later on.. Tks again jiten :)
Title:
Post by: jiten on 07 May, 2005, 11:53:18
You're welcome :]
Btw, no report?

Cheers
Title:
Post by: nEgativE on 09 May, 2005, 18:55:45
QuoteOriginally posted by jiten
You're welcome :]
Btw, no report?

Cheers

Hey Jiten, it's working dam fine :)
sorry.. i was gone for some days, and tks again []'s
I think it only doesn't count the -1 LEVELS Profile.
Title:
Post by: jiten on 10 May, 2005, 08:07:37
QuoteOriginally posted by Luso
QuoteOriginally posted by jiten
You're welcome :]
Btw, no report?

Cheers

Hey Jiten, it's working dam fine :)
sorry.. i was gone for some days, and tks again []'s
I think it only doesn't count the -1 LEVELS Profile.
Goody :]
Where do you want to count the -1 Profile so that I can add it (Online?/Registered?).

Cheers
Title:
Post by: nEgativE on 10 May, 2005, 17:02:28
Online ! :)
Tell me, is it possible removing the Login stats and built a stat for Hub uptime ? Tks :)
Title:
Post by: jiten on 10 May, 2005, 20:12:31
QuoteOriginally posted by Luso
Tell me, is it possible removing the Login stats and built a stat for Hub uptime ? Tks :)
Do you mean removing all share, login and users records and adding Hub uptime stat to the Message or something else?
Title:
Post by: nEgativE on 11 May, 2005, 11:21:57
QuoteOriginally posted by jiten
QuoteOriginally posted by Luso
Tell me, is it possible removing the Login stats and built a stat for Hub uptime ? Tks :)
Do you mean removing all share, login and users records and adding Hub uptime stat to the Message or something else?

Hi jiten, just removing the login.stat records, and add a uptime.stat record :) keep the share and users records.
Title:
Post by: jiten on 12 May, 2005, 15:44:31
Give this a try:
---------------------------------------------------------------
-- Heavily optimized by jiten (LUA 5)
-- removed login and added max uptime stats

--> Made by plop
--> Functions by nErBoS
--> Functions by [BR]Carlos
--> Convertion LUA 5 by Jelf
---------------------------------------------------------------
Bot = frmHub:GetHubBotName()
ALLUSERS={}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}
Stat = {
uptime = 0,
share = 0,
users = 0,
}
sec = 1000
min = 60*sec
os.execute("mkdir ".."\""..string.gsub("Data", "/", "\\").."\"")

function ChatArrival(user, data)
if ALLUSERS[user.sName]==nil then ALLUSERS[user.sName]=1 LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1 end
s,e,cmd= string.find(data, "%b<>%s+(%S+)")
local commands = {
["!addreguser"]=1,
["!delreguser"]=1
}
if cmd ~= nil and commands[cmd] then SetTimer(5*1000) StartTimer() end
end

function NewUserConnected(user)
local usrshare = user.iShareSize
if loadfile("Data/CLP.Stat.dat") then
dofile("Data/CLP.Stat.dat")
local uptime,share,users = Stat["uptime"],Stat["share"],Stat["users"]
if (users < frmHub:GetUsersCount()) then Stat.users = frmHub:GetUsersCount() else Stat.users = users end
if share < frmHub:GetCurrentShareAmount() then Stat.share = frmHub:GetCurrentShareAmount() else Stat.share = share end
if uptime < frmHub:GetUpTime() then Stat.uptime = frmHub:GetUpTime() else Stat.uptime = uptime end
SaveToFile("Data/CLP.Stat.dat" , Stat , "Stat")
else
if (Stat.users < frmHub:GetUsersCount()) then Stat.users = frmHub:GetUsersCount() end
if Stat.share < frmHub:GetCurrentShareAmount() then Stat.share = frmHub:GetCurrentShareAmount() end
Stat.uptime = frmHub:GetUpTime()
SaveToFile("Data/CLP.Stat.dat" , Stat , "Stat")
end
if ALLUSERS[user.sName]==nil then ALLUSERS[user.sName]=1 LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1 end
Message(user)
end

OpConnected = NewUserConnected

function UserDisconnected(user)
if ALLUSERS[user.sName] then
ALLUSERS[user.sName]=nil
if LEVELS[tostring(user.iProfile)] > 0 then
LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
end
end
end

OpDisconnected = UserDisconnected

function Message(user)
local tmp,share,SC,hubshare,ttshare = "",user.iShareSize,os.clock(),frmHub:GetCurrentShareAmount(),tonumber(Stat.share)
local days,hours,minutes = math.floor(Stat.uptime/43200, 30), math.floor(math.mod(Stat.uptime/1440, 24)), math.floor(math.mod(Stat.uptime/60, 60))
if share == nil then share = 0 end
if user.sMode == "A" then tmp = "Activo" else tmp = "Passivo" end
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..user.sName.."")
user:SendData("     -?--- Compartilhamento: "..rightSize( tonumber(share) ).." - Status: "..(GetProfileName(user.iProfile) or "N?o Registrado").." - Senha: "..(frmHub:GetUserPassword(user.sName) or "(???)").." ---?-")
user:SendData("     -?--- Conectado: "..(user.iHubs or "0").." Hub's - Com registro: "..(user.iRegHubs or "0").." - Como Operador: "..(user.iOpHubs or "0").." ---?-")
user:SendData("     -?--- Cliente: "..(user.sClient or "Desconhecido").." - Vers?o: "..(user.sClientVersion or "Indispon?vel").." - Modo: "..tmp.." - Slot's: "..(user.iSlots or "0").." ---?-")
user:SendData("     -?--- Endere?o IP: "..user.sIP.." - Conex?o: "..(user.sConnection or "Indispon?vel").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.: "..frmHub:GetHubName().."")
user:SendData("     -?--- Comunidade de Lingua Portuguesa --?-- Compartilhamento: "..rightSize( tonumber(hubshare) ) .." ---?-")
user:SendData("     -?--- Usu?rios Online : "..table.getn(frmHub:GetOnlineUsers(-1)).." - REG Online : "..getOn(3).." - OP's: "..getOn(1).." - ViP's: "..getOn(2).." - NetOP's: "..getOn(0).."  - M?ximo: "..frmHub:GetMaxUsers().." ---?-")
user:SendData("     -?--- Usu?rios Registrados: "..getAll(3).." - OP's: "..getAll(0) + getAll(1).." - ViP's: "..getAll(2).." - NetOP's: "..getAll(0).." - Total: "..table.getn(frmHub:GetRegisteredUsers()).." ---?-")
user:SendData("     -?--- Uptime: " ..math.floor(SC/86400).." dias "..math.floor(math.mod(SC/3600,24)).." horas e "..math.floor(math.mod(SC/60,60)).." minutos --?-- "..os.date().." ---?-")
user:SendData("     -?--- Peak --?-- Uptime: "..days.." dias, "..hours.." horas e "..minutes.." minutos - Compartilhamento: "..rightSize( tonumber(ttshare) ).." - Usu?rios: "..Stat.users.." ---?-")
user:SendData("     -?--- Lista de Comandos - Regras - Ajuda - Informa??o: !ajuda - !help ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData("     -?--- T?pico: "..(frmHub:GetHubTopic() or "Desconhecido").." ---?-")
user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
user:SendData(" ")
end

function getOn(p)
local r,t = frmHub:GetOnlineRegUsers(),0
for i,nick in r do
if nick.iProfile == p then
t = t + 1
end
end
return t
end

function getAll(p)
local r = table.getn(GetUsersByProfile(GetProfileName(p)))
return r
end

function rightSize(intSize) --- Thanks to kepp and NotRambitWombat
if intSize ~= 0 then
local tUnits = { "Bytes", "KB", "MB", "GB", "TB" }
intSize = tonumber(intSize);
local sUnits;
for index = 1, table.getn(tUnits) do
if(intSize < 1024) then
sUnits = tUnits[index];
break;
else  
intSize = intSize / 1024;
end
end
return string.format("%0.1f %s",intSize, sUnits);
else
return "nothing"
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
                if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
Best regards
Title:
Post by: nEgativE on 13 May, 2005, 11:45:28
Working great :) what can i say.. u know. []'s
Title:
Post by: jiten on 13 May, 2005, 16:29:33
yw :]