2013-01-18 23:39:11 +01:00
|
|
|
UUID = nil
|
2012-08-22 10:09:46 +02:00
|
|
|
HOST = 'otclient.herokuapp.com'
|
|
|
|
PORT = 80
|
2013-01-18 23:39:11 +01:00
|
|
|
FIRST_REPORT_DELAY = 15
|
2012-08-23 17:18:23 +02:00
|
|
|
REPORT_DELAY = 60
|
|
|
|
|
|
|
|
sendReportEvent = nil
|
2013-01-18 23:39:11 +01:00
|
|
|
firstReportEvent = nil
|
2012-08-23 03:50:03 +02:00
|
|
|
|
|
|
|
function initUUID()
|
2014-04-01 05:27:33 +02:00
|
|
|
UUID = g_settings:getString('report-uuid')
|
2012-08-23 03:50:03 +02:00
|
|
|
if not UUID or #UUID ~= 36 then
|
|
|
|
UUID = g_crypt.genUUID()
|
2014-04-01 05:27:33 +02:00
|
|
|
g_settings:set('report-uuid', UUID)
|
2012-08-23 03:50:03 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-22 10:51:31 +02:00
|
|
|
|
|
|
|
function init()
|
2012-08-23 17:18:23 +02:00
|
|
|
connect(g_game, { onGameStart = onGameStart,
|
|
|
|
onGameEnd = onGameEnd })
|
2012-08-22 10:51:31 +02:00
|
|
|
|
2012-08-23 03:50:03 +02:00
|
|
|
initUUID()
|
2012-08-22 10:51:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
2012-08-23 17:18:23 +02:00
|
|
|
disconnect(g_game, { onGameStart = onGameStart,
|
|
|
|
onGameEnd = onGameEnd })
|
2013-02-18 17:16:22 +01:00
|
|
|
removeEvent(firstReportEvent)
|
|
|
|
removeEvent(sendReportEvent)
|
2012-08-22 10:51:31 +02:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function configure(host, port, delay)
|
|
|
|
if not host then return end
|
|
|
|
HOST = host
|
|
|
|
PORT = port or PORT
|
|
|
|
REPORT_DELAY = delay or REPORT_DELAY
|
|
|
|
end
|
|
|
|
|
2012-08-23 03:50:03 +02:00
|
|
|
function sendReport()
|
2013-01-18 23:39:11 +01:00
|
|
|
if not HOST then return end
|
2012-08-23 17:18:23 +02:00
|
|
|
local protocolHttp = ProtocolHttp.create()
|
|
|
|
protocolHttp.onConnect = onConnect
|
|
|
|
protocolHttp.onRecv = onRecv
|
|
|
|
protocolHttp.onError = onError
|
2012-08-22 10:51:31 +02:00
|
|
|
protocolHttp:connect(HOST, PORT)
|
|
|
|
end
|
|
|
|
|
|
|
|
function onGameStart()
|
2013-01-18 23:39:11 +01:00
|
|
|
if not HOST then return end
|
2013-02-18 17:16:22 +01:00
|
|
|
removeEvent(firstReportEvent)
|
|
|
|
removeEvent(sendReportEvent)
|
2013-01-18 23:39:11 +01:00
|
|
|
firstReportEvent = addEvent(sendReport, FIRST_REPORT_DELAY*1000)
|
2012-08-23 17:18:23 +02:00
|
|
|
sendReportEvent = cycleEvent(sendReport, REPORT_DELAY*1000)
|
|
|
|
end
|
|
|
|
|
|
|
|
function onGameEnd()
|
2013-01-18 23:39:11 +01:00
|
|
|
removeEvent(firstReportEvent)
|
2013-02-18 17:16:22 +01:00
|
|
|
removeEvent(sendReportEvent)
|
2012-08-22 10:51:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onConnect(protocol)
|
|
|
|
if not g_game.isOnline() then
|
|
|
|
protocol:disconnect()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local post = ''
|
2012-08-23 03:50:03 +02:00
|
|
|
post = post .. 'uid=' .. UUID
|
2012-08-24 19:16:30 +02:00
|
|
|
post = post .. '&report_delay=' .. REPORT_DELAY
|
|
|
|
post = post .. '&os=' .. g_app.getOs()
|
2012-08-22 10:51:31 +02:00
|
|
|
post = post .. '&graphics_vendor=' .. g_graphics.getVendor()
|
|
|
|
post = post .. '&graphics_renderer=' .. g_graphics.getRenderer()
|
|
|
|
post = post .. '&graphics_version=' .. g_graphics.getVersion()
|
|
|
|
post = post .. '&painter_engine=' .. g_graphics.getPainterEngine()
|
|
|
|
post = post .. '&fps=' .. g_app.getBackgroundPaneFps()
|
|
|
|
post = post .. '&max_fps=' .. g_app.getBackgroundPaneMaxFps()
|
2012-08-23 03:50:03 +02:00
|
|
|
post = post .. '&fullscreen=' .. tostring(g_window.isFullscreen())
|
2012-08-22 10:51:31 +02:00
|
|
|
post = post .. '&window_width=' .. g_window.getWidth()
|
|
|
|
post = post .. '&window_height=' .. g_window.getHeight()
|
2013-01-18 23:39:11 +01:00
|
|
|
post = post .. '&player_name=' .. g_game.getCharacterName()
|
2012-08-24 19:16:30 +02:00
|
|
|
post = post .. '&world_name=' .. g_game.getWorldName()
|
2014-01-06 22:02:45 +01:00
|
|
|
post = post .. '&otserv_host=' .. G.host
|
|
|
|
post = post .. '&otserv_port=' .. G.port
|
|
|
|
post = post .. '&otserv_protocol=' .. g_game.getProtocolVersion()
|
|
|
|
post = post .. '&otserv_client=' .. g_game.getClientVersion()
|
2012-08-22 10:51:31 +02:00
|
|
|
post = post .. '&build_version=' .. g_app.getVersion()
|
|
|
|
post = post .. '&build_revision=' .. g_app.getBuildRevision()
|
|
|
|
post = post .. '&build_commit=' .. g_app.getBuildCommit()
|
|
|
|
post = post .. '&build_date=' .. g_app.getBuildDate()
|
|
|
|
post = post .. '&display_width=' .. g_window.getDisplayWidth()
|
|
|
|
post = post .. '&display_height=' .. g_window.getDisplayHeight()
|
2013-01-18 23:39:11 +01:00
|
|
|
post = post .. '&cpu=' .. g_platform.getCPUName()
|
|
|
|
post = post .. '&mem=' .. g_platform.getTotalSystemMemory()
|
|
|
|
post = post .. '&os_name=' .. g_platform.getOSName()
|
2013-02-18 17:16:22 +01:00
|
|
|
post = post .. getAdditionalData()
|
2012-08-22 10:51:31 +02:00
|
|
|
|
|
|
|
local message = ''
|
2012-08-23 17:37:26 +02:00
|
|
|
message = message .. "POST /report HTTP/1.1\r\n"
|
2012-08-22 10:51:31 +02:00
|
|
|
message = message .. "Host: " .. HOST .. "\r\n"
|
|
|
|
message = message .. "Accept: */*\r\n"
|
|
|
|
message = message .. "Connection: close\r\n"
|
|
|
|
message = message .. "Content-Type: application/x-www-form-urlencoded\r\n"
|
|
|
|
message = message .. "Content-Length: " .. post:len() .. "\r\n\r\n"
|
|
|
|
message = message .. post
|
|
|
|
|
|
|
|
protocol:send(message)
|
|
|
|
protocol:recv()
|
|
|
|
end
|
|
|
|
|
2013-02-18 17:16:22 +01:00
|
|
|
function getAdditionalData()
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
|
2012-08-22 10:51:31 +02:00
|
|
|
function onRecv(protocol, message)
|
|
|
|
if string.find(message, 'HTTP/1.1 200 OK') then
|
2012-08-23 03:50:03 +02:00
|
|
|
--pinfo('Stats sent to server successfully!')
|
2012-08-22 10:51:31 +02:00
|
|
|
end
|
|
|
|
protocol:disconnect()
|
|
|
|
end
|
|
|
|
|
|
|
|
function onError(protocol, message, code)
|
2013-01-30 21:23:26 +01:00
|
|
|
pdebug('Could not send statistics: ' .. message)
|
2012-08-22 10:51:31 +02:00
|
|
|
end
|