Server Board : HELP NEEDED
 

Server Board : HELP NEEDED

Started by patrick, 04 January, 2009, 16:22:58

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

patrick

--Server Board 1.03	10/20/04 LUA 5
--converted to LUA 5 - 09/15/05
--by Mutor
--
-- 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 = frmHub:GetHubBotName()	-- 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

?StIfFLEr??

I am eagerly waiting for mutor to give you a very nice reply  :P
Hope you understand how the forum works soon.
Type or paste your code inside the [ code ]   [ /code ] option please.

?StIfFLEr??

Quote--Server Board 1.03   10/20/04 LUA 5
--converted to LUA 5 - 09/15/05
--by Patrick
LOL
its mutors script u noob patrick dont asct as if you can do anything i am sure one more "-" will be comming by mutor
What say mutor I think some one just took all the credits i hope you will do the needfull.
Well anyways i have the converted version of this script but it wont be posted (untill mutor gives me the permission.)

patrick

Sorry Mutor Did Not Want To Take Your Credits
I edited it in the script in the ptokax and forgot to change it
I apologise if u misunderstood it  :'(
DID NOT REALLY WANTED TO TAKE YOUR CREDIT

So The Script Goes Like Below

patrick

SORRY Mutor IF U MISUDERSTOOD ME

bastya_elvtars

If you really want Mutor to forgive, please attach the file to the fist post by editing and remove that huge code snippet. :)
Everything could have been anything else and it would have just as much meaning.

?StIfFLEr??

But i am still waiting for mutors reply.
Eagarly waiting for his dictionary to be open.  :P
I hope this time i will be learning some more new words from him.
Please mutor do post to this forum atleast once.I would love if this Patricks gets some good bash from you.He has troubled me a lot.  :P

Yahoo

forgive me guys
but please remove this noob from the forum
he is taking credit for mutors scripts
we dont want such cheaters and liers on this board
"BoRN FIGhTEr"

patrick

Yahoo i said i did not want to take the credits.. and i also apologised for that...
so noo need to take this matter more further !!!

bastya_elvtars

Quote from: patrick on 11 January, 2009, 08:30:52
Yahoo i said i did not want to take the credits.. and i also apologised for that...
so noo need to take this matter more further !!!

Agreed. Are we going to stop this, or must I wipe all irrelevant posts from here?
Everything could have been anything else and it would have just as much meaning.

Yahoo

i will also love to have this script
"BoRN FIGhTEr"

Yahoo

"BoRN FIGhTEr"

SMF spam blocked by CleanTalk