From 6cf16cc09efa394357d19e0be4dbce803807e90e Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 2 Jan 2020 03:41:15 +0100 Subject: [PATCH] Reference by global in statistics_exporter Store export function in a global table in the lua module for statistics exporter in order to avoid a remote.call. --- plugins/statistics_exporter/instance.js | 2 +- plugins/statistics_exporter/module/export.lua | 9 ++------- plugins/statistics_exporter/module/module.json | 2 +- plugins/statistics_exporter/test/plugin.js | 4 ++-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/plugins/statistics_exporter/instance.js b/plugins/statistics_exporter/instance.js index d9b74927..aa158231 100644 --- a/plugins/statistics_exporter/instance.js +++ b/plugins/statistics_exporter/instance.js @@ -22,7 +22,7 @@ const instanceGameFlowStatistics = new Gauge( class InstancePlugin extends plugin.BaseInstancePlugin { async onMetrics() { - let string = await this.instance.server.sendRcon('/sc remote.call("statistics_exporter", "export")'); + let string = await this.instance.server.sendRcon('/sc statistics_exporter.export()'); let stats; try { stats = JSON.parse(string); diff --git a/plugins/statistics_exporter/module/export.lua b/plugins/statistics_exporter/module/export.lua index babb44da..fb7fc164 100644 --- a/plugins/statistics_exporter/module/export.lua +++ b/plugins/statistics_exporter/module/export.lua @@ -5,7 +5,8 @@ local statistics = { "entity_build_count_statistics", } -local function export() +statistics_exporter = {} +function statistics_exporter.export() local stats = { game_tick = game.tick, player_count = #game.connected_players, @@ -31,9 +32,3 @@ local function export() rcon.print(game.table_to_json(stats)) end - -return { - add_remote_interface = function() - remote.add_interface("statistics_exporter", { export = export }) - end -} diff --git a/plugins/statistics_exporter/module/module.json b/plugins/statistics_exporter/module/module.json index 253cd328..7da2637e 100644 --- a/plugins/statistics_exporter/module/module.json +++ b/plugins/statistics_exporter/module/module.json @@ -1,4 +1,4 @@ { "name": "statistics_exporter", - "load": ["export.lua"] + "require": ["export.lua"] } diff --git a/plugins/statistics_exporter/test/plugin.js b/plugins/statistics_exporter/test/plugin.js index 2716e7b8..2112a441 100644 --- a/plugins/statistics_exporter/test/plugin.js +++ b/plugins/statistics_exporter/test/plugin.js @@ -16,7 +16,7 @@ describe("statistics_exporter plugin", function() { describe(".onMetrics()", function() { it("should record statistics", async function() { instancePlugin.instance.server.rconCommandResults.set( - '/sc remote.call("statistics_exporter", "export")', + '/sc statistics_exporter.export()', JSON.stringify({ game_tick: 100, player_count: 3, @@ -51,7 +51,7 @@ describe("statistics_exporter plugin", function() { it("should pass on JSON parse errors", async function() { let string = 'An error occured\n'; instancePlugin.instance.server.rconCommandResults.set( - '/sc remote.call("statistics_exporter", "export")', string + '/sc statistics_exporter.export()', string ); let errorMessage;