PtokaX forum

Development Section => Your Developing Problems => Topic started by: NightLitch on 13 November, 2003, 20:38:30

Title: User Login Log Help me...
Post by: NightLitch on 13 November, 2003, 20:38:30
Hey Guy''s!

I have a problem solving a problem am out of idees
or should I say don't know what/how to do the function...  :))

This Is what I have done

----------------------------
--[ User Logger Function ]--
----------------------------
function DoUserLogger(curUser,data)
local nick = GetItemByName(curUser.sName)
if USERLOGGER[strlower(nick)] == nil or USERLOGGER[strlower(nick)] == "" then
SendToAll("NOT IN FILE, GETTING LOGGED")
USERLOGGER[strlower(curUser.sName)] = "online"
else
if strlower(nick) == USERLOGGER[strlower(nick)] then
SendToAll("LOGGED IN TABLE/FILE")
end
end
end

function LoggerControl(curUser,data)

-- Here I want To check if users are online or not when restarting the hubsoft
-- Cause the file won't get emty if restarting the hubsoft...
-- How Would I Do This.... Help... Me...

if GetItemByName(USERLOGGER) == 1 then

-- something or not

end
end

I want in Main() to check the file if user is logged in or not... or a better solusion how will I create a usefull
logger that will not emty the table if script being restarted..? (yes, log into a file BUT! how will the file get
erased if hub is shutdown or restarted??)

everyone understand my english... ?    ?(

Come With idees plz... or better solusions... :D

/NightLitch
Title:
Post by: pHaTTy on 13 November, 2003, 20:43:38
for erasing the file use a function like this

function OnExit()
openfile("Whereever/file.txt" "w")
Write(" ")
closefile()
end


sumit like that yep :)
Title:
Post by: NightLitch on 13 November, 2003, 20:46:41
will that work???

have tried before...

but will try again... optimist as I am... heh

ThX

/NightLitch
Title:
Post by: NightLitch on 13 November, 2003, 21:21:30
How come when I use this function and stop the hub and start
it again the script's arent loaded????

something wrong in my function???


function OnExit()
   local f = openfile(LOGGERFILE, "w")
   write(f, " ")
   closefile(f)
end


/NightLitch
Title:
Post by: NightLitch on 13 November, 2003, 21:24:22
Ok got the funtion working


function OnExit()
   local f = openfile(LOGGERFILE, "w")
   if f == nil then
   else
   write(f, " ")
   closefile(f)
   end
end


But when starting the hub again the script are not loaded why???

/NightLitch
Title:
Post by: NightLitch on 13 November, 2003, 21:38:01
Reopened...


In the new hubsoft I get a problem when restarting the script...

The Log-File is getting erased when restarting script... not good.... why???

Title:
Post by: plop on 13 November, 2003, 23:14:43
remove(filename)
thats all you need 2 delete a file.

for closing you don't need 2 say wich file.
closefile()    is enough.

plop

* edit: not 2 sure but the way you try 2 close the file could cause it not 2 be closed an then you get an error on restart of the script because the file is in use.
not 2 sure do.
Title:
Post by: NightLitch on 13 November, 2003, 23:23:25
Think you missed my problem, When I restart The scripts
the OnExit () trigger as well, shouldn't it only trigger when hubsoft
getting closed or turned off...

My Online User Table(file) is being erased when restarting script....

And That is not the way I want it...

I use last script above...

/NightLitch
Title:
Post by: pHaTTy on 14 November, 2003, 00:03:56
Hmmm, maybe because OnExit has not been perfected, needs to be only on hubclose, but it seems to be on restart as well :/
Title:
Post by: plop on 14 November, 2003, 00:58:49
what i remember is that it was the idea 2 trigger it on a restart of the scripts and on a full hub restart.
that way you can save any temp files you want.
only making it trigger on a hub restart makes it in my eyes only work half.
what you can do in your case is save the online table 2 a 2de file, and on function main() check for the amount of users.
on a script restart that will be ~= 0 so you load the temp file.
if there are no users you build a new empty table.
i hope you get my idea and that i did get your idea, really sleepy @ the moment.

plop