PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Psycho_Chihuahua on 11 September, 2004, 11:48:31

Title: Registered Users across Hubs script request
Post by: Psycho_Chihuahua on 11 September, 2004, 11:48:31
Could someone write a script to compare and edit the userdatabase between 2 (or more) hubs running on the same computer with different Ports?

For example:

User registers himself (or gets registered) in Hub A, and at the same time he gets registered in Hub B allowing connection to that Hub as well.

Hub A should register the new User in Hub B automaticaly

i dont need any cmd's for this as it should be done completly on it's own.
the only thing i would have to be able to edit are the hubadresses and ports or the path to the RegisteredUsers.dat whichever would be needed to accomplish the task.

any help would be appreciated
Title:
Post by: bastya_elvtars on 11 September, 2004, 14:34:58
If both hubs are ptokax, then we can do a script that copies RegisteredUsers.dat to the folders between the 2 ptokax lol, but i dont know what to trigger it with. Altho i can make it for ya.
Title:
Post by: plop on 11 September, 2004, 15:21:59
QuoteOriginally posted by bastya_elvtars
If both hubs are ptokax, then we can do a script that copies RegisteredUsers.dat to the folders between the 2 ptokax lol, but i dont know what to trigger it with. Altho i can make it for ya.
the idea is good but not the files.
ptokax only reads those on startup, so you need a seperate files.
have both hub's write new users 2 there own file, and let the hub's read eachothers files on a timer and delete it after processing.

plop
Title:
Post by: bastya_elvtars on 11 September, 2004, 15:43:36
U mean by triggering a regusers.dat reading process and if the users aint registered, ptokax adds them auto? Ok, gonna deal with that l8r...
Title:
Post by: Psycho_Chihuahua on 11 September, 2004, 22:20:56
well there's a website registration script whizzing round somewhere here that also allows registering from outside the hub. just that it doesnt check if username is registered already so when 2 ppl use the same nick the passwords get messed up.

but it would be gr8 if someone could accomplish this task and i'm sure Admins of Hub Networks would find something like this somewhat usefull
Title:
Post by: plop on 11 September, 2004, 22:43:07
QuoteOriginally posted by bastya_elvtars
U mean by triggering a regusers.dat reading process and if the users aint registered, ptokax adds them auto? Ok, gonna deal with that l8r...
no seperate files.
hub1 has addnewregfile1.txt.
when some1 regs himself in hub1 the nick/pw is written 2 this file.
every x minutes hub2 checks if this file is found, if yes it processes the file and adds the new users.
when done it deletes the file.
this works a lot faster as nothing has 2 be done if the file isn't found, no need 2 check if it's a old or a new user.
hub2 offcourse saves 2 addnewregfile2.txt and hub1 checks for that file.

plop
Title:
Post by: Psycho_Chihuahua on 14 September, 2004, 10:32:30
got an example Plop?

Can someone do this for me please?
Title:
Post by: Psycho_Chihuahua on 18 September, 2004, 17:11:38
anyone got a solution to this request?


pleeeease  ;(
Title:
Post by: nErBoS on 18 September, 2004, 18:33:14
Hi,

I can try to make one. How many HUBs are you runnig on your PC ??? You want to refresh the reg file from which time ??

Best regards, nErBoS
Title:
Post by: Psycho_Chihuahua on 19 September, 2004, 07:31:26
Hi nerbos

Well i'm running 2 Hubs on my PC and i would like the refresh to be done at the same time or shortly after the the user gets registered to the hub if thats possible

otherwise a refresh intervall of 30 mins would be just fine.
Title:
Post by: nErBoS on 19 September, 2004, 16:26:51
Hi,

Try out this one...

--## REG HUBs BOT
--## Requested by Psycho_Chihuahua
--## Will only work with HUBs running in the same PC
--## Made by nErBoS

sBot = "RH-Bot"

sec = 1000
min = 60*sec
hour = 60*min

--## Configuration ##--

fReg = "RegisteredUsers.dat" -- Path of the RegisteredUsers.dat of the other HUB
iTime = 30*min -- Time that will refresh the register

--## END ##--

function Main()
SetTimer(iTime)
StartTimer()
end

function OnTimer()
if (readfrom(fReg) == nil) then
SendToOps(sBot, "The file with the register of the other HUB wasn't found.")
else
local count,time = 0,clock()
readfrom(fReg)
while 1 do
local sLine = read()
if (sLine == nil) then
time = clock() - time
time = format("%0.10f", time*1000)
SendToOps(sBot, "The reg file was refresh.")
SendToOps(sBot, "New entries: "..count..". Time taken: "..time.." seconds")
break
else
local s,e,nick,pass,level = strfind(sLine, "(.+)|(.+)|(%d+)")
if (nick ~= nil and CheckReg(nick) == 0) then
AddRegUser(nick, pass, tonumber(level))
count = count + 1
end
end
end
readfrom()
end
end

function CheckReg(nick)
local aux,profiles,usr
for aux, profiles in GetProfiles() do
for aux, usr in GetUsersByProfile(profiles) do
if (usr == nick) then
return 1
end
end
end
return 0
end

Best regards, nErBoS
Title:
Post by: UwV on 20 September, 2004, 02:26:15
cool .. been looking for something like that ..


but ..

[02:14:18] New entries: 363. Time taken: 38891.0000000000 seconds
[02:14:39] The reg file was refresh.
[02:14:39] New entries: 0. Time taken: 19891.0000000000 seconds
[02:15:00] The reg file was refresh.
[02:15:00] New entries: 0. Time taken: 19860.0000000000 seconds
[02:15:21] The reg file was refresh.
[02:15:21] New entries: 0. Time taken: 19687.0000000000 seconds
[02:15:42] The reg file was refresh.
[02:15:42] New entries: 0. Time taken: 20422.0000000000 seconds
[02:16:01] The reg file was refresh.
[02:16:01] New entries: 0. Time taken: 17953.0000000000 seconds
[02:16:21] The reg file was refresh.
[02:16:21] New entries: 0. Time taken: 18578.0000000001 seconds
[02:16:42] The reg file was refresh.
[02:16:42] New entries: 0. Time taken: 20812.0000000000 seconds
[02:17:03] The reg file was refresh.
[02:17:03] New entries: 0. Time taken: 20108.9999999999 seconds
[02:17:25] The reg file was refresh.
[02:17:25] New entries: 0. Time taken: 20468.9999999999 seconds
[02:17:45] The reg file was refresh.
[02:17:45] New entries: 0. Time taken: 18844.0000000001 seconds


and it won't stop ... keeps on trying to ad and add and add ..

i haven't changed the " iTime = 30*min "
Title:
Post by: nErBoS on 20 September, 2004, 02:44:08
Hi,

LOL, i have forgot to remove the 5 seconds i had to test it. Fixed the script above.

Best regards, nErBoS
Title:
Post by: Psycho_Chihuahua on 20 September, 2004, 23:34:17
;(  ;(  ;(  it crashes my hub when i try to add a user  ;(  ;(  ;(


i get an error box with a whole lot of writing and the reference that it cant write the RegisteredUsers.dat

I've testet with TD 4, TD 4.99 and 0.330 build 15.25 all with the same result.

in the Filepath to the file i have tried with \ and / and even //. Either i get..cant find file or it crashes/locks the hub untill the error box has been clicked away (buil 15.25 - with 4 and 4.99 the whole thing crashed)

Any Idea's?
Title:
Post by: nErBoS on 21 September, 2004, 00:42:04
Hi,

Well in my script i don't write anything in the file, because if i did it would crach like you said. You said that you tried to add a user, how ??? by a command or by hubsoftware i suppose. If you tryied to write in the file, off course it will fail and give you a error. Here is a example of how to catch the userregister file of the other HUB....

"C:\\WorkFolder\\Ptokax\\RegisteredUsers.dat"
Best regards, nErBoS
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 01:00:36
Doh, the only version i didn't try lol

I'll check it out just now
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 01:54:46
Well i tried that now to

i get a "what looks like linux or macintosh" error box containing the following:
Exeption 'EFCreate Error' in module PtokaX.exe at 000C0FFD
Cannot create file D:\hub\pto2\RegisteredUsers.dat

Using
QuoteD:\\hub\\pto2\\RegisteredUsers.dat

The funny thing though is that it still does the entry's to the file just that it locks up until the error messages are one by one clicked away. once per new user
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 05:17:55
that would be a solution, exept for that each hub uses slightly different scripts and has a different MOTD, so finding a way to it script wise is probably the only way

The funny thing is on 1 hub it works and on an identical (made from the same exe just in different folder) it fails in full

so one way it works and the other not, randomly
Title:
Post by: nErBoS on 21 September, 2004, 11:11:04
Hi,

Yes i have tested and it gaves me the same error, then i have tried another aproach, i copy the file to your script folder and will check from there, try this script...

--## REG HUBs BOT
--## Requested by Psycho_Chihuahua
--## Will only work with HUBs running in the same PC
--## Made by nErBoS

sBot = "RH-Bot"

sec = 1000
min = 60*sec
hour = 60*min

--## Configuration ##--

fReg = "RegisteredUsers.dat" -- Path of the RegisteredUsers.dat of the other HUB
iTime = 30*min -- Time that will refresh the register

--## END ##--

function Main()
SetTimer(iTime)
StartTimer()
end

function OnExit()
StopTimer()
end

function OnTimer()
execute("copy "..fReg)
if (readfrom("RegisteredUsers.dat") == nil) then
SendToOps(sBot, "The file with the register of the other HUB wasn't found.")
else
local count,time = 0,clock()
local handle = openfile ("RegisteredUsers.dat", "r+")
while 1 do
local sLine = read(handle)
if (sLine == nil) then
time = clock() - time
time = format("%0.10f", time*1000)
SendToOps(sBot, "The reg file was refresh.")
SendToOps(sBot, "New entries: "..count..". Time taken: "..time.." seconds")
break
else
local s,e,nick,pass,level = strfind(sLine, "(.+)|(.+)|(%d+)")
if (nick ~= nil and CheckReg(nick) == 0) then
AddRegUser(nick, pass, tonumber(level))
count = count + 1
end
end
end
closefile(handle)
remove("RegisteredUsers.dat")
end
end

function CheckReg(nick)
local aux,profiles,usr
for aux, profiles in GetProfiles() do
for aux, usr in GetUsersByProfile(profiles) do
if (usr == nick) then
return 1
end
end
end
return 0
end

Best regards, nErBoS
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 12:14:29
yeah gr8
It works fine now thnx Nerbos. Just 1 more thing - as long as the hub's running it's fine. when i shutdown the hub however i get a couple of error Boxes.

Got an Idea why? No other script running during tests.
Title:
Post by: nErBoS on 21 September, 2004, 12:53:08
Hi,

That happens to all versions of ptokax or just one in particular ?? If one in particular, which is it ??

Best regards, nErBoS
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 15:21:41
Well with 0.330 build 15.25 it happens already when i stop the hub
(http://psycho-chihuahua.ath.cx/images/ptokax/15.25.1.jpg)
(http://psycho-chihuahua.ath.cx/images/ptokax/15.25.2.jpg)
(http://psycho-chihuahua.ath.cx/images/ptokax/15.25.3.jpg)

with 0.326 TestDrive 4 only when i've stopped the hub and then want to close it.

(http://psycho-chihuahua.ath.cx/images/ptokax/td4.jpg)

otherwise the script does the job fine  :D
Title:
Post by: nErBoS on 21 September, 2004, 22:49:22
Hi,

I have test it and didn't gave me any error.

Best regards, nErBoS
Title:
Post by: BoJlk on 21 September, 2004, 23:20:34
Unfortunetlly it gave me the same Errors...
both of the Versions.
Title:
Post by: bastya_elvtars on 21 September, 2004, 23:27:42
this occurs when ptokax wants to write to an already used file.
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 23:42:55
so in other words would have to duplicate the RegisteredUsers.dat to a local directory and then read from copy into real Userfile which it does now.

And after processing that, erase the copy?

Or is it something else?
Title:
Post by: nErBoS on 22 September, 2004, 10:32:05
Hi,

The copy his made to your script folder then the script works from there. So i don't see why the error is coming up.

Best regards, nErBoS
Title:
Post by: NightLitch on 22 September, 2004, 11:07:41
I need to say my opinion in this script.

Why did you all not listen to plop...

Make 2 seperate files...

The RegisteredUsers.dat won't be updated until you restart the hub...

And with plop's idea you get no errors... :D

No harm to no one, great work nErBoS, but try out plop's idea.

Best Regards / NightLitch
Title:
Post by: nErBoS on 23 September, 2004, 01:33:56
Hi,

I have already made that, check the last script NL  :))

Best regards, nErBoS