userinfo database
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

userinfo database

Started by MoNTeR, 13 May, 2005, 20:16:43

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MoNTeR

Hello Everyone

I've found this script by NightLitch and tried to convert it to lua 5.

After converting:

---------------------------------------------------------------------------------------
-- Userinfo Database with Cleaning function
---------------------------------------------------------------------------------------
-- By: NightLitch 2004-04-16
-- Version: 1.21c
---------------------------------------------------------------------------------------
-- Commands:
--         !getinfo - Get userinfo
--         !clean - Clean database
--         !showcleanlist - Show clean list
--
---------------------------------------------------------------------------------------
-- NOTE: Create a folder name: ( Log )
-- and files inside:
--            String.log
--            Time.log
--            IP.log
--
---------------------------------------------------------------------------------------
-- Calculate share
kb = 1024
gb = kb*kb*kb
tb = kb*kb*kb*kb

-- BotName
BotName = "[_UI_DB_]"

-- Command Prefix
Prefix = "!"

-- Number of weeks before Database is cleaned.
WEEKS = 1
---------------------------------------------------------------------------------------
-- Don't Edit from here --
String = {}
Time = {}
IP = {}
StringFile = "Log/String.log"
TimeFile = "Log/Time.log"
IPFile = "Log/IP.log"
LSDate = os.date("%d").."/"..os.date("%m").."-"..os.date("%Y").." - "..os.date("%T")

Sec = 1000
Min = 60 * Sec
Hour = 60 * Min

function UserDisconnected(curUser)
   String[curUser.sName] = curUser.sMyInfoString
   Time[curUser.sName] = os.date("%m").."/"..os.date("%d").."/"..os.date("%Y")
   IP[curUser.sName] = curUser.sIP
--   Save()
end

function OnTimer()
   Save()
end

function Main()
   frmHub:RegBot(BotName)
   LoadData(String, StringFile)
   LoadData(Time, TimeFile)
   LoadData(IP, IPFile)
   SetTimer(5*Min)
   StartTimer()
end

function OnExit()
   Save()
end

function Save()
   SaveData(String,StringFile)
   SaveData(Time,TimeFile)
   SaveData(IP,IPFile)
   SaveIP()
   SaveTime()
   SaveString()
end

function LoadData(table, file)
   local handle1 = io.open(file, "r")
   if (handle1) then

for line in io.lines() do
         local _,_,n,e = string.find(line, "(.*) %| (.*)")
         if n and e then
            table[n]=e
         end

          end
        io.close(handle1)
   end
end

function SaveData(table,file)
   local handle1,temp,temp2 = io.open(file, "r"),{},{}
   if (handle1) then

for line in io.lines() do
         local _,_,n,e = string.find(line, "(.*) %| (.*)")
         if n and e then
            temp[n]=e
         end

          end
        io.close(handle1)
   end
   for n1,e1 in temp do
      temp2[n1]=e1
   end
   for n2, e2 in temp2 do
      table[n2] = e2
   end
end

function SaveIP()
   writeto(IPFile)
   for nick, event in IP do
      IP[nick] = event
      write(nick.." | "..event.."\n")
   end
   writeto()
end

function SaveTime()
   writeto(TimeFile)
   for nick, event in Time do
      Time[nick] = event
      write(nick.." | "..event.."\n")
   end
   writeto()
end

function SaveString()
   writeto(StringFile)
   for nick, event in String do
      String[nick] = event
      write(nick.." | "..event.."\n")
   end
   writeto()
end

function DataArrival(curUser, data)
   if string.find(data, "^%b<>%s+%!restartscripts") then
      curUser:SendData("*** Database Saved ***")
      Save()
   end
   if string.sub(data, 1, 4) == "$To:" then
      local s,e,to,from,text = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
      if to==BotName then
         data = text
         data = string.sub(data,1,string.len(data)-1)
         if (ParseCommand(curUser,data) == 1) then
            return 0
         else
            return 0
         end
      end
   end
end

-- Parse Command
function ParseCommand(curUser,data)
   local _,_,cmd = string.find(data,"^%b<>%s+%"..Prefix.."(%S+)")
   if cmd then
      if Command[cmd] then
         local Com = Command[cmd](curUser,data)
         return 1
      end
   end
end

function jos.date(%d,%m,%y)
   local a, b, c = 0, 0, 0
   if m <= 2 then
      y = y - 1
      m = m + 12
   end
   if (y*10000 + m*100 + d) >= 15821015 then
      a = math.floor(y/100)
      b = 2 - a + math.floor(a/4)
   end
   if y <= 0 then c = 0.75 end
   return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b)
end

function counting(month,day,year,monthu,dayu,yearu)
   daycount = Julian[tonumber(monthu)][1] - dayu + day
   daycount = Julian[tonumber(month)][2] - daycount
   daycount = daycount - Julian[tonumber(monthu)][1] - Julian[tonumber(month)][1]
   daycount = daycount - dayu

   monthcount = Julian[tonumber(month)][3] - Julian[tonumber(monthu)][3]
   if daycount > Julian[tonumber(month)][1] then
      daycount = daycount - Julian[tonumber(month)][1]
      monthcount = monthcount +1
   end
   return monthcount, daycount
end

function Clear()
   collectgarbage()
   io.flush()
end

Command = {
["clean"] = function(curUser,data)
   local msg = "\r\n"
   msg=msg .. "\r\n   -= Cleaning Database =-"
   msg=msg.."\r\n"..string
   msg=msg.."\r\n"..space
   local s,e,month,day,year = string.find(os.date("%x"), "(%d+)%/(%d+)%/(%d+)")
   year = "20"..year
   local juliannow = jos.date(tonumber(day), tonumber(month), tonumber(year))
   local oldest = WEEKS*7
   local Count = 0
   for n,t in Time do
      local s,e,monthu,dayu,yearu = string.find(t, "(%d+)%/(%d+)%/(%d+)")
      local julianu = jos.date(tonumber(dayu), tonumber(monthu), tonumber(yearu))
      if (juliannow - julianu) > oldest then
         Count = Count +1
         monthcount, daycount = counting(month,day,year,monthu,dayu,yearu)
         msg=msg.."\r\n   "..Count..". "..n.." is "..monthcount.." month(s),"..daycount.." day(s) old. Last logged in: "..dayu.."/"..monthu.."-"..yearu
         String[n] = nil
         Time[n] = nil
         IPN[n] = nil
      end
   end
   msg=msg.."\r\n"..space
   msg=msg.."\r\n   Todays date: "..day.."/"..month.."-"..year
   msg=msg.."\r\n   "..Count.." users have been deleted from database."
   msg=msg.."\r\n"..space
   msg=msg.."\r\n"..string
   curUser:SD(BotName, msg)
   SaveIP()
   SaveTime()
   SaveString()
   Clear()
   return 1
end,
["showcleanlist"] = function(curUser,data)
   local msg = "\r\n"
   msg=msg .. "\r\n   -= Clean List =-"
   msg=msg.."\r\n"..string
   msg=msg.."\r\n"..space
   local s,e,month,day,year = string.find(os.date("%x"), "(%d+)%/(%d+)%/(%d+)")
   year = "20"..year
   local juliannow = jos.date(tonumber(day), tonumber(month), tonumber(year))
   local oldest = WEEKS*7
   local Count = 0
   for n,t in Time do
      local s,e,monthu,dayu,yearu = string.find(t, "(%d+)%/(%d+)%/(%d+)")
      local julianu = jos.date(tonumber(dayu), tonumber(monthu), tonumber(yearu))
      if (juliannow - julianu) > oldest then
         Count = Count +1
         monthcount, daycount = counting(month,day,year,monthu,dayu,yearu)
   msg=msg.."\r\n   "..Count..". "..n.." is "..monthcount.." month(s),"..daycount.." day(s) old. Last logged in: "..dayu.."/"..monthu.."-"..yearu
      end
   end
   msg=msg.."\r\n"..space
   msg=msg.."\r\n   Todays date: "..day.."/"..month.."-"..year
   msg=msg.."\r\n   "..Count.." users not deleted from database."
   msg=msg.."\r\n"..space
   msg=msg.."\r\n"..string
   curUser:SD(BotName, msg)
end,
["getinfo"] = function(curUser,data)
   local _,_,nick = string.find( data, "%b<>%s+%S+%s+(%S+)" )
   if not nick then
      curUser:SendPM(BotName,"*** Syntax: "..Prefix.."getinfo ***")
      return 1
   end
   if string.find(nick,"%d+.%d+.%d+.%d+") then
      local two = ""
      for n,i in IPN do
         ip = IPN[n]
         if ip==i then
            nick = n
            two="1"
            break
         end
      end
   end
   if two=="" then
      nick = "N/A"
   end
   local vUser = GetItemByName(nick)
   local vMyInfo = ""
   local vNick = ""
   local vIP = ""
   local vConnect = ""
   if not vUser then
      for n,i in IPN do
         if string.lower(n) == string.lower(nick) then
            vNick = n
            vIP = i
            break
         end
      end
      local tmp = String[vNick]
      if tmp then
         vMyInfo = tmp
         vConnect = "No"
      else
         curUser:SendPM(BotName,"*** User/IP not found ***")
         return 1
      end
   else
      vMyInfo = vUser.sMyInfoString
      vNick = vUser.sName
      vIP = vUser.sIP
      vConnect = "Yes"
   end
   local Client,Tag,Speed,Email,Share = ParseMyInfo(vMyInfo)
   local msg = "\r\n"
   msg=msg.."\r\n   Info on "..vNick.." !"
   msg=msg.."\r\n   IP: "..vIP
   msg=msg.."\r\n   Share: "..string.format("%.2f",Share/gb).." Gb"
   msg=msg.."\r\n   E-Mail: "..Email
   msg=msg.."\r\n   Speed: "..Speed
   msg=msg.."\r\n   Tag: "..Tag["T"]
   msg=msg.."\r\n   Client: "..Client
   msg=msg.."\r\n   Version: "..Tag["V"]
   msg=msg.."\r\n   Mode: "..tMode[Tag["M"]]
   msg=msg.."\r\n   Slot: "..Tag["S"].." slot(s)"
   msg=msg.."\r\n   User in "..Tag["H"].." hub(s)"
   msg=msg.."\r\n   Registered user in "..Tag["R"].." hub(s)"
   msg=msg.."\r\n   Operator in "..Tag["O"].." hub(s)"
   msg=msg.."\r\n   Bandwidh: "..Tag["B"].." kB/s"
   msg=msg.."\r\n   Connected: "..vConnect
   curUser:SendPM(BotName,msg)
   return 1
end,
}

-- Parse MYINFO string
function ParseMyInfo(sMyInfo)
   local sClient = "Unknown Client"
   local Error = "N/A"
   local _,_,sTa,sSpeed,sEmail,sShare = string.find(sMyInfo, "$MyINFO $ALL %S+%s+([^$]*)$ $([^$]*)$([^$]*)$([^$]+)")
   sShare = tonumber(sShare)
   for i = 1,table.getn(sClients) do
      if string.find(sMyInfo,sClients[1]) then
         sClient = sClients[2]
      end
   end
   local _,_,sVer,sMode = string.find(sMyInfo,"V:(%d+.%d+),M:([SAP])")
   local _,_,sUser,sReg,sOp = string.find(sMyInfo,"H:(%d+)/(%d+)/(%d+)")
   if not sUser then
      _,_,sUser = string.find(sMyInfo,"H:(%d+)")
   end
   local _,_,sSlot = string.find(sMyInfo,"S:(%d+)")
   local _,_,sBwidh = string.find(sMyInfo, "[BLUF]:%d*%/?(%d+)")
   if sClient=="DCGUI" and sBwidh then
      sBwidh = sBwidh * sSlot
   end
   if sBwidh==nil then
      sBwidh = "Unlimited"
   end
   if string.find(sMyInfo,"<%+%+") then
      _,_,sVer = string.find(sMyInfo,"")
      sClient = "oDC"
   elseif string.find(sMyInfo,"Ruri_Ruri") then
      sClient = "Ruri _Ruri"
   elseif sClient=="iDC" then
      _,_,sVer = string.find(sMyInfo,"")
   end
   if string.find(sMyInfo,"H:\"%d+/%d+/%d+\"") then
      sClient = "Fake"
   end
   if string.find(sMyInfo, "L:") then
      sClient = "CZDC++"
   elseif string.find(sMyInfo, "B:") then
      if not sClient=="Phantom DC++" then
         sClient = "Bear Claw DC++"  
      end
   end
   sTag = {["S"]=sSlot,["B"]=sBwidh,["H"]=sUser,["R"]=sReg,["O"]=sOp,["V"]=sVer,["M"]=sMode,["T"]=sTa}
   return sClient,sTag,sSpeed,sEmail,sShare
end

sClients = {
{ "{ "<++","DC++" },
{ "{ "{ "{ "http://dc.ketelhot.de","DCGUI" },
{ "{ "{ "zDC++","zDC++" },
{ "","MS++" },
{ "{ "<.P>","Phantom DC++" },
{ "}

tMode = {
["S"] = "Socks",
["A"] = "Active",
["P"] = "Passive",
["0"] = "N/A",
}

Julian = {
[01] = {31, 31,1},
[02] = {28, 59,2},
[03] = {31, 90,3},
[04] = {30, 120,4},
[05] = {31, 151,5},
[06] = {30, 181,6},
[07] = {31, 212,7},
[08] = {31, 243,8},
[09] = {30, 273,9},
[10] = {31, 304,10},
[11] = {30, 334,11},
[12] = {31, 365,12},
}
---------------------------------------------------------------------------------------
-- NightLitch


When i started the script i get this error:


QuoteSyntax Info.lua5.lua:173: attempt to index global `jos' (a nil value)

What's wrong? Would anybody help me to fix it please?



Best Regards

Madman

Just took a quick look...
and of what i can see.. the jos only is found as jos.date
and my guess then is that all jos.date should be os.date
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Dessamator

yap we'll help, but u better post the original script, and next time highlight the code and click "#", its easier to read like that !
Ignorance is Bliss.

jiten

Looks a bit like this one.

Cheers

Dessamator

QuoteOriginally posted by jiten
Looks a bit like this one.

Cheers
indeed it does, but this one seems to be an advanced version of that one, maybe an upgrade !, either way, that script will require quite a lot of filehandling (if its converted)
Ignorance is Bliss.

jiten

QuoteOriginally posted by Dessamator
QuoteOriginally posted by jiten
Looks a bit like this one.

Cheers
indeed it does, but this one seems to be an advanced version of that one, maybe an upgrade !, either way, that script will require quite a lot of filehandling (if its converted)
Indeed ;)
If I get some free time today, I'll finish converting it.

Dessamator

#6
---------------------------------------------------------------------------------------
-- Userinfo Database with Cleaning function
---------------------------------------------------------------------------------------
-- By: NightLitch 2004-04-16
-- Version: 1.21c
---------------------------------------------------------------------------------------
-- Commands:
--			!getinfo  - Get userinfo
--			!clean - Clean database
--			!showcleanlist - Show clean list
--
---------------------------------------------------------------------------------------
-- NOTE: Create a folder name: ( Log )
-- and files inside:
--				String.log
--				Time.log
--				IP.log
--
---------------------------------------------------------------------------------------
-- Calculate share
kb = 1024
gb = kb*kb*kb
tb = kb*kb*kb*kb

-- BotName
BotName = "[_UI_DB_]"

-- Command Prefix
Prefix = "!"

-- Number of weeks before Database is cleaned.
WEEKS = 1
---------------------------------------------------------------------------------------
-- Don't Edit from here --
String = {}
Time = {}
IP = {}
StringFile = "Log/String.log"
TimeFile = "Log/Time.log"
IPFile = "Log/IP.log"
LSDate = date("%d").."/"..date("%m").."-"..date("%Y").." - "..date("%T")

Sec = 1000
Min = 60 * Sec
Hour = 60 * Min

function UserDisconnected(curUser)
	String[curUser.sName] = curUser.sMyInfoString 
	Time[curUser.sName] = date("%m").."/"..date("%d").."/"..date("%Y")
	IP[curUser.sName] = curUser.sIP
--	Save()
end

function OnTimer()
	Save()
end

function Main()
	frmHub:RegBot(BotName)
	LoadData(String, StringFile)
	LoadData(Time, TimeFile)
	LoadData(IP, IPFile)
	SetTimer(5*Min)
	StartTimer()
end

function OnExit()
	Save()
end

function Save()
	SaveData(String,StringFile)
	SaveData(Time,TimeFile)
	SaveData(IP,IPFile)
	SaveIP()
	SaveTime()
	SaveString()
end

function LoadData(table, file)
	local handle1 = openfile(file, "r")
	if (handle1) then
    		local line = read(handle1)
    		while line do
			local _,_,n,e = strfind(line, "(.*) %| (.*)")
			if n and e then
				table[n]=e
			end
			line = read(handle1)
    		end
  		closefile(handle1)
	end
end

function SaveData(table,file)
	local handle1,temp,temp2 = openfile(file, "r"),{},{}
	if (handle1) then
    		local line = read(handle1)
    		while line do
			local _,_,n,e = strfind(line, "(.*) %| (.*)")
			if n and e then
				temp[n]=e
			end
			line = read(handle1)
    		end
  		closefile(handle1)
	end
	for n1,e1 in temp do
		temp2[n1]=e1
	end
	for n2, e2 in temp2 do
		table[n2] = e2
	end
end

function SaveIP()
	writeto(IPFile)
	for nick, event in IP do
		IP[nick] = event
		write(nick.." | "..event.."\n")
	end
	writeto()
end

function SaveTime()
	writeto(TimeFile)
	for nick, event in Time do
		Time[nick] = event
		write(nick.." | "..event.."\n")
	end
	writeto()
end

function SaveString()
	writeto(StringFile)
	for nick, event in String do
		String[nick] = event
		write(nick.." | "..event.."\n")
	end
	writeto()
end

function DataArrival(curUser, data)
	if strfind(data, "^%b<>%s+%!restartscripts") then
		curUser:SendData("*** Database Saved ***")
		Save()
	end
	if strsub(data, 1, 4) == "$To:" then
		local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
		if to==BotName then
			data = text
			data = strsub(data,1,strlen(data)-1)
			if (ParseCommand(curUser,data) == 1) then
				return 0
			else
				return 0
			end
		end
	end
end

-- Parse Command
function ParseCommand(curUser,data)
	local _,_,cmd = strfind(data,"^%b<>%s+%"..Prefix.."(%S+)")
	if cmd then
		if Command[cmd] then
			local Com = Command[cmd](curUser,data)
			return 1
		end
	end
end

function jdate(d, m, y)
	local a, b, c = 0, 0, 0
	if m <= 2 then
		y = y - 1
		m = m + 12
	end
	if (y*10000 + m*100 + d) >= 15821015 then
		a = floor(y/100)
		b = 2 - a + floor(a/4)
	end
	if y <= 0 then c = 0.75 end
	return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b)
end

function counting(month,day,year,monthu,dayu,yearu)
	daycount = Julian[tonumber(monthu)][1] - dayu + day
	daycount = Julian[tonumber(month)][2] - daycount
	daycount = daycount - Julian[tonumber(monthu)][1] - Julian[tonumber(month)][1]
	daycount = daycount - dayu

	monthcount = Julian[tonumber(month)][3] - Julian[tonumber(monthu)][3]
	if daycount > Julian[tonumber(month)][1] then
		daycount = daycount - Julian[tonumber(month)][1]
		monthcount = monthcount +1
	end
	return monthcount, daycount
end

function Clear() 
	collectgarbage() 
	flush() 
end

Command = {
["clean"] = function(curUser,data)
	local msg = "\r\n"
	msg=msg .. "\r\n	-= Cleaning Database =-"
	msg=msg.."\r\n"..string
	msg=msg.."\r\n"..space
	local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)")
	year = "20"..year
	local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
	local oldest = WEEKS*7
	local Count = 0
	for n,t in Time do
		local s,e,monthu,dayu,yearu = strfind(t, "(%d+)%/(%d+)%/(%d+)")
		local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
		if (juliannow - julianu) > oldest then
			Count = Count +1
			monthcount, daycount = counting(month,day,year,monthu,dayu,yearu)
			msg=msg.."\r\n	"..Count..". "..n.." is "..monthcount.." month(s),"..daycount.." day(s) old. Last logged in: "..dayu.."/"..monthu.."-"..yearu
			String[n] = nil
			Time[n] = nil
			IPN[n] = nil
		end
	end
	msg=msg.."\r\n"..space
	msg=msg.."\r\n	Todays date: "..day.."/"..month.."-"..year
	msg=msg.."\r\n	"..Count.." users have been deleted from database."
	msg=msg.."\r\n"..space
	msg=msg.."\r\n"..string
	curUser:SD(BotName, msg)
	SaveIP()
	SaveTime()
	SaveString()
	Clear() 
	return 1
end,
["showcleanlist"] = function(curUser,data)
	local msg = "\r\n"
	msg=msg .. "\r\n	-= Clean List =-"
	msg=msg.."\r\n"..string
	msg=msg.."\r\n"..space
	local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)")
	year = "20"..year
	local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
	local oldest = WEEKS*7
	local Count = 0
	for n,t in Time do
		local s,e,monthu,dayu,yearu = strfind(t, "(%d+)%/(%d+)%/(%d+)")
		local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
		if (juliannow - julianu) > oldest then
			Count = Count +1
			monthcount, daycount = counting(month,day,year,monthu,dayu,yearu)
	msg=msg.."\r\n	"..Count..". "..n.." is "..monthcount.." month(s),"..daycount.." day(s) old. Last logged in: "..dayu.."/"..monthu.."-"..yearu
		end
	end
	msg=msg.."\r\n"..space
	msg=msg.."\r\n	Todays date: "..day.."/"..month.."-"..year
	msg=msg.."\r\n	"..Count.." users not deleted from database."
	msg=msg.."\r\n"..space
	msg=msg.."\r\n"..string
	curUser:SD(BotName, msg)
end,
["getinfo"] = function(curUser,data)
	local _,_,nick = strfind( data, "%b<>%s+%S+%s+(%S+)" )
	if not nick then
		curUser:SendPM(BotName,"*** Syntax: "..Prefix.."getinfo  ***")
		return 1
	end
	if strfind(nick,"%d+.%d+.%d+.%d+") then
		local two = ""
		for n,i in IPN do
			ip = IPN[n]
			if ip==i then
				nick = n
				two="1"
				break
			end
		end
	end
	if two=="" then
		nick = "N/A"
	end
	local vUser = GetItemByName(nick)
	local vMyInfo = ""
	local vNick = ""
	local vIP = ""
	local vConnect = ""
	if not vUser then
		for n,i in IPN do
			if strlower(n) == strlower(nick) then
				vNick = n
				vIP = i
				break
			end
		end
		local tmp = String[vNick]
		if tmp then
			vMyInfo = tmp
			vConnect = "No"
		else
			curUser:SendPM(BotName,"*** User/IP not found ***")
			return 1
		end
	else
		vMyInfo = vUser.sMyInfoString
		vNick = vUser.sName
		vIP = vUser.sIP
		vConnect = "Yes"
	end
	local Client,Tag,Speed,Email,Share = ParseMyInfo(vMyInfo)
	local msg = "\r\n"
	msg=msg.."\r\n	Info on "..vNick.." !"
	msg=msg.."\r\n	IP: "..vIP
	msg=msg.."\r\n	Share: "..format("%.2f",Share/gb).." Gb"
	msg=msg.."\r\n	E-Mail: "..Email
	msg=msg.."\r\n	Speed: "..Speed
	msg=msg.."\r\n	Tag: "..Tag["T"]
	msg=msg.."\r\n	Client: "..Client
	msg=msg.."\r\n	Version: "..Tag["V"]
	msg=msg.."\r\n	Mode: "..tMode[Tag["M"]]
	msg=msg.."\r\n	Slot: "..Tag["S"].." slot(s)"
	msg=msg.."\r\n	User in "..Tag["H"].." hub(s)"
	msg=msg.."\r\n	Registered user in "..Tag["R"].." hub(s)"
	msg=msg.."\r\n	Operator in "..Tag["O"].." hub(s)"
	msg=msg.."\r\n	Bandwidh: "..Tag["B"].." kB/s"
	msg=msg.."\r\n	Connected: "..vConnect
	curUser:SendPM(BotName,msg)
	return 1
end,
}

-- Parse MYINFO string
function ParseMyInfo(sMyInfo)
	local sClient = "Unknown Client"
	local Error = "N/A"
	local _,_,sTa,sSpeed,sEmail,sShare = strfind(sMyInfo, "$MyINFO $ALL %S+%s+([^$]*)$ $([^$]*)$([^$]*)$([^$]+)")
	sShare = tonumber(sShare)
	for i = 1,getn(sClients) do 
		if strfind(sMyInfo,sClients[i][1]) then 
			sClient = sClients[i][2] 
		end 
	end
	local _,_,sVer,sMode = strfind(sMyInfo,"V:(%d+.%d+),M:([SAP])")
	local _,_,sUser,sReg,sOp = strfind(sMyInfo,"H:(%d+)/(%d+)/(%d+)")
	if not sUser then
		_,_,sUser = strfind(sMyInfo,"H:(%d+)")
	end
	local _,_,sSlot = strfind(sMyInfo,"S:(%d+)")
	local _,_,sBwidh = strfind(sMyInfo, "[BLUF]:%d*%/?(%d+)")
	if sClient=="DCGUI" and sBwidh then
		sBwidh = sBwidh * sSlot
	end
	if sBwidh==nil then
		sBwidh = "Unlimited"
	end
	if strfind(sMyInfo,"<%+%+") then 
		_,_,sVer = strfind(sMyInfo,"") 
		sClient = "oDC"
	elseif strfind(sMyInfo,"Ruri_Ruri") then 
		sClient = "Ruri _Ruri" 
	elseif sClient=="iDC" then 
		_,_,sVer = strfind(sMyInfo,"") 
	end
	if strfind(sMyInfo,"H:\"%d+/%d+/%d+\"") then 
		sClient = "Fake" 
	end
	if strfind(sMyInfo, "L:") then 
		sClient = "CZDC++"
	elseif strfind(sMyInfo, "B:") then 
		if not sClient=="Phantom DC++" then 
			sClient = "Bear Claw DC++"  
		end
	end
	sTag = {["S"]=sSlot,["B"]=sBwidh,["H"]=sUser,["R"]=sReg,["O"]=sOp,["V"]=sVer,["M"]=sMode,["T"]=sTa}
	return sClient,sTag,sSpeed,sEmail,sShare
end

sClients = {
{ "","MS++" },
{ "","Phantom DC++" },
{ "

thats the original in case u need it, GOOD LUCK !
Ignorance is Bliss.

chettedeboeuf

Excellent, merci pour ce script

chettedeboeuf

I have an error :

81: attempt to call global `date' (a nil value)

Dessamator

#9
---------------------------------------------------------------------------------------
-- Userinfo Database with Cleaning function
---------------------------------------------------------------------------------------
-- Lua5 By Dessamator
-- By: NightLitch 2004-04-16
-- Version: 1.21c
---------------------------------------------------------------------------------------
-- Commands:
--			!getinfo  - Get userinfo
--			!clean - Clean database
--			!showcleanlist - Show clean list
--
---------------------------------------------------------------------------------------
-- Note :Now the Log folder is created on start ! (mod by Dessamator)
---------------------------------------------------------------------------------------

-- Calculate share
kb = 1024
gb = kb*kb*kb
tb = kb*kb*kb*kb

-- BotName
BotName = "[_UI_DB_]"

-- Command Prefix
Prefix = "!"

-- Number of weeks before Database is cleaned.
WEEKS = 1
---------------------------------------------------------------------------------------
-- Don't Edit from here --
String = {}
Time = {}
IP = {}
StringFile = "Log/String.log"
TimeFile = "Log/Time.log"
IPFile = "Log/IP.log"
LSDate = os.date("%d".."/".."%m".."-".."%Y".." - ".."%T")

Sec = 1000
Min = 60 * Sec
Hour = 60 * Min

function UserDisconnected(curUser)
	String[curUser.sName] = curUser.sMyInfoString 
	Time[curUser.sName] = os.date("%m".."/".."%d".."/".."%Y")
	IP[curUser.sName] = curUser.sIP
--	Save()
end

function OnTimer()
	Save()
end

function Main()
local file = io.open(StringFile,"r")
	if not file then
		os.execute("mkdir Log")
	end
	frmHub:RegBot(BotName)
	LoadData(String, StringFile)
	LoadData(Time, TimeFile)
	LoadData(IP, IPFile)
	SetTimer(5*Min)
	StartTimer()
end

function OnExit()
	Save()
end

function Save()
	SaveData(String,StringFile)
	SaveData(Time,TimeFile)
	SaveData(IP,IPFile)
	SaveIP()
	SaveTime()
	SaveString()
end

function LoadData(table, file)
	local handle1 = io.open(file, "r")
	if (handle1) then
    		for line in handle1:lines() do
			local _,_,n,e = string.find(line, "(.*) %| (.*)")
			if n and e then
				table[n]=e
			end
			
    		end
  		handle1:close()
	end
end

function SaveData(table,file)
	local handle1,temp,temp2 = io.open(file, "r"),{},{}
	if (handle1) then
    		for line in handle1:lines() do
			local _,_,n,e = string.find(line, "(.*) %| (.*)")
			if n and e then
				temp[n]=e
			end
			
    		end
  		handle1:close()
	end
	for n1,e1 in temp do
		temp2[n1]=e1
	end
	for n2, e2 in temp2 do
		table[n2] = e2
	end
end

function SaveIP()
	io.output(IPFile)
	for nick, event in IP do
		IP[nick] = event
		io.write(nick.." | "..event.."\n")
	end
	io.output()
end

function SaveTime()
	io.output(TimeFile)
	for nick, event in Time do
		Time[nick] = event
		io.write(nick.." | "..event.."\n")
	end
	io.output()
end

function SaveString()
	io.output(StringFile)
	for nick, event in String do
		String[nick] = event
		io.write(nick.." | "..event.."\n")
	end
	io.output()
end

function ChatArrival(curUser, data)

	data = string.sub(data,1,string.len(data)-1)
	if string.find(data, "^%b<>%s+%!restartscripts") then
		curUser:SendData("*** Database Saved ***")
		Save()
	end
	if (ParseCommand(curUser,data) == 1) then
			return 1

	end
end
function ToArrival(curUser,data)
	local s,e,to,from,text = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
	if to==BotName then
		data = text
		data = string.sub(data,1,string.len(data)-1)
		if (ParseCommand(curUser,data) == 1) then
			return 1
		else
			return 0
			
		end
	end
end

-- Parse Command
function ParseCommand(curUser,data)
	local _,_,cmd = string.find(data,"^%b<>%s+%"..Prefix.."(%S+)")
	if cmd then
		if Command[cmd] then
			local Com = Command[cmd](curUser,data)
			return 1
		end
	end
end

function jdate(d, m, y)
	local a, b, c = 0, 0, 0
	if m <= 2 then
		y = y - 1
		m = m + 12
	end
	if (y*10000 + m*100 + d) >= 15821015 then
		a = math.floor(y/100)
		b = 2 - a + math.floor(a/4)
	end
	if y <= 0 then c = 0.75 end
	return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b)
end

function counting(month,day,year,monthu,dayu,yearu)
	daycount = Julian[tonumber(monthu)][1] - dayu + day
	daycount = Julian[tonumber(month)][2] - daycount
	daycount = daycount - Julian[tonumber(monthu)][1] - Julian[tonumber(month)][1]
	daycount = daycount - dayu

	monthcount = Julian[tonumber(month)][3] - Julian[tonumber(monthu)][3]
	if daycount > Julian[tonumber(month)][1] then
		daycount = daycount - Julian[tonumber(month)][1]
		monthcount = monthcount +1
	end
	return monthcount, daycount
end

function Clear() 
	collectgarbage() 
	io.flush() 
end

Command = {
["clean"] = function(curUser,data)
	local msg = "\r\n"
	msg=msg .. "\r\n	-= Cleaning Database =-"
	--msg=msg.."\r\n"..string
	--msg=msg.."\r\n"..space
	local s,e,month,day,year = string.find(os.date("%x"), "(%d+)%/(%d+)%/(%d+)")
	year = "20"..year
	local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
	local oldest = WEEKS*7
	local Count = 0
	for n,t in Time do
		local s,e,monthu,dayu,yearu = string.find(t, "(%d+)%/(%d+)%/(%d+)")
		local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
		if (juliannow - julianu) > oldest then
			Count = Count +1
			monthcount, daycount = counting(month,day,year,monthu,dayu,yearu)
			msg=msg.."\r\n	"..Count..". "..n.." is "..monthcount.." month(s),"..daycount.." day(s) old. Last logged in: "..dayu.."/"..monthu.."-"..yearu
			String[n] = nil
			Time[n] = nil
			IP[n] = nil
		end
	end
	--msg=msg.."\r\n"..space
	msg=msg.."\r\n	Todays date: "..day.."/"..month.."-"..year
	msg=msg.."\r\n	"..Count.." users have been deleted from database."
	--msg=msg.."\r\n"..space
	--msg=msg.."\r\n"..string
	curUser:SendData(BotName, msg)
	SaveIP()
	SaveTime()
	SaveString()
	Clear() 
	return 1
end,
["showcleanlist"] = function(curUser,data)
	local msg = "\r\n"
	msg=msg .. "\r\n	-= Clean List =-"
	--msg=msg.."\r\n"..string
	--msg=msg.."\r\n"..space
	local s,e,month,day,year = string.find(os.date("%x"), "(%d+)%/(%d+)%/(%d+)")
	year = "20"..year
	local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
	local oldest = WEEKS*7
	local Count = 0
	for n,t in Time do
		local s,e,monthu,dayu,yearu = string.find(t, "(%d+)%/(%d+)%/(%d+)")
		local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
		if (juliannow - julianu) > oldest then
			Count = Count +1
			monthcount, daycount = counting(month,day,year,monthu,dayu,yearu)
	msg=msg.."\r\n	"..Count..". "..n.." is "..monthcount.." month(s),"..daycount.." day(s) old. Last logged in: "..dayu.."/"..monthu.."-"..yearu
		end
	end
	--msg=msg.."\r\n"..space
	msg=msg.."\r\n	Todays date: "..day.."/"..month.."-"..year
	msg=msg.."\r\n	"..Count.." users not deleted from database."
	--msg=msg.."\r\n"..space
	--msg=msg.."\r\n"..string
	curUser:SendData(BotName, msg)
end,
["getinfo"] = function(curUser,data)
	local _,_,nick = string.find( data, "%b<>%s+%S+%s+(%S+)" )
	if not nick then
		curUser:SendPM(BotName,"*** Syntax: "..Prefix.."getinfo  ***")
		return 1
	end
	if string.find(nick,"%d+.%d+.%d+.%d+") then
		local two = ""
		for n,i in IP do
			ip = IP[n]
			if ip==i then
				nick = n
				two="1"
				break
			end
		end
	end
	if two=="" then
		nick = "N/A"
	end
	local vUser = GetItemByName(nick)
	local vMyInfo = ""
	local vNick = ""
	local vIP = ""
	local vConnect = ""
	if not vUser then
		for n,i in IP do
			if string.lower(n) == string.lower(nick) then
				vNick = n
				vIP = i
				break
			end
		end
		local tmp = String[vNick]
		if tmp then
			vMyInfo = tmp
			vConnect = "No"
		else
			curUser:SendPM(BotName,"*** User/IP not found ***")
			return 1
		end
	else
		vMyInfo = vUser.sMyInfoString
		vNick = vUser.sName
		vIP = vUser.sIP
		vConnect = "Yes"
	end
	local Client,Tag,Speed,Email,Share = ParseMyInfo(vMyInfo)
	local msg = "\r\n"
	msg=msg.."\r\n	Info on "..vNick.." !"
	msg=msg.."\r\n	IP: "..vIP
	msg=msg.."\r\n	Share: "..string.format("%.2f",Share/gb).." Gb"
	msg=msg.."\r\n	E-Mail: "..Email
	msg=msg.."\r\n	Speed: "..Speed
	msg=msg.."\r\n	Tag: "..Tag["T"]
	msg=msg.."\r\n	Client: "..Client
	msg=msg.."\r\n	Version: "..Tag["V"]
	msg=msg.."\r\n	Mode: "..tMode[Tag["M"]]
	msg=msg.."\r\n	Slot: "..Tag["S"].." slot(s)"
	msg=msg.."\r\n	User in "..Tag["H"].." hub(s)"
	msg=msg.."\r\n	Registered user in "..Tag["R"].." hub(s)"
	msg=msg.."\r\n	Operator in "..Tag["O"].." hub(s)"
	msg=msg.."\r\n	Bandwidh: "..Tag["B"].." kB/s"
	msg=msg.."\r\n	Connected: "..vConnect
	curUser:SendPM(BotName,msg)
	return 1
end,
}

-- Parse MYINFO string
function ParseMyInfo(sMyInfo)
	local sClient = "Unknown Client"
	local Error = "N/A"
	local _,_,sTa,sSpeed,sEmail,sShare = string.find(sMyInfo, "$MyINFO $ALL %S+%s+([^$]*)$ $([^$]*)$([^$]*)$([^$]+)")
	sShare = tonumber(sShare)
	for i = 1,table.getn(sClients) do 
		if string.find(sMyInfo,sClients[i][1]) then 
			sClient = sClients[i][2] 
		end 
	end
	local _,_,sVer,sMode = string.find(sMyInfo,"V:(%d+.%d+),M:([SAP])")
	local _,_,sUser,sReg,sOp = string.find(sMyInfo,"H:(%d+)/(%d+)/(%d+)")
	if not sUser then
		_,_,sUser = string.find(sMyInfo,"H:(%d+)")
	end
	local _,_,sSlot = string.find(sMyInfo,"S:(%d+)")
	local _,_,sBwidh = string.find(sMyInfo, "[BLUF]:%d*%/?(%d+)")
	if sClient=="DCGUI" and sBwidh then
		sBwidh = sBwidh * sSlot
	end
	if sBwidh==nil then
		sBwidh = "Unlimited"
	end
	if string.find(sMyInfo,"<%+%+") then 
		_,_,sVer = string.find(sMyInfo,"") 
		sClient = "oDC"
	elseif string.find(sMyInfo,"Ruri_Ruri") then 
		sClient = "Ruri _Ruri" 
	elseif sClient=="iDC" then 
		_,_,sVer = string.find(sMyInfo,"") 
	end
	if string.find(sMyInfo,"H:\"%d+/%d+/%d+\"") then 
		sClient = "Fake" 
	end
	if string.find(sMyInfo, "L:") then 
		sClient = "CZDC++"
	elseif string.find(sMyInfo, "B:") then 
		if not sClient=="Phantom DC++" then 
			sClient = "Bear Claw DC++"  
		end
	end
	sTag = {["S"]=sSlot,["B"]=sBwidh,["H"]=sUser,["R"]=sReg,["O"]=sOp,["V"]=sVer,["M"]=sMode,["T"]=sTa}
	return sClient,sTag,sSpeed,sEmail,sShare
end

sClients = {
{ "","MS++" },
{ "","Phantom DC++" },
{ "


Done, (slightly tested), and lots of debugging,
Ignorance is Bliss.

jiten

I came too late :D
Having a quick look at it, the MyINFO, client and mode parsing could use the API functions instead of being parsed ;)

Cheers m8 and nice job

MoNTeR

Quoteu better post the original script, and next time highlight the code and click "#", its easier to read like that !

U're right, sorry, my fault.


Good work Dessamator, it was really fast, thx a lot


 :))

Dessamator

#12
QuoteOriginally posted by jiten
I came too late :D
Having a quick look at it, the MyINFO, client and mode parsing could use the API functions instead of being parsed ;)

Cheers m8 and nice job
Cant be done because the myinfo string is stored in a file so that it has the info even if the user isnt online, and the api only works on online users, there arent any user stats in ptokax, for now at least, :-)
Ignorance is Bliss.

NightLitch

I can post my UI DB when I have checked it some more...
//NL

Dessamator

QuoteOriginally posted by NightLitch
I can post my UI DB when I have checked it some more...

goody, btw i didnt get this line in ur "old" script

--msg=msg.."\r\n"..string    --msg=msg.."\r\n"..space

whats the string and space??

anyways, another question this line
curUser:SD(BotName, msg)


did the old ptokax SendData with ":SD" ??? or u were trying to do something else !!
Ignorance is Bliss.

SMF spam blocked by CleanTalk