From 7203c44d10a6bf22e493f0b816fcbd5ebd475449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 15 Dec 2020 11:16:57 +0800 Subject: check config and unique token --- script/config.lua | 3 +++ script/service/telemetry.lua | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'script') diff --git a/script/config.lua b/script/config.lua index 298083a4..c9d8e075 100644 --- a/script/config.lua +++ b/script/config.lua @@ -150,6 +150,9 @@ local ConfigTemplate = { intelliSense = { searchDepth = {0, Integer}, }, + telemetry = { + enable = {true, Boolean}, + } } local OtherTemplate = { 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) -- cgit v1.2.3