PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: NoiZe on 03 March, 2004, 23:28:41

Title: Show a list of unregistered users to an OP
Post by: NoiZe on 03 March, 2004, 23:28:41
I hope someone can help me, searched my ass off but didn't find any good stand-alone script for this problem.

I run a public hub with regged users. I want to see a list of currently unregistered nicks in a PM or mainchat. Only OP's or admin's can see or trigger this.

That way it's easy to see which users still must be checked for a good share or something..  8)

Thank you!
Title:
Post by: nErBoS on 03 March, 2004, 23:59:13
Hi,

I don't believe if that is possible.

Best regards, nErBoS
Title:
Post by: kepp on 04 March, 2004, 00:11:17
Hey, hope this helps.

sBot = "show[Unregs]"

LOGGusr = {}

function Main()
frmHub:RegBot(sBot)
end

function NewUserConnected(user)
if user.iProfile == -1 then
if LOGGusr[user.sName] == nil then
LOGGusr[user.sName] = 1
end
end
end

function UserDisconnected(user)
if user.iProfile == -1 then
LOGGusr[user.sName] = nil
end
end

function DataArrival(user, data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if user.bOperator then
if (cmd=="+showregs") then
for i,v in LOGGusr do
user:SendPM(sBot,i) return 1
end
end
end
end
end
Title:
Post by: NoiZe on 04 March, 2004, 00:18:38
It seems to work! Very, very nice kepp! :))
Title:
Post by: NoiZe on 04 March, 2004, 00:29:43
Hmmn... it showed 1 user that's not regged.. after that it showed another user that was not regged.
 
But then there came more unregged users in to the hub after that user but they were not shown by the script.

I do not get it.  ?(
Title:
Post by: kepp on 04 March, 2004, 00:32:00
Did you restartscripts?
Title:
Post by: kepp on 04 March, 2004, 00:40:14
as soon as you restartscripts everyone must reconnect... else, it won't show up... Only those users who's entering the hub after scriptrestart will be shown
Title:
Post by: NoiZe on 04 March, 2004, 00:42:15
Yeah I did, but it still the same problem.

It only show's the last unregged user that joined. I need a list of all current users that are present. I think that's the problem.

And ofcourse only those who have joined after starting the script. So they have to be online at that moment.

Do you understand what I want?
Title:
Post by: kepp on 04 March, 2004, 00:45:56
It will show all users after a while if you leave the scriptrestart button alone ;)

The problem is, there is no other way to get then name of all unregistered users that are curently active...

Enjoy
Title:
Post by: NoiZe on 04 March, 2004, 00:50:48
Of course I will leave it alone  :D

Still it's not working as it should be.

Example:
[00:48] *** Joins: Tatone
[00:48] *** Joins: [Telia]Cameltoe
[00:49] *** Joins: [Cable]Canopus

All three are unregged.

But the script only show's:

[00:49] Tatone

Hmmn..  ?(
Title:
Post by: kepp on 04 March, 2004, 00:58:03
sBot = "show[Unregs]"

LOGGusr = {}

function Main()
frmHub:RegBot(sBot)
end

function NewUserConnected(user)
if user.iProfile == -1 then
if LOGGusr[user.sName] == nil then
LOGGusr[user.sName] = 1
end
end
end

function UserDisconnected(user)
if user.iProfile == -1 then
LOGGusr[user.sName] = nil
end
end

function DataArrival(user, data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if user.bOperator then
if (cmd=="+showregs") then
for i,v in LOGGusr do
user:SendPM(sBot,i)
end
end
end
end
end

Here you go... tested and works for me :)
Title:
Post by: NoiZe on 04 March, 2004, 01:14:15
Thanks, had to look very carefully for that change  :]

I will look, test, sleep and look again :D

Thanks again!
Title:
Post by: kepp on 04 March, 2004, 01:14:51
No problem, lol!!
Title:
Post by: NoiZe on 04 March, 2004, 01:18:55
Seems to work just fine now!  :))

could be a #1 at the Lua Script Award's 2004! :tongue:
Title:
Post by: NightLitch on 04 March, 2004, 01:56:03
Reminder:

When restarting script the LOGGusr table will be emty...


/NL
Title:
Post by: NoiZe on 04 March, 2004, 09:00:29
Yes indeed. You can better restart the entire hub then instead, because all users will reconnect then and everything will work fine again.
Title:
Post by: NightLitch on 04 March, 2004, 11:34:47
Here is a modified version that write's to a file:

--[ LogBot ]--
-- Originally by: Kepp
-- Modified by: NightLitch

sBot = "show[Unregs]"

LogFile = "UserLog.txt"

LOGGusr = {}

function Main()
frmHub:RegBot(sBot)
if frmHub:GetUsersCount() == 0 then
local f = openfile(LogFile, "w")
if f == nil or f=="" then
write(f, " ")
closefile(f)
else
write(f, " ")
closefile(f)
end
else
LoadFromFile (LogFile)
end
end

function NewUserConnected(user)
if user.iProfile == -1 then
if LOGGusr[user.sName] == nil then
LOGGusr[user.sName] = 1
SaveToFile(LOGGusr , "LOGGusr", LogFile)
end
end
end

function UserDisconnected(user)
if user.iProfile == -1 then
LOGGusr[user.sName] = nil
SaveToFile(LOGGusr , "LOGGusr", LogFile)
end
end

function DataArrival(user, data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if user.bOperator then
if (cmd=="+showregs") then
for i,v in LOGGusr do
user:SendPM(sBot,i)
end
end
end
end
end

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

function SaveToFile(table , tablename, file)
local hFile = openfile(file, "w");
Serialize(table, tablename, hFile);
closefile(hFile);
end

function LoadFromFile (file)
assert(readfrom(file),file.." is not found.Generating new "..file..". All is fine. Don't panic.")
dostring(read("*all"))
readfrom()
end

/NL
Title:
Post by: kepp on 04 March, 2004, 15:07:25
ok, would you like to explain a bit further, what the serializatio of the tables do? What's the point... seems every script use it lately
Title:
Post by: NightLitch on 04 March, 2004, 15:46:27
QuoteOriginally posted by kepp
ok, would you like to explain a bit further, what the serializatio of the tables do? What's the point... seems every script use it lately

Well that is just a main serialize I got from Wombat, a slight change but not noticeable.

That will order the table and then write to file.

that is the best serialize I have tried, especially if you use outer & inner table:

outer = { inner = {values},  }

And don't want "many" functions. I don't know who made it from the start maybe Wombat, as I mention I got it from him.

/NL
Title:
Post by: NoiZe on 05 March, 2004, 01:57:06
Seems to work ok, thnx!

Btw.. a better command is +showunregs  ;)

And now off to bed again.. :D