summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-22 02:35:06 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-22 02:35:06 +0200
commitb5c4994475fccfddc111b44cc4b60f3c069be4e7 (patch)
tree4ebb01d19e8a20098624ec62ef51ed179858b88b
parentNow it's possible to only show the plugin's WebAdmin content without the template around it by going to /~webadmin/ instead of /webadmin/ (diff)
downloadcuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.tar
cuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.tar.gz
cuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.tar.bz2
cuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.tar.lz
cuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.tar.xz
cuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.tar.zst
cuberite-b5c4994475fccfddc111b44cc4b60f3c069be4e7.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/Core/main.lua2
-rw-r--r--MCServer/Plugins/Core/web_chat.lua110
2 files changed, 112 insertions, 0 deletions
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 = [[
+<script type="text/javascript">
+ function createXHR()
+ {
+ var request = false;
+ try {
+ request = new ActiveXObject('Msxml2.XMLHTTP');
+ }
+ catch (err2) {
+ try {
+ request = new ActiveXObject('Microsoft.XMLHTTP');
+ }
+ catch (err3) {
+ try {
+ request = new XMLHttpRequest();
+ }
+ catch (err1)
+ {
+ request = false;
+ }
+ }
+ }
+ return request;
+ }
+
+ function loadWholePage( url )
+ {
+ var storage = document.getElementById('ChatDiv');
+ var xhr = createXHR();
+ xhr.onreadystatechange=function()
+ {
+ if(xhr.readyState == 4)
+ {
+ //alert( xhr.status + " " + xhr.statusText );
+ //if(xhr.status == 200)
+ {
+ storage.innerHTML = xhr.responseText;//getBody(xhr.responseText);
+ storage.scrollTop = storage.scrollHeight;
+ }
+ }
+ };
+ xhr.open("GET", url , true);
+ xhr.send(null);
+
+ return false;
+ }
+
+ function SendChatMessage()
+ {
+ var MessageContainer = document.getElementById('ChatMessage');
+ if( MessageContainer.value == "" ) return;
+
+ var xhr = createXHR();
+ xhr.onreadystatechange=function()
+ {
+ if(xhr.readyState == 4)
+ {
+ //alert( xhr.status + " " + xhr.statusText );
+ RefreshChat();
+ }
+ };
+ xhr.open("GET", "/~webadmin/Core/Chat/?ChatMessage=" + MessageContainer.value, true);
+ xhr.send(null);
+ MessageContainer.value = "";
+ }
+
+ function RefreshChat()
+ {
+ loadWholePage('/~webadmin/Core/Chat/?JustChat=true');
+ }
+
+ setInterval(RefreshChat, 1000);
+ window.onload = RefreshChat;
+
+ </script>
+]]
+
+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 .. "<br>"
+ 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 .. [[
+ <div style="font-family: Courier; border: 1px solid #DDD; padding: 10px; width: 97%; height: 200px; overflow: scroll;" id="ChatDiv">Chat messageessss</div>
+ <input type="text" id="ChatMessage" onKeyPress="if (event.keyCode == 13) { SendChatMessage(); }"><input type="submit" value="Submit" onClick="SendChatMessage();">
+ ]]
+ return Content
+end \ No newline at end of file