1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

merge query_online_players

This commit is contained in:
grilledham 2018-12-01 10:53:46 +00:00
commit 3883c9e770
2 changed files with 24 additions and 1 deletions

View File

@ -36,6 +36,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
@ -458,7 +459,7 @@ function Public.set_time(secs)
end
--- Gets a table {secs:number?, tick:number} with secs being the unix epoch timestamp
-- for the server time and ticks the number of game ticks it was set
-- for the server time and ticks the number of game ticks ago it was set.
-- @return table
function Public.get_time_data_raw()
return server_time
@ -479,4 +480,25 @@ function Public.get_current_time()
return math.floor(secs + diff / game.speed / 60)
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

View File

@ -26,5 +26,6 @@ function ServerCommands.server_started()
end
ServerCommands.set_time = Server.set_time
ServerCommands.query_online_players = Server.query_online_players
return ServerCommands