From e086b931ea7ab329a1142ec26c008cdb22fb065c Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 22 Aug 2012 11:22:26 +0000 Subject: Chat history limit on the WebAdmin chat Did some refactoring on the JavaScript side of the WebAdmin chat Got rid of cRoot::sRootState Fixed a crash on the WebAdmin when a page is loaded before a world exists git-svn-id: http://mc-server.googlecode.com/svn/trunk@775 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- MCServer/Plugins/Core/web_chat.lua | 132 ++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 62 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/Core/web_chat.lua b/MCServer/Plugins/Core/web_chat.lua index 66fe994eb..c8b5ded59 100644 --- a/MCServer/Plugins/Core/web_chat.lua +++ b/MCServer/Plugins/Core/web_chat.lua @@ -1,84 +1,91 @@ +local CHAT_HISTORY = 50 + local JavaScript = [[ - + OpenPage( "/~webadmin/Core/Chat/?ChatMessage=" + MessageContainer.value, function( xhr ) + { + RefreshChat(); + } ); + MessageContainer.value = ""; + } + + function RefreshChat() + { + LoadPageInto('/~webadmin/Core/Chat/?JustChat=true', document.getElementById('ChatDiv')); + } + + setInterval(RefreshChat, 1000); + window.onload = RefreshChat; + + ]] local ChatLogMessages = {} function AddMessage( PlayerName, Message ) table.insert( ChatLogMessages, { name = PlayerName, message = Message } ) + while( #ChatLogMessages > CHAT_HISTORY ) do + table.remove( ChatLogMessages, 1 ) + end end function OnChat( Player, Message ) @@ -95,6 +102,7 @@ function HandleRequest_Chat( Request ) end if( Request.Params["ChatMessage"] ~= nil ) then + LOG("Chat msg: " .. Request.Params["ChatMessage"] ) local Message = "[WebAdmin]: " .. Request.Params["ChatMessage"] cRoot:Get():GetServer():SendMessage( Message ) AddMessage("WebAdmin", Request.Params["ChatMessage"] ) -- cgit v1.2.3