The NightHawk Forum
September 09, 2010, 06:57:31 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: PtokaX 0.4.1.1 released on June 21st 2008
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Self-Redirection script  (Read 1249 times)
0 Members and 1 Guest are viewing this topic.
CrazyGuy
Administrator
Sr. Member
*****
Offline Offline

Posts: 254



View Profile WWW
« on: April 08, 2007, 10:37:19 PM »

Code:
--[[
HubJumper
LUA 5.1.x
A redirect-self script
By CrazyGuy
On request by Då®k][Wîzå®d™
Last updated April 8th 2007
]]--

Quote
<Hub-Jumper> Available commands:

      !redirhelp         -Shows this help file

      !addhub <address:port>   -Add a hub to the list
      !delhub <address:port>   -Delete a hub from the list

      !showhubs      -Shows all hubs in the list

      !jump <address:port>   -Redirect yourself to the specified hub


Attached the lua file Smiley

« Last Edit: April 09, 2007, 01:25:02 PM by CrazyGuy » Logged

Då®k][Wîzå®d™
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #1 on: April 09, 2007, 01:29:03 PM »

Nice Job CrazyGuy , really appreciate it  Wink
Logged
CrazyGuy
Administrator
Sr. Member
*****
Offline Offline

Posts: 254



View Profile WWW
« Reply #2 on: April 09, 2007, 01:33:41 PM »

You''re welcome  Grin
Logged

Då®k][Wîzå®d™
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #3 on: April 22, 2007, 11:12:57 AM »

is it possible to add a !save comand , as you can add hubs ok but when restarting scripts or hub reboot the new hub is lost .
Logged
Cêñoßy†ê
Developer
Newbie
*
Offline Offline

Posts: 4


View Profile
« Reply #4 on: April 22, 2007, 05:57:22 PM »

Try this one Wink
Code:
--[[
HubJumper
LUA 5.1.x
A redirect-self script
By CrazyGuy
On request by Då®k][Wîzå®d™
Last updated April 8th 2007
* Saves addresses to own file (04/22/07), Cêñoßy†ê
]]--
Logged
CrazyGuy
Administrator
Sr. Member
*****
Offline Offline

Posts: 254



View Profile WWW
« Reply #5 on: April 22, 2007, 11:36:24 PM »

Great work CenoByte  Grin
Logged

Då®k][Wîzå®d™
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #6 on: April 29, 2007, 01:17:17 PM »

Hmmm maybe its me but it doesnt seem to be saving to anywhere , sorry i just got round to trying it , i added another addy and after i restart scripts the last added hub is no longer there?
Logged
CrazyGuy
Administrator
Sr. Member
*****
Offline Offline

Posts: 254



View Profile WWW
« Reply #7 on: April 30, 2007, 12:30:22 PM »

Looking at CenoBytes script, he was almost there but forgot something eventually  Grin
The functions to save a file are there, but no command or OnTimer / OnExit that uses them  Tongue
Also, I don''t see something that loads the tables on startup
Logged

Cêñoßy†ê
Developer
Newbie
*
Offline Offline

Posts: 4


View Profile
« Reply #8 on: May 04, 2007, 01:18:01 PM »

Looking at CenoBytes script, he was almost there but forgot something eventually  Grin
The functions to save a file are there, but no command or OnTimer / OnExit that uses them  Tongue
Also, I don''''t see something that loads the tables on startup

Whups.. my bad.. heres new one Wink

Code:
HubJumper
LUA 5.1.x
A redirect-self script
By CrazyGuy
On request by Då®k][Wîzå®d™
Last updated April 8th 2007
* Saves addresses to own file (04/22/07), Cêñoßy†ê
* Changed Permission table  (05/04/07), Cêñoßy†ê
* Fixed file saving when restarting script  (05/04/07), Cêñoßy†ê
Logged
Då®k][Wîzå®d™
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #9 on: May 07, 2007, 09:09:04 AM »

Thx guys it works gr8 now , here we go again  Wink

is it possible first off

to have all hubs shown on the RC''s so that a user only has to right click , see the list of hubs and click the on they want instead of copy & paste ?

second

i know you have done this script exactly as i have asked

but it it also possible to use the RC''s to redirect self and also stay in the main hub running the redirect script ?

either way thx for all your hard work  Grin
Logged
CrazyGuy
Administrator
Sr. Member
*****
Offline Offline

Posts: 254



View Profile WWW
« Reply #10 on: May 28, 2007, 12:10:40 PM »

Thx guys it works gr8 now , here we go again  Wink

is it possible first off

to have all hubs shown on the RC''s so that a user only has to right click , see the list of hubs and click the on they want instead of copy & paste ?

second

i know you have done this script exactly as i have asked

but it it also possible to use the RC''s to redirect self and also stay in the main hub running the redirect script ?

either way thx for all your hard work  Grin


While testing, I haven't found a working way to have a user stay in the current hub AND open a new hub window with the new hub from the redirect tables.
But, I have added that hub addresses will be send to UserCommands so they are simply clickable.
Everytime a hub is added or deleted from the table however, all UserCommands have to be resend to all users by the script.
It works, but it might cause quite some data flow in a big hub when the rd table is big as well
Anyways, here's the script

Code:
--[[
HubJumper
LUA 5.1.x
A redirect-self script
By CrazyGuy
On request by Då®k][Wîzå®d™
Last updated April 8th 2007
* Saves addresses to own file (04/22/07), Cêñoßy†ê
* Changed Permission table  (05/04/07), Cêñoßy†ê
* Fixed file saving when restarting script  (05/04/07), Cêñoßy†ê
]]--

sBotname = "Hub-Jumper"
sFile = "Redirect.tbl"

cmdAddHub = "addhub"
cmdDelHub = "delhub"
cmdShowHubs = "showhubs"
cmdHelp = "redirhelp"
cmdRD = "jump"

tRDHubs = {}
local f,e = io.open(sFile, "a+" ) if f then f:write("" ) f:close() end

tPermissions = {
[0] = {
["add_del"] = 1, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 0,
},
[1] = {
["add_del"] = 1, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 1,
},
[2] = {
["add_del"] = 1, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 1,
},
[3] = {
["add_del"] = 0, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 1,
},
[4] = {
["add_del"] = 0, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 1,
},
[5] = {
["add_del"] = 1, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 0,
},
[-1] = {
["add_del"] = 0, -- use 1 for allowed, 0 for not allowed
["show"] = 1,
["rd"] = 1,
},
}

tCMD = {
[cmdHelp] = function(sNick,iProf,sArg)
local sHelp = "Available commands:\n\n\t\t!"..cmdHelp.."\t\t\t-Shows this help file\n"
if tPermissions[iProf].add_del == 1 then
sHelp = sHelp.."\n\t\t!"..cmdAddHub.." <address:port>\t-Add a hub to the list\n"
.."\t\t!"..cmdDelHub.." <address:port>\t-Delete a hub from the list\n"
end
if tPermissions[iProf].show == 1 then
sHelp = sHelp.."\n\t\t!"..cmdShowHubs.."\t\t-Shows all hubs in the list\n"
end
if tPermissions[iProf].rd == 1 then
sHelp = sHelp.."\n\t\t!"..cmdRD.." <address:port>\t-Redirect yourself to the specified hub\n"
end
return sHelp
end,
[cmdRD] = function(sNick,iProf,sArg)
if sArg then
if tPermissions[iProf].rd == 1 then
return 1
else
return "You are not allowed to use this command"
end
else
return "Please specify an address -> !"..cmdRD.." <address:port>"
end
end,
[cmdShowHubs] = function(sNick,iProf,sArg)
if tPermissions[iProf].show == 1 then
local sHubs = "Current hubs to redirect to:\n\n"
for k in pairs(tRDHubs) do
sHubs = sHubs.."\t\t"..tRDHubs[k].."\n"
end
return sHubs
else
return "You are not allowed to use this command"
end
end,
[cmdAddHub] = function(sNick,iProf,sArg)
if sArg then -- if address is specified
if tPermissions[iProf].add_del == 1 then
table.insert(tRDHubs,sArg) -- add hub
SaveToFile(sFile,tRDHubs,"tRDHubs")
local tAllUsers = frmHub:GetOnlineUsers()
for _,k in pairs(tAllUsers) do
SendUserCommands(k.sName)
end
return sArg.." has been added to the list"
else
return "You are not allowed to use this command"
end
else
return "Please specify an address -> !"..cmdAddHub.." <address:port>"
end
end,
[cmdDelHub] = function(sNick,iProf,sArg)
if sArg then
if tPermissions[iProf].add_del == 1 then
for k in pairs(tRDHubs) do
if tRDHubs[k] == sArg then
table.remove(tRDHubs, k) -- remove hub
SaveToFile(sFile,tRDHubs,"tRDHubs")
break
end
end
local tAllUsers = frmHub:GetOnlineUsers()
for _,k in pairs(tAllUsers) do
SendUserCommands(k.sName)
end
return sArg.." has been removed from the list"
else
return "You are not allowed to use this command"
end
else
return "Please specify an address -> !"..cmdDelHub.." <address:port>"
end
end,
}

Main = function()
dofile(sFile)
frmHub:RegBot(sBotname)
end

OnExit = function()
SaveToFile(sFile,tRDHubs,"tRDHubs")
end

ChatArrival = function(User,Data)
local _,_,cmd,sArgs = string.find(Data, "%b<>%s%p(%S+)%s(.*)|")
if sArgs then
if tCMD[cmd] then
local sReturn = tCMD[cmd](User.sName,User.iProfile,sArgs)
if sReturn == 1 then
-- user will be redirected
User:SendData(sBotname, "You will now be redirected to "..sArgs)
User:Redirect(sArgs, "You have choosen to be redirected to this hub. Enjoy your stay there")
else
-- return the message
User:SendData(sBotname,sReturn)
end
return 1
end
else
-- no arguments, could be show or help command
local _,_,sCmd = string.find(Data, "%b<>%s%p(%S+)|")
if tCMD[sCmd] then
User:SendData(sBotname, tCMD[sCmd](User.sName,User.iProfile,nil))
return 1
end
end
end

ToArrival = function(User,Data)
local _,_,cmd,sArgs = string.find(Data, "%b<>%s%p(%S+)%s(.*)|")
if sArgs then
if tCMD[cmd] then
local sReturn = tCMD[cmd](User.sName,User.iProfile,sArgs)
if sReturn == 1 then
-- user will be redirected
User:SendPM(sBotname, "You will now be redirected to "..sArgs)
User:Redirect(sArgs, "You have choosen to be redirected to this hub. Enjoy your stay there")
else
-- return the message
User:SendData(sBotname,sReturn)
end
return 1
end
else
-- no arguments, could be show or help command
local _,_,sCmd = string.find(Data, "%b<>%s%p(%S+)|")
if tCMD[sCmd] then
User:SendPM(sBotname, tCMD[sCmd](User.sName,User.iProfile,nil))
return 1
end
end
end

NewUserConnected = function(User)
SendUserCommands(User.sName)
end
OpConnected = NewUserConnected

SendUserCommands = function(sNick)
local sMenu = frmHub:GetHubName()
local User = GetItemByName(sNick)
User:SendData("$UserCommand 255 9|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Help$<%[mynick]> !"..cmdHelp.."&#124;|")
if tPermissions[User.iProfile].add_del == 1 then
User:SendData("$UserCommand 0 3 &#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Add Hub$<%[mynick]> !"..cmdAddHub.." %[line:Address]&#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Delete Hub$<%[mynick]> !"..cmdDelHub.." %[line:Address]&#124;|")
end
if tPermissions[User.iProfile].show == 1 then
User:SendData("$UserCommand 0 3 &#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Show Hubs$<%[mynick]> !"..cmdShowHubs.."&#124;|")
end
if tPermissions[User.iProfile].rd == 1 then
User:SendData("$UserCommand 0 3 &#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Redirect Self$<%[mynick]> !"..cmdRD.." %[line:Address]&#124;|")
for k in pairs(tRDHubs) do
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Redirect Self to "..tRDHubs[k].."$<%[mynick]> !"..cmdRD.." "..tRDHubs[k].."&#124;|")
end
end
end

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or ""
hFile:write(sTab..sTableName.." = {\n")
for key,value in pairs(tTable) do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t")
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
hFile:write(sTab.."\t"..sKey.." = "..sValue)
end
hFile:write(",\n")
end
end
hFile:write(sTab.."}")
end

SaveToFile = function(file, table, tablename)
local handle = io.open(file,"w")
Serialize(table,tablename,handle)
    handle:close()
end

Greetz, CG ;-)
Logged

Då®k][Wîzå®d™
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #11 on: June 08, 2007, 04:33:02 PM »

nice1 CG  Wink
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!