hi all just wondering if this can be changed over to LUA 5
--Hub Stats V.01 by chill
--Serialisation by RabidWombat
statFile = "HubStats.txt" -- The Filename
statFolder = "txt" -- The Foldername set it to nil if not wanted
Max1 = 1 -- Time between each stats saving
cmd1 = "+hubstats" -- Shows the Hub Stats
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
-- MAIN SCRIPT
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
if statFolder then
statFile = statFolder.."/"..statFile
end
HubStats = {
Logins = 0,
MaxShareAmount = frmHub:GetCurrentShareAmount(),
MaxUsers = frmHub:GetUsersCount(),
StatsSince = date("%d/%m/%y"),
}
dofile(statFile)
--------------------------------------------------------
function Main()
SetTimer(60*1000*Max1)
StartTimer()
end
function OnExit()
WriteTable(HubStats,"HubStats",statFile)
end
--------------------------------------------------------
function OnTimer()
WriteTable(HubStats,"HubStats",statFile)
end
--------------------------------------------------------
function NewUserConnected(curUser)
if (frmHub:GetCurrentShareAmount() > HubStats.MaxShareAmount) then
HubStats.MaxShareAmount = frmHub:GetCurrentShareAmount()
end
if (frmHub:GetUsersCount() > HubStats.MaxUsers) then
HubStats.MaxUsers = frmHub:GetUsersCount()
end
HubStats.Logins = HubStats.Logins + 1
end
OpConnected = NewUserConnected
--------------------------------------------------------
function DataArrival(curUser,data)
if strsub(data,1,1) == "<" then
data = strsub(data,strlen(curUser.sName)+4,strlen(data)-1)
local _,_,word1 = strfind(data,"^(%S+)")
if word1 and hubStatFunc[word1] then
curUser:SendData(hubStatFunc[word1]())
return 1
end
end
end
---------------------------------------------------------------------------------------
-- Hub Stats Functions
---------------------------------------------------------------------------------------
hubStatFunc = {
[cmd1] = function()
local msg = "--- Hub Stats Since "..HubStats.StatsSince.." ---\r\n\r\n"
msg = msg.."\tLogins: "..HubStats.Logins.."\r\n"..
"\tPeak Users: "..HubStats.MaxUsers.." - Current Users: "..frmHub:GetUsersCount().." - Max Users Allowed: "..frmHub:GetMaxUsers().."\r\n"..
"\tPeak Share: "..format("%.2f",(HubStats.MaxShareAmount/(1024*1024*1024*1024))).." TB"..
" - Current Share: "..format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024*1024))).." TB"..
" - Share/User: "..format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024)/frmHub:GetUsersCount())).." GB/User\r\n\r\n"..
GetReggedUsers()
return(msg)
end,
}
function GetReggedUsers()
local tcount,pcount = 0,0,0
local msg = ""
for _,profile in GetProfiles() do
pcount = pcount + 1
local ucount = 0
for _,_ in GetUsersByProfile(profile) do
ucount = ucount + 1
tcount = tcount + 1
end
msg = msg.."\t - "..profile..": "..ucount.."\r\n"
end
msg = "\tTotal Regged User: "..tcount.." in "..pcount.." Profiles\r\n\r\n"..msg
return(msg)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = openfile(file,"w")
Serialize(table,tablename,handle)
closefile(handle)
end
--------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
write(hFile,sTab..sTableName.." = {\n");
for key,value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile,sTab.."\t"..sKey.." = "..sValue);
end
write(hFile,",\n");
end
write(hFile,sTab.."}");
end
any help would be great :)
TY, AMediaMan
PS. Sorry i guess this should go into the request for script section. :(
Here try this...
--Converted to Lua5 by Jelf 07/03/05
--Hub Stats V.01 by chill
--Serialisation by RabidWombat
statFile = "HubStats.txt" -- The Filename
statFolder = "txt" -- The Foldername set it to nil if not wanted
Max1 = 1 -- Time between each stats saving
cmd1 = "+hubstats" -- Shows the Hub Stats
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
-- MAIN SCRIPT
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
if statFolder then
statFile = statFolder.."/"..statFile
local _,_,path = string.find(statFile, "(.+[/_\\]).+$")
if path ~= nil then
os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"")
end
end
HubStats = {
Logins = 0,
MaxShareAmount = frmHub:GetCurrentShareAmount(),
MaxUsers = frmHub:GetUsersCount(),
StatsSince = os.date("%d/%m/%y"),
}
--------------------------------------------------------
function Main()
SetTimer(60*1000*Max1)
StartTimer()
end
function OnExit()
SaveToFile(statFile, HubStats,"HubStats")
end
--------------------------------------------------------
function OnTimer()
SaveToFile(statFile, HubStats,"HubStats")
end
--------------------------------------------------------
function NewUserConnected(curUser)
if (frmHub:GetCurrentShareAmount() > HubStats.MaxShareAmount) then
HubStats.MaxShareAmount = frmHub:GetCurrentShareAmount()
end
if (frmHub:GetUsersCount() > HubStats.MaxUsers) then
HubStats.MaxUsers = frmHub:GetUsersCount()
end
HubStats.Logins = HubStats.Logins + 1
end
OpConnected = NewUserConnected
--------------------------------------------------------
function ChatArrival(curUser,data)
if string.sub(data,1,1) == "<" then
data = string.sub(data,string.len(curUser.sName)+4,string.len(data)-1)
local _,_,word1 = string.find(data,"^(%S+)")
if word1 and hubStatFunc[word1] then
curUser:SendData(hubStatFunc[word1]())
return 1
end
end
end
---------------------------------------------------------------------------------------
-- Hub Stats Functions
---------------------------------------------------------------------------------------
hubStatFunc = {
[cmd1] = function()
local msg = "--- Hub Stats Since "..HubStats.StatsSince.." ---\r\n\r\n"
msg = msg.."\tLogins: "..HubStats.Logins.."\r\n"..
"\tPeak Users: "..HubStats.MaxUsers.." - Current Users: "..frmHub:GetUsersCount().." - Max Users Allowed: "..frmHub:GetMaxUsers().."\r\n"..
"\tPeak Share: "..string.format("%.2f",(HubStats.MaxShareAmount/(1024*1024*1024*1024))).." TB"..
" - Current Share: "..string.format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024*1024))).." TB"..
" - Share/User: "..string.format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024)/frmHub:GetUsersCount())).." GB/User\r\n\r\n"..
GetReggedUsers()
return(msg)
end,
}
function GetReggedUsers()
local tcount,pcount = 0,0,0
local msg = ""
for _,profile in GetProfiles() do
pcount = pcount + 1
local ucount = 0
for _,_ in GetUsersByProfile(profile) do
ucount = ucount + 1
tcount = tcount + 1
end
msg = msg.."\t - "..profile..": "..ucount.."\r\n"
end
msg = "\tTotal Regged User: "..tcount.." in "..pcount.." Profiles\r\n\r\n"..msg
return(msg)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
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
Ty Jelf it seems to work fine :) may i ask whats the
real difference between 4 and 5 ? Just wondering.
Thnx again, AMediaMan
integrated functions i think, mostly. i.e. strsub() is now string.sub() and date() is now os.date()
QuoteOriginally posted by shufty
integrated functions i think, mostly. i.e. strsub() is now string.sub() and date() is now os.date()
can someone tell me more so i can convert my scripts to lua 5.
Compare my guestbuuk of lua4 and lua5. lua5 version.
--//RangeBlaster v2.07 by Phatty
--//IP Keys written by John, and Phatty
Bot = "IPRangeBlock"
Ranges = {}
function Main()
frmHub:RegBot(Bot)
LoadIps()
end
function LoadIps()
local tmp = 0
local handle = openfile("RangeBlaster/Ranges.dat","r")
line = read(handle)
while line do
tmp = tmp + 1
local s,e,ipr1,ipr2 = strfind(line,"(%S+)|(%S+)")
if ipr2 == nil then
SendToAll(Bot,"Error on line "..line)
end
local s,e,ipa1,ipb1,ipc1,ipd1 = strfind(ipr1, "(%d*).(%d*).(%d*).(%d*)")
local s,e,ipa2,ipb2,ipc2,ipd2 = strfind(ipr2, "(%d*).(%d*).(%d*).(%d*)")
si1 = CheckNumber(ipa1)..CheckNumber(ipb1)..CheckNumber(ipc1)..CheckNumber(ipd1)
si2 = CheckNumber(ipa2)..CheckNumber(ipb2)..CheckNumber(ipc2)..CheckNumber(ipd2)
Ranges[si1] = si2
line = read(handle)
end
SendToAll(Bot,"Successfully loaded "..tmp)
end
function Blocked(userip)
local s,e,range1,range2,range3,range4 = strfind(userip,"(%d+).(%d+).(%d+).(%d+)")
checker = CheckNumber(range1)..CheckNumber(range2)..CheckNumber(range3)..CheckNumber(range4)
--SendToAll(Bot,"IP-Test..."..checker)
for i,p in Ranges do
local s,e,xstart = strfind(i, "(%d*)")
local s,e,xend = strfind(p, "(%d*)")
if checker > xstart and checker < xend then
collectgarbage()
flush()
return 1
else
end
end
end
function CheckNumber(number)
numbera = tonumber(number)
if numbera < 10 then
numbera = "00"..number
elseif numbera < 100 then
numbera = "0"..number
else
numbera = number
end
return numbera
end
function DataArrival(user,data)
if strsub(data, 1, 13) == "$ValidateNick" then
if Blocked(user.sIP) == 1 then
user:SendData(Bot, "This hub is private, leave a message to ip-tracer@sm3yfx.net,and explain ho you are, you will now be disconnected!")
user:SendData(Bot, "Disconnecting...")
SendPmToOps(Bot, user.sName.." - "..user.sIP.." has been blasted by "..Bot.."!")
SendToAll(Bot, user.sName.." - "..user.sIP.." has been blasted by "..Bot.."!")
user:Disconnect()
end
end
end
Here ya go......
--//Converted to Lua5 by Jelf 08/03/05
--//RangeBlaster v2.07 by Phatty
--//IP Keys written by John, and Phatty
Bot = "IPRangeBlock"
path = "RangeBlaster/Ranges.dat"
Ranges = {}
-------------------------
function Main()
frmHub:RegBot(Bot)
LoadIps()
end
-------------------------
function LoadIps()
local tmp = 0
local handle = io.open(path,"r")
line = handle:read()
while line do
tmp = tmp + 1
local s,e,ipr1,ipr2 = string.find(line,"(%S+)|(%S+)")
if ipr2 == nil then
SendToAll(Bot,"Error on line "..line)
end
local s,e,ipa1,ipb1,ipc1,ipd1 = string.find(ipr1, "(%d*).(%d*).(%d*).(%d*)")
local s,e,ipa2,ipb2,ipc2,ipd2 = string.find(ipr2, "(%d*).(%d*).(%d*).(%d*)")
si1 = CheckNumber(ipa1)..CheckNumber(ipb1)..CheckNumber(ipc1)..CheckNumber(ipd1)
si2 = CheckNumber(ipa2)..CheckNumber(ipb2)..CheckNumber(ipc2)..CheckNumber(ipd2)
Ranges[si1] = si2
line = handle:read()
end
SendToAll(Bot,"Successfully loaded "..tmp)
end
--------------------------
function Blocked(userip)
local s,e,range1,range2,range3,range4 = string.find(userip,"(%d+).(%d+).(%d+).(%d+)")
checker = CheckNumber(range1)..CheckNumber(range2)..CheckNumber(range3)..CheckNumber(range4)
--SendToAll(Bot,"IP-Test..."..checker)
for i,p in Ranges do
local s,e,xstart = string.find(i, "(%d*)")
local s,e,xend = string.find(p, "(%d*)")
if checker > xstart and checker < xend then
collectgarbage()
io.flush()
return 1
else
end
end
end
-------------------------
function CheckNumber(number)
numbera = tonumber(number)
if numbera < 10 then
numbera = "00"..number
elseif numbera < 100 then
numbera = "0"..number
else
numbera = number
end
return numbera
end
------------------------
function ValidateNickArrival(user)
if Blocked(user.sIP) == 1 then
user:SendData(Bot, "This hub is private, leave a message to [EMAIL]ip-tracer@sm3yfx.net[/EMAIL],and explain who you are, you will now be disconnected!")
user:SendData(Bot, "Disconnecting...")
SendPmToOps(Bot, user.sName.." - "..user.sIP.." has been blasted by "..Bot.."!")
SendToAll(Bot, user.sName.." - "..user.sIP.." has been blasted by "..Bot.."!")
user:Disconnect()
end
end
QuoteOriginally posted by bastya_elvtars
Compare my guestbuuk of lua4 and lua5. lua5 version.
i also would like to learn how to convert to lua5, can u plz give links to get your guestbooks?
thx on advince :))
I got a question for you Jelf :) is it possible to add a clear or a reset to the hub stats script i posted above ? Maybe even make it individual reset ? Say like reset total logins or peak users, peak share. That would be cool if it is possible :)
AMediaMan
PS. How about adding a right click function :)
Thnx again for all the help , AMediaMan
Here, this should do you :)..
--Added Send Commands By TiMeTrAVelleR
--Added extra commands to reset hubstats - use +hubstathelp for commands
--Converted to Lua5 and added extra commands by Jelf 13/03/05
--Hub Stats V.01 by chill
--Serialisation by RabidWombat
statFile = "HubStats.txt" -- The Filename
statFolder = "txt" -- The Foldername set it to nil if not wanted
Max1 = 1 -- Time between each stats saving
cmd1 = "+hubstats" -- Shows the Hub Stats
SendComm = 1 -- Send UserCommands 1 = On 0 = Off
AllowedProfiles = {
[0] = 1, -- Masters
[1] = 0, -- Operators
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
}
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
-- MAIN SCRIPT
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
if statFolder then
statFile = statFolder.."/"..statFile
local _,_,path = string.find(statFile, "(.+[/_\\]).+$")
if path ~= nil then
os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"")
end
end
------------------------
HubStats = {
Logins = 0,
MaxShareAmount = frmHub:GetCurrentShareAmount(),
MaxUsers = frmHub:GetUsersCount(),
StatsSince = os.date("%d/%m/%y"),
}
-----------------------
function Main()
SetTimer(60*1000*Max1)
StartTimer()
end
-----------------------
function OnExit()
SaveToFile(statFile, HubStats,"HubStats")
end
-----------------------
function OnTimer()
SaveToFile(statFile, HubStats,"HubStats")
end
-----------------------
function NewUserConnected(curUser)
if (frmHub:GetCurrentShareAmount() > HubStats.MaxShareAmount) then
HubStats.MaxShareAmount = frmHub:GetCurrentShareAmount()
end
if (frmHub:GetUsersCount() > HubStats.MaxUsers) then
HubStats.MaxUsers = frmHub:GetUsersCount()
end
HubStats.Logins = HubStats.Logins + 1
if SendComm == 1 and AllowedProfiles[curUser.iProfile] == 1 then
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Show Help$<%[mynick]> +hubstathelp||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Show Hubstats$<%[mynick]> +hubstats||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset All$<%[mynick]> +resetall||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset Logins$<%[mynick]> +resetlogins||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset Share$<%[mynick]> +resetshare||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset Users$<%[mynick]> +resetusers||")
end
end
OpConnected = NewUserConnected
-----------------------
function ChatArrival(curUser,data)
if string.sub(data,1,1) == "<" then
data = string.sub(data,string.len(curUser.sName)+4,string.len(data)-1)
local _,_,word1 = string.find(data,"^(%S+)")
if word1 and hubStatFunc[word1] then
curUser:SendData(hubStatFunc[word1]())
return 1
elseif (word1 == "+resetall") then
HubStats.Logins = 0
HubStats.MaxUsers = 0
HubStats.MaxShareAmount = 0
HubStats.StatsSince = os.date("%d/%m/%y")
curUser:SendData("--- Hubstats have been totally reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+resetlogins") then
HubStats.Logins = 0
curUser:SendData("--- Hubstats logins have been reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+resetusers") then
HubStats.MaxUsers = 0
curUser:SendData("--- Hubstats MaxUsers have been reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+resetshare") then
HubStats.MaxShareAmount = 0
curUser:SendData("--- Hubstats MaxShare have been reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+hubstathelp") then
message = ""
message = message.. "\r\n\r\nThe following Hubstats commands are available:\r\n\r\n"
message = message.. " +hubstats -- Shows Current Hubstats \r\n"
message = message.. " +resetlogins -- Resets Hubstats logins \r\n"
message = message.. " +resetusers -- Resets Hubstats MaxUsers \r\n"
message = message.. " +resetshare -- Resets Hubstats MaxShare \r\n"
message = message.. " +resetall -- Resets all Hubstats \r\n"
curUser:SendData(message)
return 1
end
end
end
---------------------------------------------------------------------------------------
-- Hub Stats Functions
---------------------------------------------------------------------------------------
hubStatFunc = {
[cmd1] = function()
local msg = "--- Hub Stats Since "..HubStats.StatsSince.." ---\r\n\r\n"
msg = msg.."\tLogins: "..HubStats.Logins.."\r\n"..
"\tPeak Users: "..HubStats.MaxUsers.." - Current Users: "..frmHub:GetUsersCount().." - Max Users Allowed: "..frmHub:GetMaxUsers().."\r\n"..
"\tPeak Share: "..string.format("%.2f",(HubStats.MaxShareAmount/(1024*1024*1024*1024))).." TB"..
" - Current Share: "..string.format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024*1024))).." TB"..
" - Share/User: "..string.format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024)/frmHub:GetUsersCount())).." GB/User\r\n\r\n"..
GetReggedUsers()
return(msg)
end,
}
-------------------------
function GetReggedUsers()
local tcount,pcount = 0,0,0
local msg = ""
for _,profile in GetProfiles() do
pcount = pcount + 1
local ucount = 0
for _,_ in GetUsersByProfile(profile) do
ucount = ucount + 1
tcount = tcount + 1
end
msg = msg.."\t - "..profile..": "..ucount.."\r\n"
end
msg = "\tTotal Regged User: "..tcount.." in "..pcount.." Profiles\r\n\r\n"..msg
return(msg)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
SaveToFile = function(file,table , tablename )
local hFile = io.open (file , "w")
Save_Serialize(table, tablename, hFile);
hFile:close()
end
---------------------
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(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
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
WOW Jelf very very cool, it seems to work just fine. I ty much. Great job and ty again.
AMediaMan
Anytime :D
I wonder how many times i can ask for add ons without being a pest :) hahaha any chance of adding right clicks for this script ? say masters can reset stats, and op's and anyone else can view the hubstats ? I think that would be a cool add on :) Just asking.
Thnx for all the help,
AMediaMan
Ummm .. This script already has right clicks??
When you say Ops and anyone else can see hubstats, do mean everyone right down to non regged?
Try this:
--Added Send Commands By TiMeTrAVelleR
--Added extra commands to reset hubstats - use +hubstathelp for commands
--Converted to Lua5 and added extra commands by Jelf 13/03/05
--Hub Stats V.01 by chill
--Serialisation by RabidWombat
statFile = "HubStats.txt" -- The Filename
statFolder = "txt" -- The Foldername set it to nil if not wanted
Max1 = 1 -- Time between each stats saving
cmd1 = "+hubstats" -- Shows the Hub Stats
SendComm = 1 -- Send UserCommands 1 = On 0 = Off
AllowedProfiles = {
[0] = 1, -- Masters
[1] = 0, -- Operators
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
}
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
-- MAIN SCRIPT
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
if statFolder then
statFile = statFolder.."/"..statFile
local _,_,path = string.find(statFile, "(.+[/_\\]).+$")
if path ~= nil then
os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"")
end
end
------------------------
HubStats = {
Logins = 0,
MaxShareAmount = frmHub:GetCurrentShareAmount(),
MaxUsers = frmHub:GetUsersCount(),
StatsSince = os.date("%d/%m/%y"),
}
-----------------------
function Main()
SetTimer(60*1000*Max1)
StartTimer()
end
-----------------------
function OnExit()
SaveToFile(statFile, HubStats,"HubStats")
end
-----------------------
function OnTimer()
SaveToFile(statFile, HubStats,"HubStats")
end
-----------------------
function NewUserConnected(curUser)
if (frmHub:GetCurrentShareAmount() > HubStats.MaxShareAmount) then
HubStats.MaxShareAmount = frmHub:GetCurrentShareAmount()
end
if (frmHub:GetUsersCount() > HubStats.MaxUsers) then
HubStats.MaxUsers = frmHub:GetUsersCount()
end
HubStats.Logins = HubStats.Logins + 1
if SendComm == 1 and AllowedProfiles[curUser.iProfile] == 1 then
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Show Help$<%[mynick]> +hubstathelp||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Show Hubstats$<%[mynick]> +hubstats||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset All$<%[mynick]> +resetall||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset Logins$<%[mynick]> +resetlogins||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset Share$<%[mynick]> +resetshare||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Reset Users$<%[mynick]> +resetusers||")
elseif SendComm == 1 and (curUser.iProfile == 1 or curUser.iProfile == 2 or curUser.iProfile == 3 or curUser.iProfile == 4 or curUser.iProfile == 5 or curUser.iProfile == -1) then
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Show Help$<%[mynick]> +hubstathelp||")
curUser:SendData("$UserCommand 1 3 -=Hubstats=-\\Show Hubstats$<%[mynick]> +hubstats||")
end
end
OpConnected = NewUserConnected
-----------------------
function ChatArrival(curUser,data)
if string.sub(data,1,1) == "<" then
data = string.sub(data,string.len(curUser.sName)+4,string.len(data)-1)
local _,_,word1 = string.find(data,"^(%S+)")
if word1 and hubStatFunc[word1] then
curUser:SendData(hubStatFunc[word1]())
return 1
elseif (word1 == "+resetall") and (curUser.iProfile == 0 or curUser.iProfile == 5) then
HubStats.Logins = 0
HubStats.MaxUsers = 0
HubStats.MaxShareAmount = 0
HubStats.StatsSince = os.date("%d/%m/%y")
curUser:SendData("--- Hubstats have been totally reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+resetlogins") and (curUser.iProfile == 0 or curUser.iProfile == 5) then
HubStats.Logins = 0
curUser:SendData("--- Hubstats logins have been reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+resetusers") and (curUser.iProfile == 0 or curUser.iProfile == 5) then
HubStats.MaxUsers = 0
curUser:SendData("--- Hubstats MaxUsers have been reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+resetshare") and (curUser.iProfile == 0 or curUser.iProfile == 5) then
HubStats.MaxShareAmount = 0
curUser:SendData("--- Hubstats MaxShare have been reset by " ..curUser.sName.. " ---")
SaveToFile(statFile, HubStats,"HubStats")
return 1
elseif (word1 == "+hubstathelp") and (curUser.iProfile == 0 or curUser.iProfile == 5) then
message = ""
message = message.. "\r\n\r\nThe following Hubstats commands are available:\r\n\r\n"
message = message.. " +hubstats -- Shows Current Hubstats \r\n"
message = message.. " +resetlogins -- Resets Hubstats logins \r\n"
message = message.. " +resetusers -- Resets Hubstats MaxUsers \r\n"
message = message.. " +resetshare -- Resets Hubstats MaxShare \r\n"
message = message.. " +resetall -- Resets all Hubstats \r\n"
curUser:SendData(message)
return 1
elseif (word1 == "+hubstathelp") and (curUser.iProfile == 1 or curUser.iProfile == 2 or curUser.iProfile == 3 or curUser.iProfile == 4 or curUser.iProfile == -1) then
message = ""
message = message.. "\r\n\r\nThe following Hubstats commands are available:\r\n\r\n"
message = message.. " +hubstats -- Shows Current Hubstats \r\n"
message = message.. " +hubstathelp -- Show Help \r\n"
curUser:SendData(message)
return 1
end
end
end
---------------------------------------------------------------------------------------
-- Hub Stats Functions
---------------------------------------------------------------------------------------
hubStatFunc = {
[cmd1] = function()
local msg = "--- Hub Stats Since "..HubStats.StatsSince.." ---\r\n\r\n"
msg = msg.."\tLogins: "..HubStats.Logins.."\r\n"..
"\tPeak Users: "..HubStats.MaxUsers.." - Current Users: "..frmHub:GetUsersCount().." - Max Users Allowed: "..frmHub:GetMaxUsers().."\r\n"..
"\tPeak Share: "..string.format("%.2f",(HubStats.MaxShareAmount/(1024*1024*1024*1024))).." TB"..
" - Current Share: "..string.format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024*1024))).." TB"..
" - Share/User: "..string.format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024)/frmHub:GetUsersCount())).." GB/User\r\n\r\n"..
GetReggedUsers()
return(msg)
end,
}
-------------------------
function GetReggedUsers()
local tcount,pcount = 0,0,0
local msg = ""
for _,profile in GetProfiles() do
pcount = pcount + 1
local ucount = 0
for _,_ in GetUsersByProfile(profile) do
ucount = ucount + 1
tcount = tcount + 1
end
msg = msg.."\t - "..profile..": "..ucount.."\r\n"
end
msg = "\tTotal Regged User: "..tcount.." in "..pcount.." Profiles\r\n\r\n"..msg
return(msg)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
SaveToFile = function(file,table , tablename )
local hFile = io.open (file , "w")
Save_Serialize(table, tablename, hFile);
hFile:close()
end
---------------------
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(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
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
Well damn Jelf hahaha im sorry i didnt realize the right click was there lol. As far as commands i want everyone to be able to see the hubstats, reg and non reg :) But i only want masters to be able to reset. Sorry for buggin ya.
jiten im gonna check yours out as well ty for the response :)
AMediaMan
PS. Here are my profiles i would like the masters and netfounder to be the only ones that can reset. anyone else can view the hubstats :)
0|Master|11111110111101111111111000000001
1|Operator|11110100111101111100110000000001
2|VIP|10000000000001111100110000000000
3|Reg|10000000000000000000000000000000
4|Moderator|11110100111101111111000000000001
5|NetFounder|11111111111111111111111000000001
very nice jiten :) the only problem is that anyone can type the help command and then see and use the reset commands :) I can only have the masters and netfounder to be able to reset the stats if that is possible. But your version is working great other than that thnx for your help.
AMediaMan
First post updated.
Yw m8 :]
Getting closer jiten lol, but op's can still reset the stats.
Any way of stopping them from being able to? Sorry for
being a pest :) Thnx for all the help.
AMediaMan
Post updated.
Best regards,
jiten
Thank You jiten all seems to work fine :)
Thnx again, AMediaMan
yw m8 ;)