PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Shurlock on 24 July, 2004, 02:47:56

Title: CPU consumption?
Post by: Shurlock on 24 July, 2004, 02:47:56
Hi all,

I would very much like to write a script that creates (or appends to an existing) complete  logfile for each entering user.

The file will contain facts like logon, logoff, kicks & bans (with reason), etc.

Once created, the file will be accessable to OP's and higher levels.
These checks however will obviously not be as numerous as the actual creations (or appendings) themselves.
It should however give a complete view of the user in question.

Reason? I very much dislike registering people that we know nothing about!
This could give an answer to that question of a period of time.
(Meaning: you can request registration after a month or so)

Before I start working on this, there's but 1 simple question I know no answer to:
How consuming is the command: writeto(filename)   for the CPU  ???

If this would pull down hub activities too much, I'll just not start trying!  :)

Thanks for any explanations.

Regards,
Shurlock.

[PS: CPU = PIII/1000Mhz   Memory=512Mb  Users=appr. 350]
Title:
Post by: plop on 24 July, 2004, 03:40:40
last time i checked it took 0.05 seconds 2 write a 55KB file 2 disk.
this was on a p2 266 with 128MB running freebsd with a scsi-2 hdd (20MB/s).
it's not a real mather of cpu power (this is where DMA cuts in), specialy when the file fits into the cache of the hdd.

plop
Title:
Post by: nErBoS on 24 July, 2004, 15:22:44
Hi,

About saving info from users try out the major scripts, like:  RoboCop, ChannelBot, NXS, Brain-Master, etc (this is the bots that i remenber with offline info.)

Best regards, nErBoS
Title:
Post by: D-J Valhala on 25 July, 2004, 00:38:59
Try that one great script  :D
========================================
-- Simple Offline Info by NightLitch
-- Commands is sent in Main-Chat
-- Create folder UserInfo

-- BotName --
BotName = "BOT_NAME_HERE"
-- Prefix --
Prefix = "+"

--Command--
cmd1 = "off"
-- Tables --
Temp = {}
Info = {}
-- Info Path --
InfoLog = "UserInfo/"

-- New User Connected --
function NewUserConnected(curUser,data)
LogInfo(curUser)
end
-- Data Arrival --
function DataArrival(curUser, data)
if strsub(data, 1, 1) == "<" then
data = strsub(data,1,strlen(data)-1)
if (GetCom(curUser,data) == 1) then
return 1
else
return 0
end
end
end
-- Get Command --
function GetCom(curUser,data)
local _,_,cmd = strfind(data,"^%b<>%s+%"..Prefix.."(%S+)")
if cmd then
if IPCommand[cmd] and curUser.iProfile==0 then
local Com = IPCommand[cmd](curUser,data)
return 1
end
end
end
-- Commands --
IPCommand = {
[cmd1] = function(curUser,data)
local _,_,nick = strfind( data,"%b<>%s+%S+%s+(%S+)")
if (nick == nil or nick == "") then
curUser:SendData(BotName,"Syntax: "..Prefix..cmd1.." ")
return 1
end
local IP, Profile, MyInfo = GetInfo(nick)
if IP==0 and Profile==0 and MyInfo==0 then
curUser:SendData(BotName,"User not found.")
return 1
end
ClientTAG = {
{ " { " { " { " { "zDC++","zDC++" },{ "","MS++V" },
{ "","MS++V" },{ " { "<.P>","Phantom DC++" },}
local _,_,Nick = strfind( MyInfo, "^%$MyINFO %$ALL (%S+)%s*")
local _,_,Speed,Share = strfind( MyInfo, "^%$MyINFO %$ALL [^ ]+ [^$]*%$ $([^$]+)[^$]%$[^$]*%$%s*(%d+)%$" )
local _,_,Slots = strfind( MyInfo, "S:(%d+)")
local _,_, Ver,Mode = strfind(MyInfo,"V:(%S+),M:([S,A,P])")
local _,_, Hubs = strfind(MyInfo,"H:(%x+)")
local Client = "Unknown"
for i = 1,getn(ClientTAG) do
if strfind(MyInfo,ClientTAG[i][1]) then
Client = ClientTAG[i][2]
end
end
local line = "\r\n"
line = line .. "\r\n User Info on: "..Nick
line = line .. "\r\n --------------------------------------------------------------------"
line = line .. "\r\n --------------------------------------------------------------------"
line = line .. "\r\n IP: "..IP
line = line .. "\r\n Client: "..Client
line = line .. "\r\n Version: "..Ver
line = line .. "\r\n Mode: "..Mode
line = line .. "\r\n Hubs: "..Hubs
line = line .. "\r\n Slots: "..Slots
line = line .. "\r\n Speed: "..Speed
line = line .. "\r\n Share: "..format("%.2f",Share/1024/1024/1024)
line = line .. "\r\n --------------------------------------------------------------------"
line = line .. "\r\n --------------------------------------------------------------------"
curUser:SendData(BotName,line)
end,

}

-- Log Users Info --
function LogInfo(curUser)
Info[strlower(curUser.sName)] = {["IP"]=curUser.sIP,["PROFILE"]=curUser.iProfile,["MYINFO"]=curUser.sMyInfoString,}
SaveToFile(InfoLog..strlower(curUser.sName)..".dat" , Info , "Info")
Info = nil
Info = {}
collectgarbage()
flush()
return 1
end
-- Get Info --
function GetInfo(nick)
LoadFromFile(InfoLog..strlower(nick)..".dat")
local usr = Info[strlower(nick)]
if usr then
IP = usr["IP"]
Profile = usr["PROFILE"]
MyInfo = usr["MYINFO"]
return IP,Profile, MyInfo
else
return 0,0,0
end
end
-- Serialize --
function Serialize(tTable, sTableName, hFile, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(hFile, "hFile equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";

write(hFile, sTab..sTableName.." = {\n" );

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile, sTab.."\t"..sKey.." = "..sValue);
end

write(hFile, ",\n");
end

write(hFile, sTab.."}");
end
-- Save Table to File --
function SaveToFile(file , table , tablename)
local hFile = openfile(file, "w");
Serialize(table, tablename, hFile);
closefile(hFile);
end
-- Load Table From File --
function LoadFromFile (file)
assert(readfrom(file),file.." is not found.Generating new "..file..". All is fine. Don't panic.")
dostring(read("*all"))
readfrom()
end
:D  it's a good one  :P have fun mate