Server scripts
 

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

Server scripts

Started by ?StIfFLEr??, 30 October, 2008, 16:07:55

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

?StIfFLEr??

--[[
This is a sample script base dupon my HTML parser
It grabs the content of a specified HTML file
and displays it in given intervals or on-demand.
Requested by achiever.
 
Distributed under a modified BSD license, see at the end of the file]]
 
-- Settings.
 
Timer = 0 -- Set to 0 to disable, otherwise specify the interval in minutes.
 
Command = "servers" -- The command for getting the serverinfo. NO prefix!
 
Filename = "D:/gigabyte limits/0.4.0.0/scripts/servers" -- We need full path with FORWARD slashes: c:/path/to/html
 
-- End of settings, only edit below if you know what you are doing.
 
function OnStartup()
  if Timer ~= 0 then
    local x = Core.SendToAll("<"..SetMan.GetString(21)..">\r\n"..HTML_ToText (Filename))
    TmrMan.AddTimer(Timer*60000, "x")
  end
end
 
function ChatArrival (user, data)
  local cmd = string.match (data, "^%b<>%s+[%+%!%-%?%?](%S+)%|$")
  if cmd == Command then
    Core.SendToUser(user,"<"..SetMan.GetString(21)..">\r\n"..HTML_ToText (Filename))
    return 1
  end
end
 
-- function OnTimer()
--   SendToAll(frmHub:GetHubBotName(),"\r\n"..HTML_ToText (Filename))
-- end
 
function HTML_ToText (file)
  -- Declare variables, load the file. Make tags lowercase.
  local nl = "\r\n"
  local text
  local f,err=io.open (file)
  if f then
    text = f:read ("*a")
    f:close()
  else
    Core.SendToOps ("*** "..err)
    return
  end
  text = string.gsub (text,"(%b<>)",
  function (tag)
    return tag:lower()
  end)
  --[[ 
  First we kill the developer formatting (tabs, CR, LF)
  and produce a long string with no newlines and tabs.
  We also kill repeated spaces as browsers ignore them anyway.
  ]]
  local devkill=
    {
      ["("..string.char(10)..")"] = " ",
      ["("..string.char(13)..")"] = " ",
      ["("..string.char(15)..")"] = "",
      ["(%s%s+)"]=" ",
    }
  for pat, res in pairs (devkill) do
    text = string.gsub (text, pat, res)
  end
  -- Then we remove the header. We do this by stripping it first.
  text = string.gsub (text, "(<%s*head[^>]*>)", "<head>")
  text = string.gsub (text, "(<%s*%/%s*head%s*>)", "</head>")
  text = string.gsub (text, "(<head>,*<%/head>)", "")
  -- Kill all scripts. First we nuke their attribs.
  text = string.gsub (text, "(<%s*script[^>]*>)", "<script>")
  text = string.gsub (text, "(<%s*%/%s*script%s*>)", "</script>")
  text = string.gsub (text, "(<script>,*<%/script>)", "")
  -- Ok, same for styles.
  text = string.gsub (text, "(<%s*style[^>]*>)", "<style>")
  text = string.gsub (text, "(<%s*%/%s*style%s*>)", "</style>")
  text = string.gsub (text, "(<style>.*<%/style>)", "")
  
  -- Replace <td> and <th> with tabulators.
  text = string.gsub (text, "(<%s*td[^>]*>)","\t")
  text = string.gsub (text, "(<%s*th[^>]*>)","\t")
  
  -- Replace <br> with linebreaks.
  text = string.gsub (text, "(<%s*br%s*%/%s*>)",nl)
  
  -- Replace <li> with an asterisk surrounded by spaces.
  -- Replace </li> with a newline.
  text = string.gsub (text, "(<%s*li%s*%s*>)"," *  ")
  text = string.gsub (text, "(<%s*/%s*li%s*%s*>)",nl)
  
  -- <p>, <div>, <tr>, <ul> will be replaced to a double newline.
  text = string.gsub (text, "(<%s*div[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*p[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*tr[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*%/*%s*ul[^>]*>)", nl..nl)
    
  -- Some petting with the <a> tags. :-P
--[[   local addresses = {}
  local c = 0
  for url,name in string.gfind (text, "<%s*a%s*href=[\'\"](%S-)[\'\"][^>]*>(.+)<%s*%/a%s*>") do
    c = c + 1
    string.gsub (name, "<%s*a%s*href=[^>]+>(.+)<%s*%/a[^>]*>",
    function (nm)
      nm = string.gsub (nm, "(%b<>)","")
      nm = nm.."["..c.."]"
      return nm
    end)
    table.insert (addresses, {url, name})
    print(url, nm)
  end ]]
  
  -- Nuke all other tags now.
  text = string.gsub (text, "(%b<>)","")
  
  -- Replace entities to their correspondant stuff where applicable.
  -- C# is owned badly here by using a table. :-P
  -- A metatable secures entities, so you can add them natively as keys.
  -- Enclosing brackets also get added automatically (capture!)
  local entities = {}
  setmetatable (entities,
  {
    __newindex = function (tbl, key, value)
      key = string.gsub (key, "(%#)" , "%%#")
      key = string.gsub (key, "(%&)" , "%%&")
      key = string.gsub (key, "(%;)" , "%%;")
      key = string.gsub (key, "(.+)" , "("..key..")")
      rawset (tbl, key, value)
    end
  })
  entities = 
  {
    ["&nbsp;"] = " ",
    ["&bull;"] = " *  ",
    ["&lsaquo;"] = "<",
    ["&rsaquo;"] = ">",
    ["&trade;"] = "(tm)",
    ["&frasl;"] = "/",
    ["&lt;"] = "<",
    ["&gt;"] = ">",
    ["&copy;"] = "(c)",
    ["&reg;"] = "(r)",
    -- Then kill all others.
    -- You can customize this table if you would like to, 
    -- I just got bored of copypasting. :-)
    -- http://hotwired.lycos.com/webmonkey/reference/special_characters/
    ["%&.+%;"] = "",
  }
  for entity, repl in pairs (entities) do
    text = string.gsub (text, entity, repl)
  end
--   text = text..nl..nl..("-"):rep(27)..nl..nl
--   
--   for k,v in ipairs (addresses) do
--     text = text.."["..k.."] "..v[1]..nl
--   end
  
  return text
  
end
 
 
--[[
Copyright (c) 2007, bastya_elvtars
 
All rights reserved.
 
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
 
    * Redistributions of source code must retain the above copyright notice, this
      list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of contributors may be used
      to endorse or promote products derived from this code without specific
      prior written permission.
 
THIS CODE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]

--Server Board
--
-- Provides common message board. Allow users to read/write the board by profiles
-- Option to delete messages, permission bt profile
-- Caches board messages to exteernal text file for script/hub restarts
--
--	+Changes from v 1.00
--		+Added  case sensitive commands, request by NeoUltimicia
--		+Added  date/time to message, request by NeoUltimicia
--		+Errors now sent to PM as well as main
--		+Corrected save string and tweaked table read
--	+Changes from v 1.01
--		+converted to LUA 5 - by blackwings
--		+these prefixes can be used = !+?$# - by blackwings
--	+Changes from v 1.02
--		+fixed a load file bug - by blackwings
--	+Changes from v 1.03
--		+fixed file handling bug
--		+fixed left over lua4 parts
--		-removed VaildCmd stuff
--		+changed MsgBoard function to ToArrival
--		+fixed Prefix error
--		+added auto detect if bot has hubbotname
--		+fixed some minor bugs
--		+added support for mainchat
--		+fixed extra linespacing
--		^ Moded by Madman ^
--	?To Do
--		?Allow users to delete their own messages
--		?Add context menu
--
--User Settings-------------------------------------------------------------------------------------
Comm1 = string.lower("servers")			-- Script Command, read board
Comm2 = string.lower("addserver")			-- Script Command, write to board
Comm3 = string.lower("delserver")			-- Script Command, delete messages
MaxMessages = 50		-- Max number of messages to cache
MsgBoardFile = "Serverboard.txt"	-- Message file, creat this file in your scripts dir.
rprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1}  	-- Which profiles may read the board?
wprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1}  	-- Which profiles may write to the board?
dprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1} 	-- Which profiles may delete messages?
Hub = frmHub:GetHubName()	-- Hub name, pulled from the Px
Bot = "[SECURITY?]"	-- Botname, use frmHub:GetHubBotName() or "BotName"
--End User Settings----------------------------------------------------------------------------------
BoardMessages = {}

function Main()
	LoadFromFile(MsgBoardFile)
	if not (Bot == frmHub:GetHubBotName()) then
		frmHub:RegBot(Bot)
	end
end

function ToArrival(user,data)
	local s,e,whoTo = string.find(data, "%$To:%s(%S+)")
	if whoTo == Bot then
		  return MsgBoard(user, data)
	end
end

function ChatArrival(user, data)
	return MsgBoard(user, data)
end

function MsgBoard(user, data)
	local data = string.sub(data,1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%$%#](%S+)")
	if cmd then
		s,e,Prefix = string.find(data, "%b<>%s+(%p)%S+")
		local tCmds = {
			[Comm1] = function(user, data)
				if rprofiles[user.iProfile]==1 then
					ReadBoard(user) 
				end
			end,
			[Comm2] = function(user, data)
				if wprofiles[user.iProfile]==1 then
					local s,e,msg = string.find(data, "%b<>%s+%S+%s(.*)")
					if msg == nil then
						local dsp
						dsp = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
						dsp = dsp.."\t"..Hub.."\tMessage Board\r\n"
						dsp = dsp.."\tDid you forget what you were going to say?\r\n"
						dsp = dsp.."\tCommand syntax is ->> "..Prefix..Comm2.." <your message>\r\n"
						dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
						user:SendData(Bot,dsp)
						SendPmToNick(user.sName,Bot,dsp)
						return 1
					else
						Write2Board(user, msg)
						
					end
				end
			end,
			[Comm3] = function(user, data)
				if dprofiles[user.iProfile]==1 then
					local s,e,delmsg = string.find(data, "%b<>%s+%S+%s+(%d+)")
					if (delmsg == nil) then
						local dsp0
						dsp0 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
						dsp0 = dsp0.."\t"..Hub.."\tMessage Board\r\n"
						dsp0 = dsp0.."\tDelete which message? Provide message number\r\n"
						dsp0 = dsp0.."\tCommand syntax is ->> "..Prefix..Comm3.." <msg #>\r\n"
						dsp0 = dsp0.."\tType ->> "..Prefix..Comm1.."  to list messages \r\n"
						dsp0 = dsp0.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
						user:SendData(Bot,dsp0)
						SendPmToNick(user.sName,Bot,dsp0)
						return 1
					else
						--if BoardMessages[delmsg] ~= 1 then user:SendData(Bot,dsp0) return 1 end
						table.remove(BoardMessages, delmsg)
						SaveToFile(MsgBoardFile , BoardMessages , "BoardMessages")
						user:SendData(Bot,"Server [ "..delmsg.." ] has been deleted.")
						
						return 0
					end
				end
			end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](user, data)
		end
	end
end

function ReadBoard(user)
	local n = table.getn(BoardMessages)
	local dsp1
	dsp1 = ""
	dsp1 = dsp1.."Servers:-"
	dsp1 = dsp1.."\n"
		for i = 1, n do
			dsp1 = dsp1.."[ "..i.." ]\t"..BoardMessages[i].."\r\n"
		end
		SendToAll(Bot, dsp1)
end


function Write2Board(user, msg)
	local dsp2
	dsp2 = ""
	dsp2 = dsp2.." "..user.sName.."'s Server added."
	dsp2 = dsp2..""
	dsp2 = dsp2.."Type "..Prefix..Comm1.." in main."
	dsp2 = dsp2.."\t"
	SendToAll(Bot, dsp2)
	table.insert(BoardMessages, (""..os.date("%B %d %Y %X ").." [ "..user.sName.."'s ] Server: ")..msg)
		if table.getn(BoardMessages) > MaxMessages then table.remove(BoardMessages, 1) end
		SaveToFile(MsgBoardFile , BoardMessages , "BoardMessages")
	end

function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

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

function LoadFromFile(file)
	local handle = io.open(file,"r")
	if (handle ~= nil) then
		dofile(file)
		handle:flush()
		handle:close()
	end
end

these two are server scripts tat we use to detect servers on lan automatically generated html file by agsm software
and the other one is the add server script which the users usually add the server can these both scripts be merged and with a right clik to detect servers and add lan server it would b great!!!!


?StIfFLEr??

and also can it be converted to new api??

?StIfFLEr??

plz can some 1 merge these two scripts.....
its an urgent request

?StIfFLEr??

Bustya here are the two scripts would be pleased if you can have a look at it.

?StIfFLEr??

Actually it was something that i got from one of my friend.
Anyways i just added the script so as to show it as an example.
I never believed in removing the credit of the maker.May be the person who actually used it did.
Anyways mutor it would be nice if you could help.

?StIfFLEr??

Mutor i can understand your feelings i am sorry on his behalf.
Well as far as i know he does not exist on hub anymore.
but i tried to convert ur messageboard script which actually worked to save the server ip address added by users and its working fine with the other server script.
I haven't forgot to write your name in that script.
Quote--Server Board
-- Orginal script By Mutor
-- Changes made to server board and converted by ?StIfFLEr??

Psycho_Chihuahua

Besides, Bastya already mentioned his disinterest in that script as you can read in this post --> http://forum.ptokax.org/index.php?topic=7900.msg76321#msg76321
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

?StIfFLEr??

Thanks for that i at least tried on my own something and combined both the scripts.
I think this forum will have no replies from my side as a request.  :P
Thanks for to the help --- to everyone who posted so far.

SMF spam blocked by CleanTalk