PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Dj_OcTaGoN on 12 October, 2004, 19:25:49

Title: Write txt files in Robocop
Post by: Dj_OcTaGoN on 12 October, 2004, 19:25:49
Howdy!

I wonder if there is a way to give Master an "write to textfile" function so he/she could change the network/rules/faq etc textfiles which follows with Robocop.
The hubowner is 90% away from the hub and havent got time to update these files with hubadresses etc...

Kick me in my arse if i missed an obvious similar thread....

cheers // Dj_OcTaGoN
Title:
Post by: Dj_OcTaGoN on 12 October, 2004, 20:41:48
Ok thanks! It?s great!

Cool that u can add scripts as well!

cheers // Dj_OcTaGoN
Title:
Post by: Herodes on 13 October, 2004, 01:53:19
Hello ... this ver can also make and delete folders ..
-- save string
-- by chill
-- Great script chill ....thx

-- Minor Mods by Mutor
-- Added Right Click Menu
-- Added help
--
--- touched by Herodes 6 / 8 - 2004
--- secured all the folders apart from 'scripts' folder of PtokaX
--- added folder operations ... (create / delete ) 7 / 8 - 2004
--
-- +save filename text
-- e.g. +save txt/textfile.txt text
--
-- +load filename
-- +del filename
-- +list dir
-- +edhelp
--
--
aprof = 0 -- for only masters
secure = "on"  --- change to anything else to be able to access any folder any where on the pc its running on...
thisfile = "texteditor.lua" --- !! SECURITY WARNING !! --- BE SURE TO PUT THE FILENAME OF THIS SCRIPT HERE (replace between the quotes ex: "filename.lua" )
--

function NewUserConnected(curUser)
if curUser.iProfile == aprof then
customCMDS(curUser)
curUser:SendData(" *** Notice :: Right click hub tab for editor commands. ***")
else
return
end
end

OpConnected = NewUserConnected

--$UserCommand 1 X  Where -> 1=Hub Menu 2=User Menu 3=Hub/User Menu
function customCMDS(curUser)
--curUser:SendData("$UserCommand 255 7") --clear the menu first
curUser:SendData("$UserCommand 1 1 [Editor]\\List Dir $<%[mynick]> +list %[line:Folder]||")
curUser:SendData("$UserCommand 1 1 [Editor]\\Read File $<%[mynick]> +load %[line:Path/Filename]||")
curUser:SendData("$UserCommand 1 1 [Editor]\\Save File $<%[mynick]> +save %[line:Path/Filename] %[line:Text]||")
curUser:SendData("$UserCommand 1 1 [Editor]\\Delete File $<%[mynick]> +del %[line:Path/Filename]||")
curUser:SendData("$UserCommand 1 1 [Editor]\\Create Dir $<%[mynick]> +dirdo %[line:Name of Folder]||")
curUser:SendData("$UserCommand 1 1 [Editor]\\Delete Dir $<%[mynick]> +dirdel %[line:Name of Folder]||")
curUser:SendData("$UserCommand 1 1 [Editor]\\Editor Help $<%[mynick]> +edhelp .||")
end

function DataArrival(curUser,data)
if (strsub(data,1,1) == "<") and (curUser.iProfile == aprof) then
local _,_,cmd,fileordir = strfind(data,"^%b<>%s+(%S+)%s+([^|^ ]+)")
if fileordir ~= "" and fileordir ~= nil then
if strfind(fileordir, thisfile) and secure == "on" then
curUser:SendData(curUser.sName, "Sorry I can't allow you to access this file ...")
return 1
else
if cmd == "+save" then
local _,_,sdata = strfind(data,"^%b<>%s+%S+%s+%S+%s+(.*)|$")
if sdata then
SaveFile(fileordir,sdata)
SendPM(curUser,"Saved data to: "..fileordir)
end
return 1
elseif cmd == "+load" then
local sdata = LoadFile(fileordir)
SendPM(curUser,"File Loaded: "..fileordir..",\r\n"..sdata)
return 1
elseif cmd == "+del" then
DelFile(fileordir)
SendPM(curUser,"Deleted File: "..fileordir)
return 1
elseif cmd == "+list" then
if strfind(fileordir, "/%.%.") and secure == "on" then
curUser:SendData(curUser.sName, "You cant access this folder I am afraid ... sorry")
return 1
else
local dir = ListDir(fileordir)
SendPM(curUser,dir)
return 1
end
elseif( strfind(data, "+edhelp" ,1))  then
hmsg = "\r\n"
hmsg = hmsg.."\r\n\t--<>----------------------------------------------------------------------------<>--"
hmsg = hmsg.."\r\n\t\t\t [ Editor Help ]"
hmsg = hmsg.."\r\n\t--<>----------------------------------------------------------------------------<>--"
hmsg = hmsg.."\r\n\t+save \t=\tSave to file\t-> 'path/filename' 'text'"
hmsg = hmsg.."\r\n\t+load \t=\tLoad a file\t-> 'path/filename'"
hmsg = hmsg.."\r\n\t+del \t=\tDelete file\t\t-> 'path/filename'"
hmsg = hmsg.."\r\n\t+list \t=\tList folder\t\t-> 'path' [/ = scripts dir]"
hmsg = hmsg.."\r\n\t+dirdo\t=\tCreate folder\t-> 'foldername'"
hmsg = hmsg.."\r\n\t+dirdel\t=\tDelete folder\t-> 'foldername'"
hmsg = hmsg.."\r\n\t+edhelp \t=\tShow help"
hmsg = hmsg.."\r\n\t--<>----------------------------------------------------------------------------<>--"
SendPM(curUser,hmsg)
return 1
elseif cmd == "!banip" then
local ip = fileordir
local handle = openfile("ipban/"..date("%d%m%Y").."-ipban.txt","a")
write(handle,date("%d/%m/%Y-%H:%M:%S")..", Banner: "..curUser.sName..", Banned IP: "..ip.."\n")
closefile(handle)
elseif cmd == "+dirdo" then
execute("mkdir "..fileordir)
SendPM(curUser,"Created Folder: "..fileordir)
return 1
elseif cmd == "+dirdel" then
if strfind(fileordir, "/%.%.") and secure == "on" then
curUser:SendData(curUser.sName, "You cant delete this folder ... sorry")
return 1
else
execute("rmdir "..fileordir)
SendPM(curUser,"Deleted Folder: "..fileordir)
return 1
end
end
end
end
end
end

function SendPM(curUser,data)
curUser:SendPM(curUser.sName,data)
end


function SaveFile(filename,sdata)
local handle = openfile(filename,"w")
write(handle,sdata)
closefile(handle)
end

function LoadFile(filename)
local handle = openfile(filename,"r")
local sdata = ""
if handle then
sdata = read(handle,"*a")
sdata = gsub(sdata,"|",strchar(166))
sdata = gsub(sdata,"\n","\r\n")
closefile(handle)
end
return sdata
end

function DelFile(filename)
remove(filename)
end

function ListDir(dir)
if (dir == "/") or (dir == "dir") then
dir = ""
end
--execute("dir \""..dir.."\" /a-d /b > dirlist.txt") --Show Directories in bare format
--execute("dir \""..dir.."\" /b > dirlist.txt") --Bare Format
--execute("dir \""..dir.."\" /a-d > dirlist.txt") --Show Directories
execute("dir \""..dir.."\" /o:gn > dirlist.txt") --Show Directories first then files , by name
local sdata = LoadFile("dirlist.txt")
DelFile("dirlist.txt")
return("\r\n"..sdata)
end
Title: Hey!!
Post by: enema on 13 October, 2004, 06:57:48
This little thing gives a lot of opportunities. I wonder, why didnt I ask for this myself. Is there a script for MOTD change when owner is not around???
Title:
Post by: Dj_OcTaGoN on 13 October, 2004, 10:04:41
I found that the script Mutor posted didnt work properly, the second posted Herodes did work well but the right-click function doesnt work..
 (Yes, i have "Accept custom user commands from hub" ticked  :D )

cheers // Dj_OcTaGoN
Title:
Post by: nErBoS on 13 October, 2004, 11:45:49
Hi,

Fixed the right click commands....

-- save string
-- by chill
-- Great script chill ....thx

-- Minor Mods by Mutor
-- Added Right Click Menu
-- Added help
--
--- touched by Herodes 6 / 8 - 2004
--- secured all the folders apart from 'scripts' folder of PtokaX
--- added folder operations ... (create / delete ) 7 / 8 - 2004
--
-- +save filename text
-- e.g. +save txt/textfile.txt text
--
-- +load filename
-- +del filename
-- +list dir
-- +edhelp
--
--
aprof = 0 -- for only masters
secure = "on"  --- change to anything else to be able to access any folder any where on the pc its running on...
thisfile = "texteditor.lua" --- !! SECURITY WARNING !! --- BE SURE TO PUT THE FILENAME OF THIS SCRIPT HERE (replace between the quotes ex: "filename.lua" )
--

function NewUserConnected(curUser)
if curUser.iProfile == aprof then
customCMDS(curUser)
curUser:SendData(" *** Notice :: Right click hub tab for editor commands. ***")
else
return
end
end

OpConnected = NewUserConnected

--$UserCommand 1 X  Where -> 1=Hub Menu 2=User Menu 3=Hub/User Menu
function customCMDS(curUser)
--curUser:SendData("$UserCommand 255 7") --clear the menu first
curUser:SendData("$UserCommand 1 3 [Editor]\\List Dir $<%[mynick]> +list %[line:Folder]||")
curUser:SendData("$UserCommand 1 3 [Editor]\\Read File $<%[mynick]> +load %[line:Path/Filename]||")
curUser:SendData("$UserCommand 1 3 [Editor]\\Save File $<%[mynick]> +save %[line:Path/Filename] %[line:Text]||")
curUser:SendData("$UserCommand 1 3 [Editor]\\Delete File $<%[mynick]> +del %[line:Path/Filename]||")
curUser:SendData("$UserCommand 1 3 [Editor]\\Create Dir $<%[mynick]> +dirdo %[line:Name of Folder]||")
curUser:SendData("$UserCommand 1 3 [Editor]\\Delete Dir $<%[mynick]> +dirdel %[line:Name of Folder]||")
curUser:SendData("$UserCommand 1 3 [Editor]\\Editor Help $<%[mynick]> +edhelp .||")
end

function DataArrival(curUser,data)
if (strsub(data,1,1) == "<") and (curUser.iProfile == aprof) then
local _,_,cmd,fileordir = strfind(data,"^%b<>%s+(%S+)%s+([^|^ ]+)")
if fileordir ~= "" and fileordir ~= nil then
if strfind(fileordir, thisfile) and secure == "on" then
curUser:SendData(curUser.sName, "Sorry I can't allow you to access this file ...")
return 1
else
if cmd == "+save" then
local _,_,sdata = strfind(data,"^%b<>%s+%S+%s+%S+%s+(.*)|$")
if sdata then
SaveFile(fileordir,sdata)
SendPM(curUser,"Saved data to: "..fileordir)
end
return 1
elseif cmd == "+load" then
local sdata = LoadFile(fileordir)
SendPM(curUser,"File Loaded: "..fileordir..",\r\n"..sdata)
return 1
elseif cmd == "+del" then
DelFile(fileordir)
SendPM(curUser,"Deleted File: "..fileordir)
return 1
elseif cmd == "+list" then
if strfind(fileordir, "/%.%.") and secure == "on" then
curUser:SendData(curUser.sName, "You cant access this folder I am afraid ... sorry")
return 1
else
local dir = ListDir(fileordir)
SendPM(curUser,dir)
return 1
end
elseif( strfind(data, "+edhelp" ,1))  then
hmsg = "\r\n"
hmsg = hmsg.."\r\n\t--<>----------------------------------------------------------------------------<>--"
hmsg = hmsg.."\r\n\t\t\t [ Editor Help ]"
hmsg = hmsg.."\r\n\t--<>----------------------------------------------------------------------------<>--"
hmsg = hmsg.."\r\n\t+save \t=\tSave to file\t-> 'path/filename' 'text'"
hmsg = hmsg.."\r\n\t+load \t=\tLoad a file\t-> 'path/filename'"
hmsg = hmsg.."\r\n\t+del \t=\tDelete file\t\t-> 'path/filename'"
hmsg = hmsg.."\r\n\t+list \t=\tList folder\t\t-> 'path' [/ = scripts dir]"
hmsg = hmsg.."\r\n\t+dirdo\t=\tCreate folder\t-> 'foldername'"
hmsg = hmsg.."\r\n\t+dirdel\t=\tDelete folder\t-> 'foldername'"
hmsg = hmsg.."\r\n\t+edhelp \t=\tShow help"
hmsg = hmsg.."\r\n\t--<>----------------------------------------------------------------------------<>--"
SendPM(curUser,hmsg)
return 1
elseif cmd == "!banip" then
local ip = fileordir
local handle = openfile("ipban/"..date("%d%m%Y").."-ipban.txt","a")
write(handle,date("%d/%m/%Y-%H:%M:%S")..", Banner: "..curUser.sName..", Banned IP: "..ip.."\n")
closefile(handle)
elseif cmd == "+dirdo" then
execute("mkdir "..fileordir)
SendPM(curUser,"Created Folder: "..fileordir)
return 1
elseif cmd == "+dirdel" then
if strfind(fileordir, "/%.%.") and secure == "on" then
curUser:SendData(curUser.sName, "You cant delete this folder ... sorry")
return 1
else
execute("rmdir "..fileordir)
SendPM(curUser,"Deleted Folder: "..fileordir)
return 1
end
end
end
end
end
end

function SendPM(curUser,data)
curUser:SendPM(curUser.sName,data)
end


function SaveFile(filename,sdata)
local handle = openfile(filename,"w")
write(handle,sdata)
closefile(handle)
end

function LoadFile(filename)
local handle = openfile(filename,"r")
local sdata = ""
if handle then
sdata = read(handle,"*a")
sdata = gsub(sdata,"|",strchar(166))
sdata = gsub(sdata,"\n","\r\n")
closefile(handle)
end
return sdata
end

function DelFile(filename)
remove(filename)
end

function ListDir(dir)
if (dir == "/") or (dir == "dir") then
dir = ""
end
--execute("dir \""..dir.."\" /a-d /b > dirlist.txt") --Show Directories in bare format
--execute("dir \""..dir.."\" /b > dirlist.txt") --Bare Format
--execute("dir \""..dir.."\" /a-d > dirlist.txt") --Show Directories
execute("dir \""..dir.."\" /o:gn > dirlist.txt") --Show Directories first then files , by name
local sdata = LoadFile("dirlist.txt")
DelFile("dirlist.txt")
return("\r\n"..sdata)
end

Best regards, nErBoS
Title:
Post by: Dj_OcTaGoN on 13 October, 2004, 23:12:36
hey,

yeah i tried it, i might have done something wrong, there were no errors but nothing worked, no cmds, no right-click.
Well I think its good that u can delete files, but of course, there is a risk that u do somehing which u didnt want to do...
But for me its no problem, I trust those who got access to this script and made clear where and what the Master are allowed to change/add/delete (only .lua and .txt files)
Guess it?s good there are 2 mods of this script, one for more access and one for limited access

cheers // Dj_OcTaGoN
Title:
Post by: Herodes on 13 October, 2004, 23:16:42
QuoteOriginally posted by Dj_OcTaGoN
Guess it?s good there are 2 mods of this script, one for more access and one for limited access
I am pretty sure that can be done to work from a single script ...lets give it some time .. it might appear  ;)
heh
Title:
Post by: Dj_OcTaGoN on 13 October, 2004, 23:51:56
Hmm...i changed to nErBoS updated version...now i cant find anything when trying to use the cmds in another hub running the updated script or see any right-click menu (It shows up in Main as text), in my own hub the script works perfect as well as the right-click.. :D

This is what i got when trying use "+list /" in the other hub:
Volume in drive C has no label.
 Volume Serial Number is xxxx-xxxx

 Directory of C:\
This when logging in:
[00:08]  # Use !help in main for your commands!
[00:08] $UserCommand 1 3 [Editor]\List Dir $<%[mynick]> +list %[line:Folder]||
[00:08] $UserCommand 1 3 [Editor]\Read File $<%[mynick]> +load %[line:Path/Filename]||
[00:08] $UserCommand 1 3 [Editor]\Save File $<%[mynick]> +save %[line:Path/Filename] %[line:Text]||
[00:08] $UserCommand 1 3 [Editor]\Delete File $<%[mynick]> +del %[line:Path/Filename]||
[00:08] $UserCommand 1 3 [Editor]\Create Dir $<%[mynick]> +dirdo %[line:Name of Folder]||
[00:08] $UserCommand 1 3 [Editor]\Delete Dir $<%[mynick]> +dirdel %[line:Name of Folder]||
[00:08] $UserCommand 1 3 [Editor]\Editor Help $<%[mynick]> +edhelp .||
[00:08]  *** Notice :: Right click hub tab for editor commands. ***
cheers // Dj_OcTaGoN
Title:
Post by: Dj_OcTaGoN on 14 October, 2004, 10:19:27
Yeah i got profile 0 in the other hub, the only difference in Profiles between my own hub and the other one is that i have OP/MOD/MASTER/NETFOUNDER in my hub, only OP/Master in the other one.

Btw Mutor your version is working now, both right-click and sending cmds (though im not sure it works in the other hub...havent got the hubowner to replace the "update" I did lol).

Just one thing, having +save cmd in right-click arent very usefull, u whont be able to save more than one textline, and THIS can make u replace the content of a whole textfile into one line of text. Or is there a way to get around this?

cheers // Dj_OcTaGoN
Title:
Post by: Herodes on 14 October, 2004, 11:19:43
QuoteOriginally posted by Dj_OcTaGoN
Just one thing, having +save cmd in right-click arent very usefull, u whont be able to save more than one textline, and THIS can make u replace the content of a whole textfile into one line of text. Or is there a way to get around this?
There should be a way arround it .. but I dont like its looks .. and I havent tried ... at the end of a line put a " | " ...

otherwise i agree it should be in the menu .. .
Title: yeeeeee
Post by: Dj_OcTaGoN on 14 October, 2004, 15:42:02
Ok, dunno what happened...but nErBoS script is working in the other hub as well now!

cheers // Dj_OcTaGoN
Title:
Post by: Dj_OcTaGoN on 17 October, 2004, 12:52:09
Is there a way to recieve syntax status from hub (get the syntaxstatus from hub into PM at demand)? If i add a script to a hub i want to know if there are any errors.
thanx in advance

cheers // Dj_OcTaGoN
Title:
Post by: Herodes on 18 October, 2004, 12:22:36
yeah there u go ...
put this in any script ...
--- tezlo's script ...

nicktosend = "Herodes"

report = _ALERT
_ALERT = function(str)
local err = "- - - - - - - - - - - - - error - - - - - - - - - - - - -\r\n"..str.."\r\n- - - - - - - - - - - - - error - - - - - - - - - - - - -"
SendToNick(nicktosend, err)
report(str)
end
Title:
Post by: Dj_OcTaGoN on 19 October, 2004, 14:44:40
Ok, I?ve tried it without any success, guess im doing it all wrong..
Do I need to put the code in every script I want to get the syntaxstatus from? And it would be great with a trigger I think, like "!getstatus".
thx in advance

cheers // Dj_OcTaGoN
Title:
Post by: Herodes on 19 October, 2004, 18:20:17
uhm when there is an error you should know it as soon as it happens ...

so "no-news-is-good-news"

and dont expect to get any error reports if everything works .. :)
Title:
Post by: Dj_OcTaGoN on 19 October, 2004, 19:12:12
Thats the weird thing, i tried it in my own hub (added a script which i knew had a syntax error) but no PM from hub when typing !restartscripts
:D
Title:
Post by: Herodes on 19 October, 2004, 23:15:21
if the script fails to initiate it is bound not to send anything as it is not initiated (running) ....