mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
Add uid param to stats module
This commit is contained in:
@@ -1,9 +1,23 @@
|
||||
HOST = 'otclient.herokuapp.com'
|
||||
PORT = 80
|
||||
UUID = nil
|
||||
|
||||
--HOST = 'localhost'
|
||||
--PORT = 3000
|
||||
|
||||
function initUUID()
|
||||
UUID = g_settings.getString('report-uuid')
|
||||
if not UUID or #UUID ~= 36 then
|
||||
UUID = g_crypt.genUUID()
|
||||
g_settings.set('report-uuid', UUID)
|
||||
end
|
||||
end
|
||||
|
||||
function init()
|
||||
connect(g_game, { onGameStart = onGameStart })
|
||||
|
||||
initUUID()
|
||||
|
||||
protocolHttp = ProtocolHttp.create()
|
||||
connect(protocolHttp, { onConnect = onConnect,
|
||||
onRecv = onRecv,
|
||||
@@ -19,33 +33,31 @@ function terminate()
|
||||
protocolHttp = nil
|
||||
end
|
||||
|
||||
function sendInfo()
|
||||
function sendReport()
|
||||
protocolHttp:connect(HOST, PORT)
|
||||
end
|
||||
|
||||
-- events
|
||||
function onGameStart()
|
||||
scheduleEvent(sendInfo, 5*1000)
|
||||
scheduleEvent(sendReport, 5*1000)
|
||||
end
|
||||
|
||||
function onConnect(protocol)
|
||||
pinfo('Connected to stats server.')
|
||||
|
||||
if not g_game.isOnline() then
|
||||
perror('Could not send stats. Game not online.')
|
||||
protocol:disconnect()
|
||||
return
|
||||
end
|
||||
|
||||
local post = ''
|
||||
post = post .. 'os=' .. g_app.getOs()
|
||||
post = post .. 'uid=' .. UUID
|
||||
post = post .. '&os' .. g_app.getOs()
|
||||
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()
|
||||
post = post .. '&fullscreen=' .. fromboolean(g_window.isFullscreen())
|
||||
post = post .. '&fullscreen=' .. tostring(g_window.isFullscreen())
|
||||
post = post .. '&window_width=' .. g_window.getWidth()
|
||||
post = post .. '&window_height=' .. g_window.getHeight()
|
||||
post = post .. '&player_name=' .. g_game.getLocalPlayer():getName()
|
||||
@@ -74,11 +86,11 @@ end
|
||||
|
||||
function onRecv(protocol, message)
|
||||
if string.find(message, 'HTTP/1.1 200 OK') then
|
||||
pinfo('Stats sent to server successfully!')
|
||||
--pinfo('Stats sent to server successfully!')
|
||||
end
|
||||
protocol:disconnect()
|
||||
end
|
||||
|
||||
function onError(protocol, message, code)
|
||||
perror('Could not send statistics. ' .. message .. 'Code: ' .. code)
|
||||
perror('Could not send statistics: ' .. message)
|
||||
end
|
||||
|
Reference in New Issue
Block a user