PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: BlazeXxX on 31 October, 2003, 03:30:09

Title: Top 10 Stats
Post by: BlazeXxX on 31 October, 2003, 03:30:09
Top 10 Kicker,Top 10 online users etc.. script by VidFramne

-- Start Copying From this line

-- A Kick-Counter By VidFamne, with lot of help by tezlo's code

-- Just type +TopKicker in main, and you get the best Kickers in your staff :-)

-- Added save- and load-function, with help of DirtyFinger's code and Steve Dekorte's code

-- Added a OP-Chat-Counter by VidFamne ( 23.05.2003 ) Just type +TopChatter in main.

-- Guibs added Top-Banner, thanx :)

-- Added TopOnliner (exprimental) By VidFamne ( 08.06.2003 ) Just type +TopOnliner in main.

-- and get the current TopOnliner in your Hub. :)

-- Added MyTime :) Just type +MyTime and get your current time spent in hub ( 09.06.2003 ) by VidFamne

-- Optimized a bit ( 09.06.2003 ) by VidFamne

-- Added Modified Julian day(minute) number function. Create 2 textfiles called Kickers.txt and Timer.txt

-- and put them in the same folder as your script.

-- Optimized a bit and add autosave and autoload, by VidFamne ( 21.06.2003 )









Tlist = {["Onliners"]={["login"]={}, ["Time"]={}}}

list = {["Kickers"]={}, ["Chatters"]={}, ["Banners"]={}}

nr = 10 --<-------Numbers of "Toppers" You want to show

limit = 15 --<-------Limitter for Time-counter, to filter away "short-time" visitors.Set in minutes.

Timefile = "Timer.txt"

Kickerfile = "Kickers.txt"





function Main()

Tlist = loadTableFromFile(Timefile)

list=loadTableFromFile(Kickerfile)

end



function DataArrival(curUser, sData)



if ( strsub(sData, 1, 5) == "$Kick" ) then

list.Kickers[curUser.sName] = list.Kickers[curUser.sName] or 0

list.Kickers[curUser.sName] = list.Kickers[curUser.sName]+1

saveTableToFile(Kickerfile,list)



elseif( strsub(sData, 1, 1) == "<" ) then

list.Chatters[curUser.sName] = list.Chatters[curUser.sName] or 0

list.Chatters[curUser.sName] = list.Chatters[curUser.sName]+1

saveTableToFile(Kickerfile,list)

end



if( strsub(sData, 1, 1) == "<" ) then

sData=strsub(sData,1,strlen(sData)-1)

s,e,cmd = strfind( sData, "%b<>%s+(%S+)" )



if (cmd=="!nickban") or (cmd=="!ban") then

list.Banners[curUser.sName] = list.Banners[curUser.sName] or 0

list.Banners[curUser.sName] = list.Banners[curUser.sName]+1

saveTableToFile(Kickerfile,list)



elseif (cmd=="+TopKicker") and (curUser.bOperator) then

local curtime = date()

SendToNick(curUser.sName,"\r\n\tTOP KICKER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")

local Index = sorting(list.Kickers)

for i = 1, Index.n do

local key = Index

SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Kickers[key])

SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

if i>=nr then break end

end

return 1

elseif (cmd=="+TopChatter") then

local curtime = date()

SendToNick(curUser.sName,"\r\n\tTOP CHATTER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")

local Index = sorting(list.Chatters)

for i = 1, Index.n do

local key = Index

SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Chatters[key])

SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

if i>=nr then break end

end

return 1

elseif (cmd=="+TopBanner") and (curUser.bOperator) then

local curtime = date()

SendToNick(curUser.sName,"\r\n\tTOP BANNER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")

local Index = sorting(list.Banners)

for i = 1, Index.n do

local key = Index

SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Banners[key])

SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

if i>=nr then break end

end

return 1

elseif (cmd=="+TopOnliner") then

local curtime = date()

local now = Calc(Tlist.Onliners.login, Tlist.Onliners.Time)

SendToNick(curUser.sName,"\r\n\tTOP ONLINER\t\t\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")

local Index = sorting(now)

for i = 1, Index.n do

local key = Index

local days, hrs, min = Timemess(now[key])

SendToNick(curUser.sName, "**** "..i.." [ "..key.." ] has been here for; "..days.." days, "..hrs.." hours and "..min.." minutes")

SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------------------------------------------")

if i>=nr then break end

end

return 1

elseif (cmd=="+MyTime") then

local curtime = date()

usrtime = MyTime(Tlist.Onliners.login, Tlist.Onliners.Time, curUser)

local days, hrs, min = Timemess(usrtime)

SendToNick(curUser.sName,"*** You have been here for "..days.." days, "..hrs.." hours and "..min.." minutes in this hub \t( "..curtime.." )" )

return 1

end

end

end



function sorting(table)

local index = {n=0}

foreach(table, function(key, value) tinsert(%index, key) end)

local func = function(a, b) return %table[a] > %table end

sort(index, func) return index

end



function loadTableFromFile(file)

readfrom(file)

local aString = read("*all")

return unpickle(aString)

end



function saveTableToFile(file,table)

local aString = pickle(table)

writeto(file)

write(aString)

writeto()

end



function NewUserConnected(curUser)

local minute = Jmn(a)

Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0

Tlist.Onliners.login[curUser.sName] = tonumber(minute)

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

saveTableToFile(Timefile,Tlist)

end



function UserDisconnected(curUser)

local minute = Jmn(a)

if Tlist.Onliners.login[curUser.sName] == nil then

Tlist.Onliners.Time[curUser.sName] = nil

else

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

if Tlist.Onliners.Time[curUser.sName] <= limit then

Tlist.Onliners.Time[curUser.sName] = nil

Tlist.Onliners.login[curUser.sName] = nil

else

Tlist.Onliners.login[curUser.sName] = nil

saveTableToFile(Timefile,Tlist)

end

end

end



function OpConnected(curUser)

local minute = Jmn(a)

Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0

Tlist.Onliners.login[curUser.sName] = tonumber(minute)

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

saveTableToFile(Timefile,Tlist)

end



function OpDisconnected(curUser)

local minute = Jmn(a)

if Tlist.Onliners.login[curUser.sName] == nil then

Tlist.Onliners.Time[curUser.sName] = nil

else

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0

Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

if Tlist.Onliners.Time[curUser.sName] <= limit then

Tlist.Onliners.Time[curUser.sName] = nil

Tlist.Onliners.login[curUser.sName] = nil

else

Tlist.Onliners.login[curUser.sName] = nil

saveTableToFile(Timefile,Tlist)

end

end

end



function Calc(a, c)

local indeX = {}

foreach(a, function(key,value)

for key, value in %a do

for key2, value2 in %c do

if (key == key2) then

local minute = Jmn()

local diff = tonumber(value2) + minute - tonumber(value)

rawset(%indeX, key, diff) end end end end)

return indeX

end



function MyTime(a, c, curUser)

local minute = Jmn()

local onTime =""

for key, value in a do

for key2, value2 in c do

if key == curUser.sName

and key2 == curUser.sName then

onTime = tonumber(value2) + minute - tonumber(value)

return onTime

end

end

end

end



function Jmn() --(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)

D = tonumber(date("%d"))

H = tonumber(date("%H"))

minutE = tonumber(date("%M"))

Y = tonumber(date("%Y"))

M = tonumber(date("%m"))

if M <= 2 then

M = M + 12

Y=Y-1

end

mn = 1440*(floor(Y*365,25) + floor((M+1)*30,6) + D -428) + H*60 + minutE

return mn

end



function Timemess(T)

local min = tonumber(T)

local days = floor(min/1440)

local hrs = floor((min-(days*1440))/60)

min = floor(min-(days*1440)-(hrs*60))

return days, hrs, min

end



----------------------------------------------

-- Pickle.lua

-- An table serialization utility for lua

-- Steve Dekorte, Apr 2000

-- Freeware

----------------------------------------------



function pickle(t)

return Pickle:clone():pickle_(t)

end



Pickle = {

clone = function (t) local nt={}; for i, v in t do nt=v end return nt end

}



function Pickle:pickle_(root)

if type(root) ~= "table" then

error("can only pickle tables, not ".. type(root).."s")

end

self._tableToRef = {}

self._refToTable = {}

local savecount = 0

self:ref_(root)

local s = ""



while getn(self._refToTable) > savecount do

savecount = savecount + 1

local t = self._refToTable[savecount]

s = s.."{\n"

for i, v in t do

s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))

end

s = s.."},\n"

end



return format("{%s}", s)

end



function Pickle:value_(v)

local vtype = type(v)

if vtype == "string" then return format("%q", v)

elseif vtype == "number" then return v

elseif vtype == "table" then return "{"..self:ref_(v).."}"

else --error("pickle a "..type(v).." is not supported")

end

end



function Pickle:ref_(t)

local ref = self._tableToRef[t]

if not ref then

if t == self then error("can't pickle the pickle class") end

tinsert(self._refToTable, t)

ref = getn(self._refToTable)

self._tableToRef[t] = ref

end

return ref

end



----------------------------------------------

-- unpickle

----------------------------------------------



function unpickle(s)

if type(s) ~= "string" then

error("can't unpickle a "..type(s)..", only strings")

end

local tables = dostring("return "..s)



for tnum = 1, getn(tables) do

local t = tables[tnum]

local tcopy = {}; for i, v in t do tcopy = v end

for i, v in tcopy do

local ni, nv

if type(i) == "table" then ni = tables[i[1]] else ni = i end

if type(v) == "table" then nv = tables[v[1]] else nv = v end

t[ni] = nv

end

end

return tables[1]

end

-- Finish Copying
Title:
Post by: VidFamne on 28 January, 2004, 04:10:56
Its been a while since last time, so I'm a bit "rosty".
Added a OnExit-function.
But sorry to say I cant test it, cause I havent got the latest Ptokax.
And this version is only for Ptokax with the new OnExit()-function
-- A Kick-Counter By VidFamne, with lot of help by tezlo's code
-- Just type +TopKicker in main, and you get the best Kickers in your staff :-)
-- Added save- and load-function, with help of DirtyFinger's code and Steve Dekorte's code
-- Added a OP-Chat-Counter by VidFamne ( 23.05.2003 ) Just type +TopChatter in main.
-- Guibs added Top-Banner, thanx :)
-- Added TopOnliner (exprimental) By VidFamne ( 08.06.2003 ) Just type +TopOnliner in main.
-- and get the current TopOnliner in your Hub. :)
-- Added MyTime :) Just type +MyTime and get your current time spent in hub ( 09.06.2003 ) by VidFamne
-- Optimized a bit ( 09.06.2003 ) by VidFamne
-- Added Modified Julian day(minute) number function. Create 2 textfiles called Kickers.txt and Timer.txt
-- and put them in the same folder as your script.
-- Optimized a bit and add autosave and autoload, by VidFamne ( 21.06.2003 )
-- Added OnExit(), by VidFamne ( 2004-01-28 ), and therefor removed autosavefunction.


nr = 10 --<-------Numbers of "Toppers" You want to show
limit = 15 --<-------Limitter for Time-counter, to filter away "short-time" visitors.Set in minutes.


Tlist = {["Onliners"]={["login"]={}, ["Time"]={}}}
list = {["Kickers"]={}, ["Chatters"]={}, ["Banners"]={}}

Timefile = "Timer.txt"
Kickerfile = "Kickers.txt"


 

function Main()
  Tlist = loadTableFromFile(Timefile)
  list=loadTableFromFile(Kickerfile)
end
 

function OnExit()

  saveTableToFile(Kickerfile,list)
  saveTableToFile(Timefile,Tlist)

end


function DataArrival(curUser, sData)
 
  if ( strsub(sData, 1, 5) == "$Kick" ) then
    list.Kickers[curUser.sName] = list.Kickers[curUser.sName] or 0
    list.Kickers[curUser.sName] = list.Kickers[curUser.sName]+1
 
  elseif( strsub(sData, 1, 1) == "<" ) then
    list.Chatters[curUser.sName] = list.Chatters[curUser.sName] or 0
    list.Chatters[curUser.sName] = list.Chatters[curUser.sName]+1
  end

    if( strsub(sData, 1, 1) == "<" ) then
 
      sData=strsub(sData,1,strlen(sData)-1)
      s,e,cmd = strfind( sData, "%b<>%s+(%S+)" )

        if (cmd=="!nickban") or (cmd=="!ban") then
 
          list.Banners[curUser.sName] = list.Banners[curUser.sName] or 0
          list.Banners[curUser.sName] = list.Banners[curUser.sName]+1  

        elseif (cmd=="+TopKicker") and (curUser.bOperator) then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP KICKER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Kickers)
 
            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Kickers[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end
                     
            end
 
        return 1

        elseif (cmd=="+TopChatter") then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP CHATTER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Chatters)

            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Chatters[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end

            end

        return 1

        elseif (cmd=="+TopBanner") and (curUser.bOperator) then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP BANNER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Banners)

            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Banners[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end

            end

         return 1

         elseif (cmd=="+TopOnliner") then

           local curtime = date()
           local now = Calc(Tlist.Onliners.login, Tlist.Onliners.Time)

             SendToNick(curUser.sName,"\r\n\tTOP ONLINER\t\t\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")

             local Index = sorting(now)

                for i = 1, Index.n do

                  local key = Index[i]
                  local days, hrs, min = Timemess(now[key])

                    SendToNick(curUser.sName, "**** "..i.." [ "..key.." ] has been here for; "..days.." days, "..hrs.." hours and "..min.." minutes")
                    SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------------------------------------------")

                      if i>=nr then break end

                end

         return 1

         elseif (cmd=="+MyTime") then

           local curtime = date()
           usrtime = MyTime(Tlist.Onliners.login, Tlist.Onliners.Time, curUser)
           local days, hrs, min = Timemess(usrtime)

             SendToNick(curUser.sName,"*** You have been here for "..days.." days, "..hrs.." hours and "..min.." minutes in this hub \t( "..curtime.." )" )

          return 1

         end

    end

end
 


function sorting(table)

  local index = {n=0}

    foreach(table, function(key, value) tinsert(%index, key) end)
 
      local func = function(a, b) return %table[a] > %table[b] end
 
        sort(index, func) return index

end
 


function loadTableFromFile(file)

  readfrom(file)

   local aString = read("*all")

     return unpickle(aString)

end
 


function saveTableToFile(file,table)

   local aString = pickle(table)

     writeto(file)

       write(aString)

     writeto()

end
 


function NewUserConnected(curUser)

  local minute = Jmn(a)

  Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0

  Tlist.Onliners.login[curUser.sName] = tonumber(minute)

  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0

  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])  

end
 


function UserDisconnected(curUser)

  local minute = Jmn(a)

    if Tlist.Onliners.login[curUser.sName] == nil then

      Tlist.Onliners.Time[curUser.sName] = nil

      else

        Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
        Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

        if Tlist.Onliners.Time[curUser.sName] <= limit then

          Tlist.Onliners.Time[curUser.sName] = nil
          Tlist.Onliners.login[curUser.sName] = nil

          else

            Tlist.Onliners.login[curUser.sName] = nil  
        end
    end
end
 


function OpConnected(curUser)

local minute = Jmn(a)

  Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0

  Tlist.Onliners.login[curUser.sName] = tonumber(minute)

  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0

  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])  

end
 


function OpDisconnected(curUser)

  local minute = Jmn(a)

    if Tlist.Onliners.login[curUser.sName] == nil then

      Tlist.Onliners.Time[curUser.sName] = nil

      else

        Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
        Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

        if Tlist.Onliners.Time[curUser.sName] <= limit then

          Tlist.Onliners.Time[curUser.sName] = nil
          Tlist.Onliners.login[curUser.sName] = nil

          else

            Tlist.Onliners.login[curUser.sName] = nil  
        end
    end
end
 


function Calc(a, c)

  local indeX = {}

    foreach(a, function(key,value)

      for key, value in %a do

        for key2, value2 in %c do

          if (key == key2) then

          local minute = Jmn()
          local diff = tonumber(value2) + minute - tonumber(value)

            rawset(%indeX, key, diff) end end end end)

    return indeX

end
 


function MyTime(a, c, curUser)

  local minute = Jmn()
  local onTime =""

    for key, value in a do

      for key2, value2 in c do

        if key == curUser.sName and key2 == curUser.sName then

          onTime = tonumber(value2) + minute - tonumber(value)

          return onTime

         end

      end

   end

end
 


function Jmn() --(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)

  D = tonumber(date("%d"))
  H = tonumber(date("%H"))
  minutE = tonumber(date("%M"))
  Y = tonumber(date("%Y"))
  M = tonumber(date("%m"))

    if M <= 2 then

      M = M + 12
      Y=Y-1

    end

        mn = 1440*(floor(Y*365,25) + floor((M+1)*30,6) + D -428) + H*60 + minutE
        return mn

end
 


function Timemess(T)

  local min = tonumber(T)
  local days = floor(min/1440)
  local hrs = floor((min-(days*1440))/60)
  min = floor(min-(days*1440)-(hrs*60))
  return days, hrs, min

end
Rest of the code comes a bit down  :))
Title:
Post by: VidFamne on 28 January, 2004, 04:13:08
here is the rest of it;----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, <[URL]http://www.dekorte.com,[/URL]> Apr 2000
-- Freeware
----------------------------------------------


function pickle(t)

return Pickle:clone():pickle_(t)

end


Pickle = {

clone = function (t) local nt={}; for i, v in t do nt[i]=v end return nt end

}


function Pickle:pickle_(root)

if type(root) ~= "table" then

error("can only pickle tables, not ".. type(root).."s")

end

self._tableToRef = {}

self._refToTable = {}

local savecount = 0

self:ref_(root)

local s = ""


while getn(self._refToTable) > savecount do

savecount = savecount + 1

local t = self._refToTable[savecount]

s = s.."{\n"

for i, v in t do

s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))

end

s = s.."},\n"

end


return format("{%s}", s)

end


function Pickle:value_(v)

local vtype = type(v)

if vtype == "string" then return format("%q", v)

elseif vtype == "number" then return v

elseif vtype == "table" then return "{"..self:ref_(v).."}"

else --error("pickle a "..type(v).." is not supported")

end

end


function Pickle:ref_(t)

local ref = self._tableToRef[t]

if not ref then

if t == self then error("can't pickle the pickle class") end

tinsert(self._refToTable, t)

ref = getn(self._refToTable)

self._tableToRef[t] = ref

end

return ref

end


----------------------------------------------
-- unpickle
----------------------------------------------


function unpickle(s)

if type(s) ~= "string" then

error("can't unpickle a "..type(s)..", only strings")

end

local tables = dostring("return "..s)


for tnum = 1, getn(tables) do

local t = tables[tnum]

local tcopy = {}; for i, v in t do tcopy[i] = v end

for i, v in tcopy do

local ni, nv

if type(i) == "table" then ni = tables[i[1]] else ni = i end

if type(v) == "table" then nv = tables[v[1]] else nv = v end

t[ni] = nv

end

end

return tables[1]

end
Title:
Post by: VidFamne on 03 February, 2004, 03:52:25
hehe, a  tiny little change here :))
Added so you dont have to create the two text-files anymore.
It is creating it, all by itself,
but still it only for the debugversion of Ptokax.
Wish I have it ;)
EDIT; A bugfix added
;-- A Kick-Counter By VidFamne, with lot of help by tezlo's code
-- Just type +TopKicker in main, and you get the best Kickers in your staff :-)
-- Added save- and load-function, with help of DirtyFinger's code and Steve Dekorte's code
-- Added a OP-Chat-Counter by VidFamne ( 23.05.2003 ) Just type +TopChatter in main.
-- Guibs added Top-Banner, thanx :)
-- Added TopOnliner (exprimental) By VidFamne ( 08.06.2003 ) Just type +TopOnliner in main.
-- and get the current TopOnliner in your Hub. :)
-- Added MyTime :) Just type +MyTime and get your current time spent in hub ( 09.06.2003 ) by VidFamne
-- Optimized a bit ( 09.06.2003 ) by VidFamne
-- Added Modified Julian day(minute) number function.
-- Optimized a bit and add autosave and autoload, by VidFamne ( 21.06.2003 )
-- Added OnExit(), by VidFamne ( 2004-01-28 ), and therefor removed autosavefunction, in some places.
-- Change a tiny bit; ( 2004-02-03 ) Now you dont have to create the two text-files,
-- Its doing it by itself ;))

nr = 10 --<-------Numbers of "Toppers" You want to show
limit = 15 --<-------Limitter for Time-counter, to filter away "short-time" visitors.Set in minutes.


Tlist = {["Onliners"]={["login"]={}, ["Time"]={}}}
list = {["Kickers"]={}, ["Chatters"]={}, ["Banners"]={}}

Timefile = "Timer.txt"
Kickerfile = "Kickers.txt"


 

function Main()
  Tlist, list = loadTableFromFile(Timefile), loadTableFromFile(Kickerfile)
end
 

function OnExit()
  saveTableToFile(Kickerfile,list)
  saveTableToFile(Timefile,Tlist)
end


function DataArrival(curUser, sData)
 
  if ( strsub(sData, 1, 5) == "$Kick" ) then
    list.Kickers[curUser.sName] = list.Kickers[curUser.sName] or 0
    list.Kickers[curUser.sName] = list.Kickers[curUser.sName]+1
 
  elseif( strsub(sData, 1, 1) == "<" ) then
    list.Chatters[curUser.sName] = list.Chatters[curUser.sName] or 0
    list.Chatters[curUser.sName] = list.Chatters[curUser.sName]+1
  end

    if( strsub(sData, 1, 1) == "<" ) then
 
      sData=strsub(sData,1,-2)
      s,e,cmd = strfind( sData, "%b<>%s+(%S+)" )

        if (cmd=="!nickban") or (cmd=="!ban") then
 
          list.Banners[curUser.sName] = list.Banners[curUser.sName] or 0
          list.Banners[curUser.sName] = list.Banners[curUser.sName]+1  

        elseif (cmd=="+TopKicker") and (curUser.bOperator) then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP KICKER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Kickers)
 
            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Kickers[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end
                     
            end
 
        return 1

        elseif (cmd=="+TopChatter") then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP CHATTER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Chatters)

            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Chatters[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end

            end

        return 1

        elseif (cmd=="+TopBanner") and (curUser.bOperator) then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP BANNER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Banners)

            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Banners[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end

            end

         return 1

         elseif (cmd=="+TopOnliner") then

           local curtime = date()
           local now = Calc(Tlist.Onliners.login, Tlist.Onliners.Time)

             SendToNick(curUser.sName,"\r\n\tTOP ONLINER\t\t\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")

             local Index = sorting(now)

                for i = 1, Index.n do

                  local key = Index[i]
                  local days, hrs, min = Timemess(now[key])

                    SendToNick(curUser.sName, "**** "..i.." [ "..key.." ] has been here for; "..days.." days, "..hrs.." hours and "..min.." minutes")
                    SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------------------------------------------")

                      if i>=nr then break end

                end

         return 1

         elseif (cmd=="+MyTime") then

           local curtime = date()
           usrtime = MyTime(Tlist.Onliners.login, Tlist.Onliners.Time, curUser)
           local days, hrs, min = Timemess(usrtime)

             SendToNick(curUser.sName,"*** You have been here for "..days.." days, "..hrs.." hours and "..min.." minutes in this hub \t( "..curtime.." )" )

          return 1

         end

    end

end
 


function sorting(table)

  local index = {n=0}
  foreach(table, function(key, value) tinsert(%index, key) end)
  local func = function(a, b) return %table[a] > %table[b] end
  sort(index, func) return index

end
 


function loadTableFromFile(file)
  if readfrom(file) ~= nil then
   local aString = read("*all")
     return unpickle(aString)
  else
   saveTableToFile(Kickerfile,list)
   saveTableToFile(Timefile,Tlist)
   readfrom(file)
   local aString = read("*all")
     return unpickle(aString)
  end
end
 


function saveTableToFile(file,table)

   local aString = pickle(table)
     writeto(file)
       write(aString)
     writeto()

end
 


function NewUserConnected(curUser)

  local minute = Jmn(a)
  Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0
  Tlist.Onliners.login[curUser.sName] = tonumber(minute)
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])  

end
 


function UserDisconnected(curUser)

  local minute = Jmn(a)
 
    if Tlist.Onliners.login[curUser.sName] == nil then
     Tlist.Onliners.Time[curUser.sName] = nil
    else
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

      if Tlist.Onliners.Time[curUser.sName] <= limit then
       Tlist.Onliners.Time[curUser.sName] = nil
       Tlist.Onliners.login[curUser.sName] = nil
      else
       Tlist.Onliners.login[curUser.sName] = nil  
      end
    end
end
 


function OpConnected(curUser)

  local minute = Jmn(a)
  Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0
  Tlist.Onliners.login[curUser.sName] = tonumber(minute)
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])  

end
 


function OpDisconnected(curUser)

  local minute = Jmn(a)
 
    if Tlist.Onliners.login[curUser.sName] == nil then
     Tlist.Onliners.Time[curUser.sName] = nil
    else
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

      if Tlist.Onliners.Time[curUser.sName] <= limit then
       Tlist.Onliners.Time[curUser.sName] = nil
       Tlist.Onliners.login[curUser.sName] = nil
      else
       Tlist.Onliners.login[curUser.sName] = nil  
      end
    end
 
end
 


function Calc(a, c)

  local indeX = {}

    foreach(a, function(key,value)
      for key, value in %a do
        for key2, value2 in %c do
          if (key == key2) then
          local minute = Jmn()
          local diff = tonumber(value2) + minute - tonumber(value)
          rawset(%indeX, key, diff) end end end end)
    return indeX

end
 


function MyTime(a, c, curUser)

  local minute = Jmn()
  local onTime =""

    for key, value in a do
      for key2, value2 in c do
        if key == curUser.sName and key2 == curUser.sName then
          onTime = tonumber(value2) + minute - tonumber(value)
          return onTime
        end
      end
    end
 
end
 


function Jmn() --(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)

  D = tonumber(date("%d"))
  H = tonumber(date("%H"))
  minutE = tonumber(date("%M"))
  Y = tonumber(date("%Y"))
  M = tonumber(date("%m"))

    if M <= 2 then
      M = M + 12
      Y=Y-1
    end

        mn = 1440*(floor(Y*365,25) + floor((M+1)*30,6) + D -428) + H*60 + minutE
        return mn

end
 


function Timemess(T)

  local min = tonumber(T)
  local days = floor(min/1440)
  local hrs = floor((min-(days*1440))/60)
  min = floor(min-(days*1440)-(hrs*60))
  return days, hrs, min

end
Title:
Post by: VidFamne on 03 February, 2004, 03:53:58
here comes the rest;----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, [URL]http://www.dekorte.com,[/URL] Apr 2000
-- Freeware
----------------------------------------------

function pickle(t)
  return Pickle:clone():pickle_(t)
end

Pickle = {
  clone = function (t) local nt={}; for i, v in t do nt[i]=v end return nt end
}

function Pickle:pickle_(root)
  if type(root) ~= "table" then
    error("can only pickle tables, not ".. type(root).."s")
  end
  self._tableToRef = {}
  self._refToTable = {}
  local savecount = 0
  self:ref_(root)
  local s = ""

  while getn(self._refToTable) > savecount do
    savecount = savecount + 1
    local t = self._refToTable[savecount]
    s = s.."{\n"
    for i, v in t do
        s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
    end
    s = s.."},\n"
  end

  return format("{%s}", s)
end

function Pickle:value_(v)
  local vtype = type(v)
  if     vtype == "string" then return format("%q", v)
  elseif vtype == "number" then return v
  elseif vtype == "table" then return "{"..self:ref_(v).."}"
  else --error("pickle a "..type(v).." is not supported")
  end  
end

function Pickle:ref_(t)
  local ref = self._tableToRef[t]
  if not ref then
    if t == self then error("can't pickle the pickle class") end
    tinsert(self._refToTable, t)
    ref = getn(self._refToTable)
    self._tableToRef[t] = ref
  end
  return ref
end

----------------------------------------------
-- unpickle
----------------------------------------------

function unpickle(s)
  if type(s) ~= "string" then
    error("can't unpickle a "..type(s)..", only strings")
  end
  local tables = dostring("return "..s)
 
  for tnum = 1, getn(tables) do
    local t = tables[tnum]
    local tcopy = {}; for i, v in t do tcopy[i] = v end
    for i, v in tcopy do
      local ni, nv
      if type(i) == "table" then ni = tables[i[1]] else ni = i end
      if type(v) == "table" then nv = tables[v[1]] else nv = v end
      t[ni] = nv
    end
  end
  return tables[1]
end
Title:
Post by: BlazeXxX on 04 February, 2004, 12:25:35
Nicee work VidFrame :) :)

Looks much better now!
Title: Error
Post by: XPMAN on 08 February, 2004, 02:15:18
Excellent script BlazeXxX.....i did get this error though:

 
QuoteSyntax error: attempt to call global `pickle' (a nil value)  stack traceback:    
1:  function `saveTableToFile' at line 370 [file `....18.BACKUP\scripts\topstats.lua']    
 2:  function `loadTableFromFile' at line 346 [file `....18.BACKUP\scripts\topstats.lua']  
  3:  function `Main' at line 62 [file `....18.BACKUP\scripts\topstats.lua']    

After i loaded it i did a syntax check and it was ok, but when i started the script i got that error. Any ideas on what caused it or how to fix it. I am a beta tester testing the 330 25 PtokaX hub software.  

I also checked and the two txt files wasnt made, also the  +MyTime  did not work.  from what i could tell the +TopOnliner and +TopChatter did work but the results didnt seem to save. After I restared the hub everything cleared out.
Title:
Post by: VidFamne on 08 February, 2004, 03:36:46
Please copy the last updated script, and I think it will be fine.
Also note; the script is in two post, cause its size. :))
Title: New script
Post by: XPMAN on 08 February, 2004, 04:06:49
I did. Took this last part of the main  :

function Timemess(T)



  local min = tonumber(T)

  local days = floor(min/1440)

  local hrs = floor((min-(days*1440))/60)

  min = floor(min-(days*1440)-(hrs*60))

  return days, hrs, min



end

[ HIT TWO CARRIAGE RETURNS THEN STARTED WITH THE SECOND PART]


function pickle(t)

  return Pickle:clone():pickle_(t)

end



Pickle = {

  clone = function (t) local nt={}; for i, v in t do nt=v end return nt end

}


That was how i was supposed to do it,........or not...i left the  :

----------------------------------------------

-- Pickle.lua

-- An table serialization utility for lua

-- Steve Dekorte, http://www.dekorte.com, Apr 2000

-- Freeware

----------------------------------------------

off because i didnt know if that could be in the middle of the script or not.

Sorry for being dumb on this, but i think i did it right, but please tell me if i didnt.
Title: Got it!!
Post by: XPMAN on 08 February, 2004, 04:32:08
Finally got it working. Hate to be a pain but was wondering if there was anyway to have the time the users are in the hub not cleared out when the hub was reset......basically keep a total running total of all the time they have spent in the hub.

Was needing something that kept a running total so i could keep up with how long in a certain period of time members were in the hub. Maybe be nice to clear from main chat also.  Its an awesome script!! Only missing a couple of functions that I really,really need. Thnx in advance for taking the time to help ;)
Title:
Post by: VidFamne on 08 February, 2004, 15:21:32
It is not cleared out, its saved to file, but only if the user stays in hub for minimum of 15 minutes. (Its adjustable. Just change the value of 'limit', to the time you want)
About the main-messages; its only the user who type the command who can see the  'toppers'  in main
Hope this will solve some ;))
Title: Thnx
Post by: XPMAN on 08 February, 2004, 22:04:50
Seems to work perfectly now!! Thnx alot for taking the time to help me. :)
Title:
Post by: Andersk33 on 10 February, 2004, 18:08:13
Hi all..

I tried the script and it works fine..  :D

get the good work up guys.... :D
/Anders
Title:
Post by: VidFamne on 16 February, 2004, 12:57:48
Thanx for the appreciation. :))
Added a +NickTime -command.
Works with offline users too.
Hopefully without any bugs.:)-- A Kick-Counter By VidFamne, with lot of help by tezlo's code
-- Just type +TopKicker in main, and you get the best Kickers in your staff :-)
-- Added save- and load-function, with help of DirtyFinger's code and Steve Dekorte's code
-- Added a OP-Chat-Counter by VidFamne ( 23.05.2003 ) Just type +TopChatter in main.
-- Guibs added Top-Banner, thanx :)
-- Added TopOnliner (exprimental) By VidFamne ( 08.06.2003 ) Just type +TopOnliner in main.
-- and get the current TopOnliner in your Hub. :)
-- Added MyTime :) Just type +MyTime and get your current time spent in hub ( 09.06.2003 ) by VidFamne
-- Optimized a bit ( 09.06.2003 ) by VidFamne
-- Added Modified Julian day(minute) number function.
-- Optimized a bit and add autosave and autoload, by VidFamne ( 21.06.2003 )
-- Added OnExit(), by VidFamne ( 2004-01-28 ), and therefor removed autosavefunction, in some places.
-- Change a tiny bit; ( 2004-02-03 ) Now you dont have to create the two text-files,
-- Its doing it by itself ;))
-- Added "+NickTime" -command, so we can see a specific User's "Ontime". Working  with offline users too.
-- Just type +NickTime   ( 2004-02-16 )

nr = 10 --<-------Numbers of "Toppers" You want to show
limit = 8 --<-------Limitter for Time-counter, to filter away "short-time" visitors. Set in minutes.


Tlist = {["Onliners"]={["login"]={}, ["Time"]={}}}
list = {["Kickers"]={}, ["Chatters"]={}, ["Banners"]={}}

Timefile = "Timer.txt"
Kickerfile = "Kickers.txt"


 

function Main()
  Tlist, list = loadTableFromFile(Timefile), loadTableFromFile(Kickerfile)
end
 

function OnExit()
         saveTableToFile(Kickerfile,list)
         saveTableToFile(Timefile,Tlist)    
end


function DataArrival(curUser, sData)
 
  if ( strsub(sData, 1, 5) == "$Kick" ) then
    list.Kickers[curUser.sName] = list.Kickers[curUser.sName] or 0
    list.Kickers[curUser.sName] = list.Kickers[curUser.sName]+1
 
  elseif( strsub(sData, 1, 1) == "<" ) then
    list.Chatters[curUser.sName] = list.Chatters[curUser.sName] or 0
    list.Chatters[curUser.sName] = list.Chatters[curUser.sName]+1  
 
      sData=strsub(sData,1,-2)
      s,e,cmd,arg = strfind( sData, "%b<>%s+(%S+)%s*(%S*)" )

        if (cmd=="!nickban") or (cmd=="!ban") then
 
          list.Banners[curUser.sName] = list.Banners[curUser.sName] or 0
          list.Banners[curUser.sName] = list.Banners[curUser.sName]+1  

        elseif (cmd=="+TopKicker") and (curUser.bOperator) then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP KICKER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Kickers)
 
            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Kickers[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end
                     
            end
return 1
       

        elseif (cmd=="+TopChatter") then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP CHATTER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Chatters)

            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Chatters[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end

            end
return 1
         

        elseif (cmd=="+TopBanner") and (curUser.bOperator) then

          local curtime = date()
          SendToNick(curUser.sName,"\r\n\tTOP BANNER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
          local Index = sorting(list.Banners)

            for i = 1, Index.n do

              local key = Index[i]
              SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Banners[key])
              SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")

                if i>=nr then break end

            end
return 1
         

         elseif (cmd=="+TopOnliner") then

           local curtime = date()
           local now = Calc(Tlist.Onliners.login, Tlist.Onliners.Time)
             SendToNick(curUser.sName,"\r\n\tTOP ONLINER\t\t\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
           local Index = sorting(now)
                for i = 1, Index.n do
                  local key = Index[i]
                  local days, hrs, min = Timemess(now[key])
                    SendToNick(curUser.sName, "**** "..i.." [ "..key.." ] has been here for; "..days.." days, "..hrs.." hours and "..min.." minutes")
                    SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------------------------------------------")
                  if i>=nr then break end
                end
return 1
         

         elseif (cmd=="+MyTime") then

           local curtime = date()
           local usrtime = MyTime(Tlist.Onliners.login, Tlist.Onliners.Time, curUser)
           local days, hrs, min = Timemess(usrtime)
             SendToNick(curUser.sName,"*** You have been here for "..days.." days, "..hrs.." hours and "..min.." minutes in this hub \t( "..curtime.." )" )

          return 1
 
 elseif (cmd=="+NickTime") then
  local nick = arg
           local curtime = date()
           local usrtime = nickTime(Tlist.Onliners.login, Tlist.Onliners.Time, nick)
if  usrtime ==nil then
SendToNick(curUser.sName,"**** "..nick.." isn't in our records****\t( "..curtime.." )") return 1 end
           local days, hrs, min = Timemess(usrtime)
              SendToNick(curUser.sName,"*** "..nick.." have been here for "..days.." days, "..hrs.." hours and "..min.." minutes in this hub \t( "..curtime.." )" )

          return 1
         end end
end
 


function sorting(table)

  local index = {n=0}
  foreach(table, function(key, value) tinsert(%index, key) end)
  local func = function(a, b) return %table[a] > %table[b] end
  sort(index, func) return index
end
 


function loadTableFromFile(file)
  if readfrom(file) ~= nil then
   local aString = read("*all")
     return unpickle(aString)
  else
   saveTableToFile(Kickerfile,list)
   saveTableToFile(Timefile,Tlist)
  readfrom(file)
   local aString = read("*all")
    return unpickle(aString)
  end
end
 


function saveTableToFile(file,table)

   local aString = pickle(table)
     writeto(file)
       write(aString)
     writeto()
end
 


function NewUserConnected(curUser)

  local minute = Jmn(a)
  Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0
  Tlist.Onliners.login[curUser.sName] = tonumber(minute)
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])  

end
 


function UserDisconnected(curUser)

  local minute = Jmn(a)
 
    if Tlist.Onliners.login[curUser.sName] == nil then
     Tlist.Onliners.Time[curUser.sName] = nil
    else
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

      if Tlist.Onliners.Time[curUser.sName] <= limit then
       Tlist.Onliners.Time[curUser.sName] = nil
       Tlist.Onliners.login[curUser.sName] = nil
      else
       Tlist.Onliners.login[curUser.sName] = nil  
      end
    end
end
 


function OpConnected(curUser)

  local minute = Jmn(a)
  Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0
  Tlist.Onliners.login[curUser.sName] = tonumber(minute)
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
  Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])  

end
 


function OpDisconnected(curUser)

  local minute = Jmn(a)
 
    if Tlist.Onliners.login[curUser.sName] == nil then
     Tlist.Onliners.Time[curUser.sName] = nil
    else
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
     Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])

      if Tlist.Onliners.Time[curUser.sName] <= limit then
       Tlist.Onliners.Time[curUser.sName] = nil
       Tlist.Onliners.login[curUser.sName] = nil
      else
       Tlist.Onliners.login[curUser.sName] = nil  
      end
    end
 
end
 


function Calc(a, c)

  local indeX = {}
    foreach(a, function(key,value)
      for key, value in %a do
        for key2, value2 in %c do
          if (key == key2) then
          local minute = Jmn()
          local diff = tonumber(value2) + minute - tonumber(value)
          rawset(%indeX, key, diff)
          end
        end
      end
    end)
    return indeX
end



function MyTime(a, c, curUser)

  local minute = Jmn()
  local onTime =""
    for key, value in a do
      for key2, value2 in c do
        if key == curUser.sName and key2 == curUser.sName then
          onTime = tonumber(value2) + minute - tonumber(value)
          return onTime
        end
      end
    end
 
end
 


function Jmn() --(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)

  D = tonumber(date("%d"))
  H = tonumber(date("%H"))
  minutE = tonumber(date("%M"))
  Y = tonumber(date("%Y"))
  M = tonumber(date("%m"))
    if M <= 2 then
      M = M + 12
      Y=Y-1
    end
        mn = 1440*(floor(Y*365,25) + floor((M+1)*30,6) + D -428) + H*60 + minutE
        return mn
end
 

function Timemess(T)

  local min = tonumber(T)
  local days = floor(min/1440)
  local hrs = floor((min-(days*1440))/60)
  min = floor(min-(days*1440)-(hrs*60))
  return days, hrs, min
end

function nickTime(a, c, e)

  local minute = Jmn()
  local onTime =""
    for k, v in a do
       for k2, v2 in c do
        if k==e and k2==e then
onTime = tonumber(v2) + minute - tonumber(v) return onTime
elseif (a[e] == nil) then
onTime = tonumber(c[e]) return onTime          
        end end end
end
Title:
Post by: VidFamne on 16 February, 2004, 12:59:00
Here comes the rest;----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, [URL]http://www.dekorte.com,[/URL] Apr 2000
-- Freeware
----------------------------------------------

function pickle(t)
  return Pickle:clone():pickle_(t)
end

Pickle = {
  clone = function (t) local nt={}; for i, v in t do nt[i]=v end return nt end
}

function Pickle:pickle_(root)
  if type(root) ~= "table" then
    error("can only pickle tables, not ".. type(root).."s")
  end
  self._tableToRef = {}
  self._refToTable = {}
  local savecount = 0
  self:ref_(root)
  local s = ""

  while getn(self._refToTable) > savecount do
    savecount = savecount + 1
    local t = self._refToTable[savecount]
    s = s.."{\n"
    for i, v in t do
        s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
    end
    s = s.."},\n"
  end

  return format("{%s}", s)
end

function Pickle:value_(v)
  local vtype = type(v)
  if     vtype == "string" then return format("%q", v)
  elseif vtype == "number" then return v
  elseif vtype == "table" then return "{"..self:ref_(v).."}"
  else --error("pickle a "..type(v).." is not supported")
  end  
end

function Pickle:ref_(t)
  local ref = self._tableToRef[t]
  if not ref then
    if t == self then error("can't pickle the pickle class") end
    tinsert(self._refToTable, t)
    ref = getn(self._refToTable)
    self._tableToRef[t] = ref
  end
  return ref
end

----------------------------------------------
-- unpickle
----------------------------------------------

function unpickle(s)
  if type(s) ~= "string" then
    error("can't unpickle a "..type(s)..", only strings")
  end
  local tables = dostring("return "..s)
 
  for tnum = 1, getn(tables) do
    local t = tables[tnum]
    local tcopy = {}; for i, v in t do tcopy[i] = v end
    for i, v in tcopy do
      local ni, nv
      if type(i) == "table" then ni = tables[i[1]] else ni = i end
      if type(v) == "table" then nv = tables[v[1]] else nv = v end
      t[ni] = nv
    end
  end
  return tables[1]
end
Title:
Post by: Andersk33 on 16 February, 2004, 23:18:44
Hi..

I tried the uppdate, but i cant see my self in the "+TopOnline" comand..........
Im the owner at the hub, and it worked with the second newest version......

i hope you can ckeck it out....

A happy users of you script...... :)
Title:
Post by: B-B-I on 28 February, 2004, 11:47:47
Great Script

Just what i was looking for


Thanks ;)
Title:
Post by: Scorpion on 29 March, 2004, 16:44:56
could u make it not case sensimble, i could make it but i don't know the comand to uppcase a string :)
Title:
Post by: Scorpion on 30 March, 2004, 01:36:08
and another thing can u make it to remember users even when the go down, and even when the hub go's down with a time limit or something