Author Topic: Check if Offline User is Registered  (Read 1942 times)

0 Members and 1 Guest are viewing this topic.

Offline pR0Ps

  • Member
  • ***
  • Posts: 27
  • Karma: +0/-2
Check if Offline User is Registered
« 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.

PtokaX forum

Check if Offline User is Registered
« on: 04 July, 2010, 17:18:49 »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
Re: Check if Offline User is Registered
« Reply #1 on: 04 July, 2010, 17:50:28 »
Quote
GetReg(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 American Idiot's Change Nick 2.0 as reference, he uses it there.
Ignorance is Bliss.

Offline pR0Ps

  • Member
  • ***
  • Posts: 27
  • Karma: +0/-2
Re: Check if Offline User is Registered
« Reply #2 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?

Code: [Select]
--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

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
Re: Check if Offline User is Registered
« Reply #3 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:
Code: [Select]
If RegMan.GetReg(user) then ...
As for your long way of doing it, using
Code: [Select]
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
Ignorance is Bliss.

Offline pR0Ps

  • Member
  • ***
  • Posts: 27
  • Karma: +0/-2
Re: Check if Offline User is Registered
« Reply #4 on: 10 August, 2010, 07:12:30 »
Forgot to thank you for your help, I got it working perfectly :)

PtokaX forum

Re: Check if Offline User is Registered
« Reply #4 on: 10 August, 2010, 07:12:30 »