local CHAT_HISTORY = 50
local LastMessageID = 0
local JavaScript = [[
]]
local ChatLogMessages = {}
function AddMessage( PlayerName, Message )
LastMessageID = LastMessageID + 1
table.insert( ChatLogMessages, { name = PlayerName, message = Message, id = LastMessageID } )
while( #ChatLogMessages > CHAT_HISTORY ) do
table.remove( ChatLogMessages, 1 )
end
end
function OnChat( Player, Message )
AddMessage( Player:GetName(), Message )
end
function HandleRequest_Chat( Request )
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
if( value.id > LastIdx ) then
Content = Content .. "[" .. value.name .. "]: " .. value.message .. "
"
end
end
Content = Content .. "<>" .. LastMessageID .. "<>" .. LastIdx
return Content
end
if( Request.PostParams["ChatMessage"] ~= nil ) then
if( Request.PostParams["ChatMessage"] == "/help" ) then
Commands = "Available commands"
AddMessage(Commands, "
" .. "/help, /reload" )
return Commands
elseif( Request.PostParams["ChatMessage"] == "/reload" ) then
Server = cRoot:Get():GetServer()
Server:SendMessage( cChatColor.Green .. "Reloading all plugins." )
AddMessage("Reloading all plugins", "")
cRoot:Get():GetPluginManager():ReloadPlugins()
return ""
else
cmd = Request.PostParams["ChatMessage"]
if string.sub(cmd,1,string.len("/")) == "/" then
AddMessage('Unknown Command "' .. Request.PostParams["ChatMessage"] .. '"', "")
return ""
end
end
local Message = "[WebAdmin]: " .. Request.PostParams["ChatMessage"]
cRoot:Get():GetServer():SendMessage( Message )
AddMessage("WebAdmin", Request.PostParams["ChatMessage"] )
return ""
end
local Content = JavaScript
Content = Content .. [[
]]
return Content
end