diff options
Diffstat (limited to 'script/service')
-rw-r--r-- | script/service/telemetry.lua | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua index 5b9bbd5d..2434cf1a 100644 --- a/script/service/telemetry.lua +++ b/script/service/telemetry.lua @@ -3,10 +3,16 @@ local timer = require 'timer' local config = require 'config' local client = require 'provider.client' local nonil = require 'without-check-nil' +local util = require 'utility' -local token = ('%016X'):format(math.random(0, math.maxinteger)) -local function push() - local link = net.connect('tcp', '119.45.194.183', 11577) +local tokenPath = (ROOT / 'log' / 'token'):string() +local token = util.loadFile(tokenPath) +if not token then + token = ('%016X'):format(math.random(0, math.maxinteger)) + util.saveFile(token) +end + +local function pushClient(link) nonil.enable() local clientName = client.info.clientInfo.name local clientVersion = client.info.clientInfo.version @@ -16,9 +22,15 @@ local function push() , token , table.concat({clientName, clientVersion}, ' ') )) - net.update() end timer.wait(5, function () - timer.loop(60, push)() + timer.loop(60, function () + if not config.config.telemetry.enable then + return + end + local link = net.connect('tcp', '119.45.194.183', 11577) + pushClient(link) + net.update() + end)() end) |