PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: sylvi on 26 November, 2004, 11:01:03

Title: tmp Selfreg to Hub B
Post by: sylvi on 26 November, 2004, 11:01:03
I need a simple selfreg script for a seccond Hub. Hub A and hub B are on the same server. All users with status reguser and higher in hub A should be able to invite himself by command !invite in hub B, so in hub B the user should have status reguser. If the user will leave hub B he should be deleted in the RegisteredUsers.dat and will only be able to came back in the hub through invite himself in
Title:
Post by: sylvi on 28 November, 2004, 11:56:53
Please help,  i think there is a mistake in my script. One user in Hub A invite himself to Hub B, the file regestrierteUser.dat  from Hub B will open and will complete overwrite, Why? But the user is not added at the moment, first when i restart the hub B he is added, what can i do that it work like addregser?


sBot = "X-Planet-Invite"
regfile = "C:\\x-planet\\RegisteredUsers.dat"
function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!inviteme") then
local s,e,pass = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (pass == nil) then
user:SendPM(sBot, "Syntax Error, !inviteme , you must write a password.")
else
--- AddRegUser(user.sName, pass, 3)
invitename = user.sName.."|"..pass.."|3"
writeto(regfile)
write(invitename.."\n")
writeto()
SendToOps(sBot, "The user "..user.sName.." has invite himself to X-Planet.")
user:SendPM(sBot, "You have been successufly invite to X-Planet with the pass: "..pass)
user:SendPM(sBot, "Please connect X-planet.dyndns.ws:8268 and type your password.")
end
return
end
end
end
Title:
Post by: nErBoS on 28 November, 2004, 15:50:12
Hi,

Use this script in your HUB A...

--## HUB INVITER BOT (PART 1)
--## Requested by sylvi
--## Made by nErBoS
--## Commands:
--## +invite - Will invite yourself to another HUB with a password

sBot = "HI1-Bot"

fPathRegUsers2 = "C:\\WorkFolder\\temp\\Ptokax2\\" -- Path of ptokax the second hub

function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (user.iProfile ~= 1 and (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot)) then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+invite") then
local s,e,sPass = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (sPass == nil) then
user:SendPM(sBot, "Syntax Error, +invite , you must write a pass.")
elseif (strfind(sPass, "[%c|\n\r]")) then
user:SendPM(sBot, "Invalid Password. Try Again.")
elseif (strfind(user.sName, "[%c|\n\r]")) then
user:SendPM(sBot, "Your nick is invalid. Please choose a new one.")
elseif (CheckReg(user.sName) ~= nil) then
user:SendPM(sBot, "You nick is already regged in the other HUB.")
else
AddReg(user.sName,sPass,user.iProfile)
user:SendPM(sBot, "You have been regged in the other HUB with the password: "..sPass)
end
return 1
end
end
end

function CheckReg(sName)
execute("copy "..fPathRegUsers2.."RegisteredUsers.dat")
if (readfrom("RegisteredUsers.dat") ~= nil) then
readfrom("RegisteredUsers.dat")
while 1 do
local sLine = read()
if (sLine == nil) then
readfrom()
return nil
else
local s,e,sNick = strfind(sLine, "(.+)|")
if (sNick ~= nil and sNick == sName) then
readfrom()
return 1
end
end
end
end
end

function AddReg(sNick, sPass, iLevel)
if (readfrom(fPathRegUsers2.."scripts\\NewUsers.dat") == nil) then
writeto(fPathRegUsers2.."scripts\\NewUsers.dat")
  write(sNick.."##"..sPass.."##"..iLevel.."\r\n")
writeto()
else
appendto(fPathRegUsers2.."scripts\\NewUsers.dat")
  write(sNick.."##"..sPass.."##"..iLevel.."\r\n")
writeto()
end
end

And use this one in your HUB B...

--## HUB INVITER BOT (PART 2)
--## Requested by sylvi
--## Made by nErBoS

sBot = "HI1-Bot"

function Main()
frmHub:RegBot(sBot)
end

function UserDisconnected(user)
DelRegUser(user.sName)
end

function DataArrival(user, data)
if (strsub(data,1,13) == "$ValidateNick") then
CheckForNewUser()
end
end

function CheckForNewUser()
if (readfrom("NewUsers.dat") ~= nil) then
readfrom("NewUsers.dat")
while 1 do
local sLine = read()
if (sLine == nil) then
readfrom()
writeto("NewUsers.dat")
write("")
writeto()
break
else
local s,e,sNick,sPass,iLevel = strfind(sLine, "(.+)##(.+)##(%d+)")
if (sNick ~= nil and sPass ~= nil and iLevel ~= nil) then
AddRegUser(sNick,sPass,iLevel)
end
end
end
end
end

Best regards, nErBoS
Title:
Post by: sylvi on 28 November, 2004, 18:27:58
Hi nErBoS,

thx for the work.

great script but i think there are some mistakes, it don?t work.
Title:
Post by: sylvi on 28 November, 2004, 20:11:50
Hi nErBoS,

Script Hub B

Quoteif (reafrom("NewUsers.dat") ~= nil) then

if (readfrom("NewUsers.dat") ~= nil) then


I think the mistake is in the position where the newuser.dat file should read out and add the users to hub.

The users don?t be added
Title:
Post by: sylvi on 30 November, 2004, 12:33:46
Hi nErBoS,

can you help me with this Skript from Hub B.
Title:
Post by: nErBoS on 30 November, 2004, 13:22:34
Hi,

Is the file "NewUsers.dat" been created in the script folder of HUB B ?? Is the script given any error ?? I have made a little fix in the second script, try out.

Best regards, nErBoS
Title:
Post by: charlie on 30 November, 2004, 17:47:49
Hi nerbos,

i also try this script, because i think it is a great idee...
i think there are mistakes...

first in script for hub A
Quotefunction AddReg(sNick, sPass, iLevel)
   if (reafrom(fPathRegUsers2.."scripts\\NewUsers.dat") == nil) then


shoud this not mean: readfrom

and same is in script for hub B.

I change it an script in hub A creat the newusers.dat file.
But the script in Hub B can?t read out of them, and so nothing happend : Syntax Error: bad argument #1 to `strfind' (string expected, got nil)
Title:
Post by: nErBoS on 01 December, 2004, 03:17:14
Hi,

Made a edit on the scripts above correcting the "readfrom" syntax (sharp eye :D ) and the error, try it now please.

Best regards, nErBoS
Title:
Post by: sylvi on 01 December, 2004, 06:25:45
Hi nErBoS

I have the Script A and B editiert.

Script Hub A


--## HUB INVITER BOT (PART 1)
--## Requested by sylvi
--## Made by nErBoS
--## Commands:
--## +invite - Will invite yourself to another HUB with a password

sBot = "Invite-Hub-A"

fPathRegUsers2 = "C:\\x-planet\\" -- Path of ptokax the second hub

function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (user.iProfile ~= 1 and (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot)) then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+invite") then
local s,e,pass = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (pass == nil) then
user:SendPM(sBot, "Syntax Error, +invite , you must write a pass.")
elseif (strfind(pass, "[%c|\n\r]")) then
user:SendPM(sBot, "Invalid Password. Try Again.")
elseif (strfind(user.sName, "[%c|\n\r]")) then
user:SendPM(sBot, "Your nick is invalid. Please choose a new one.")
elseif (CheckReg(user.sName) ~= nil) then
user:SendPM(sBot, "You nick is already regged in the other HUB.")
else
AddReg(user.sName,pass,user.iProfile)
user:SendPM(sBot, "You have been regged in the other HUB with the password: "..pass)
end
return 1
end
end
end

function CheckReg(sName)
execute("copy "..fPathRegUsers2.."RegisteredUsers.dat")
if (readfrom("RegisteredUsers.dat") ~= nil) then
readfrom("RegisteredUsers.dat")
while 1 do
local sLine = read()
if (sLine == nil) then
readfrom()
return nil
else
local s,e,sNick = strfind(sLine, "(.+)|")
if (sNick ~= nil and sNick == sName) then
readfrom()
return 1
end
end
end
end
end

function AddReg(sNick, pass, iLevel)
if (readfrom(fPathRegUsers2.."scripts\\NewUsers.dat") == nil) then
writeto(fPathRegUsers2.."scripts\\NewUsers.dat")
  write(sNick.."##"..pass.."##"..iLevel.."\r\n")
writeto()
else
appendto(fPathRegUsers2.."scripts\\NewUsers.dat")
  write(sNick.."##"..pass.."##"..iLevel.."\r\n")
writeto()
end
end


Script from Hub B it now


--## HUB INVITER BOT (PART 2)
--## Requested by sylvi
--## Made by nErBoS

sBot = "Invite-Hub-B"

function Main()
frmHub:RegBot(sBot)
end

function UserDisconnected(user)
DelRegUser(user.sName)
end

function DataArrival(user, data)
if (strsub(data,1,8) == "$Version") then
CheckForNewUser()
end
end

function CheckForNewUser()
if (readfrom("NewUsers.dat") ~= nil) then
readfrom("NewUsers.dat")
while 1 do
local sLine = read()
if (sLine == nil) then
readfrom()
writeto("NewUsers.dat")
write("")
writeto()
break
else
local s,e,sNick,sPass,iLevel = strfind(data, "(.+)##(.+)##(%d+)")
if (sNick ~= nil and sPass ~= nil and iLevel ~= nil) then
AddRegUser(sNick,sPass,iLevel)
end
end
end
end
end


The Scrip from Hub B dont work.

QuoteIs the file "NewUsers.dat" been created in the script folder of HUB B ??


yes, Scripts/Newuser.dat with user##password##Level

QuoteIs the script given any error ??


no error

But the script B can?t read and add from the NewUser.dat

nErBoS please help me,
Title:
Post by: nErBoS on 01 December, 2004, 15:13:47
Hi,

Try to use the script of HUB B that i have edited, like i said in the last post.

Best regards, nErBoS
Title:
Post by: sylvi on 01 December, 2004, 15:34:19
Hi nErBoS,

sorry, the Script from Hub B dont addet user.

I have Ptokax PtokaX DC Hub 0.3.3.0 build 15.25 [debug] on Hub A and B
Title:
Post by: nErBoS on 03 December, 2004, 00:31:22
Hi,

I need to catch some free time to test it, when i have i will check it.

Best regards, nErBoS
Title:
Post by: nErBoS on 05 December, 2004, 00:34:16
Hi,

I have correct both scripts above in my post and i have tested.

Best regards, nErBoS
Title:
Post by: sylvi on 05 December, 2004, 15:04:27
Big thx nErBos :P  :P  :P