summaryrefslogtreecommitdiffstats
path: root/MCServer
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-22 14:24:29 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-22 14:24:29 +0200
commit0da4f7eaa274e33065c5a9ec031af5d971112d66 (patch)
tree22321f1734ad8cc1d9a3a864e412f48a631d7184 /MCServer
parentChat history limit on the WebAdmin chat (diff)
downloadcuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.tar
cuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.tar.gz
cuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.tar.bz2
cuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.tar.lz
cuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.tar.xz
cuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.tar.zst
cuberite-0da4f7eaa274e33065c5a9ec031af5d971112d66.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/Core/web_chat.lua58
1 files changed, 40 insertions, 18 deletions
diff --git a/MCServer/Plugins/Core/web_chat.lua b/MCServer/Plugins/Core/web_chat.lua
index c8b5ded59..4ee679729 100644
--- a/MCServer/Plugins/Core/web_chat.lua
+++ b/MCServer/Plugins/Core/web_chat.lua
@@ -1,4 +1,5 @@
local CHAT_HISTORY = 50
+local LastMessageID = 0
local JavaScript = [[
<script type="text/javascript">
@@ -24,7 +25,7 @@ local JavaScript = [[
return request;
}
- function OpenPage( url, callback )
+ function OpenPage( url, postParams, callback )
{
var xhr = createXHR();
xhr.onreadystatechange=function()
@@ -34,25 +35,37 @@ local JavaScript = [[
callback( xhr )
}
};
- xhr.open("GET", url , true);
- xhr.send(null);
+ xhr.open( (postParams!=null)?"POST":"GET", url , true);
+ if( postParams != null )
+ {
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+ }
+ xhr.send(postParams);
}
- function LoadPageInto( url, storage )
+ function LoadPageInto( url, postParams, storage )
{
- OpenPage( url, function( xhr )
+ OpenPage( url, postParams, function( xhr )
{
var ScrollBottom = storage.scrollTop + storage.offsetHeight;
var bAutoScroll = (ScrollBottom >= storage.scrollHeight); // Detect whether we scrolled to the bottom of the div
- storage.innerHTML = xhr.responseText;
+ results = xhr.responseText.split("<<divider>>");
+ if( results[2] != LastMessageID ) return; // Check if this message was meant for us
- if( bAutoScroll == true )
+ LastMessageID = results[1];
+ if( results[0] != "" )
{
- storage.scrollTop = storage.scrollHeight;
+ storage.innerHTML += results[0];
+
+ if( bAutoScroll == true )
+ {
+ storage.scrollTop = storage.scrollHeight;
+ }
}
} );
+
return false;
}
@@ -61,7 +74,8 @@ local JavaScript = [[
var MessageContainer = document.getElementById('ChatMessage');
if( MessageContainer.value == "" ) return;
- OpenPage( "/~webadmin/Core/Chat/?ChatMessage=" + MessageContainer.value, function( xhr )
+ var postParams = "ChatMessage=" + MessageContainer.value;
+ OpenPage( "/~webadmin/Core/Chat/", postParams, function( xhr )
{
RefreshChat();
} );
@@ -70,19 +84,23 @@ local JavaScript = [[
function RefreshChat()
{
- LoadPageInto('/~webadmin/Core/Chat/?JustChat=true', document.getElementById('ChatDiv'));
+ var postParams = "JustChat=true&LastMessageID=" + LastMessageID;
+ LoadPageInto("/~webadmin/Core/Chat/", postParams, document.getElementById('ChatDiv'));
}
setInterval(RefreshChat, 1000);
window.onload = RefreshChat;
+ var LastMessageID = 0;
+
</script>
]]
local ChatLogMessages = {}
function AddMessage( PlayerName, Message )
- table.insert( ChatLogMessages, { name = PlayerName, message = Message } )
+ LastMessageID = LastMessageID + 1
+ table.insert( ChatLogMessages, { name = PlayerName, message = Message, id = LastMessageID } )
while( #ChatLogMessages > CHAT_HISTORY ) do
table.remove( ChatLogMessages, 1 )
end
@@ -93,25 +111,29 @@ function OnChat( Player, Message )
end
function HandleRequest_Chat( Request )
- if( Request.Params["JustChat"] ~= nil ) then
+ if( Request.PostParams["JustChat"] ~= nil ) then
+ local LastIdx = 0
+ if( Request.PostParams["LastMessageID"] ~= nil ) then LastIdx = tonumber( Request.PostParams["LastMessageID"] ) end
local Content = ""
for key, value in pairs(ChatLogMessages) do
- Content = Content .. "[" .. value.name .. "]: " .. value.message .. "<br>"
+ if( value.id > LastIdx ) then
+ Content = Content .. "[" .. value.name .. "]: " .. value.message .. "<br>"
+ end
end
+ Content = Content .. "<<divider>>" .. LastMessageID .. "<<divider>>" .. LastIdx
return Content
end
- if( Request.Params["ChatMessage"] ~= nil ) then
- LOG("Chat msg: " .. Request.Params["ChatMessage"] )
- local Message = "[WebAdmin]: " .. Request.Params["ChatMessage"]
+ if( Request.PostParams["ChatMessage"] ~= nil ) then
+ local Message = "[WebAdmin]: " .. Request.PostParams["ChatMessage"]
cRoot:Get():GetServer():SendMessage( Message )
- AddMessage("WebAdmin", Request.Params["ChatMessage"] )
+ AddMessage("WebAdmin", Request.PostParams["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>
+ <div style="font-family: Courier; border: 1px solid #DDD; padding: 10px; width: 97%; height: 200px; overflow: scroll;" id="ChatDiv"></div>
<input type="text" id="ChatMessage" onKeyPress="if (event.keyCode == 13) { SendChatMessage(); }"><input type="submit" value="Submit" onClick="SendChatMessage();">
]]
return Content