Send reports periodically

This commit is contained in:
Eduardo Bart 2012-08-23 12:18:23 -03:00
parent a306027cec
commit 1a226f7983
1 changed files with 17 additions and 14 deletions

View File

@ -1,6 +1,9 @@
HOST = 'otclient.herokuapp.com' HOST = 'otclient.herokuapp.com'
PORT = 80 PORT = 80
UUID = nil UUID = nil
REPORT_DELAY = 60
sendReportEvent = nil
--HOST = 'localhost' --HOST = 'localhost'
--PORT = 3000 --PORT = 3000
@ -14,32 +17,31 @@ function initUUID()
end end
function init() function init()
connect(g_game, { onGameStart = onGameStart }) connect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
initUUID() initUUID()
protocolHttp = ProtocolHttp.create()
connect(protocolHttp, { onConnect = onConnect,
onRecv = onRecv,
onError = onError })
end end
function terminate() function terminate()
disconnect(g_game, { onGameStart = onGameStart }) disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
disconnect(protocolHttp, { onConnect = onConnect,
onRecv = onRecv,
onError = onError })
protocolHttp = nil
end end
function sendReport() function sendReport()
local protocolHttp = ProtocolHttp.create()
protocolHttp.onConnect = onConnect
protocolHttp.onRecv = onRecv
protocolHttp.onError = onError
protocolHttp:connect(HOST, PORT) protocolHttp:connect(HOST, PORT)
end end
-- events
function onGameStart() function onGameStart()
scheduleEvent(sendReport, 5*1000) sendReportEvent = cycleEvent(sendReport, REPORT_DELAY*1000)
end
function onGameEnd()
sendReportEvent:cancel()
end end
function onConnect(protocol) function onConnect(protocol)
@ -50,6 +52,7 @@ function onConnect(protocol)
local post = '' local post = ''
post = post .. 'uid=' .. UUID post = post .. 'uid=' .. UUID
post = post .. '&report_delay' .. REPORT_DELAY
post = post .. '&os' .. g_app.getOs() post = post .. '&os' .. g_app.getOs()
post = post .. '&graphics_vendor=' .. g_graphics.getVendor() post = post .. '&graphics_vendor=' .. g_graphics.getVendor()
post = post .. '&graphics_renderer=' .. g_graphics.getRenderer() post = post .. '&graphics_renderer=' .. g_graphics.getRenderer()