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
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