From b5c4994475fccfddc111b44cc4b60f3c069be4e7 Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 22 Aug 2012 00:35:06 +0000 Subject: Web chat for the WebAdmin :D git-svn-id: http://mc-server.googlecode.com/svn/trunk@773 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- MCServer/Plugins/Core/main.lua | 2 + MCServer/Plugins/Core/web_chat.lua | 110 +++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 MCServer/Plugins/Core/web_chat.lua diff --git a/MCServer/Plugins/Core/main.lua b/MCServer/Plugins/Core/main.lua index 803600431..9aed80ab1 100644 --- a/MCServer/Plugins/Core/main.lua +++ b/MCServer/Plugins/Core/main.lua @@ -22,6 +22,7 @@ function Initialize( Plugin ) PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_DIG) PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLED) PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE) + PluginManager:AddHook(Plugin, cPluginManager.E_PLUGIN_CHAT) -- used in web_chat.lua Plugin:AddCommand("/help", " - [Page] Show this message", "core.help") Plugin:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist") @@ -137,6 +138,7 @@ function Initialize( Plugin ) local WebPlugin = Plugin:CreateWebPlugin() WebPlugin:SetName( Plugin:GetName() ) WebPlugin:AddTab( "Server Settings", HandleRequest_ServerSettings ) + WebPlugin:AddTab( "Chat", HandleRequest_Chat ) WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList ) WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList ) WebPlugin:AddTab( "Permissions", HandleRequest_Permissions ) diff --git a/MCServer/Plugins/Core/web_chat.lua b/MCServer/Plugins/Core/web_chat.lua new file mode 100644 index 000000000..66fe994eb --- /dev/null +++ b/MCServer/Plugins/Core/web_chat.lua @@ -0,0 +1,110 @@ +local JavaScript = [[ + +]] + +local ChatLogMessages = {} + +function AddMessage( PlayerName, Message ) + table.insert( ChatLogMessages, { name = PlayerName, message = Message } ) +end + +function OnChat( Player, Message ) + AddMessage( Player:GetName(), Message ) +end + +function HandleRequest_Chat( Request ) + if( Request.Params["JustChat"] ~= nil ) then + local Content = "" + for key, value in pairs(ChatLogMessages) do + Content = Content .. "[" .. value.name .. "]: " .. value.message .. "
" + end + return Content + end + + if( Request.Params["ChatMessage"] ~= nil ) then + local Message = "[WebAdmin]: " .. Request.Params["ChatMessage"] + cRoot:Get():GetServer():SendMessage( Message ) + AddMessage("WebAdmin", Request.Params["ChatMessage"] ) + return "" + end + + local Content = JavaScript + Content = Content .. [[ +
Chat messageessss
+ + ]] + return Content +end \ No newline at end of file -- cgit v1.2.3