Write txt files in Robocop
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Write txt files in Robocop

Started by Dj_OcTaGoN, 12 October, 2004, 19:25:49

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dj_OcTaGoN

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


Dj_OcTaGoN

#1
Ok thanks! It?s great!

Cool that u can add scripts as well!

cheers // Dj_OcTaGoN


Herodes

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

enema

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???

Dj_OcTaGoN

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


nErBoS

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
--## nErBoS Spot ##--

Dj_OcTaGoN

#6
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


Herodes

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

Dj_OcTaGoN

#8
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


Dj_OcTaGoN

#9
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


Herodes

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 .. .

Dj_OcTaGoN

Ok, dunno what happened...but nErBoS script is working in the other hub as well now!

cheers // Dj_OcTaGoN


Dj_OcTaGoN

#12
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


Herodes

#13
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

Dj_OcTaGoN

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


Herodes

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 .. :)

Dj_OcTaGoN

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


Herodes

if the script fails to initiate it is bound not to send anything as it is not initiated (running) ....

SMF spam blocked by CleanTalk