PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Help with scripts => Topic started by: pR0Ps on 04 July, 2010, 17:18:49

Title: Check if Offline User is Registered
Post by: pR0Ps on 04 July, 2010, 17:18:49
How would I check if an offline user is registered? I'm writing an offline message script and for security reasons want only users that are registered to be able to receive them. I'm guessing it has something to do with matching the username with an entry in the table that RegMan.GetRegsByProfile(nProfileNumber) returns but I'm not entirely sure. Any help would be much appreciated.
Title: Re: Check if Offline User is Registered
Post by: Dessamator on 04 July, 2010, 17:50:28
QuoteGetReg(sNick)         - Return registered user with given nick as registered user table or nil when reg with this nick not exist.
You can also use that getregbyprofile, although you need to loop through the table to find that particular user. By the way you can use Mutor's Change Nick 2.0 as reference, he uses it there.
Title: Re: Check if Offline User is Registered
Post by: pR0Ps on 05 July, 2010, 04:26:01
OK, going off that I quickly wrote up a function, I don't have the facilities to test it at the moment though (on my Linux box). Will this get the job done?


--Determines if the user is a registered user
function validUser (user)
--0 to 3 are the registered profiles
for i = 0, 3 do
local t = RegMan.GetRegsByProfile(i)
for _, u in ipairs (t) do
if (u.sNick == user) then
return true
end
end
end
return false
end
Title: Re: Check if Offline User is Registered
Post by: Dessamator on 05 July, 2010, 09:12:45
That might work but it looks like taking the long way  around the Great Wall , to go into China, what I originally meant was something like:
If RegMan.GetReg(user) then ...

As for your long way of doing it, using
GetRegs() - Return table with all registered users as registered user tables.

would be better because you want to check all registered users regardless of profile
Title: Re: Check if Offline User is Registered
Post by: pR0Ps on 10 August, 2010, 07:12:30
Forgot to thank you for your help, I got it working perfectly :)