From 0a82e1b68ef4864bd9ef84209c030dc02baea403 Mon Sep 17 00:00:00 2001 From: grilledham Date: Sat, 1 Dec 2018 10:49:14 +0000 Subject: [PATCH] query_online_players --- features/server.lua | 22 ++++++++++++++++++++++ features/server_commands.lua | 2 ++ 2 files changed, 24 insertions(+) diff --git a/features/server.lua b/features/server.lua index d4c3f2b8..00842b45 100644 --- a/features/server.lua +++ b/features/server.lua @@ -26,6 +26,7 @@ local data_get_all_tag = '[DATA-GET-ALL]' local data_tracked_tag = '[DATA-TRACKED]' local ban_sync_tag = '[BAN-SYNC]' local unbanned_sync_tag = '[UNBANNED-SYNC]' +local query_players_tag = '[QUERY-PLAYERS]' Public.raw_print = raw_print @@ -440,4 +441,25 @@ function Public.unban_non_sync(PlayerSpecification) game.unban_player(PlayerSpecification) end +--- Called be the web server to re sync which players are online. +function Public.query_online_players() + local message = {query_players_tag, '['} + + for _, p in ipairs(game.connected_players) do + table.insert(message, '"') + local name = escape(p.name) + table.insert(message, name) + table.insert(message, '",') + end + + if message[#message] == '",' then + message[#message] = '"' + end + + table.insert(message, ']') + + message = table.concat(message) + raw_print(message) +end + return Public diff --git a/features/server_commands.lua b/features/server_commands.lua index 3e860b07..2abca3a7 100644 --- a/features/server_commands.lua +++ b/features/server_commands.lua @@ -25,4 +25,6 @@ function ServerCommands.server_started() script.raise_event(Server.events.on_server_started, {}) end +ServerCommands.query_online_players = Server.query_online_players + return ServerCommands