HUB side LUA string loader for Ptokax...
 

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

HUB side LUA string loader for Ptokax...

Started by UwV, 22 January, 2007, 17:14:17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

UwV

As a previeuw on my "soon to be released" client script...
--[[--
         UwV jan. 2007
         HUB  side LUA string loader for Ptokax .
         On PM  Arrival from clients who's nicks are set in preset table,
          checks if string begins with :  LUACODE  and ends with LUACODE  (end is to see if script got a 'full pm")
          and then (per request) optionally for preset IP adress(es)
          if all required criteria are met it will  then strip the "tags" from the data and try execute the remaining string.
          i am simply using it to update values  from a clientside script to a serverside script for updating  contextmenu items..
          but it can be used for executing any lua code to you liking basicly
   --]]--
tMyTab = {}
-----------------------------------------------------------------------------------------
-- LOCAL HUB setting
--  edit as you like
tMyTab._sMenuTitle = "{-= ReleaseBot =-}" --  main menu,  nil to disable

-- REMOTE CLIENT script server related settings ..
tMyTab._sRelBot = "-=Holly-Book=-"              -- multi release client

-------------------------------------------------------------------------------------------------------------------------------------------------------
tMyTab._iAutoRefesh  = 1
-- these next values are automaticly updated by hollybook client script. if the value above is set to 1 so basicly,.. no need to touch em ..
-- but we do need em on script boot.. (or if you want to disable the auto updating by setting the value  to nil )
-- tMyTab._iAutoRefesh  = 0 -- will set it to  send a message to hollybbok client that lest it know not to send updated context menu values.

tMasters = {["master1"] = 1,}							--- or as set by clientside script
tEditors = {["editor1"] = 1, ["editor2"] = 1,}		-- "	"	" 
tContrib = {["Contributor1"] = 1, }			 -- "	"	" 
tTypes 	= {["name"] = 1, ["name2"] = 1,}			-- "	"	" 

sHelpCmd = "hollyhelp"							-- "	"	" 
sWritCmd = "write"									-- "	"	" 
sNwrlCmd = "rels"									-- "	"	" 
sReadCmd = "hollyread"							-- "	"	" 
sShowCmd = "hollyshow"						-- "	"	" 
sDelRelCmd = "hollydel"							-- "	"	" 
sFindCmd = "hollyfind"								-- "	"	" 
sEdtrCmd = "hollyeditor"							--- "	"	" 
sContCmd = "hollywriter"							-- "	"	" 
sReportCmd = "hollyreport"						-- "	"	" 
sStatCmd = "hollystats"							-- "	"	" 
sCredCmd = "hollycredits"						-- "	"	" 
sSpamCmd = "hollyspam"						-- "	"	" 
sVerifyCmd = "hollypass"							-- "	"	" 
sStyleCmd = "hollystyle"							-- "	"	" 
sAdminCmd = "hollyset"							-- "	"	" 
sPrefPre = "!"											-- "	"	" 
iMaxNew = 34											-- "	"	" 

------------------------------
-- end of all settings
-- script start editing below this line completely on own risk ;0)
------------------------------

sWriteCmds, sReadCmds = "", ""
sMasterCmds, sEditorCmds =  "" , ""
sContribCmds, sVIPCmds, sRegCmds =  "" , "", ""
sScriptName, sMyRevision = "hollybook_3.14", "_rev.17b"

function RefeshMenu()
	local sFullMenu = tMyTab._sMenuTitle..""..tMyTab._sRelBot.." ("..sScriptName..sMyRevision..")\\"
	local tTemp = {}

	for i,v in pairs( tTypes) do
		table.insert(tTemp, i )
	end
	table.sort( tTemp, function (a,b) return (string.lower(a) < string.lower(b)) end)

	local sLevel = "$UserCommand 1 3 "..sFullMenu.."[LEVEL] Menu for [USERNAME] \\"
	local sFromTo = "$$To: "..tMyTab._sRelBot.." From: %[mynick] $<%[mynick]> "..sPrefPre

	local sRead = sLevel.."Read\\"
	for i,v in pairs(tTemp) do
		sReadCmds = sReadCmds..sRead..v.." "..sFromTo..sReadCmd.." "..v.."&#124;|"
	end
	local sWrite = sLevel.."Write\\"
	for i,v in pairs( tTemp ) do
		sWriteCmds = sWriteCmds..sWrite..v.." "..sFromTo..sWritCmd.." "..v.." %[line:What to Write ?]&#124;|"
	end

	sRegCmds = "$UserCommand 0 3|"..
		sLevel.."ReleaseBot Help "..sFromTo..sHelpCmd.."&#124;|"

	sVIPCmds =  "$UserCommand 0 3|"..
		sLevel.."Get Last "..iMaxNew.." Releases "..sFromTo..sNwrlCmd.."&#124;|"..
		sLevel.."Extra \\Show Current Stats "..sFromTo..sStatCmd.."&#124;|"..
		sLevel.."Extra \\Show Credits "..sFromTo..sCredCmd.."&#124;|"

	sContribCmds = "$UserCommand 0 3|"..
		sLevel.."Find Releases "..sFromTo..sFindCmd.." %[line: <Arg1> (Arg2)]&#124;|"..
		sLevel.."Delete Release "..sFromTo..sDelRelCmd.." %[line:What  ID nr to Delete ?]&#124;|"

	sEditorCmds =  "$UserCommand 0 3|"..
		sLevel.."Extra \\Show Full stats Report "..sFromTo..sReportCmd.."&#124;|"..
		sLevel.."Extra \\Show ALL releases\\Click me if you dare ;) "..sFromTo..sShowCmd .."&#124;|"..
		sLevel.."Settings  \\Add/Del/Show Contributors "..sFromTo..sContCmd.." %[line: <add/del/show> (nick) ]&#124;|"..
		sLevel.."Verify Your Identity "..sFromTo..sVerifyCmd.." %[line: Your Password  ?,. please? ]&#124;|"

	sMasterCmds = "$UserCommand 0 3|"..
		sLevel.."Settings \\Add/Del/Show Editors "..sFromTo..sEdtrCmd.." %[line: <add/del/show]> (nick) ]&#124;|"..
		sLevel.."Settings \\Change/Show Settings "..sFromTo..sAdminCmd.." %[line: <show/setting/copy> (towhat/copywhat)&#124;|"..
		sLevel.."Settings \\Add/Del/Show/Merge Styles "..sFromTo..sStyleCmd.." %[line: <add/del/merge/show/help> (trig) (trig2/style) (style)&#124;|"..
		sLevel.."And guess what ??? ,... \\Click me if you dare ;) "..sFromTo..sSpamCmd.."&#124;|"

		collectgarbage("collect")
		io.flush()
end

function Main()
	if tMyTab._sMenuTitle then tMyTab._sMenuTitle = tMyTab._sMenuTitle.."\\" else tMyTab._sMenuTitle = "" end
	sFullMenu = tMyTab._sMenuTitle..""..tMyTab._sRelBot
	RefeshMenu()
end
	

function OpConnected(curUser) -- For all operators
	local sUserName = curUser.sName
	if sUserName == tMyTab._sRelBot and not tMyTab._iAutoRefesh then
		SendPmToNick(sUserName, sUserName, sPrefPre.."this_hub_no_menu")
	end
	local sProfileName = "Contributor"
	local sData = sRegCmds..sReadCmds..sWriteCmds..sContribCmds..sVIPCmds
	if tMasters[sUserName] then
		sProfileName = "Master"
		sData = sData..sEditorCmds..sMasterCmds
	elseif tEditors[sUserName] then
		sProfileName = "Editor"
		sData = sData..sEditorCmds
	else
		if tContrib[sUserName] then
			 sData = sData.."$UserCommand 1 3 "..sFullMenu.."[LEVEL] Menu for [USERNAME] \\Verify $$To: "..tMyTab._sRelBot.." From: %[mynick] $<%[mynick]> "..sPrefPre..sVerifyCmd.." %[line: Your Password  ?,. please? ]&#124;|"
		end
	end
	sData = string.gsub(sData, "%[USERNAME%]", sUserName)
	sData = string.gsub(sData, "%[LEVEL%]", sProfileName)
	sData = sData.. "$UserCommand 0 3"
	curUser:SendData(sData)
	collectgarbage("collect")
	io.flush()
end

function NewUserConnected(curUser)
	if tContrib[curUser.sNick] then
		OpConnected(curUser)   -- Treat as op
	elseif curUser.iProfile ~= -1 then -- All other regs send help and latest releases commands
		local sData = "$UserCommand 0 3|"..sRegCmds
		if curUser.iProfile == 2 then -- For VIP's Only send all styles in read contextmenu..
			sData = sRegCmds..sVIPCmds..sReadCmds
		end
		sData = string.gsub(sData, "%[USERNAME%]", curUser.sName)
		sData = string.gsub(sData, "%[LEVEL%]", frmHub:GetProfileName(curUser.iProfile))
		sData = sData.."$UserCommand 0 3 "
		curUser:SendData(sData)
	end
end


if tMyTab._iAutoRefesh then
	--[[--
			UwV jan. 2007
			-------------------     HUB  side LUA string loader for Ptokax .                 --------------------------------
			On PM  Arrival from clients who's nicks are set in preset table,
			 checks if string begins with :  LUACODE  and ends with LUACODE  (end is to see if script got a 'full pm")
			 and then (per request) optionally for preset IP adress(es)
			 if all required criteria are met it will  then strip the "tags" from the data and try execute the remaining string.
			 i am simply using it to update values  from a clientside script to a serverside script for updating  contextmenu items..
			 but it can be used for executing any lua code to you liking basicly
			 and as long as your message is not to long for the hub antiflood settings. and under 64Kb  ;)
	--]]--
	--  Nicks
	setNicks = { ["uw\-testing\-holly"] =1, [tMyTab._sRelBot] = 1, }
	-- Limit to only ip's from table ? ( 1 = yes ,  nil  = no  )
	setNoOtherIPs = 1
	-- IP address(es) go in here if used.
	setIPs = { ["127.0.0.1"] = 1, ["192.168.10.10"] = 1  }

	ToArrival = function(User,Data)
		if setNicks[User.sName] then
			local s,e, sLUACODE = string.find(Data,  "LUACODE(.+)LUACODE")
			if sLUACODE then
				SendPmToNick(User.sName, frmHub:GetHubBotName(), "RECIEVING LUACODE " )
				if setNoOtherIPs and not setIPs[User.sIP] then
					OnError("N.B.   IP MISMATCH on LUA arrival from "..User.sName.."  - > "..User.sIP.."  is not known to  me." )
				else
					SendPmToNick(User.sName, frmHub:GetHubBotName(), "------  ---  --  LOADING  STRING !  -- --- -------"  )
					assert( loadstring(sLUACODE)) ()
					local sReply  =  "------  ---  --  ALL LOADED OK  \\o/  -- --- -------\r\n\r\n\tRefreshed Menu,...  log out, log in,.. to see the new thing."
					SendPmToNick(User.sName, frmHub:GetHubBotName(), sReply )
					RefeshMenu()
				end
				collectgarbage("collect")
				io.flush()
				return 1
			end
		end
	end
end

--errortracker-----------------------------------------------
tMyTab._ErrorsTo = {      -- table with nicks to get ErrorMsg
	[tMyTab._sRelBot] = 1,
	}
tMyTab._sErrorBotName = "-=Multi-Error=-"   -- duh..
---------------------------------- end of settings
OnError = function(ErrorMsg)
	for i, v in pairs( tMyTab._ErrorsTo) do
		SendPmToNick(v, tMyTab._sErrorBotName, ErrorMsg)
	end
end
--------------------------------------------------------------

\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

UwV

sending is done like ....
-- lets send data to our  PtokaX script to update the context menu values now :)
HB._fFormatCodeToSend = function()
	local sCode =  ""
	local tTempContrib, tTempEditors, tTempMasters = {},{},{}
	for i ,v in pairs(HB._tContrib) do
		tTempContrib[i] = "1"  -- add nick but not pass
		if HB._tEditors[i] then
			tTempEditors[i] = "1"  -- add nick but not pass
			if tMasters[i] then
				tTempMasters[i] = "1" -- add nick but not pass
			end
		end
	end
	sLUACODE = " tContrib = "..HB._fSimpleTableToLine( tTempContrib ).." tEditors = "..HB._fSimpleTableToLine( tTempEditors )..
	" tMasters = "..HB._fSimpleTableToLine( tTempMasters ).." tTypes = "..HB._fSimpleTableToLine( HB._tTypes )..
	" sHelpCmd = \""..sHelpCmd.."\" sWritCmd = \""..sWritCmd .."\" sNwrlCmd  = \""..sNwrlCmd.."\" sReadCmd = \""..sReadCmd.."\" "..
	" sShowCmd = \""..sShowCmd.."\" sDelRelCmd = \""..sDelRelCmd.."\" sFindCmd = \""..sFindCmd.."\" sEdtrCmd = \""..sEdtrCmd.."\" "..
	" sContCmd = \""..sContCmd.."\"  sReportCmd = \""..sReportCmd.."\" sStatCmd = \""..sStatCmd.."\"  sCredCmd = \""..sCredCmd.."\" "..
	" sSpamCmd = \""..sSpamCmd.."\" sVerifyCmd = \""..sVerifyCmd.."\" sStyleCmd  = \""..sStyleCmd.."\" sAdminCmd = \""..sAdminCmd.."\" "..
	" sPrefPre = \""..sPrefPre.."\" iMaxNew = \""..iMaxNew.."\" "
	return sLUACODE
end

HB._tSendNoMenu = {}
-- send  PM to self in all hubs where own nick is in table " tOwnNicks "
HB._fSendMenuDataToAll = function(sLines)
	for _,hub in pairs(SU.fGetHubs()) do
		local tNick = SU.fGetOwnNick(hub)
			if tOwnNicks[tNick] and not HB._tSendNoMenu[hub:getAddress()] then
			-- Send PM
			DC():SendHubMessage( SU.fGetHubID(hub), "$To: "..tNick.." From: "..tNick.." $<"..tNick.."> LUACODE "..sLines.." tMyTab._sSubMenu = \""..tNick.."\"  LUACODE|")
		end
	end
end

HB._fSimpleTableToLine = function(tTable)
	local tLine = ""
	for i,v in pairs(tTable) do
		tLine = tLine .." [\""..i.."\"] = \""..string.gsub(v, "\"", "\\\"").."\" ,"
	end
		tLine ="{ "..tLine .." }"
	return tLine
end


HB._fSendMenuDataToAll(HB._fFormatCodeToSend() )

(obviously this is not all,  i left out the rest of the script since it is irrelevant here.   this shows how and what ...
\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

SMF spam blocked by CleanTalk