[Help] Onjoin Info
 

News:

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

[Help] Onjoin Info

Started by nEgativE, 17 October, 2006, 02:57:31

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nEgativE

Hello all, hello jiten.. could u give a help here, is it possible have a topsharer user here ? and the uptime record it's not working so well i think, don't know why..

--> http://board.univ-angers.fr
--> Made by plop
--> Functions by nErBoS, [BR]Carlos
--> Convertion Lua5 by Jelf and heavily optimized by jiten

Bot = frmHub:GetHubBotName()
sChatBot = frmHub:GetOpChatName()

ALLUSERS={}
LEVELS = {["-1"]=0, ["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["4"]=0, ["5"]=0, ["6"]=0}

Stat = {
	uptime = 0,
	share = 0,
	users = 0,
}

sec = 1000 
min = 60*sec

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

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

OpConnected = NewUserConnected

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

OpDisconnected = UserDisconnected

function Message(user)
	local tmp,share,SC,hubshare,ttshare = "",user.iShareSize,os.clock(),frmHub:GetCurrentShareAmount(),tonumber(Stat.share)
	local days,hours,minutes = math.floor(Stat.uptime/43200, 30), math.floor(math.mod(Stat.uptime/1440, 24)), math.floor(math.mod(Stat.uptime/60, 60))
	if share == nil then
	share = 0
end
	if user.sMode == "A" then
	tmp = "Activo"
	elseif user.sMode == "P" then
	tmp = "Passivo"
	elseif user.sMode == "5" then
	tmp = "Socks5"
	SendPmToOps(sChatBot,"-?--- Utilizador: "..user.sName..", est? a usar o Cliente DC em Modo: "..(user.sMode or "Indispon?vel").." - IP: "..(user.sIP or "Indispon?vel").."")
	else tmp = "Desconhe?ido"
	SendPmToOps(sChatBot,"-?--- Utilizador: "..user.sName..", est? a usar o Cliente DC em Modo: "..(user.sMode or "Desconhe?ido").." - IP: "..(user.sIP or "Indispon?vel").."")
end
	user:SendData("         -?--- Ligado: "..(user.iHubs or "?").." Hub's - Com registo: "..(user.iRegHubs or "?").." - Como Operador: "..(user.iOpHubs or "?").." ---?-") 
	user:SendData("         -?--- Partilha: "..rightSize( tonumber(share) ).." - Perfil: "..(GetProfileName(user.iProfile) or "Sem registo").." - Password: "..(frmHub:GetUserPassword(user.sName) or "Sem Password").." ---?-") 
	user:SendData("         -?--- Cliente: "..(user.sClient or "?").." - Vers?o: "..(user.sClientVersion or "?").." - Modo: "..tmp.." - Slot's: "..(user.iSlots or "?").." - Liga??o: "..(user.sConnection or "?").." ---?-") 
	user:SendData("   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
	user:SendData("   -?--- "..frmHub:GetHubName().." ---?-")
	user:SendData(" ")
	user:SendData("         -?--- Partilha: "..rightSize( tonumber(hubshare + share) ).." --?-- Lista de Comandos: !ajuda - !help ---?-")
	user:SendData("         -?--- Online --?-- OP's: "..getOn(0) + getOn(1) + getOn(2).." - Moderadores: "..getOn(3).." - ViP's: "..getOn(4).." - GiGa: "..getOn(6).." - Membros: "..getOn(5).." - Total: "..(frmHub:GetUsersCount()).." ---?-") 
	user:SendData("         -?--- Registos --?-- OP's: "..getAll(0) + getAll(1) + getAll(2).." - Moderadores: "..getAll(3).." - ViP's: "..getAll(4).." - GiGa: "..getAll(6).." - Membros: "..getAll(5).." - Total: "..table.getn(frmHub:GetRegisteredUsers()).." ---?-")
	user:SendData("         -?--- Recordes --?-- Partilha: "..rightSize( tonumber(ttshare) ).." - Utilizadores: "..Stat.users.." - Uptime: "..days.." dia's ---?-") 
	user:SendData("         -?--- Uptime: " ..math.floor(SC/86400).." dia's "..math.floor(math.mod(SC/3600,24)).." hora's e "..math.floor(math.mod(SC/60,60)).." minuto's --?-- "..os.date().." ---?-")
	user:SendData("         -?--- T?pico: "..(frmHub:GetHubTopic() or "Indispon?vel").." ---?-")
	user:SendData("   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
	user:SendData(" ")
end

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

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

function rightSize(intSize)
	if intSize ~= 0 then 
		local tUnits = { "Bytes", "KiB", "MiB", "GiB", "TiB" } 
		intSize = tonumber(intSize); 
		local sUnits; 
		for index = 1, table.getn(tUnits) do 
			if(intSize < 1024) then 
				sUnits = tUnits[index]; 
				break; 
			else  
				intSize = intSize / 1024; 
			end 
		end 
		return string.format("%0.1f %s",intSize, sUnits); 
	else 
		return "0 Bytes" 
	end 
end 

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

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

jiten

This script is really screaming for a rewrite :P

I'll see what I can do about this one too.

Best regards

Herodes

Quote from: jiten on 07 November, 2006, 19:23:05
This script is really screaming for a rewrite :P

I'll see what I can do about this one too.

Best regards
jiten: I think that it'll be better if you put your time at something like Nightlitch's Advanced MOTD script. Same functionality in purpose but far more flexible and feature rich.

nEgativE

Thx jiten.. i'll wait :) if it possible, make it to Lua 5.1 also..

jiten

Slightly tested...

--[[

	OnJoin 1.01 - LUA 5.1 by jiten (11/10/2006)
	???????????????????????????????????????????
	Based on: 
	
	- OnJoin by plop
	  Functions by nErBoS, [BR]Carlos
	  Convertion Lua5 by Jelf and heavily optimized by jiten

]]--


tSettings = {
	-- Bot Name
	sBot = frmHub:GetHubBotName(),

	-- Database
	fStats = "tStats.tbl",
}

tStats = {}

Main = function()
	if loadfile(tSettings.fStats) then dofile(tSettings.fStats) end
end

NewUserConnected = function(user)
	local tModes, sOnline, sRegistered = { ["A"] = "Active", ["P"] = "Passive", ["5"] = "Socks" }, "   ? ", "   ? "
	-- Count online users per profile
	for i, v in ipairs(GetProfiles()) do sOnline = sOnline..v..": "..(#frmHub:GetOnlineUsers(i-1))..", " end
	-- Count users per profile
	for i, v in ipairs(GetProfiles()) do sRegistered = sRegistered..v..": "..#GetUsersByProfile(v)..", " end
	-- Check uptime and share
	tStats.iUptime, tStats.iTotalShare = (tStats.iUptime or 0), (tStats.iTotalShare or 0)
	if frmHub:GetUpTime() > tStats.iUptime then tStats.iUptime = frmHub:GetUpTime() end
	if frmHub:GetCurrentShareAmount() > tStats.iTotalShare then tStats.iTotalShare = frmHub:GetCurrentShareAmount() end
	-- Build message
	local sMessage = "\r\n\r\n\t"..string.rep("_", 30).."\r\n\t\tUser Information\r\n\t"..string.rep("?", 30).."\r\n\t"..
	"? Nick: "..(user.sName or "n/a").."\r\n\t"..
	"? Password: "..(frmHub:GetUserPassword(user.sName) or "n/a").."\r\n\t"..
	"? Share: "..DoUnits(user.iShareSize).."\r\n\t"..
	"? Profile: "..(GetProfileName(user.iProfile) or "Unregistered User").."\r\n\t"..
	"? IP: "..(user.sIP or "n/a").."\r\n\t"..
	"? Client: "..(user.sClient or "n/a").."\r\n\t"..
	"? Client Version: "..(user.sClientVersion or "n/a").."\r\n\t"..
	"? Mode: "..(tModes[user.sMode] or "n/a").."\r\n\t"..
	"? Slots: "..(user.iSlots or "n/a").."\r\n\t"..
	"? Connection: "..(user.sConnection or "n/a").."\r\n\t"..
	"? Total Hubs: "..(user.iHubs or "n/a").."\r\n\t"..
	"? Registered Hubs: "..(user.iRegHubs or "n/a").."\r\n\t"..
	"? Operator Hubs: "..(user.iOpHubs or "n/a").."\r\n\r\n\t"..
	string.rep("_", 30).."\r\n\t\tHub Information\r\n\t"..string.rep("?", 30).."\r\n\t"..
	"? Hub Name: "..(frmHub:GetHubName() or "n/a").."\r\n\t"..
	"? Hub Current Share Amount: "..DoUnits(frmHub:GetCurrentShareAmount()).."\r\n\t"..
	"? Current Uptime: "..SecondsToTime(frmHub:GetUpTime()).."\r\n\t"..
	"? Current Topic: "..(frmHub:GetHubTopic() or "n/a").."\r\n\t"..
	"? Online Users per Profile:\r\n\t"..sOnline.."\r\n\t"..
	"? Registered Users per Profile:\r\n\t"..sRegistered.."\r\n\t"..
	"? Uptime Peak: "..SecondsToTime(tStats.iUptime).."\r\n\t"..
	"? Share Peak: "..DoUnits(tStats.iTotalShare).."\r\n\t"..
	"? Users Peak: "..(frmHub:GetMaxUsersPeak() or 0)
	-- Send
	user:SendData(tSettings.sBot, sMessage)
end

OpConnected = NewUserConnected

OnExit = function()
	-- Save
	local hFile = io.open(tSettings.fStats, "w+") Serialize(tStats, "tStats", hFile); hFile:close()
end

SecondsToTime = function(iSeconds)
	-- Build table with time fields
	local T = os.date("!*t", tonumber(iSeconds)); 
	-- Format to string
	local sTime = string.format("%i month(s), %i day(s), %i hour(s), %i minute(s)", T.month-1, T.day-1, T.hour, T.min)
	-- For each digit
	for i in string.gmatch(sTime, "%d+") do
		-- Reduce if is preceeded by 0
		if tonumber(i) == 0 then sTime = string.gsub(sTime, "^"..i.."%s(%S+),%s", "") end
	end
	-- Return
	return sTime
end

-- By kepp and NotRambitWombat
DoUnits = function(iValue)
	if iValue and iValue ~= 0 then 
		local tUnits, iValue, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(iValue)
		for i in ipairs(tUnits) do 
			if (iValue < 1024) then sUnits = tUnits[i]; break else iValue = iValue/1024 end
		end 
		return string.format("%0.2f %s", iValue, sUnits);
	end
	return 0
end

Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key, value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]", key) or string.format("[%d]", key);
			if(type(value) == "table") then
				Serialize(value, sKey, hFile, sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q", value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end

SMF spam blocked by CleanTalk