From 458abdba24f34c5877066ff95467d112f0eefb9b Mon Sep 17 00:00:00 2001 From: grilledham Date: Fri, 21 Sep 2018 19:48:12 +0100 Subject: [PATCH 01/43] server module --- control.lua | 17 +++++++++++++ poll.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++ server.lua | 24 ++++++++++++++++++ server_commands.lua | 9 +++++++ 4 files changed, 112 insertions(+) create mode 100644 server.lua create mode 100644 server_commands.lua diff --git a/control.lua b/control.lua index d01ff294..8b1b8c08 100644 --- a/control.lua +++ b/control.lua @@ -28,6 +28,9 @@ require 'paint' require 'score' require 'popup' +Server = require 'server' +ServerCommands = require 'server_commands' + local Event = require 'utils.event' local Donators = require 'resources.donators' @@ -310,3 +313,17 @@ Event.add( end end ) + +Event.add( + defines.events.on_research_started, + function(event) + Server.to_discord_raw('**Research ' .. event.research.name .. ' started.**') + end +) + +Event.add( + defines.events.on_research_finished, + function(event) + Server.to_discord_raw('**Research ' .. event.research.name .. ' finished.**') + end +) diff --git a/poll.lua b/poll.lua index b4353dc4..baecc4be 100644 --- a/poll.lua +++ b/poll.lua @@ -2,6 +2,7 @@ local Gui = require 'utils.gui' local Global = require 'utils.global' local Event = require 'utils.event' local UserGroups = require 'user_groups' +local Server = require 'server' local default_poll_duration = 300 * 60 -- in ticks local duration_max = 3600 -- in seconds @@ -105,6 +106,48 @@ local function do_remaining_time(poll, remaining_time_label) end end +local function send_poll_result_to_discord(poll) + local result = {'Poll #', poll.id} + + local created_by_player = poll.created_by + if created_by_player and created_by_player.valid then + table.insert(result, ' Created by ') + table.insert(result, created_by_player.name) + end + + local edited_by_players = poll.edited_by + if next(edited_by_players) then + table.insert(result, ' Edited by ') + for pi, _ in pairs(edited_by_players) do + local p = game.players[pi] + if p and p.valid then + table.insert(result, p.name) + table.insert(result, ', ') + end + end + table.remove(result) + end + + table.insert(result, '\\n**Question: ') + table.insert(result, poll.question) + table.insert(result, '**\\n') + + local answers = poll.answers + local answers_count = #answers + for i, a in ipairs(answers) do + table.insert(result, '[') + table.insert(result, a.voted_count) + table.insert(result, '] - ') + table.insert(result, a.text) + if i ~= answers_count then + table.insert(result, '\\n') + end + end + + local message = table.concat(result) + Server.to_discord_embed(message) +end + local function redraw_poll_viewer_content(data) local poll_viewer_content = data.poll_viewer_content local remaining_time_label = data.remaining_time_label @@ -654,6 +697,7 @@ local function create_poll(event) table.insert(polls, poll_data) show_new_poll(poll_data) + send_poll_result_to_discord(poll_data) Gui.remove_data_recursivly(frame) frame.destroy() @@ -1196,6 +1240,7 @@ function Class.poll(data) table.insert(polls, poll_data) show_new_poll(poll_data) + send_poll_result_to_discord(poll_data) return true, id end @@ -1270,6 +1315,23 @@ local function poll_result_command(cmd) player_print(result) end +function Class.send_poll_result_to_discord(id) + if type(id) ~= 'number' then + Server.to_discord_embed('poll-id must be a number') + return + end + + for _, poll_data in ipairs(polls) do + if poll_data.id == id then + send_poll_result_to_discord(poll_data) + return + end + end + + local message = table.concat {'poll #', id, ' not found'} + Server.to_discord_embed(message) +end + commands.add_command( 'poll', '<{question = "question", answers = {"answer 1", "answer 2"}, duration = 300 | nil}> - Creates a new poll (Admin and regulars only).', diff --git a/server.lua b/server.lua new file mode 100644 index 00000000..2757b821 --- /dev/null +++ b/server.lua @@ -0,0 +1,24 @@ +local Public = {} + +local discord_tag = '[CHAT]' +local discord_raw_tag = '[CHAT-RAW]' +local discord_admin_tag = '[ADMIN]' +local discord_embed_tag = '[EMBED]' + +function Public.to_discord(message) + print(discord_tag .. message) +end + +function Public.to_discord_raw(message) + print(discord_raw_tag .. message) +end + +function Public.to_admin(message) + print(discord_admin_tag .. message) +end + +function Public.to_discord_embed(message) + print(discord_embed_tag .. message) +end + +return Public diff --git a/server_commands.lua b/server_commands.lua new file mode 100644 index 00000000..4cfddd0d --- /dev/null +++ b/server_commands.lua @@ -0,0 +1,9 @@ +local Poll = require 'poll' + +local Public = {} + +function Public.get_poll_result(id) + Poll.send_poll_result_to_discord(id) +end + +return Public From 648521716fa8066deb010ea0e34302cdd334deae Mon Sep 17 00:00:00 2001 From: grilledham Date: Sat, 22 Sep 2018 17:41:20 +0100 Subject: [PATCH 02/43] updates --- server.lua | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/server.lua b/server.lua index 2757b821..ddf37cd5 100644 --- a/server.lua +++ b/server.lua @@ -1,9 +1,13 @@ local Public = {} -local discord_tag = '[CHAT]' -local discord_raw_tag = '[CHAT-RAW]' -local discord_admin_tag = '[ADMIN]' -local discord_embed_tag = '[EMBED]' +local discord_tag = '[DISCORD]' +local discord_raw_tag = '[DISCORD-RAW]' +local discord_admin_tag = '[DISCORD-ADMIN]' +local discord_admin_raw_tag = '[DISCORD-ADMIN-RAW]' +local discord_embed_tag = '[DISCORD-EMBED]' +local discord_embed_raw_tag = '[DISCORD-EMBED-RAW]' +local discord_admin_embed_tag = '[DISCORD-ADMIN-EMBED]' +local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' function Public.to_discord(message) print(discord_tag .. message) @@ -17,8 +21,24 @@ function Public.to_admin(message) print(discord_admin_tag .. message) end +function Public.to_admin_raw(message) + print(discord_admin_raw_tag .. message) +end + function Public.to_discord_embed(message) print(discord_embed_tag .. message) end +function Public.to_discord_embed_raw(message) + print(discord_embed_raw_tag .. message) +end + +function Public.to_admin_embed(message) + print(discord_admin_embed_tag .. message) +end + +function Public.to_admin_embed_raw(message) + print(discord_admin_embed_raw_tag .. message) +end + return Public From 46b45d972c9a0576f6c97b02fb4c365ddde30fd6 Mon Sep 17 00:00:00 2001 From: grilledham Date: Sat, 22 Sep 2018 21:02:22 +0100 Subject: [PATCH 03/43] updates --- poll.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poll.lua b/poll.lua index baecc4be..5fb6a2f2 100644 --- a/poll.lua +++ b/poll.lua @@ -1298,7 +1298,7 @@ local function poll_command(cmd) if not suc then player_print(result) else - player_print(table.concat {'Poll #', result, ' successfully created.'}) + player_print(table.concat {'[POLL] ','Poll #', result, ' successfully created.'}) end end From 5c2948e9b790daf25e933abd6dfbb47478c110f8 Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 25 Sep 2018 14:45:47 +0100 Subject: [PATCH 04/43] updates --- control.lua | 5 ++--- user_groups.lua | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/control.lua b/control.lua index 8b1b8c08..5c37b99a 100644 --- a/control.lua +++ b/control.lua @@ -15,7 +15,6 @@ require 'reactor_meltdown' require 'train_saviour' require 'map_gen.shared.perlin_noise' require 'map_layout' -require 'bot' require 'player_colors' -- GUIs the order determines the order they appear at the top. require 'info' @@ -320,10 +319,10 @@ Event.add( Server.to_discord_raw('**Research ' .. event.research.name .. ' started.**') end ) - +local Server = require 'server' Event.add( defines.events.on_research_finished, function(event) - Server.to_discord_raw('**Research ' .. event.research.name .. ' finished.**') + Server.to_discord_raw('**Research ' .. event.research.name .. ' finished.**') end ) diff --git a/user_groups.lua b/user_groups.lua index 1b2804a5..fbf19e24 100644 --- a/user_groups.lua +++ b/user_groups.lua @@ -1,4 +1,4 @@ -global.regulars = require 'resources.regulars' +global.regulars = {}--require 'resources.regulars' local Donators = require 'resources.donators' global.donators = Donators.donators local Event = require 'utils.event' From fff6559f2eb6bc131980bf61b6d8a97c0518f147 Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 2 Oct 2018 00:10:53 +0100 Subject: [PATCH 05/43] updates --- server_commands.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server_commands.lua b/server_commands.lua index 4cfddd0d..c1a40ad3 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -1,4 +1,5 @@ local Poll = require 'poll' +local UserGroups = require 'user_groups' local Public = {} @@ -6,4 +7,16 @@ function Public.get_poll_result(id) Poll.send_poll_result_to_discord(id) end +function Public.regular_sync(names) + global.regulars = names +end + +function Public.regular_promote(name) + global.regulars[name] = true +end + +function Public.regular.demote(name) + global.regulars[name] = nil +end + return Public From e9770c85229249afe8161736bffc99b7739fc4ab Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 2 Oct 2018 00:16:36 +0100 Subject: [PATCH 06/43] fixed typo --- server_commands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_commands.lua b/server_commands.lua index c1a40ad3..2f889f17 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -15,7 +15,7 @@ function Public.regular_promote(name) global.regulars[name] = true end -function Public.regular.demote(name) +function Public.regular_demote(name) global.regulars[name] = nil end From 4e080475c175f27889f9268ff2585fdbb278fe93 Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 2 Oct 2018 00:31:46 +0100 Subject: [PATCH 07/43] updates --- server.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.lua b/server.lua index ddf37cd5..0bd54da1 100644 --- a/server.lua +++ b/server.lua @@ -8,6 +8,8 @@ local discord_embed_tag = '[DISCORD-EMBED]' local discord_embed_raw_tag = '[DISCORD-EMBED-RAW]' local discord_admin_embed_tag = '[DISCORD-ADMIN-EMBED]' local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' +local regular_promote_tag = '[REGULAR-PROMOTE]' +local regular_deomote_tag = '[REGULAR-DEOMOTE]' function Public.to_discord(message) print(discord_tag .. message) @@ -41,4 +43,13 @@ function Public.to_admin_embed_raw(message) print(discord_admin_embed_raw_tag .. message) end +function Public.regular_promote(target, promotor) + local message = table.concat {regular_promote_tag, target, ' ', promotor or ''} + print(message) +end + +function Public.regular_deomote(target) + print(regular_deomote_tag .. target) +end + return Public From b553e1daa8a31fd0716384b60783d677a3cf553a Mon Sep 17 00:00:00 2001 From: grilledham Date: Wed, 3 Oct 2018 21:03:19 +0100 Subject: [PATCH 08/43] updates --- control.lua | 6 ++--- server.lua | 42 +++++++++++++++++++++++---------- server_commands.lua | 16 ++++--------- user_groups.lua | 57 ++++++++++++++++++++++++++++++++++++++------- 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/control.lua b/control.lua index 5c37b99a..ed890b28 100644 --- a/control.lua +++ b/control.lua @@ -1,7 +1,7 @@ require 'config' require 'utils.utils' require 'utils.list_utils' -require 'user_groups' +local UserGroups = require 'user_groups' require 'custom_commands' require 'base_data' require 'train_station_names' @@ -159,7 +159,7 @@ local function player_joined(event) return end - local message = Donators.welcome_messages[player.name] + local message = UserGroups.get_donator_welcome_message(player.name) if not message then return end @@ -323,6 +323,6 @@ local Server = require 'server' Event.add( defines.events.on_research_finished, function(event) - Server.to_discord_raw('**Research ' .. event.research.name .. ' finished.**') + Server.to_discord_raw('**Research ' .. event.research.name .. ' finished.**') end ) diff --git a/server.lua b/server.lua index 0bd54da1..25eedebc 100644 --- a/server.lua +++ b/server.lua @@ -1,7 +1,13 @@ local Public = {} +local raw_print = print +function print(str) + raw_print('[PRINT] ' .. str) +end + local discord_tag = '[DISCORD]' local discord_raw_tag = '[DISCORD-RAW]' +local discord_bold_tag = '[DISCORD-BOLD]' local discord_admin_tag = '[DISCORD-ADMIN]' local discord_admin_raw_tag = '[DISCORD-ADMIN-RAW]' local discord_embed_tag = '[DISCORD-EMBED]' @@ -11,45 +17,57 @@ local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' local regular_promote_tag = '[REGULAR-PROMOTE]' local regular_deomote_tag = '[REGULAR-DEOMOTE]' +Public.raw_print = raw_print + function Public.to_discord(message) - print(discord_tag .. message) + raw_print(discord_tag .. message) end function Public.to_discord_raw(message) - print(discord_raw_tag .. message) + raw_print(discord_raw_tag .. message) +end + +function Public.to_discord_bold(message) + raw_print(discord_bold_tag .. message) end function Public.to_admin(message) - print(discord_admin_tag .. message) + raw_print(discord_admin_tag .. message) end function Public.to_admin_raw(message) - print(discord_admin_raw_tag .. message) + raw_print(discord_admin_raw_tag .. message) end function Public.to_discord_embed(message) - print(discord_embed_tag .. message) + raw_print(discord_embed_tag .. message) end function Public.to_discord_embed_raw(message) - print(discord_embed_raw_tag .. message) + raw_print(discord_embed_raw_tag .. message) end function Public.to_admin_embed(message) - print(discord_admin_embed_tag .. message) + raw_print(discord_admin_embed_tag .. message) end function Public.to_admin_embed_raw(message) - print(discord_admin_embed_raw_tag .. message) + raw_print(discord_admin_embed_raw_tag .. message) end function Public.regular_promote(target, promotor) - local message = table.concat {regular_promote_tag, target, ' ', promotor or ''} - print(message) + local control_message = table.concat {regular_promote_tag, target, ' ', promotor} + local discord_message = table.concat {discord_bold_tag, promotor .. ' promoted ' .. target .. ' to regular.'} + + raw_print(control_message) + raw_print(discord_message) end -function Public.regular_deomote(target) - print(regular_deomote_tag .. target) +function Public.regular_deomote(target, demotor) + local discord_message = table.concat {discord_bold_tag, target, ' was demoted from regular by ', demotor, '.'} + + raw_print(regular_deomote_tag .. target) + raw_print(discord_message) end return Public diff --git a/server_commands.lua b/server_commands.lua index 2f889f17..ede30eb6 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -3,20 +3,12 @@ local UserGroups = require 'user_groups' local Public = {} -function Public.get_poll_result(id) - Poll.send_poll_result_to_discord(id) -end +Public.get_poll_result = Poll.send_poll_result_to_discord -function Public.regular_sync(names) - global.regulars = names -end +Public.regular_sync = UserGroups.sync_regulars -function Public.regular_promote(name) - global.regulars[name] = true -end +Public.regular_promote = UserGroups.server_add_regular -function Public.regular_demote(name) - global.regulars[name] = nil -end +Public.regular_demote = UserGroups.server_remove_regular return Public diff --git a/user_groups.lua b/user_groups.lua index fbf19e24..76eb3bcb 100644 --- a/user_groups.lua +++ b/user_groups.lua @@ -1,8 +1,11 @@ -global.regulars = {}--require 'resources.regulars' -local Donators = require 'resources.donators' -global.donators = Donators.donators local Event = require 'utils.event' local Utils = require 'utils.utils' +local Server = require 'server' +--local Donators = require 'resources.donators' + +global.regulars = {} +global.donators = {} +global.donator_welcome_messages = {} local Module = {} @@ -22,9 +25,11 @@ Module.is_regular = function(player_name) return Utils.cast_bool(global.regulars[player_name] or global.regulars[player_name:lower()]) --to make it backwards compatible end -Module.add_regular = function(player_name) + +Module.add_regular = + function(player_name) local actor = Utils.get_actor() - if Module.is_regular(player_name) then + --[[ if Module.is_regular(player_name) then player_print(player_name .. ' is already a regular.') else if game.players[player_name] then @@ -35,13 +40,16 @@ Module.add_regular = function(player_name) else player_print(player_name .. ' does not exist.') end - end + end ]] + global.regulars[player_name] = true + game.print(actor .. ' promoted ' .. player_name .. ' to regular.') + Server.regular_promote(player_name, actor) end Module.remove_regular = function(player_name) local actor = Utils.get_actor() - if game.players[player_name] then + --[[ if game.players[player_name] then player_name = game.players[player_name].name if Module.is_regular(player_name) then game.print(player_name .. ' was demoted from regular by ' .. actor .. '.') @@ -49,13 +57,37 @@ Module.remove_regular = global.regulars[player_name] = nil global.regulars[player_name:lower()] = nil --backwards compatible update_file() + end ]] + global.regulars[player_name] = nil + game.print(player_name .. ' was demoted from regular by ' .. actor .. '.') + Server.regular_deomote(player_name, actor) +end + +function Module.server_add_regular(player_name) + global.regulars[player_name] = true +end + +function Module.server_remove_regular(player_name) + global.regulars[player_name] = nil +end + +function Module.sync_regulars(names) + local r = {} + for _, name in ipairs(names) do + r[name] = true end + + global.regulars = r end Module.print_regulars = function() + local result = {} for k, _ in pairs(global.regulars) do - player_print(k) + table.insert(result, k) end + + result = table.concat(result, ', ') + game.print(result) end function Module.get_rank(player) @@ -81,6 +113,15 @@ function Module.player_has_donator_perk(player_name, perk_flag) return bit32.band(d, perk_flag) == perk_flag end +function Module.get_donator_welcome_message(player_name) + return global.donator_welcome_messages[player_name] +end + +function Module.sync_donators(donators, messages) + global.donators = donators + global.donator_welcome_messages = messages +end + Event.add( defines.events.on_player_joined_game, function(event) From b14b6c6ee7c10884692215f68fecbca85084da00 Mon Sep 17 00:00:00 2001 From: grilledham Date: Wed, 3 Oct 2018 23:26:33 +0100 Subject: [PATCH 09/43] updates --- custom_commands.lua | 41 +++++++++++++++++++++++++++++++++++++++++ server.lua | 9 +++++++++ user_groups.lua | 27 +++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/custom_commands.lua b/custom_commands.lua index 89ae78eb..73781ca2 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -247,6 +247,45 @@ local function regular(cmd) end end +local function donator(cmd) + local player = game.player + if player and not player.admin then + cant_run(cmd.name) + return + end + + if cmd.parameter == nil then + player_print('Command failed. Usage: /donator ') + return + end + + local params = {} + for param in string.gmatch(cmd.parameter, '%S+') do + table.insert(params, param) + end + if params[2] == nil then + player_print('Command failed. Usage: /donator ') + return + end + + local perks = params[2] + if perks == 'nil' then + perks = nil + end + + if (tonumber(perks) == nil and perks ~= nil) then + player_print("Command failed. perks must be number or the string 'nil' to remove donator.") + return + end + + local target = params[1] + + UserGroups.set_donator(target, perks) + + local message = table.concat {'Player ', target, ' donator perks set to ', perks} + player_print(message) +end + local function afk() for _, v in pairs(game.players) do if v.afk_time > 300 then @@ -657,6 +696,8 @@ commands.add_command('tppos', 'Teleports you to a selected entity. (Admins only) commands.add_command('walkabout', ' - Send someone on a walk. (Admins only)', walkabout) commands.add_command('regulars', 'Prints a list of game regulars.', UserGroups.print_regulars) commands.add_command('regular', ', Change regular status of a player. (Admins only)', regular) +commands.add_command('donator', ' Change donator perks for a player. (Admins only)', donator) +commands.add_command('donators', 'Prints a list of game donators and thier perks.', UserGroups.print_donators) commands.add_command('afk', 'Shows how long players have been afk.', afk) commands.add_command( 'follow', diff --git a/server.lua b/server.lua index 25eedebc..de742eea 100644 --- a/server.lua +++ b/server.lua @@ -16,6 +16,7 @@ local discord_admin_embed_tag = '[DISCORD-ADMIN-EMBED]' local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' local regular_promote_tag = '[REGULAR-PROMOTE]' local regular_deomote_tag = '[REGULAR-DEOMOTE]' +local donator_set_tag = '[DONATOR-SET]' Public.raw_print = raw_print @@ -70,4 +71,12 @@ function Public.regular_deomote(target, demotor) raw_print(discord_message) end +function Public.donator_set(target, perks) + perks = perks or 'nil' + + local message = table.concat {donator_set_tag, target, ' ', perks} + + raw_print(message) +end + return Public diff --git a/user_groups.lua b/user_groups.lua index a994d214..a3ad6b18 100644 --- a/user_groups.lua +++ b/user_groups.lua @@ -1,10 +1,10 @@ local Event = require 'utils.event' local Utils = require 'utils.utils' local Server = require 'server' ---local Donators = require 'resources.donators' +local Donators = require 'resources.donators' global.regulars = {} -global.donators = {} +global.donators = Donators.donators global.donator_welcome_messages = {} local Game = require 'utils.game' @@ -118,11 +118,34 @@ function Module.get_donator_welcome_message(player_name) return global.donator_welcome_messages[player_name] end +function Module.set_donator(player_name, perks) + global.donators[player_name] = perks + Server.donator_set(player_name, perks) +end + function Module.sync_donators(donators, messages) global.donators = donators global.donator_welcome_messages = messages end +function Module.server_set_donator(player_name, perks) + global.donators[player_name] = perks +end + +function Module.print_donators() + local result = {} + for k, v in pairs(global.donators) do + table.insert(result, k) + table.insert(result, ' : ') + table.insert(result, v) + table.insert(result, ', ') + end + table.remove(result) + + result = table.concat(result) + game.print(result) +end + Event.add( defines.events.on_player_joined_game, function(event) From abc8861904df83f074335a2d9e8a2c5eede22e83 Mon Sep 17 00:00:00 2001 From: grilledham Date: Fri, 16 Nov 2018 16:46:17 +0000 Subject: [PATCH 10/43] fixed requires --- server_commands.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server_commands.lua b/server_commands.lua index ede30eb6..81b76a03 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -1,5 +1,5 @@ -local Poll = require 'poll' -local UserGroups = require 'user_groups' +local Poll = require 'features.gui.poll' +local UserGroups = require 'features.user_groups' local Public = {} From 9160612e9cb97021cc4d504fa16038a06ae8fb6e Mon Sep 17 00:00:00 2001 From: grilledham Date: Sat, 17 Nov 2018 18:56:05 +0000 Subject: [PATCH 11/43] updates --- features/user_groups.lua | 1 + server.lua | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/features/user_groups.lua b/features/user_groups.lua index 736ed66b..9b97ad36 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -30,6 +30,7 @@ end Module.add_regular = function(player_name) local actor = Utils.get_actor() + --[[ if Module.is_regular(player_name) then Game.player_print(player_name .. ' is already a regular.') else diff --git a/server.lua b/server.lua index de742eea..281be750 100644 --- a/server.lua +++ b/server.lua @@ -17,6 +17,7 @@ local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' local regular_promote_tag = '[REGULAR-PROMOTE]' local regular_deomote_tag = '[REGULAR-DEOMOTE]' local donator_set_tag = '[DONATOR-SET]' +local start_scenario_tag = '[START-SCENARIO]' Public.raw_print = raw_print @@ -79,4 +80,14 @@ function Public.donator_set(target, perks) raw_print(message) end +function Public.start_scenario(scenario_name) + local message = start_scenario_tag + + if type(scenario_name) == 'string' then + message = message .. scenario_name + end + + raw_print(message) +end + return Public From 01a2d61f9d1bfd545df5a9718e118dc0f5d0a2be Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 19 Nov 2018 20:13:40 +0000 Subject: [PATCH 12/43] merge develop --- features/custom_commands.lua | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/features/custom_commands.lua b/features/custom_commands.lua index 7ca3f5ef..e3a9d557 100644 --- a/features/custom_commands.lua +++ b/features/custom_commands.lua @@ -618,34 +618,7 @@ local function show_rail_block() player.print('show_rail_block_visualisation set to ' .. tostring(show)) end -<<<<<<< HEAD -commands.add_command('kill', 'Will kill you.', kill) -commands.add_command('tpplayer', ' - Teleports you to the player. (Admins only)', teleport_player) -commands.add_command('invoke', ' - Teleports the player to you. (Admins only)', invoke) -commands.add_command('tppos', 'Teleports you to a selected entity. (Admins only)', teleport_location) -commands.add_command('walkabout', ' - Send someone on a walk. (Admins only)', walkabout) -commands.add_command('regulars', 'Prints a list of game regulars.', UserGroups.print_regulars) -commands.add_command('regular', ', Change regular status of a player. (Admins only)', regular) -commands.add_command('donator', ' Change donator perks for a player. (Admins only)', donator) -commands.add_command('donators', 'Prints a list of game donators and thier perks.', UserGroups.print_donators) -commands.add_command('afk', 'Shows how long players have been afk.', afk) -commands.add_command( - 'follow', - ' makes you follow the player. Use /unfollow to stop following a player.', - follow -) -commands.add_command('unfollow', 'stops following a player.', unfollow) -commands.add_command( - 'tpmode', - 'Toggles tp mode. When on place a ghost entity to teleport there (Admins only)', - toggle_tp_mode -) - -commands.add_command('tempban', ' Temporarily bans a player (Admins only)', tempban) -commands.add_command('zoom', ' Sets your zoom.', zoom) -======= --- Add all commands to command list ->>>>>>> 5a60a55a645c1ad7a28650367fe5ec9ef3e5c1e8 if _DEBUG then commands.add_command('all-tech', 'researches all technologies (debug only)', all_tech) end From 0f3eba80428f87e825ce2be5a9c00c6e663eeee3 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 19 Nov 2018 20:13:45 +0000 Subject: [PATCH 13/43] ping --- server.lua | 28 ++++++++++++++++++++++++---- server_commands.lua | 6 ++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/server.lua b/server.lua index 281be750..e76753b2 100644 --- a/server.lua +++ b/server.lua @@ -1,3 +1,5 @@ +local Token = require 'utils.global_token' + local Public = {} local raw_print = print @@ -18,6 +20,7 @@ local regular_promote_tag = '[REGULAR-PROMOTE]' local regular_deomote_tag = '[REGULAR-DEOMOTE]' local donator_set_tag = '[DONATOR-SET]' local start_scenario_tag = '[START-SCENARIO]' +local ping_tag = '[PING]' Public.raw_print = raw_print @@ -81,12 +84,29 @@ function Public.donator_set(target, perks) end function Public.start_scenario(scenario_name) - local message = start_scenario_tag - - if type(scenario_name) == 'string' then - message = message .. scenario_name + if type(scenario_name) ~= 'string' then + game.print('start_scenario - scenario_name ' .. tostring(scenario_name) .. ' must be a string.') + return end + local message = start_scenario_tag .. scenario_name + + raw_print(message) +end + +local default_ping_token = + Token.register( + function(sent_tick) + local now = game.tick + local diff = now - sent_tick + + local message = table.concat({'Ping in ', diff, ' ticks ', 'sent: ', sent_tick, ' received: ', now}) + game.print(message) + end +) + +function Public.ping(func_token) + local message = table.concat({ping_tag, func_token or default_ping_token, ' ', game.tick}) raw_print(message) end diff --git a/server_commands.lua b/server_commands.lua index 81b76a03..ad00f363 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -1,5 +1,6 @@ local Poll = require 'features.gui.poll' local UserGroups = require 'features.user_groups' +local Token = require 'utils.global_token' local Public = {} @@ -11,4 +12,9 @@ Public.regular_promote = UserGroups.server_add_regular Public.regular_demote = UserGroups.server_remove_regular +function Public.raise_callback(func_token, data) + local func = Token.get(func_token) + func(data) +end + return Public From f4612a7046ecfd3c971c065595889cfa04a0addb Mon Sep 17 00:00:00 2001 From: grilledham Date: Sat, 24 Nov 2018 14:15:14 +0000 Subject: [PATCH 14/43] more functions --- control.lua | 32 ++++++++++++++ server.lua | 100 +++++++++++++++++++++++++++++++++++++++++++- server_commands.lua | 8 ++++ 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/control.lua b/control.lua index a1f771aa..9a4b8417 100644 --- a/control.lua +++ b/control.lua @@ -47,3 +47,35 @@ require 'features.gui.blueprint_helper' require 'features.gui.paint' require 'features.gui.score' require 'features.gui.popup' + +Server.on_data_set_changed( + 'Test', + function(data) + game.print(serpent.block(data)) + end +) + +Server.on_data_set_changed( + 'Test 2', + function(data) + game.print(serpent.block(data)) + end +) + +Server.on_data_set_changed( + 'Test,2', + function(data) + game.print(serpent.block(data)) + end +) + +local Event = require('utils.event') +Event.add( + Server.events.on_server_started, + function(tbl) + game.print('on_server_started') + print('on_server_started') + game.print(serpent.block(tbl)) + print(serpent.block(tbl)) + end +) diff --git a/server.lua b/server.lua index e76753b2..25de18ca 100644 --- a/server.lua +++ b/server.lua @@ -1,4 +1,5 @@ local Token = require 'utils.global_token' +local Event = require 'utils.event' local Public = {} @@ -21,9 +22,19 @@ local regular_deomote_tag = '[REGULAR-DEOMOTE]' local donator_set_tag = '[DONATOR-SET]' local start_scenario_tag = '[START-SCENARIO]' local ping_tag = '[PING]' +local data_set_tag = '[DATA-SET]' +local data_get_tag = '[DATA-GET]' +local data_get_all_tag = '[DATA-GET-ALL]' +local data_tracked_tag = '[DATA-TRACKED]' Public.raw_print = raw_print +local data_set_handlers = {} + +defines.events.on_server_started = script.generate_event_name() + +Public.events = {on_server_started = defines.events.on_server_started} + function Public.to_discord(message) raw_print(discord_tag .. message) end @@ -100,7 +111,7 @@ local default_ping_token = local now = game.tick local diff = now - sent_tick - local message = table.concat({'Ping in ', diff, ' ticks ', 'sent: ', sent_tick, ' received: ', now}) + local message = table.concat({'Pong in ', diff, ' tick(s) ', 'sent tick: ', sent_tick, ' received tick: ', now}) game.print(message) end ) @@ -110,4 +121,91 @@ function Public.ping(func_token) raw_print(message) end +function Public.set_data(data_set, key, value) + if type(data_set) ~= 'string' then + error('data_set must be a string') + end + if type(key) ~= 'string' then + error('key must be a string') + end + + local message + local vt = type(value) + if vt == 'nil' then + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '"}'}) + elseif vt == 'string' then + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"\\"', value, '\\""}'}) + elseif vt == 'number' or vt == 'boolean' then + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', value, '"}'}) + elseif vt == 'function' then + error('value cannot be a function') + else + value = serpent.line(value) + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', value, '"}'}) + end + + raw_print(message) +end + +local function data_set_changed(data) + local handlers = data_set_handlers[data.data_set] + if handlers == nil then + return + end + + if _DEBUG then + for _, handler in ipairs(handlers) do + local success, err = pcall(handler, data) + if not success then + log(err) + error(err) + end + end + else + for _, handler in ipairs(handlers) do + local success, err = pcall(handler, data) + if not success then + log(err) + end + end + end +end + +function Public.on_data_set_changed(data_set, handler) + if type(data_set) ~= 'string' then + error('data_set must be a string') + end + + local handlers = data_set_handlers[data_set] + if handlers == nil then + handlers = {handler} + data_set_handlers[data_set] = handlers + else + table.insert(handlers, handler) + end +end + +Public.raise_data_set = data_set_changed + +function Public.get_tracked_data_sets() + local message = {data_tracked_tag, '['} + + for k, _ in pairs(data_set_handlers) do + table.insert(message, '"') + table.insert(message, k) + table.insert(message, '"') + table.insert(message, ',') + end + + if message[#message] == ',' then + table.remove(message) + end + + table.insert(message, ']') + + message = table.concat(message) + raw_print(message) + game.print(message) +end + return Public diff --git a/server_commands.lua b/server_commands.lua index ad00f363..7f47b95d 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -1,6 +1,7 @@ local Poll = require 'features.gui.poll' local UserGroups = require 'features.user_groups' local Token = require 'utils.global_token' +local Server = require 'server' local Public = {} @@ -17,4 +18,11 @@ function Public.raise_callback(func_token, data) func(data) end +Public.raise_data_set = Server.raise_data_set +Public.get_tracked_data_sets = Server.get_tracked_data_sets + +function Public.server_started() + script.raise_event(Server.events.on_server_started, {}) +end + return Public From 4e0f30db176ca8dbb109428b055b0ad880e09d02 Mon Sep 17 00:00:00 2001 From: grilledham Date: Sun, 25 Nov 2018 11:52:50 +0000 Subject: [PATCH 15/43] updates --- server.lua | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/server.lua b/server.lua index 25de18ca..beab6e51 100644 --- a/server.lua +++ b/server.lua @@ -135,15 +135,20 @@ function Public.set_data(data_set, key, value) message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '"}'}) elseif vt == 'string' then message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"\\"', value, '\\""}'}) - elseif vt == 'number' or vt == 'boolean' then + elseif vt == 'number' then message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', value, '"}'}) + elseif vt == 'boolean' then + message = + table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', tostring(value), '"}'}) elseif vt == 'function' then error('value cannot be a function') else value = serpent.line(value) - message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', value, '"}'}) + value = value:gsub("'", "\\'") + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, "\",value:'", value, "'}"}) end + game.print(message) raw_print(message) end @@ -208,4 +213,31 @@ function Public.get_tracked_data_sets() game.print(message) end +function Public.try_get_data(data_set, key, callback_token) + if type(data_set) ~= 'string' then + error('data_set must be a string') + end + if type(key) ~= 'string' then + error('key must be a string') + end + if type(callback_token) ~= 'number' then + error('callback_token must be a number') + end + + local message = table.concat {data_get_tag, callback_token, ' {', 'data_set:"', data_set, '",key:"', key, '"}'} + raw_print(message) +end + +function Public.try_get_all_data(data_set, callback_token) + if type(data_set) ~= 'string' then + error('data_set must be a string') + end + if type(callback_token) ~= 'number' then + error('callback_token must be a number') + end + + local message = table.concat {data_get_all_tag, callback_token, ' {', 'data_set:"', data_set, '"}'} + raw_print(message) +end + return Public From 7b42a7a5ee82b671d9f5e9132d9799db5558adb9 Mon Sep 17 00:00:00 2001 From: grilledham Date: Sun, 25 Nov 2018 19:18:51 +0000 Subject: [PATCH 16/43] updates --- control.lua | 15 +++++++++++++++ server.lua | 11 +++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/control.lua b/control.lua index cdc85681..329455c1 100644 --- a/control.lua +++ b/control.lua @@ -78,3 +78,18 @@ Event.add( print(serpent.block(tbl)) end ) + +local Token = require('utils.global_token') +local data_callback = Token.register( + function(data) + game.print(serpent.line(data)) + end +) + +function get_data(data_set, key) + Server.try_get_data(data_set, key, data_callback) +end + +function get_all_data(data_set, key) + Server.try_get_all_data(data_set, data_callback) +end diff --git a/server.lua b/server.lua index beab6e51..3dc979a1 100644 --- a/server.lua +++ b/server.lua @@ -134,6 +134,9 @@ function Public.set_data(data_set, key, value) if vt == 'nil' then message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '"}'}) elseif vt == 'string' then + -- Excessive escaping because the data is serialized twice. + value = value:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"\\"', value, '\\""}'}) elseif vt == 'number' then message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', value, '"}'}) @@ -142,9 +145,13 @@ function Public.set_data(data_set, key, value) table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', tostring(value), '"}'}) elseif vt == 'function' then error('value cannot be a function') - else + else -- table value = serpent.line(value) - value = value:gsub("'", "\\'") + + -- Less escaping than the string case as serpent provides one level of escaping. + -- Need to escape single quotes as serpent uses double quotes for strings. + value = value:gsub('\\', '\\\\'):gsub("'", "\\'") + message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, "\",value:'", value, "'}"}) end From 018675c9c4a7c75d38c8fa1adf361a6aad664ae1 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 11:44:27 +0000 Subject: [PATCH 17/43] user_groups to sync regulars with server --- features/user_groups.lua | 110 ++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 64 deletions(-) diff --git a/features/user_groups.lua b/features/user_groups.lua index 7c9005e5..8eb2f70c 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -2,84 +2,53 @@ local Event = require 'utils.event' local Utils = require 'utils.utils' local Server = require 'server' local Donators = require 'resources.donators' +local Game = require 'utils.game' +local Token = require 'utils.global_token' global.regulars = {} global.donators = Donators.donators global.donator_welcome_messages = {} -local Game = require 'utils.game' local Module = {} -local function update_file() - local data = {'{\n'} - for player_name, _ in pairs(global.regulars) do - table.insert(data, "['") - table.insert(data, player_name) - table.insert(data, "''] = true,\n") - end - table.insert(data, '}') - - game.write_file('regulars.lua', table.concat(data), false, 0) -end - Module.is_regular = function(player_name) return Utils.cast_bool(global.regulars[player_name] or global.regulars[player_name:lower()]) --to make it backwards compatible end -Module.add_regular = - function(player_name) +Module.add_regular = function(player_name) local actor = Utils.get_actor() - --[[ - if Module.is_regular(player_name) then + + if (Module.is_regular(player_name)) then Game.player_print(player_name .. ' is already a regular.') else - if game.players[player_name] then - player_name = game.players[player_name].name - game.print(actor .. ' promoted ' .. player_name .. ' to regular.') - global.regulars[player_name] = true - update_file() - else - Game.player_print(player_name .. ' does not exist.') - end - end ]] - global.regulars[player_name] = true - game.print(actor .. ' promoted ' .. player_name .. ' to regular.') - Server.regular_promote(player_name, actor) -end - -Module.remove_regular = - function(player_name) - local actor = Utils.get_actor() - --[[ if game.players[player_name] then - player_name = game.players[player_name].name - if Module.is_regular(player_name) then - game.print(player_name .. ' was demoted from regular by ' .. actor .. '.') - end - global.regulars[player_name] = nil - global.regulars[player_name:lower()] = nil --backwards compatible - update_file() - end ]] - global.regulars[player_name] = nil - game.print(player_name .. ' was demoted from regular by ' .. actor .. '.') - Server.regular_deomote(player_name, actor) -end - -function Module.server_add_regular(player_name) - global.regulars[player_name] = true -end - -function Module.server_remove_regular(player_name) - global.regulars[player_name] = nil -end - -function Module.sync_regulars(names) - local r = {} - for _, name in ipairs(names) do - r[name] = true + global.regulars[player_name] = true + Server.set_data('regulars', player_name, true) + game.print(actor .. ' promoted ' .. player_name .. ' to regular.') end +end - global.regulars = r +Module.remove_regular = function(player_name) + local actor = Utils.get_actor() + + if (Module.is_regular(player_name)) then + global.regulars[player_name] = nil + Server.set_data('regulars', player_name, nil) + game.print(player_name .. ' was demoted from regular by ' .. actor .. '.') + else + Game.player_print(player_name .. ' is not a regular.') + end +end + +local sync_regulars_callback = + Token.register( + function(data) + global.regulars = data.entries + end +) + +function Module.sync_regulars() + Server.try_get_all_data('regulars', sync_regulars_callback) end Module.print_regulars = function() @@ -152,11 +121,24 @@ Event.add( function(event) local correctCaseName = Game.get_player_by_index(event.player_index).name if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then - global.regulars[correctCaseName:lower()] = nil - global.regulars[correctCaseName] = true - update_file() + Server.set_data('regulars', correctCaseName:lower(), nil) + Server.set_data('regulars', correctCaseName, true) end end ) +Event.add( + Server.events.on_server_started, + function() + Module.sync_regulars() + end +) + +Server.on_data_set_changed( + 'regulars', + function(data) + global.regulars[data.key] = data.value + end +) + return Module From 69fa8309f0c5b3277999bfe50314b5230bfc19fb Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 11:44:35 +0000 Subject: [PATCH 18/43] updates --- control.lua | 59 ++++++++++++++++++++------------------------- server.lua | 69 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 66 insertions(+), 62 deletions(-) diff --git a/control.lua b/control.lua index 329455c1..585eb7f5 100644 --- a/control.lua +++ b/control.lua @@ -47,40 +47,9 @@ require 'features.gui.paint' require 'features.gui.score' require 'features.gui.popup' -Server.on_data_set_changed( - 'Test', - function(data) - game.print(serpent.block(data)) - end -) - -Server.on_data_set_changed( - 'Test 2', - function(data) - game.print(serpent.block(data)) - end -) - -Server.on_data_set_changed( - 'Test,2', - function(data) - game.print(serpent.block(data)) - end -) - -local Event = require('utils.event') -Event.add( - Server.events.on_server_started, - function(tbl) - game.print('on_server_started') - print('on_server_started') - game.print(serpent.block(tbl)) - print(serpent.block(tbl)) - end -) - local Token = require('utils.global_token') -local data_callback = Token.register( +local data_callback = + Token.register( function(data) game.print(serpent.line(data)) end @@ -93,3 +62,27 @@ end function get_all_data(data_set, key) Server.try_get_all_data(data_set, data_callback) end + +local Event = require('utils.event') +Event.add( + Server.events.on_server_started, + function(tbl) + game.print('on_server_started') + print('on_server_started') + game.print(serpent.block(tbl)) + print(serpent.block(tbl)) + + Server.try_get_all_data('webtest', data_callback) + end +) + +local data_token = + Token.register( + function(data) + global.data = data.entries + end +) + +function get_data_set(data_set) + Server.try_get_all_data(data_set, data_token) +end diff --git a/server.lua b/server.lua index 3dc979a1..d4a6312c 100644 --- a/server.lua +++ b/server.lua @@ -129,6 +129,9 @@ function Public.set_data(data_set, key, value) error('key must be a string') end + data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + key = key:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + local message local vt = type(value) if vt == 'nil' then @@ -155,7 +158,40 @@ function Public.set_data(data_set, key, value) message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, "\",value:'", value, "'}"}) end - game.print(message) + raw_print(message) +end + +function Public.try_get_data(data_set, key, callback_token) + if type(data_set) ~= 'string' then + error('data_set must be a string') + end + if type(key) ~= 'string' then + error('key must be a string') + end + if type(callback_token) ~= 'number' then + error('callback_token must be a number') + end + + -- Excessive escaping because the data is serialized twice. + data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + key = key:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + + local message = table.concat {data_get_tag, callback_token, ' {', 'data_set:"', data_set, '",key:"', key, '"}'} + raw_print(message) +end + +function Public.try_get_all_data(data_set, callback_token) + if type(data_set) ~= 'string' then + error('data_set must be a string') + end + if type(callback_token) ~= 'number' then + error('callback_token must be a number') + end + + -- Excessive escaping because the data is serialized twice. + data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + + local message = table.concat {data_get_all_tag, callback_token, ' {', 'data_set:"', data_set, '"}'} raw_print(message) end @@ -203,6 +239,9 @@ function Public.get_tracked_data_sets() local message = {data_tracked_tag, '['} for k, _ in pairs(data_set_handlers) do + -- Excessive escaping because the data is serialized twice. + k = k:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') + table.insert(message, '"') table.insert(message, k) table.insert(message, '"') @@ -217,34 +256,6 @@ function Public.get_tracked_data_sets() message = table.concat(message) raw_print(message) - game.print(message) -end - -function Public.try_get_data(data_set, key, callback_token) - if type(data_set) ~= 'string' then - error('data_set must be a string') - end - if type(key) ~= 'string' then - error('key must be a string') - end - if type(callback_token) ~= 'number' then - error('callback_token must be a number') - end - - local message = table.concat {data_get_tag, callback_token, ' {', 'data_set:"', data_set, '",key:"', key, '"}'} - raw_print(message) -end - -function Public.try_get_all_data(data_set, callback_token) - if type(data_set) ~= 'string' then - error('data_set must be a string') - end - if type(callback_token) ~= 'number' then - error('callback_token must be a number') - end - - local message = table.concat {data_get_all_tag, callback_token, ' {', 'data_set:"', data_set, '"}'} - raw_print(message) end return Public From 1332ad5a8d4d46bc6e1c19a1504e8cd450078396 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 26 Nov 2018 07:10:37 -0500 Subject: [PATCH 19/43] Move spawn control (#456) --- {features => map_gen/misc}/spawn_control.lua | 0 map_gen/presets/mobius_strip.lua | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {features => map_gen/misc}/spawn_control.lua (100%) diff --git a/features/spawn_control.lua b/map_gen/misc/spawn_control.lua similarity index 100% rename from features/spawn_control.lua rename to map_gen/misc/spawn_control.lua diff --git a/map_gen/presets/mobius_strip.lua b/map_gen/presets/mobius_strip.lua index ac66bd21..2513f689 100644 --- a/map_gen/presets/mobius_strip.lua +++ b/map_gen/presets/mobius_strip.lua @@ -105,7 +105,7 @@ end map = b.apply_effect(map, effect) -local Spawn_Control = require 'features.spawn_control' +local Spawn_Control = require 'map_gen.misc.spawn_control' Spawn_Control.add_spawn('left', -88, -88) Spawn_Control.add_spawn('right', 88, 88) From b5477034b72a4d04eac8fbe59961441da1d700cb Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 26 Nov 2018 07:11:26 -0500 Subject: [PATCH 20/43] Move infinite storage (#463) --- control.lua | 1 - {features => map_gen/misc}/infinite_storage_chest.lua | 0 map_layout.lua | 3 ++- 3 files changed, 2 insertions(+), 2 deletions(-) rename {features => map_gen/misc}/infinite_storage_chest.lua (100%) diff --git a/control.lua b/control.lua index e5cecb07..d41b1700 100644 --- a/control.lua +++ b/control.lua @@ -21,7 +21,6 @@ require 'features.donator_messages' require 'features.train_saviour' require 'features.fish_market' require 'features.free_item_logging' ---require 'features.infinite_storage_chest' require 'features.nuke_control' require 'features.player_colors' require 'features.reactor_meltdown' diff --git a/features/infinite_storage_chest.lua b/map_gen/misc/infinite_storage_chest.lua similarity index 100% rename from features/infinite_storage_chest.lua rename to map_gen/misc/infinite_storage_chest.lua diff --git a/map_layout.lua b/map_layout.lua index 1de4a7ef..f7a86434 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -139,7 +139,8 @@ local terrain_modules = { --require 'map_gen.misc.nightfall' --require 'map_gen.misc.creep_spread' --require 'map_gen.misc.car_body' ---require 'features.silly_player_names' +--require 'map_gen.misc.silly_player_names' +--require 'map_gen.misc.infinite_storage_chest' if #entity_modules > 0 then shape = shape or b.full_shape From 6697f4cb9935e29342be7668612930110e67419a Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 26 Nov 2018 07:11:38 -0500 Subject: [PATCH 21/43] Delete features/silly_player_names.lua -- fixes 508f75c4b9c41b394e7063d8ccec00c18a472826 (#462) --- features/silly_player_names.lua | 159 -------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 features/silly_player_names.lua diff --git a/features/silly_player_names.lua b/features/silly_player_names.lua deleted file mode 100644 index 1ee1c187..00000000 --- a/features/silly_player_names.lua +++ /dev/null @@ -1,159 +0,0 @@ -require 'utils.list_utils' -local Game = require 'utils.game' -local Event = require 'utils.event' -local naming_words = require 'resources.naming_words' -local Utils = require('utils.utils') -global.actual_name = {} -global.silly_names = {} -global.silly_names.count = 0 - -local name_combinations = #naming_words.adverbs * #naming_words.adjectives * #naming_words.nouns - ---- Creates name by combining elements from the passed table --- @param1 table including adverbs, adjectives, and nouns --- @returns name as a string -local function create_name(words_table) - local adverb, adjective, noun - adverb = table.get_random(words_table.adverbs) - adjective = table.get_random(words_table.adjectives) - noun = table.get_random(words_table.nouns) - return adverb .. '_' .. adjective .. '_' .. noun -end - ---- Calls create_name until a unique name is returned --- @param1 table including adverbs, adjectives, and nouns --- @returns name as a string -local function create_unique_name(words_table) - local silly_names = global.silly_names - local name = create_name(words_table) - - while table.contains(silly_names, name) do - name = create_name(words_table) - end - return name -end - ---- Assigns a player a name, stores their old and silly names --- @param1 Takes a LuaPlayer -local function name_player(player) - -- Store a player's original name in case they want it back. - if not global.actual_name[player.index] then - global.actual_name[player.index] = player.name - end - - -- Because create_unique_name enters a while loop looking for a unique name, ensure we never get stuck. - local ceiling = math.min(name_combinations * 0.25, 10000) - if global.silly_names.count > ceiling then - global.silly_names = {} - global.silly_names.count = 0 - end - - local name = create_unique_name(naming_words) - - table.insert(global.silly_names, name) - global.silly_names.count = global.silly_names.count + 1 - local str = player.name .. ' will now be known as: ' .. name - game.print(str) - Utils.print_admins(str .. ' (ID: ' .. player.index .. ')', false) - player.name = name -end - ---- Restores a player's actual name -local function restore_name(cmd) - local player = Game.get_player_by_index(cmd.player_index) - player.name = global.actual_name[player.index] - player.print('Your true name has been restored.') -end - ---- Passes _event_ on to name_players -local function name_player_event(event) - local player = Game.get_player_by_index(event.player_index) - name_player(player) -end - ---- Passes target or player on to name_players -local function name_player_command(cmd) - local player = game.player - local param = cmd.parameter - local target - - if param then - target = game.players[param] - if player and not player.admin then - -- Yes param, yes player, no admin/server = fail, non-admins, non-server cannot use command on others - Game.player_print("Sorry you don't have permission to use the roll-name command on other players.") - return - else - -- Yes param, yes admin/server = check target - if target then - -- Yes param, yes admin/server, yes target = change name - name_player(target) - return - else - -- Yes param, yes admin/server, no target = fail, wrong player name - Game.player_print(table.concat {"Sorry, player '", param, "' was not found."}) - return - end - end - else - -- No param = check if server - if not player then - -- No param, no player = server trying to change its name - Game.player_print('The server cannot change its name') - return - end - -- No param, not server = change self name - name_player(player) - return - end -end - ---- Prints the original name of the target -local function check_name(cmd) - local current_name = cmd.parameter - if not current_name then - Game.player_print('Usage: /name-check ') - return - end - - local target = game.players[current_name] - if not target then - Game.player_print('player ' .. current_name .. ' not found') - return - end - - local actual_name = global.actual_name[target.index] - Game.player_print(target.name .. ' is actually: ' .. actual_name) -end - ---- Prints the index of the target -local function get_player_id(cmd) - local player = game.player - -- Check if the player can run the command - if player and not player.admin then - Utils.cant_run(cmd.name) - return - end - -- Check if the target is valid - local target_name = cmd['parameter'] - if not target_name then - Game.player_print('Usage: /get-player-id ') - return - end - local target_index = game.players[target_name].index - Game.player_print(target_name .. ' -- ' .. target_index) -end - -if global.scenario.config.players_assigned_names == true then - Event.add(defines.events.on_player_created, name_player_event) -end - -if global.scenario.config.players_roll_names == true then - commands.add_command('name-roll', 'Assigns you a random, silly name', name_player_command) -end - -if global.scenario.config.players_roll_names == true or global.scenario.config.players_assigned_names == true then - commands.add_command('name-restore', 'Removes your fun name and gives you back your actual name', restore_name) - commands.add_command('name-check', ' Check the original name of a player', check_name) - commands.add_command('get-player-id', 'Gets the ID of a player (Admin only)', get_player_id) -end From 218f53da83247424323709be0743bed1b7e1f8e9 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 12:40:38 +0000 Subject: [PATCH 22/43] fixed donator_messages --- features/donator_messages.lua | 4 +-- features/user_groups.lua | 58 ++++++++++++++++++++++------------- resources/donators.lua | 57 +++++++++++++++++----------------- 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/features/donator_messages.lua b/features/donator_messages.lua index 288448ed..42e9bf43 100644 --- a/features/donator_messages.lua +++ b/features/donator_messages.lua @@ -1,6 +1,6 @@ local Game = require 'utils.game' local Event = require 'utils.event' -local Donators = require 'resources.donators' +local UserGroups = require 'features.user_groups' local function player_joined(event) local player = Game.get_player_by_index(event.player_index) @@ -8,7 +8,7 @@ local function player_joined(event) return end - local message = Donators.welcome_messages[player.name] + local message = UserGroups.get_donator_welcome_message(player.name) if not message then return end diff --git a/features/user_groups.lua b/features/user_groups.lua index 8eb2f70c..d93ee1f4 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -7,7 +7,6 @@ local Token = require 'utils.global_token' global.regulars = {} global.donators = Donators.donators -global.donator_welcome_messages = {} local Module = {} @@ -72,7 +71,7 @@ function Module.get_rank(player) end function Module.is_donator(player_name) - return global.donators[player_name] + return global.donators[player_name] ~= nil end function Module.player_has_donator_perk(player_name, perk_flag) @@ -81,38 +80,47 @@ function Module.player_has_donator_perk(player_name, perk_flag) return false end - return bit32.band(d, perk_flag) == perk_flag + local flags = d.perk_flags + if not flags then + return false + end + + return bit32.band(flags, perk_flag) == perk_flag end function Module.get_donator_welcome_message(player_name) - return global.donator_welcome_messages[player_name] + local d = global.donators[player_name] + if not d then + return nil + end + + return d.welcome_messages end -function Module.set_donator(player_name, perks) - global.donators[player_name] = perks - Server.donator_set(player_name, perks) +function Module.set_donator(player_name, data) + global.donators[player_name] = data + Server.set_data('donators', player_name, data) end -function Module.sync_donators(donators, messages) - global.donators = donators - global.donator_welcome_messages = messages -end +local sync_donators_callback = + Token.register( + function(data) + global.donators = data.entries + end +) -function Module.server_set_donator(player_name, perks) - global.donators[player_name] = perks +function Module.sync_donators() + Server.try_get_all_data('donators', sync_donators_callback) end function Module.print_donators() local result = {} - for k, v in pairs(global.donators) do - table.insert(result, k) - table.insert(result, ' : ') - table.insert(result, v) - table.insert(result, ', ') - end - table.remove(result) - result = table.concat(result) + for k, _ in pairs(global.donators) do + table.insert(result, k) + end + + result = table.concat(result, ', ') game.print(result) end @@ -131,6 +139,7 @@ Event.add( Server.events.on_server_started, function() Module.sync_regulars() + Module.sync_donators() end ) @@ -141,4 +150,11 @@ Server.on_data_set_changed( end ) +Server.on_data_set_changed( + 'donators', + function(data) + global.donators[data.key] = data.value + end +) + return Module diff --git a/resources/donators.lua b/resources/donators.lua index e41adb35..df6e6d2e 100644 --- a/resources/donators.lua +++ b/resources/donators.lua @@ -7,33 +7,32 @@ Module.donator_perk_flags = { local d = Module.donator_perk_flags -Module.donators = { - ['aldldl'] = d.rank, - ['Geostyx'] = d.rank, - ['Linaori'] = d.rank, - ['Xertez'] = d.rank, - ['Chevalier1200'] = d.rank + d.train, - ['DraugTheWhopper'] = d.rank + d.train, - ['der-dave.com'] = d.rank + d.train, - ['Jayefuu'] = d.rank, - ['Valansch'] = d.rank, - ['plague006'] = d.rank, - ['chromaddict'] = d.rank, - ['InphinitePhractals'] = d.rank + d.train, - ['shoghicp'] = d.rank + d.train, - ['DuelleuD'] = d.rank + d.train, - ['henrycn1997'] = d.rank + d.train, - ['Raiguard'] = d.rank + d.train, -} - -Module.welcome_messages = { - ['Linaori'] = 'I present to you Linaori of house Refactorio, Lady of the Void, Remover of Spaghetti, Queen of the Endless Nauvis, Breaker of Biters and Mother of Code!', - ['Valansch'] = 'Welcome Valansch, .', - ['der-dave.com'] = "Dave doesn't want a welcome message.", - ['plague006'] = 'plague wrote this dumb message you have to read. If you want your own dumb on-join message be sure to donate on Patreon!', - ['shoghicp'] = 'Need more servers!', - ['aldldl'] = "ALo's Here", - ['Raiguard'] = "I am... was... God. The one you call 'The Almighty'. The creator of Factories. But now, I am dead. The Biters killed me. I am sorry.", -} - +Module.donators = {} +--[[ { + ['aldldl'] = {perk_flags = d.rank, welcome_messages = "ALo's Here"}, + ['Geostyx'] = {perk_flags = d.rank}, + ['Linaori'] = { + perk_flags = d.rank, + welcome_messages = 'I present to you Linaori of house Refactorio, Lady of the Void, Remover of Spaghetti, Queen of the Endless Nauvis, Breaker of Biters and Mother of Code!' + }, + ['Xertez'] = {perk_flags = d.rank}, + ['Chevalier1200'] = {perk_flags = d.rank + d.train}, + ['DraugTheWhopper'] = {perk_flags = d.rank + d.train}, + ['der-dave.com'] = {perk_flags = d.rank + d.train, welcome_messages = "Dave doesn't want a welcome message."}, + ['Jayefuu'] = {perk_flags = d.rank}, + ['Valansch'] = {perk_flags = d.rank, welcome_messages = 'Welcome Valansch, .'}, + ['plague006'] = { + perk_flags = d.rank, + welcome_messages = 'plague wrote this dumb message you have to read. If you want your own dumb on-join message be sure to donate on Patreon!' + }, + ['chromaddict'] = {perk_flags = d.rank}, + ['InphinitePhractals'] = {perk_flags = d.rank + d.train}, + ['shoghicp'] = {perk_flags = d.rank + d.train, welcome_messages = 'Need more servers!'}, + ['DuelleuD'] = {perk_flags = d.rank + d.train}, + ['henrycn1997'] = {perk_flags = d.rank + d.train}, + ['Raiguard'] = { + perk_flags = d.rank + d.train, + welcome_messages = "I am... was... God. The one you call 'The Almighty'. The creator of Factories. But now, I am dead. The Biters killed me. I am sorry." + } +} ]] return Module From 13408d329a7b7c4437d2f68d5d164048f2d872f8 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 16:06:52 +0000 Subject: [PATCH 23/43] removed donators and regulars from the scenario --- resources/donators.lua | 30 +- resources/regulars.lua | 1130 ---------------------------------------- 2 files changed, 1 insertion(+), 1159 deletions(-) delete mode 100644 resources/regulars.lua diff --git a/resources/donators.lua b/resources/donators.lua index df6e6d2e..d4f21687 100644 --- a/resources/donators.lua +++ b/resources/donators.lua @@ -5,34 +5,6 @@ Module.donator_perk_flags = { train = 0x2 } -local d = Module.donator_perk_flags - Module.donators = {} ---[[ { - ['aldldl'] = {perk_flags = d.rank, welcome_messages = "ALo's Here"}, - ['Geostyx'] = {perk_flags = d.rank}, - ['Linaori'] = { - perk_flags = d.rank, - welcome_messages = 'I present to you Linaori of house Refactorio, Lady of the Void, Remover of Spaghetti, Queen of the Endless Nauvis, Breaker of Biters and Mother of Code!' - }, - ['Xertez'] = {perk_flags = d.rank}, - ['Chevalier1200'] = {perk_flags = d.rank + d.train}, - ['DraugTheWhopper'] = {perk_flags = d.rank + d.train}, - ['der-dave.com'] = {perk_flags = d.rank + d.train, welcome_messages = "Dave doesn't want a welcome message."}, - ['Jayefuu'] = {perk_flags = d.rank}, - ['Valansch'] = {perk_flags = d.rank, welcome_messages = 'Welcome Valansch, .'}, - ['plague006'] = { - perk_flags = d.rank, - welcome_messages = 'plague wrote this dumb message you have to read. If you want your own dumb on-join message be sure to donate on Patreon!' - }, - ['chromaddict'] = {perk_flags = d.rank}, - ['InphinitePhractals'] = {perk_flags = d.rank + d.train}, - ['shoghicp'] = {perk_flags = d.rank + d.train, welcome_messages = 'Need more servers!'}, - ['DuelleuD'] = {perk_flags = d.rank + d.train}, - ['henrycn1997'] = {perk_flags = d.rank + d.train}, - ['Raiguard'] = { - perk_flags = d.rank + d.train, - welcome_messages = "I am... was... God. The one you call 'The Almighty'. The creator of Factories. But now, I am dead. The Biters killed me. I am sorry." - } -} ]] + return Module diff --git a/resources/regulars.lua b/resources/regulars.lua deleted file mode 100644 index 8de4cd03..00000000 --- a/resources/regulars.lua +++ /dev/null @@ -1,1130 +0,0 @@ -return { - ["Aliiien0110"] = true, - ["Altech"] = true, - ["Angus100"] = true, - ["Animal"] = true, - ["Atoms"] = true, - ["Bazul"] = true, - ["Bemm"] = true, - ["Chunhung"] = true, - ["CmdrRat"] = true, - ["Copperbotte"] = true, - ["Drlloyd1337"] = true, - ["Factorian12321"] = true, - ["Fire3231"] = true, - ["Gizan"] = true, - ["Gotze"] = true, - ["Haribo112"] = true, - ["HighInFiberOptics"] = true, - ["JinNJuice"] = true, - ["Kyte"] = true, - ["Maniah"] = true, - ["Mariocraft2001"] = true, - ["Namelesshunter"] = true, - ["NbITUK"] = true, - ["Newcott"] = true, - ["Nexarius"] = true, - ["PogomanD"] = true, - ["Ralp"] = true, - ["Redcrafter100"] = true, - ["Ruslan_kc"] = true, - ["Sangria_louie"] = true, - ["Sholvo"] = true, - ["SimonFlapse"] = true, - ["TheElvenGamer"] = true, - ["TheOrangeAngle"] = true, - ["TheThane"] = true, - ["Tommy17"] = true, - ["VERBUGA"] = true, - ["Zehir"] = true, - ["ZjosH"] = true, - ["_Joe_"] = true, - ["aalexx"] = true, - ["acolyteofcthulu"] = true, - ["adidas"] = true, - ["adlmr"] = true, - ["adobewallhacks"] = true, - ["ajdiller88"] = true, - ["alvinmj"] = true, - ["ansible32"] = true, - ["aplavins"] = true, - ["argetlam_elda"] = true, - ["arnietom"] = true, - ["assemblystorm"] = true, - ["b4x"] = true, - ["ballbuster"] = true, - ["banakeg"] = true, - ["barnaba"] = true, - ["baronting"] = true, - ["bhenoa"] = true, - ["bigglesthepirate"] = true, - ["bighamster"] = true, - ["binzerle"] = true, - ["bissi"] = true, - ["bjhunter"] = true, - ["bloodydevil"] = true, - ["blzz"] = true, - ["boail"] = true, - ["bobbje"] = true, - ["bobucles"] = true, - ["brainclot"] = true, - ["brftjx"] = true, - ["brikir"] = true, - ["brl_chacal"] = true, - ["bufferoverflow"] = true, - ["ccaspanello"] = true, - ["cchpucky"] = true, - ["chessindustries"] = true, - ["chukles"] = true, - ["circit"] = true, - ["cogito123"] = true, - ["collin08"] = true, - ["coogan"] = true, - ["cool"] = true, - ["cpaca0"] = true, - ["cpenguinred"] = true, - ["craigrood"] = true, - ["crusher_sut"] = true, - ["cybernoise"] = true, - ["cydes"] = true, - ["damian0816"] = true, - ["davoud"] = true, - ["delta124"] = true, - ["derdu"] = true, - ["df1229"] = true, - ["dmaonk"] = true, - ["dpoba"] = true, - ["ducktaperules"] = true, - ["eaglesight"] = true, - ["eithel"] = true, - ["empirebuilder1"] = true, - ["esperiom"] = true, - ["everlord"] = true, - ["exp11235"] = true, - ["extraxyz"] = true, - ["fana13"] = true, - ["fish"] = true, - ["flowild"] = true, - ["franc_ist"] = true, - ["fremiamagus"] = true, - ["frissi"] = true, - ["fuzz_pucker"] = true, - ["g-h-o-s-t"] = true, - ["geckozila"] = true, - ["gespenstdermaschine"] = true, - ["grahamm"] = true, - ["grandstore256"] = true, - ["griffinonetwo"] = true, - ["ground_walker"] = true, - ["gynox"] = true, - ["hackguy"] = true, - ["hazelnuthead"] = true, - ["heardofsnails"] = true, - ["heaser"] = true, - ["helpower2"] = true, - ["hunter117x"] = true, - ["i-make-robots"] = true, - ["iexyi"] = true, - ["inator1192"] = true, - ["ireasonless1"] = true, - ["jbc363"] = true, - ["jbev2"] = true, - ["jedifan"] = true, - ["jinnjuice"] = true, - ["joe32"] = true, - ["jono777"] = true, - ["judaires"] = true, - ["junhinhow"] = true, - ["kaig3n"] = true, - ["kev007"] = true, - ["kevinma"] = true, - ["kidflash"] = true, - ["koretego"] = true, - ["kostrahb"] = true, - ["leadhades27"] = true, - ["lejnel"] = true, - ["leviculus"] = true, - ["li7ro"] = true, - ["lillepallt"] = true, - ["lord_kill"] = true, - ["lordxleasy"] = true, - ["luk4kasz"] = true, - ["lunastarwarp"] = true, - ["m_m0"] = true, - ["mafisch3"] = true, - ["marckhardt"] = true, - ["markupolioncz"] = true, - ["marucan"] = true, - ["mauerstein10"] = true, - ["maximuskylus"] = true, - ["maxthespunkymunk"] = true, - ["mcschnee"] = true, - ["medival3"] = true, - ["merssedes"] = true, - ["mh"] = true, - ["mithril_ryder"] = true, - ["mrkoss"] = true, - ["mrsjaakbraak"] = true, - ["nbituk"] = true, - ["neumond"] = true, - ["nibu"] = true, - ["ninjrkillr"] = true, - ["noodletrains"] = true, - ["olexn"] = true, - ["oliveawesomesauz"] = true, - ["palulukan"] = true, - ["passepartout911"] = true, - ["petebra11"] = true, - ["pfg"] = true, - ["philip017"] = true, - ["phountix"] = true, - ["pietloke"] = true, - ["pilypas"] = true, - ["pirion"] = true, - ["procrastinator_diedz"] = true, - ["rafaelvalim"] = true, - ["rascher"] = true, - ["rayijin"] = true, - ["redlabel"] = true, - ["rhobes"] = true, - ["rickeyhb"] = true, - ["rico2403"] = true, - ["rikkert"] = true, - ["rlidwka"] = true, - ["rododendro"] = true, - ["rorror"] = true, - ["rulerofdabacon"] = true, - ["saltlands"] = true, - ["samy_the_samy"] = true, - ["saneman"] = true, - ["selen"] = true, - ["sergeant_steve"] = true, - ["settdigger"] = true, - ["sharpshot2566"] = true, - ["shimmshamm"] = true, - ["sir"] = true, - ["skilledspacepolice"] = true, - ["skykittena"] = true, - ["sl"] = true, - ["slastraf"] = true, - ["snerktk"] = true, - ["sonopard"] = true, - ["sovietdefender"] = true, - ["spatbee"] = true, - ["stat0x00"] = true, - ["steponitnicejob"] = true, - ["stig219"] = true, - ["struppi"] = true, - ["tarpon907"] = true, - ["teondar"] = true, - ["yago2003"] = true, - ["zacman0510"] = true, - ["zila"] = true, - ["zoigo"] = true, - ["Beriev"] = true, - ["Zalmozis"] = true, - ["Farcear"] = true, - ["WD_STEVE2"] = true, - ["erezd"] = true, - ["Rhamuk"] = true, - ["Patton1918"] = true, - ["Zaen"] = true, - ["Kingdud"] = true, - ["Admiral_Ackweed"] = true, - ["StormySkies"] = true, - ["Wadiyatalkinbeet"] = true, - ["megamega"] = true, - ["ZTX"] = true, - ["eiis1000"] = true, - ["UTIDI"] = true, - ["XATEV"] = true, - ["Robobrine"] = true, - ["Rakeplay"] = true, - ["Lucas16"] = true, - ["Factorioio"] = true, - ["VikingCyborg"] = true, - ["Caps_errors"] = true, - ["usgundertaker"] = true, - ["GeneralB.97"] = true, - ["Spechok"] = true, - ["emailkanji"] = true, - ["StarLite"] = true, - ["Velguarder"] = true, - ["VIRUSgamesplay"] = true, - ["fenderpuddy"] = true, - ["DQ_Shell"] = true, - ["JoeGames00"] = true, - ["Sholax"] = true, - ["Darian007"] = true, - ["EmptyRov"] = true, - ["sanders80"] = true, - ["dazonker"] = true, - ["andrewy2k"] = true, - ["DarkRedman"] = true, - ["Builder101"] = true, - ["StandaardStefan"] = true, - ["Liutio"] = true, - ["actorpuss"] = true, - ["TeZwo"] = true, - ["Furancebob"] = true, - ["NathanG"] = true, - ["Jayefuu"] = true, - ["VincentMonster"] = true, - ["Marcuss2"] = true, - ["Some_meme"] = true, - ["Ralozey"] = true, - ["Azer"] = true, - ["ruetama"] = true, - ["invincibl_"] = true, - ["TWLTriston"] = true, - ["GerMic"] = true, - ["ausmister"] = true, - ["rimbas"] = true, - ["ManuelG"] = true, - ["vvictor"] = true, - ["zellking"] = true, - ["GhostThunder"] = true, - ["Melduron"] = true, - ["musa3299"] = true, - ["puycss"] = true, - ["Aronak"] = true, - ["Brathahn"] = true, - ["Bryce940"] = true, - ["kuumottaja"] = true, - ["DrunkBoxer"] = true, - ["Bobbuilder2222d"] = true, - ["tbell91"] = true, - ["Progman"] = true, - ["Andreas133"] = true, - ["Jaertof"] = true, - ["hsxu"] = true, - ["ponderer1"] = true, - ["lone-pine"] = true, - ["LevyTaxes"] = true, - ["50fffff"] = true, - ["Flashbacks"] = true, - ["MrTrainCow"] = true, - ["Akhrem"] = true, - ["YAMATO_Hajime"] = true, - ["Jimarad"] = true, - ["Aerost"] = true, - ["doubleh2"] = true, - ["pY4x3g"] = true, - ["murph_murph"] = true, - ["Epresba"] = true, - ["Paul1998"] = true, - ["TBob"] = true, - ["balintbcs"] = true, - ["Mike-_-"] = true, - ["mexicanninja"] = true, - ["StormMA"] = true, - ["Heretek"] = true, - ["robertkruijt"] = true, - ["Rebel_NL"] = true, - ["saluchru"] = true, - ["flyingARMADILDO"] = true, - ["chicki2"] = true, - ["porelos"] = true, - ["Gundex"] = true, - ["Hyrkoon"] = true, - ["benw91ne"] = true, - ["lintaba"] = true, - ["Morgan3rd"] = true, - ["vlexoo"] = true, - ["Chevalier1200"] = true, - ["Havelyn"] = true, - ["Snowpig7u"] = true, - ["Ynotimagine740"] = true, - ["LupiGaming"] = true, - ["HeyDeath360"] = true, - ["Margin_of_Error"] = true, - ["Chyza"] = true, - ["themostinternet"] = true, - ["Triyan"] = true, - ["plague006"] = true, - ["Corlin"] = true, - ["Schidnsepp"] = true, - ["Trolzrus"] = true, - ["VintageAura"] = true, - ["Recoilless"] = true, - ["SpaceCat-Chan"] = true, - ["Leon55"] = true, - ["tazzyflame"] = true, - ["zbirka"] = true, - ["sadist_hun"] = true, - ["sellarsarem"] = true, - ["tiesvrielink"] = true, - ["elahrairah"] = true, - ["pobiega"] = true, - ["Mr.AsianEngineer"] = true, - ["NekoBaron"] = true, - ["Pallando"] = true, - ["RedDagger"] = true, - ["Sbarando"] = true, - ["pixel-perfect"] = true, - ["Aldnoah5566"] = true, - ["LynDone"] = true, - ["PTP17"] = true, - ["Jouster"] = true, - ["Igie"] = true, - ["Bunchofrocks"] = true, - ["Mattyk87"] = true, - ["Vinerr"] = true, - ["mastah_mind"] = true, - ["Empire232"] = true, - ["Sigma1"] = true, - ["NoGames"] = true, - ["WeirdWhirl"] = true, - ["qlimax93"] = true, - ["soporis"] = true, - ["vedolv"] = true, - ["JonathanAtis"] = true, - ["SmotPokin42000"] = true, - ["Theysaywhatnow"] = true, - ["SwampD0nkey"] = true, - ["Anubi5"] = true, - ["Slas"] = true, - ["McTheDerp"] = true, - ["qwert33"] = true, - ["UA-IX"] = true, - ["Janakas"] = true, - ["Grooohm"] = true, - ["oafthor"] = true, - ["exbboi"] = true, - ["ClassAction"] = true, - ["Zhukovo"] = true, - ["Wolve"] = true, - ["liltaco"] = true, - ["BenSeidel"] = true, - ["kriskill000"] = true, - ["DUDv2"] = true, - ["Peterie"] = true, - ["Tomza"] = true, - ["DoITCreative"] = true, - ["Aspin"] = true, - ["samrrr"] = true, - ["johnm4jc"] = true, - ["Shinhan"] = true, - ["MINIMAN10000"] = true, - ["Latty319"] = true, - ["DoubleDough"] = true, - ["Jenus358"] = true, - ["redkyleb"] = true, - ["RAV416steam"] = true, - ["killer111995"] = true, - ["ichvii"] = true, - ["Artman40"] = true, - ["Arti20"] = true, - ["larshp"] = true, - ["Tafonath"] = true, - ["Zwulf"] = true, - ["ajicurry"] = true, - ["boksiora"] = true, - ["matthew1206"] = true, - ["improvshark"] = true, - ["cedrik1995"] = true, - ["kova66"] = true, - ["TonyTroll"] = true, - ["Amuxix"] = true, - ["360cow"] = true, - ["MangaFairy"] = true, - ["innocen3"] = true, - ["maxflo13"] = true, - ["Arizon"] = true, - ["CrisBK"] = true, - ["podolskydmitr"] = true, - ["RM8"] = true, - ["the1ultimate-t1u"] = true, - ["keita_wi"] = true, - ["Paulot"] = true, - ["Rados"] = true, - ["Sephir"] = true, - ["snowbranch"] = true, - ["ExError"] = true, - ["Outlay"] = true, - ["BigDaddyBongDong"] = true, - ["Mjau"] = true, - ["mobieh22"] = true, - ["zoomy500"] = true, - ["Preizhour"] = true, - ["hasannuh"] = true, - ["Apologet"] = true, - ["viceroypenguin"] = true, - ["Rufa"] = true, - ["nekonyan"] = true, - ["SnowDrifter"] = true, - ["brockmasters"] = true, - ["monkee"] = true, - ["blacksunshine693"] = true, - ["Claude47"] = true, - ["Winged_Shade"] = true, - ["NWABroseidon"] = true, - ["Lusquifer"] = true, - ["Cruelcoder"] = true, - ["Unrealrules"] = true, - ["Lithidoria"] = true, - ["LordElmi"] = true, - ["Kane.Nexus"] = true, - ["OmegaLunch"] = true, - ["korokoroneruneru"] = true, - ["Krengrus"] = true, - ["Rinncar72"] = true, - ["Patti2507"] = true, - ["f198904011"] = true, - ["BTG"] = true, - ["SwaggerC4"] = true, - ["biohaze"] = true, - ["SMikiS"] = true, - ["sejyoo"] = true, - ["Askiph"] = true, - ["undefinable"] = true, - ["snapboogie"] = true, - ["Wesoly1234"] = true, - ["benzoni"] = true, - ["Verlioka"] = true, - ["Ran_Mw"] = true, - ["SPARKZ102"] = true, - ["slowcrazy54"] = true, - ["adam1285"] = true, - ["Breadnought"] = true, - ["Bluev0"] = true, - ["LeCobalt"] = true, - ["Lavacreeper2000"] = true, - ["manowscar1990"] = true, - ["Cytrox"] = true, - ["arty714"] = true, - ["DrkgoonXV"] = true, - ["Roxmuhr"] = true, - ["Asddsa76"] = true, - ["bunny232"] = true, - ["D_Riv"] = true, - ["anonymous12123"] = true, - ["AmarthZ"] = true, - ["numberoverzero"] = true, - ["maxim67899"] = true, - ["sklipnoty"] = true, - ["ThatTallNerd"] = true, - ["Presbo"] = true, - ["Renny"] = true, - ["CapitanSky"] = true, - ["Multifunktionsmixer"] = true, - ["AndreyZakharov"] = true, - ["Ardordo"] = true, - ["CallMeTaste"] = true, - ["Dagol"] = true, - ["Eloras"] = true, - ["Fakamantina"] = true, - ["IEXYI"] = true, - ["Kapy"] = true, - ["Lulaidon"] = true, - ["MrJimmyPenguin"] = true, - ["Nick_Nitro"] = true, - ["Piewdennis"] = true, - ["RattenEros"] = true, - ["Sergeant_Steve"] = true, - ["Spaceballs"] = true, - ["Terarink"] = true, - ["TheWearyGamer"] = true, - ["Thuro"] = true, - ["Whouser"] = true, - ["YMan"] = true, - ["aceforg"] = true, - ["cocoilove"] = true, - ["kvdango"] = true, - ["mikanor99"] = true, - ["ralphmace"] = true, - ["rantell"] = true, - ["real_scnerd"] = true, - ["settan"] = true, - ["thislsamerica"] = true, - ["vesorakia"] = true, - ["wavethrash"] = true, - ["xjohnson"] = true, - ["Ryix"] = true, - ["Mylon"] = true, - ["Terminutter"] = true, - ["Hafgrim"] = true, - ["l3igspeck"] = true, - ["lyman"] = true, - ["zsintai1987"] = true, - ["xubos"] = true, - ["Elsa-Zhou"] = true, - ["SirBlubbalot"] = true, - ["bulb5"] = true, - ["fellan03"] = true, - ["Irx99"] = true, - ["Spocks"] = true, - ["OmniMancer"] = true, - ["TfGuy44"] = true, - ["Krul"] = true, - ["moncada"] = true, - ["Wr1190"] = true, - ["Phoenix27833"] = true, - ["reddutton"] = true, - ["4yDo"] = true, - ["jpszat"] = true, - ["DaHolli"] = true, - ["Blaster"] = true, - ["BluJester"] = true, - ["thisisjack"] = true, - ["Appadeia"] = true, - ["Scuideie-Guy"] = true, - ["drakferion"] = true, - ["thelegendxp"] = true, - ["SteelMK"] = true, - ["Marviniusus"] = true, - ["FrostDestructor"] = true, - ["Gorganus"] = true, - ["Sirnumnum"] = true, - ["telefrog"] = true, - ["wrex82"] = true, - ["fce2"] = true, - ["wampastompa09"] = true, - ["Magic"] = true, - ["ReinekeWF"] = true, - ["JokerOfTheZ"] = true, - ["DOSorDIE"] = true, - ["i9962784"] = true, - ["Shotch"] = true, - ["Hyp3rX"] = true, - ["Didalus"] = true, - ["Olekplane1"] = true, - ["FuryZ"] = true, - ["Upsidedowneye"] = true, - ["LegionMammal978"] = true, - ["judos"] = true, - ["blyck"] = true, - ["MrPiols"] = true, - ["necdet"] = true, - ["penguincc3"] = true, - ["Monkfish"] = true, - ["catalist"] = true, - ["DarkQuantum"] = true, - ["TCP"] = true, - ["Cheeselicker"] = true, - ["Bulkje"] = true, - ["bkerlin"] = true, - ["Altafen"] = true, - ["mar123322"] = true, - ["Zijkhal"] = true, - ["aldldl"] = true, - ["Cooldude2606"] = true, - ["jeemchan"] = true, - ["Patrickle"] = true, - ["eZethNesthrown"] = true, - ["nathanweir"] = true, - ["Novikov"] = true, - ["GoatWizard"] = true, - ["fargas"] = true, - ["wot_tak"] = true, - ["FullFruntall"] = true, - ["strangeloveb52"] = true, - ["Snyp"] = true, - ["arron"] = true, - ["UKWoody"] = true, - ["Schallfalke"] = true, - ["Avelix"] = true, - ["Dichromium"] = true, - ["Dimava"] = true, - ["fantasychef"] = true, - ["siniidrooq"] = true, - ["Harmlessbeltbot"] = true, - ["Meddleman"] = true, - ["hamsterking5"] = true, - ["hasuthika"] = true, - ["wflagg"] = true, - ["abnoeh"] = true, - ["Mimiick"] = true, - ["Default_Sound"] = true, - ["eyemint"] = true, - ["Shaun_das_Schaf"] = true, - ["Fynko"] = true, - ["Apolomir"] = true, - ["Tomy52499"] = true, - ["Coyote101"] = true, - ["safriq"] = true, - ["Collider"] = true, - ["pietruszka123"] = true, - ["DylanJohn129"] = true, - ["MafungoLoud"] = true, - ["inetknght"] = true, - ["Tharax"] = true, - ["Fexx"] = true, - ["kaimix"] = true, - ["mayhem162"] = true, - ["longshot162"] = true, - ["Truenkan"] = true, - ["sonliviy"] = true, - ["squish8294"] = true, - ["Endzone"] = true, - ["Tomymy"] = true, - ["warriordragon25"] = true, - ["mph703"] = true, - ["cqd123123"] = true, - ["benitomakefactory"] = true, - ["Stokmeister"] = true, - ["zookham"] = true, - ["Albombe"] = true, - ["Kushlord"] = true, - ["ActitisHypoleucos"] = true, - ["strutter18"] = true, - ["Minifinger"] = true, - ["Hurley93"] = true, - ["henrycn1997"] = true, - ["iop77"] = true, - ["Hayse"] = true, - ["jasoncubed132"] = true, - ["Farglon"] = true, - ["FTL_Space_Warp"] = true, - ["nicname123"] = true, - ["pyz3n"] = true, - ["raudorn"] = true, - ["jojohnst"] = true, - ["bigyihsuan"] = true, - ["Petrane"] = true, - ["the_bebster"] = true, - ["Irunfold"] = true, - ["Del3ta"] = true, - ["Beelzemon"] = true, - ["polycephaland"] = true, - ["Gadidou"] = true, - ["vorxil"] = true, - ["FIREBUNNIE"] = true, - ["kazmodah"] = true, - ["Kno"] = true, - ["Atoms88"] = true, - ["degard66"] = true, - ["ABambooBilbo"] = true, - ["TuxWhale"] = true, - ["Shucru"] = true, - ["yxlotl"] = true, - ["templarchon"] = true, - ["LeeJando"] = true, - ["natedognatedog10"] = true, - ["manclaouss"] = true, - ["Geostyx"] = true, - ["Vadigix"] = true, - ["sssdsdsdsss"] = true, - ["rusty_au"] = true, - ["joe9go"] = true, - ["The_Pau"] = true, - ["Bobanaut"] = true, - ["Lestibornes"] = true, - ["nelch1"] = true, - ["domii894"] = true, - ["Rixon1967"] = true, - ["Asonael"] = true, - ["DonSeverus"] = true, - ["PhoenixPyro"] = true, - ["dalindes"] = true, - ["COOL-ITEM"] = true, - ["cpy"] = true, - ["VicTicus"] = true, - ["Linaori"] = true, - ["exabyte"] = true, - ["actitishypoleucos"] = true, - ["beelzemon"] = true, - ["firebunnie"] = true, - ["Grufe"] = true, - ["jbro1231"] = true, - ["Tamsay"] = true, - ["donto"] = true, - ["Cheeseftw"] = true, - ["jokerwm"] = true, - ["Sabeth"] = true, - ["sqamsqam"] = true, - ["bobfrankly"] = true, - ["Pentbot"] = true, - ["PandasUnicorn"] = true, - ["Kazakmau5"] = true, - ["best2"] = true, - ["fandoce"] = true, - ["Razaekel"] = true, - ["VladiKoro"] = true, - ["Purgen"] = true, - ["Xtreemecore"] = true, - ["Epskampie"] = true, - ["MdRuz"] = true, - ["WCTech"] = true, - ["jimmyhunter"] = true, - ["Monki"] = true, - ["Dewless"] = true, - ["NumptyToucan"] = true, - ["gmhinch"] = true, - ["Apokalipsion"] = true, - ["Jonah82"] = true, - ["nosman123"] = true, - ["brancanes"] = true, - ["XaLpHa1989"] = true, - ["Lethyes"] = true, - ["Yearupie"] = true, - ["vad7ik"] = true, - ["Ludvik"] = true, - ["Tolip"] = true, - ["supercuteboy123"] = true, - ["Hiji56"] = true, - ["Add3r"] = true, - ["Zardinio"] = true, - ["Ruby_Schnee_nee_Rose"] = true, - ["basepsy"] = true, - ["Xertez"] = true, - ["grufe"] = true, - ["terarink"] = true, - ["xalpha1989"] = true, - ["CandBacon"] = true, - ["snoetje"] = true, - ["markupolionCZ"] = true, - ["everLord"] = true, - ["Pirion"] = true, - ["iSTEVE"] = true, - ["mrhaug"] = true, - ["HydraX26"] = true, - ["Ivan00"] = true, - ["MinestoPix"] = true, - ["Tux0n0"] = true, - ["Twitch93"] = true, - ["itamastericano"] = true, - ["j0nni"] = true, - ["pickles28"] = true, - ["rft50"] = true, - ["ANV1L"] = true, - ["Conor0709"] = true, - ["ZarSama"] = true, - ["captcougar1969"] = true, - ["dmcdouga"] = true, - ["motorsteak"] = true, - ["ultrajer"] = true, - ["zenys19"] = true, - ["soni"] = true, - ["cyberdomus"] = true, - ["AFD"] = true, - ["morokko"] = true, - ["cko6o4ku"] = true, - ["Tamika"] = true, - ["22144418"] = true, - ["Genoone"] = true, - ["wengPC"] = true, - ["nizzy"] = true, - ["nadarith"] = true, - ["SLQ"] = true, - ["Shanchan"] = true, - ["Hempy"] = true, - ["Zonezero"] = true, - ["wotwotvodka"] = true, - ["Turboknot"] = true, - ["SteamEngine"] = true, - ["chrisisthebe"] = true, - ["JohnBosch"] = true, - ["sivael"] = true, - ["DarthLeahcim"] = true, - ["acul009"] = true, - ["moqart"] = true, - ["morbus69"] = true, - ["steelhero"] = true, - ["Achskelmos"] = true, - ["Lucasuper32"] = true, - ["sid123"] = true, - ["SuicideBunny"] = true, - ["Grizmu"] = true, - ["fusionross"] = true, - ["termi56"] = true, - ["Thoren41"] = true, - ["LeBalafrey"] = true, - ["WillyMF1"] = true, - ["Ferefang"] = true, - ["Angrivator"] = true, - ["Subcinericius"] = true, - ["Tallios"] = true, - ["spik3"] = true, - ["aledeludx"] = true, - ["Samuel2507"] = true, - ["QDeathNick"] = true, - ["rafe1"] = true, - ["Bawz"] = true, - ["Zr4g0n"] = true, - ["ro88ie"] = true, - ["antarcus"] = true, - ["skzap"] = true, - ["ImPureGames"] = true, - ["bawz"] = true, - ["terradus"] = true, - ["terz42"] = true, - ["thadius856"] = true, - ["the_ledgendary"] = true, - ["the_squid"] = true, - ["thelaughingcheese"] = true, - ["tickterd"] = true, - ["timmypwn"] = true, - ["toledini"] = true, - ["toof_kitty"] = true, - ["trekie4747"] = true, - ["trevoqr"] = true, - ["tuttifrectte"] = true, - ["tvardero"] = true, - ["twinotter"] = true, - ["vengefulpm"] = true, - ["vonlam999"] = true, - ["wadiyatalkinabeet"] = true, - ["warnotte"] = true, - ["watchinghawk"] = true, - ["wekkka"] = true, - ["wickvitaminc"] = true, - ["williambellwisdo"] = true, - ["wurzeltroll42"] = true, - ["xaddr"] = true, - ["xanting"] = true, - ["xdihe"] = true, - ["xeoxius"] = true, - ["xsidd"] = true, - ["Dominoscraft"] = true, - ["Teondar"] = true, - ["tafyline"] = true, - ["gartenfreund"] = true, - ["LycostA"] = true, - ["Dark1244"] = true, - ["cinzhal"] = true, - ["OECEMESO"] = true, - ["npo6ka"] = true, - ["3061867813"] = true, - ["WorrDogg"] = true, - ["skace"] = true, - ["I_dream_of_corn"] = true, - ["ailishi19"] = true, - ["POzilGeR"] = true, - ["robot3331"] = true, - ["Yoannbla"] = true, - ["smashngrabb"] = true, - ["Slayerfear"] = true, - ["DraugTheWhopper"] = true, - ["Grandma_x"] = true, - ["Factorio401"] = true, - ["Yeke"] = true, - ["IsThisNameTakenAlready"] = true, - ["Westy124444"] = true, - ["Bobthecreepyone"] = true, - ["Fattmann"] = true, - ["Eriksonn"] = true, - ["McAfterburner"] = true, - ["TheWickedMaster"] = true, - ["nofunnyno"] = true, - ["Arfloot"] = true, - ["berkys32"] = true, - ["JB_Delta"] = true, - ["SherlockGY"] = true, - ["Foxer1125"] = true, - [".Shang"] = true, - ["CHAOSGamerBC"] = true, - ["darkestdot"] = true, - ["BigGrant101"] = true, - ["JumboTheSunBro"] = true, - ["KJNine"] = true, - ["wilzek"] = true, - ["JustBull"] = true, - ["camodude387"] = true, - ["Rouden"] = true, - ["Glismod"] = true, - ["Graav"] = true, - ["QuaxzRu"] = true, - ["8mittim8"] = true, - ["opiboble"] = true, - ["floxys"] = true, - ["pepsin92"] = true, - ["BlaQkout"] = true, - ["Narcotic84"] = true, - ["arondir"] = true, - ["ihatehangovers"] = true, - ["Cretlin"] = true, - ["niko8"] = true, - ["neuro666"] = true, - ["kreeg"] = true, - ["Jimbogab"] = true, - ["Medival3"] = true, - ["willzcn"] = true, - ["uranopa3"] = true, - ["JSONROY"] = true, - ["o12eMaRkAbLeo"] = true, - ["VanHate"] = true, - ["RichardMNixon"] = true, - ["Subsup"] = true, - ["Sitrom"] = true, - ["odgaar"] = true, - ["glxl"] = true, - ["Julian1109"] = true, - ["ice9000"] = true, - ["plukona"] = true, - ["Serule"] = true, - ["IDragonfyreI"] = true, - ["jan1412"] = true, - ["ko5h"] = true, - ["DJStrikerLP"] = true, - ["maverick85"] = true, - ["kacperion"] = true, - ["Heinrich0815"] = true, - ["Martox111"] = true, - ["skudd3r"] = true, - ["Ingenieur_quoi"] = true, - ["SumBeam"] = true, - ["ScienceLion"] = true, - ["dimash"] = true, - ["TNT_MAN1111"] = true, - ["crayzz2"] = true, - ["Gerkiz"] = true, - ["piterfersin"] = true, - ["SiMoZ_287"] = true, - ["SSeltmann"] = true, - ["AbsoluteZeroIs0K"] = true, - ["jufacto"] = true, - ["okan009"] = true, - ["CounterfeitThe"] = true, - ["TZsec"] = true, - ["jamesh92"] = true, - ["Flameoguy"] = true, - ["Toledini"] = true, - ["alnmike"] = true, - ["Krzys132"] = true, - ["jrz126"] = true, - ["Rothguard"] = true, - ["Rascher"] = true, - ["XeoXius"] = true, - ["InphinitePhractals"] = true, - ["Breadface"] = true, - ["safariursis"] = true, - ["Marucan"] = true, - ["rykstar"] = true, - ["CommanderFrog"] = true, - ["SchniSchnaSchnuck"] = true, - ["Ronin114"] = true, - ["masoudd"] = true, - ["powder12321"] = true, - ["KipenKnos"] = true, - ["Satyr"] = true, - ["wolfram74"] = true, - ["Husdafacka"] = true, - ["The_Real_Black"] = true, - ["ThatsBuilder"] = true, - ["minipini55"] = true, - ["Wanzek"] = true, - ["thehotcrafter"] = true, - ["Johanna_mo"] = true, - ["Cute_Anime_Loli"] = true, - ["J_B_der_Held"] = true, - ["AKTheKnight"] = true, - ["Orib0ck"] = true, - ["dredonkey"] = true, - ["Karev"] = true, - ["HappyPills"] = true, - ["A-l-a-n"] = true, - ["shadewolf"] = true, - ["rellec"] = true, - ["shoo_be_doo"] = true, - ["MovingMike"] = true, - ["slantedSunlight"] = true, - ["LymBAOBEI"] = true, - ["Forge36"] = true, - ["RoGHurricane"] = true, - ["Pyroguy"] = true, - ["Xeter"] = true, - ["Sebast8714"] = true, - ["AurelienG"] = true, - ["tronas10"] = true, - ["Crivvens"] = true, - ["Plawerth"] = true, - ["makuikui"] = true, - ["mahury"] = true, - ["Alfredoo"] = true, - ["brandon1311"] = true, - ["TrickyVic"] = true, - ["BuzuL"] = true, - ["Tigrium"] = true, - ["flooxy"] = true, - ["halpenny911"] = true, - ["Grumpalo"] = true, - ["chfisher77"] = true, - ["Forlanceabice"] = true, - ["oloklir"] = true, - ["skylarmb"] = true, - ["ThatNateGuy"] = true, - ["ezocker"] = true, - ["omarassi12"] = true, - ["Sjetil"] = true, - ["Jon8RFC"] = true, - ["kalikas"] = true, - ["ichmo"] = true, - ["CrazyStephen"] = true, - ["Refy"] = true, - ["ZachMarquoi"] = true, - ["MeepMerp"] = true, - ["InventorX"] = true, - ["Pandarnash"] = true, - ["Cramly"] = true, - ["DwarvenArmy"] = true, - ["Evandot"] = true, - ["HT1014"] = true, - ["Drastien"] = true, - ["sunseille"] = true, - ["taroxyz"] = true, - ["Strucki"] = true, - ["mzore"] = true, - ["nasmw"] = true, - ["hellden"] = true, - ["Eaggra"] = true, - ["jaxjace"] = true, - ["Proph3t3ss"] = true, - ["Sense545"] = true, - ["blueboyjj"] = true, - ["KingZeothh"] = true, - ["Bricktator"] = true, - ["CptPonk"] = true, - ["Zorzzz"] = true, - ["AIRZYC"] = true, - ["Digzol"] = true, - ["roosterbrewster"] = true, - ["Explodia"] = true, - ["Rvl"] = true, - ["ds227"] = true, - ["chromaddict"] = true, - ["MadPeakyBlinder"] = true, - ["yay2010"] = true, - ["remarkablysilly"] = true, - ["swake"] = true, - ["TheNetworkDoctor"] = true, - ["tria_225"] = true, - ["Mesohorknee"] = true, - ["alyptica"] = true, - ["radred"] = true, - ["DeathSlayer"] = true, - ["Captain_Murder"] = true, - ["RadianRaze"] = true, - ["Aeropar"] = true, - ["Maloy12"] = true, - ["Tatarr"] = true, - ["raskl"] = true, - ["Minidodo"] = true, - ["ghastly_figure"] = true, - ["Biker"] = true, - ["boeljoet"] = true, - ["FreezeHun"] = true, - ["ksb4145"] = true, - ["Acruid"] = true, - ["kabutas"] = true, - ["anb505"] = true, - ["a591281892"] = true, - ["UnfortunatePotato"] = true, - ["galletto"] = true, - ["Cubicgraphics"] = true, - ["Zapdos"] = true, - ["14nickel"] = true, - ["my_saw"] = true, - ["BlueRock"] = true, - ["MooLer"] = true, - ["MachineEmpathist"] = true, - ["Xolas"] = true, - ["Taint_Puncher"] = true, - ["Thorgal"] = true, - ["Jularen"] = true, - ["Raiguard"] = true, - ["muchbetter321"] = true, - ["Skybreaker"] = true, - ["IamTzu"] = true, - ["ETK03"] = true -} From a1f63ce2b70ce9151fe05752e2739e95a415afd2 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 16:07:07 +0000 Subject: [PATCH 24/43] removed testing code --- control.lua | 44 ++------------------------------------------ 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/control.lua b/control.lua index 585eb7f5..85df7c94 100644 --- a/control.lua +++ b/control.lua @@ -8,8 +8,8 @@ require 'map_gen.shared.perlin_noise' require 'map_layout' -- Specific to RedMew hosts, can be disabled safely if not hosting on RedMew servers -Server = require 'server' -ServerCommands = require 'server_commands' +require 'server' +require 'server_commands' -- Library modules which, if missing, will cause other feature modules to fail require 'features.base_data' @@ -46,43 +46,3 @@ require 'features.gui.blueprint_helper' require 'features.gui.paint' require 'features.gui.score' require 'features.gui.popup' - -local Token = require('utils.global_token') -local data_callback = - Token.register( - function(data) - game.print(serpent.line(data)) - end -) - -function get_data(data_set, key) - Server.try_get_data(data_set, key, data_callback) -end - -function get_all_data(data_set, key) - Server.try_get_all_data(data_set, data_callback) -end - -local Event = require('utils.event') -Event.add( - Server.events.on_server_started, - function(tbl) - game.print('on_server_started') - print('on_server_started') - game.print(serpent.block(tbl)) - print(serpent.block(tbl)) - - Server.try_get_all_data('webtest', data_callback) - end -) - -local data_token = - Token.register( - function(data) - global.data = data.entries - end -) - -function get_data_set(data_set) - Server.try_get_all_data(data_set, data_token) -end From b22499cc9b96675b03e3a0d7a1444aa700c4b2d4 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 16:07:24 +0000 Subject: [PATCH 25/43] clean up + comments --- server.lua | 87 +++++++++++++++++++++++++++++++-------------- server_commands.lua | 24 ++++++------- 2 files changed, 72 insertions(+), 39 deletions(-) diff --git a/server.lua b/server.lua index d4a6312c..9820b51a 100644 --- a/server.lua +++ b/server.lua @@ -1,5 +1,4 @@ local Token = require 'utils.global_token' -local Event = require 'utils.event' local Public = {} @@ -17,9 +16,6 @@ local discord_embed_tag = '[DISCORD-EMBED]' local discord_embed_raw_tag = '[DISCORD-EMBED-RAW]' local discord_admin_embed_tag = '[DISCORD-ADMIN-EMBED]' local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' -local regular_promote_tag = '[REGULAR-PROMOTE]' -local regular_deomote_tag = '[REGULAR-DEOMOTE]' -local donator_set_tag = '[DONATOR-SET]' local start_scenario_tag = '[START-SCENARIO]' local ping_tag = '[PING]' local data_set_tag = '[DATA-SET]' @@ -33,67 +29,73 @@ local data_set_handlers = {} defines.events.on_server_started = script.generate_event_name() +--- The event id for the on_server_started event. +-- The event is raised whenever the server goes from the starting state to the running state. +-- It provides a good opportunity to request data from the web server. +-- Note that if the server is stopped then started again, this event will be raised again. +-- @usage +-- Event.add(Server.events.on_server_started, +-- function() +-- Server.try_get_all_data('regulars', callback) +-- end) Public.events = {on_server_started = defines.events.on_server_started} +--- Sends a message to the linked discord channel. The message is sanitized of markdown server side. +-- @param message message to send. function Public.to_discord(message) raw_print(discord_tag .. message) end +--- Sends a message to the linked discord channel. The message is not sanitized of markdown. +-- @param message message to send. function Public.to_discord_raw(message) raw_print(discord_raw_tag .. message) end +--- Sends a message to the linked discord channel. The message is sanitized of markdown server side, then made bold. +-- @param message message to send. function Public.to_discord_bold(message) raw_print(discord_bold_tag .. message) end +--- Sends a message to the linked admin discord channel. The message is sanitized of markdown server side. +-- @param message message to send. function Public.to_admin(message) raw_print(discord_admin_tag .. message) end +--- Sends a message to the linked admin discord channel. The message is not sanitized of markdown. +-- @param message message to send. function Public.to_admin_raw(message) raw_print(discord_admin_raw_tag .. message) end +--- Sends a embed message to the linked discord channel. The message is sanitized of markdown server side. +-- @param message the content of the embed. function Public.to_discord_embed(message) raw_print(discord_embed_tag .. message) end +--- Sends a embed message to the linked discord channel. The message is not sanitized of markdown. +-- @param message the content of the embed. function Public.to_discord_embed_raw(message) raw_print(discord_embed_raw_tag .. message) end +--- Sends a embed message to the linked admin discord channel. The message is sanitized of markdown server side. +-- @param message the content of the embed. function Public.to_admin_embed(message) raw_print(discord_admin_embed_tag .. message) end +--- Sends a embed message to the linked admin discord channel. The message is not sanitized of markdown. +-- @param message the content of the embed. function Public.to_admin_embed_raw(message) raw_print(discord_admin_embed_raw_tag .. message) end -function Public.regular_promote(target, promotor) - local control_message = table.concat {regular_promote_tag, target, ' ', promotor} - local discord_message = table.concat {discord_bold_tag, promotor .. ' promoted ' .. target .. ' to regular.'} - - raw_print(control_message) - raw_print(discord_message) -end - -function Public.regular_deomote(target, demotor) - local discord_message = table.concat {discord_bold_tag, target, ' was demoted from regular by ', demotor, '.'} - - raw_print(regular_deomote_tag .. target) - raw_print(discord_message) -end - -function Public.donator_set(target, perks) - perks = perks or 'nil' - - local message = table.concat {donator_set_tag, target, ' ', perks} - - raw_print(message) -end - +--- Stops and saves the factorio server and starts the named scenario. +-- @param scenario_name The name of the scenario as appears in the scenario table on http://redmew.com/admin function Public.start_scenario(scenario_name) if type(scenario_name) ~= 'string' then game.print('start_scenario - scenario_name ' .. tostring(scenario_name) .. ' must be a string.') @@ -116,11 +118,20 @@ local default_ping_token = end ) +--- Pings the web server. +-- @param func_token The function that is called when the web server replies. +-- The function is passed the tick that the ping was sent. function Public.ping(func_token) local message = table.concat({ping_tag, func_token or default_ping_token, ' ', game.tick}) raw_print(message) end +--- Sets the web server's persistent data storage. If you pass nil for the value removes the data. +-- Data set this will by synced in with other server if they choose to. +-- There can only be one key for each data_set. +-- @param data_set +-- @param key +-- @param value Any type that is not a function. set to nil to remove the data. function Public.set_data(data_set, key, value) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -129,6 +140,7 @@ function Public.set_data(data_set, key, value) error('key must be a string') end + -- Excessive escaping because the data is serialized twice. data_set = data_set:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') key = key:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"') @@ -161,6 +173,12 @@ function Public.set_data(data_set, key, value) raw_print(message) end +--- Gets data from the web server's persistent data storage. +-- The callback is passed a table {data_set: string, key: string, value: any}. +-- If the value is nil, it means there is no stored data for that data_set key pair. +-- @param data_set +-- @param key +-- @param callback_token function Public.try_get_data(data_set, key, callback_token) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -180,6 +198,11 @@ function Public.try_get_data(data_set, key, callback_token) raw_print(message) end +--- Gets all the data for the data_set from the web server's persistent data storage. +-- The callback is passed a table {data_set: string, entries: {dictionary key -> value}}. +-- If there is no data stored for the data_set entries will be nil. +-- @param data_set +-- @param callback_token function Public.try_get_all_data(data_set, callback_token) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -219,6 +242,15 @@ local function data_set_changed(data) end end +--- Register a handler to be called when the data_set changes. +-- The handler is passed a table {data_set:string, key:string, value:any} +-- If value is nil that means the key was removed. +-- The handler may be called even if the value hasn't changed. It's up to the implementer +-- to determine if the value has changed, or not care. +-- To prevent desyncs the same handlers must be registered for all clients. The easiest way to do this +-- is in the control stage, i.e before on_init or on_load would be called. +-- @param data_set +-- @param handler function Public.on_data_set_changed(data_set, handler) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -235,6 +267,7 @@ end Public.raise_data_set = data_set_changed +--- Called by the web server to determine which data_sets are being tracked. function Public.get_tracked_data_sets() local message = {data_tracked_tag, '['} diff --git a/server_commands.lua b/server_commands.lua index 7f47b95d..31629b5c 100644 --- a/server_commands.lua +++ b/server_commands.lua @@ -3,26 +3,26 @@ local UserGroups = require 'features.user_groups' local Token = require 'utils.global_token' local Server = require 'server' -local Public = {} +--- This module is for the web server to call functions and raise events. +-- Not intended to be called by scripts. +-- Needs to be in the _G table so it can be accessed by the web server. +ServerCommands = {} -Public.get_poll_result = Poll.send_poll_result_to_discord +ServerCommands.get_poll_result = Poll.send_poll_result_to_discord -Public.regular_sync = UserGroups.sync_regulars +ServerCommands.regular_sync = UserGroups.sync_regulars +ServerCommands.donator_sync = UserGroups.sync_donators -Public.regular_promote = UserGroups.server_add_regular - -Public.regular_demote = UserGroups.server_remove_regular - -function Public.raise_callback(func_token, data) +function ServerCommands.raise_callback(func_token, data) local func = Token.get(func_token) func(data) end -Public.raise_data_set = Server.raise_data_set -Public.get_tracked_data_sets = Server.get_tracked_data_sets +ServerCommands.raise_data_set = Server.raise_data_set +ServerCommands.get_tracked_data_sets = Server.get_tracked_data_sets -function Public.server_started() +function ServerCommands.server_started() script.raise_event(Server.events.on_server_started, {}) end -return Public +return ServerCommands From 420b584228afdf1abfab3a168cd5c518da3b4ff3 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 16:50:38 +0000 Subject: [PATCH 26/43] removed unused function donators --- features/custom_commands.lua | 39 ------------------------------------ 1 file changed, 39 deletions(-) diff --git a/features/custom_commands.lua b/features/custom_commands.lua index 76f048a6..b635ba17 100644 --- a/features/custom_commands.lua +++ b/features/custom_commands.lua @@ -152,45 +152,6 @@ local function regular(cmd) end end -local function donator(cmd) - local player = game.player - if player and not player.admin then - cant_run(cmd.name) - return - end - - if cmd.parameter == nil then - player_print('Command failed. Usage: /donator ') - return - end - - local params = {} - for param in string.gmatch(cmd.parameter, '%S+') do - table.insert(params, param) - end - if params[2] == nil then - player_print('Command failed. Usage: /donator ') - return - end - - local perks = params[2] - if perks == 'nil' then - perks = nil - end - - if (tonumber(perks) == nil and perks ~= nil) then - player_print("Command failed. perks must be number or the string 'nil' to remove donator.") - return - end - - local target = params[1] - - UserGroups.set_donator(target, perks) - - local message = table.concat {'Player ', target, ' donator perks set to ', perks} - player_print(message) -end - --- Check players' afk times local function afk() for _, v in pairs(game.players) do From 4e000efbb81ed6433b46a442d325579516bd5999 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 16:55:12 +0000 Subject: [PATCH 27/43] added missing server require --- features/gui/poll.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/features/gui/poll.lua b/features/gui/poll.lua index a541a5f0..7bab4608 100644 --- a/features/gui/poll.lua +++ b/features/gui/poll.lua @@ -5,6 +5,7 @@ local UserGroups = require 'features.user_groups' local Game = require 'utils.game' local math = require 'utils.math' local Utils = require 'utils.utils' +local Server = require 'server' local default_poll_duration = 300 * 60 -- in ticks local duration_max = 3600 -- in seconds From 8fe49e8930e662028b736b389919084b20a65c58 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sun, 25 Nov 2018 20:09:23 +0100 Subject: [PATCH 28/43] Added a market retailer to manage the markets --- features/retailer.lua | 106 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 features/retailer.lua diff --git a/features/retailer.lua b/features/retailer.lua new file mode 100644 index 00000000..1848f1a1 --- /dev/null +++ b/features/retailer.lua @@ -0,0 +1,106 @@ +local Debug = require 'map_gen.Diggy.Debug' +local Global = require 'utils.global' +local format = string.format +local insert = table.insert + +local Retailer = {} + +---Global storage +---Markets are indexed by the group_name and is a sequential list of LuaEntities +---Items are indexed by the group name and is a list indexed by the item name and contains the prices per item +local memory = { + markets = {}, + items = {}, +} + +Global.register({ + memory = memory, +}, function (tbl) + memory = tbl.memory +end) + +---Add a market to the group_name retailer. +---@param group_name string +---@param market_entity LuaEntity +function Retailer.add_market(group_name, market_entity) + if not memory.markets[group_name] then + memory.markets[group_name] = {market_entity} + return + end + + insert(memory.markets[group_name], market_entity) +end + +---Sets an item for all the group_name markets. +---@param group_name string +---@param item_name string +---@param prices table associative table where the key is the currency item and the value the amount of it +function Retailer.set_item(group_name, item_name, prices) + if not memory.items[group_name] then + memory.items[group_name] = {} + end + + local market_format_prices = {} + for currency, amount in pairs(prices) do + insert(market_format_prices, {currency, amount}) + end + + memory.items[group_name][item_name] = market_format_prices +end + +---Returns all item for the group_name retailer. +---@param group_name string +function Retailer.get_items(group_name) + return memory.items[group_name] or {} +end + +---Removes an item from the markets for the group_name retailer. +---@param group_name string +---@param item_name string +function Retailer.remove_item(group_name, item_name) + if not memory.items[group_name] then + return + end + + memory.items[group_name][item_name] = nil +end + +---Ships the current list of items with their prices to all markets for the group_name retailer. +---@param group_name string +function Retailer.ship_items(group_name) + local markets = memory.markets[group_name] + if not markets then + return + end + + local market_items = memory.items[group_name] + if not market_items then + -- items have not been added yet + return + end + + for _, market in ipairs(markets) do + if market.valid then + -- clean the current inventory + local remove_market_item = market.remove_market_item + -- remove re-indexes the offers, to prevent shifting, go backwards + local current_market_items = market.get_market_items() + if current_market_items then + for current_index = #current_market_items, 1, -1 do + remove_market_item(current_index) + end + end + + -- re-add the whole list + local add_market_item = market.add_market_item + for item_name, prices in pairs(market_items) do + add_market_item({ + price = prices, + offer = {type = 'give-item', item = item_name, count = 1} + }) + end + end + end +end + +return Retailer From ab1dff64f58db25a5a1ead378ddb334473bee759 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sun, 25 Nov 2018 20:09:46 +0100 Subject: [PATCH 29/43] Cleanup Experience and MarketExchange to use the Retailer --- docs/scenarios/Diggy.md | 6 +- map_gen/Diggy/Config.lua | 110 +++---- map_gen/Diggy/Feature/Experience.lua | 258 +++++++++++++-- map_gen/Diggy/Feature/MarketExchange.lua | 386 ----------------------- map_gen/Diggy/Feature/StartingZone.lua | 21 +- map_gen/Diggy/FormatMarketItems.lua | 45 --- map_gen/Diggy/Template.lua | 28 +- 7 files changed, 304 insertions(+), 550 deletions(-) delete mode 100644 map_gen/Diggy/Feature/MarketExchange.lua delete mode 100644 map_gen/Diggy/FormatMarketItems.lua diff --git a/docs/scenarios/Diggy.md b/docs/scenarios/Diggy.md index 281725ff..54697ea6 100644 --- a/docs/scenarios/Diggy.md +++ b/docs/scenarios/Diggy.md @@ -74,6 +74,6 @@ your own resources (for example bobs or angels) with a value and the scenario wi spawn chances. ### Adding Market Items -Items can be configured by adding the desired item under the `MarketExchange` configuration. You only have to define a -level at which it unlocks, a price or prices in case it can cost more, and what the item prototype is. For a list of -items, you can look up each possible item on the [Factorio raw data page](https://wiki.factorio.com/Data.raw#item). +Items can be configured by adding the desired item under the `Experience` configuration. You only have to define a level +at which it unlocks and a price. For a list of items, you can look up each possible item on the +[Factorio raw data page](https://wiki.factorio.com/Data.raw#item). diff --git a/map_gen/Diggy/Config.lua b/map_gen/Diggy/Config.lua index 69ec2e0a..277a92ac 100644 --- a/map_gen/Diggy/Config.lua +++ b/map_gen/Diggy/Config.lua @@ -11,6 +11,9 @@ local Config = { -- initial starting position size, higher values are not recommended starting_size = 8, + + -- where the market should spawn + market_spawn_position = {x = 0, y = 3}, }, -- controls the Daylight (Default diggy: enabled = true) @@ -34,7 +37,7 @@ local Config = { manual_mining_speed_modifier = 1000, -- increase the amount of inventory slots for the player force - character_inventory_slots_bonus = 1000, + character_inventory_slots_bonus = 0, -- increases the run speed of all characters for the player force character_running_speed_modifier = 2, @@ -43,7 +46,7 @@ local Config = { character_health_bonus = 1000000, -- unlock all research by default, only useful when testing - unlock_all_research = false, + unlock_all_research = true, -- adds additional items to the player force when starting in addition to defined in start_items above starting_items = { @@ -114,9 +117,9 @@ local Config = { ['refined-concrete'] = 0.06, }, cracking_sounds = { - 'CRACK', - 'KRRRR', - 'R U N', + 'CRACK', + 'KRRRR', + 'R U N', } }, @@ -338,58 +341,6 @@ local Config = { }, }, - -- controls the market and buffs - MarketExchange = { - enabled = true, - - -- percentage * mining productivity level gets added to mining speed - mining_speed_productivity_multiplier = 5, - - -- market config - market_spawn_position = {x = 0, y = 3}, - currency_item = 'coin', - - -- add or remove a table entry to add or remove a unlockable item from the mall. - -- format: {unlock_at_level, price, prototype_name}, - -- alternative format: {level = 32, price = {{"stone", 2500}, {"coin", 100}}, name = 'power-armor'}, - unlockables = require('map_gen.Diggy.FormatMarketItems').initialize_unlockables( - { - {level = 1, price = 5, name = 'iron-axe'}, - {level = 2, price = 5, name = 'raw-wood'}, - {level = 3, price = 20, name = 'pistol'}, - {level = 3, price = 2, name = 'firearm-magazine'}, - {level = 5, price = 2, name = 'stone-brick'}, - {level = 6, price = 6, name = 'small-lamp'}, - {level = 6, price = 5, name = 'raw-fish'}, - {level = 8, price = 10, name = 'stone-wall'}, - {level = 10, price = 85, name = 'shotgun'}, - {level = 10, price = 2, name = 'shotgun-shell'}, - {level = 13, price = 25, name = 'steel-axe'}, - {level = 13, price = 50, name = 'light-armor'}, - {level = 15, price = 85, name = 'submachine-gun'}, - {level = 18, price = 8, name = 'piercing-rounds-magazine'}, - {level = 18, price = 8, name = 'piercing-shotgun-shell'}, - {level = 20, price = 100, name = 'heavy-armor'}, - {level = 25, price = 250, name = 'modular-armor'}, - {level = 25, price = 100, name = 'landfill'}, - {level = 28, price = 250, name = 'personal-roboport-equipment'}, - {level = 28, price = 75, name = 'construction-robot'}, - {level = 32, price = 850, name = 'power-armor'}, - {level = 34, price = 100, name = 'battery-equipment'}, - {level = 33, price = 1000, name = 'fusion-reactor-equipment'}, - {level = 36, price = 150, name = 'energy-shield-equipment'}, - {level = 42, price = 650, name = 'combat-shotgun'}, - {level = 46, price = 25, name = 'uranium-rounds-magazine'}, - {level = 58, price = 250, name = 'rocket-launcher'}, - {level = 58, price = 40, name = 'rocket'}, - {level = 66, price = 80, name = 'explosive-rocket'}, - {level = 73, price = 2000, name = 'satellite'}, - {level = 100, price = 1, name = 'iron-stick'}, - } - ), - }, - - --Tracks players causing collapses Antigrief = { enabled = true, @@ -423,10 +374,47 @@ local Config = { ['death-penalty'] = 0.002, -- XP deduct in percentage of total experience when a player dies (Diggy default: 0.002 which equals 0.2%) }, - buffs = { --Define new buffs here, they are handed out for each level. - ['mining_speed'] = {value = 5}, - ['inventory_slot'] = {value = 1}, - ['health_bonus'] = {value = 2.5, double_level = 5}, -- double_level is the level interval for receiving a double bonus (Diggy default: 5 which equals every 5th level) + buffs = { + -- define new buffs here, they are handed out for each level + mining_speed = {value = 5}, + inventory_slot = {value = 1}, + -- double_level is the level interval for receiving a double bonus (Diggy default: 5 which equals every 5th level) + health_bonus = {value = 2.5, double_level = 5}, + }, + + -- add or remove a table entry to add or remove a unlockable item from the market. + unlockables = { + {level = 1, price = 5, name = 'iron-axe'}, + {level = 2, price = 5, name = 'raw-wood'}, + {level = 3, price = 20, name = 'pistol'}, + {level = 3, price = 2, name = 'firearm-magazine'}, + {level = 5, price = 2, name = 'stone-brick'}, + {level = 6, price = 6, name = 'small-lamp'}, + {level = 6, price = 5, name = 'raw-fish'}, + {level = 8, price = 10, name = 'stone-wall'}, + {level = 10, price = 85, name = 'shotgun'}, + {level = 10, price = 2, name = 'shotgun-shell'}, + {level = 13, price = 25, name = 'steel-axe'}, + {level = 13, price = 50, name = 'light-armor'}, + {level = 15, price = 85, name = 'submachine-gun'}, + {level = 18, price = 8, name = 'piercing-rounds-magazine'}, + {level = 18, price = 8, name = 'piercing-shotgun-shell'}, + {level = 20, price = 100, name = 'heavy-armor'}, + {level = 25, price = 250, name = 'modular-armor'}, + {level = 25, price = 100, name = 'landfill'}, + {level = 28, price = 250, name = 'personal-roboport-equipment'}, + {level = 28, price = 75, name = 'construction-robot'}, + {level = 32, price = 850, name = 'power-armor'}, + {level = 34, price = 100, name = 'battery-equipment'}, + {level = 33, price = 1000, name = 'fusion-reactor-equipment'}, + {level = 36, price = 150, name = 'energy-shield-equipment'}, + {level = 42, price = 650, name = 'combat-shotgun'}, + {level = 46, price = 25, name = 'uranium-rounds-magazine'}, + {level = 58, price = 250, name = 'rocket-launcher'}, + {level = 58, price = 40, name = 'rocket'}, + {level = 66, price = 80, name = 'explosive-rocket'}, + {level = 73, price = 2000, name = 'satellite'}, + {level = 100, price = 1, name = 'iron-stick'}, }, }, diff --git a/map_gen/Diggy/Feature/Experience.lua b/map_gen/Diggy/Feature/Experience.lua index 8e4ddd25..302b231e 100644 --- a/map_gen/Diggy/Feature/Experience.lua +++ b/map_gen/Diggy/Feature/Experience.lua @@ -4,9 +4,18 @@ local Game = require 'utils.game' local Global = require 'utils.global' local ForceControl = require 'features.force_control' local Debug = require 'map_gen.Diggy.Debug' +local Retailer = require 'features.retailer' +local Gui = require 'utils.gui' +local force_control = require 'features.force_control' +local utils = require 'utils.utils' +local format = string.format +local string_format = string.format +local floor = math.floor +local log = math.log +local insert = table.insert --- Will be registered in Experience.register -local ForceControl_builder = {} +-- hack +local alien_coin_modifiers = require 'map_gen.Diggy.Config'.features.ArtefactHunting.alien_coin_modifiers -- this local Experience = {} @@ -39,15 +48,9 @@ Global.register({ health_bonus = tbl.health_bonus end) - local config = {} -local string_format = string.format -local alien_coin_modifiers = require 'map_gen.Diggy.Config'.features.ArtefactHunting.alien_coin_modifiers -local floor = math.floor local level_up_formula = (function (level_reached) - local floor = math.floor - local log = math.log local Config = require 'map_gen.Diggy.Config'.features.Experience local difficulty_scale = floor(Config.difficulty_scale) local level_fine_tune = floor(Config.xp_fine_tune) @@ -72,6 +75,20 @@ local level_up_formula = (function (level_reached) return value - lower_value end) +---Updates the market contents based on the current level. +---@param force LuaForce the force which the unlocking requirement should be based of +function Experience.update_market_contents(force) + local current_level = ForceControl.get_force_data(force).current_level + local force_name = force.name + for _, prototype in ipairs(config.unlockables) do + if (current_level >= prototype.level) then + Retailer.set_item(force_name, prototype.name, {coin = prototype.price}) + end + end + + Retailer.ship_items(force_name) +end + ---Updates a forces manual mining speed modifier. By removing active modifiers and re-adding ---@param force LuaForce the force of which will be updated ---@param level_up number a level if updating as part of a level up (optional) @@ -238,10 +255,12 @@ local function on_entity_died (event) end end end - local text = string_format('+ %d XP', exp) - Game.print_floating_text(entity.surface, entity.position, text, {r = 144, g = 202, b = 249}) - ForceControl.add_experience(force, exp) - return + if exp then + local text = string_format('+ %d XP', exp) + Game.print_floating_text(entity.surface, entity.position, text, {r = 144, g = 202, b = 249}) + ForceControl.add_experience(force, exp) + return + end end if entity.force.name ~= 'enemy' then @@ -266,49 +285,228 @@ local function on_player_respawned(event) end end ----Get list of defined buffs ----@return table with the same format as in the Diggy Config ----@see Diggy.Config.features.Experience.Buffs -function Experience.get_buffs() - return config.buffs -end - local level_table = {} ---Get experiment requirement for a given level ----Primarily used for the market GUI to display total experience required to unlock a specific item +---Primarily used for the Experience GUI to display total experience required to unlock a specific item ---@param level number a number specifying the level ---@return number required total experience to reach supplied level -function Experience.calculate_level_xp(level) +local function calculate_level_xp(level) if level_table[level] == nil then local value if level == 1 then value = level_up_formula(level-1) else - value = level_up_formula(level-1)+Experience.calculate_level_xp(level-1) + value = level_up_formula(level-1)+calculate_level_xp(level-1) end - table.insert(level_table, level, value) + insert(level_table, level, value) end return level_table[level] end +local function redraw_title(data) + local force_data = force_control.get_force_data('player') + data.frame.caption = utils.comma_value(force_data.total_experience) .. ' total experience earned!' +end + +local function apply_heading_style(style, width) + style.font = 'default-bold' + style.width = width +end + +local function redraw_heading(data, header) + local head_condition = (header == 1) + local frame = (head_condition) and data.experience_list_heading or data.buff_list_heading + local header_caption = (head_condition) and 'Reward Item' or 'Reward Buff' + Gui.clear(frame) + + local heading_table = frame.add({type = 'table', column_count = 2}) + apply_heading_style(heading_table.add({ type = 'label', caption = 'Requirement'}).style, 100) + apply_heading_style(heading_table.add({type = 'label', caption = header_caption}).style, 220) +end + +local function redraw_progressbar(data) + local force_data = force_control.get_force_data('player') + local flow = data.experience_progressbars + Gui.clear(flow) + + apply_heading_style(flow.add({type = 'label', tooltip = 'Currently at level: ' .. force_data.current_level .. '\nNext level at: ' .. utils.comma_value((force_data.total_experience - force_data.current_experience) + force_data.experience_level_up_cap) ..' xp\nRemaining xp: ' .. utils.comma_value(force_data.experience_level_up_cap - force_data.current_experience), name = 'Diggy.Experience.Frame.Progress.Level', caption = 'Progress to next level:'}).style) + local level_progressbar = flow.add({type = 'progressbar', tooltip = floor(force_data.experience_percentage*100)*0.01 .. '% xp to next level'}) + level_progressbar.style.width = 350 + level_progressbar.value = force_data.experience_percentage * 0.01 +end + +local function redraw_table(data) + local experience_scroll_pane = data.experience_scroll_pane + Gui.clear(experience_scroll_pane) + + redraw_progressbar(data) + redraw_heading(data, 1) + + local last_level = 0 + local current_force_level = force_control.get_force_data('player').current_level + + for _, prototype in ipairs(config.unlockables) do + local current_item_level = prototype.level + local first_item_for_level = current_item_level ~= last_level + local color + + if current_force_level >= current_item_level then + color = {r = 1, g = 1, b = 1 } + else + color = {r = 0.5, g = 0.5, b = 0.5 } + end + + local list = experience_scroll_pane.add({type = 'table', column_count = 2}) + + local level_caption = '' + if first_item_for_level then + level_caption = 'level ' .. current_item_level + end + + local level_column = list.add({ + type = 'label', + caption = level_caption, + tooltip = 'XP: ' .. utils.comma_value(calculate_level_xp(current_item_level)), + }) + level_column.style.minimal_width = 100 + level_column.style.font_color = color + + local item_column = list.add({ + type = 'label', + caption = prototype.name + }) + item_column.style.minimal_width = 22 + item_column.style.font_color = color + + last_level = current_item_level + end +end + +local function redraw_buff(data) + local buff_scroll_pane = data.buff_scroll_pane + Gui.clear(buff_scroll_pane) + + local all_levels_shown = false + for name, effects in pairs(config.buffs) do + local list = buff_scroll_pane.add({type = 'table', column_count = 2}) + list.style.horizontal_spacing = 16 + + local level_caption = '' + if not all_levels_shown then + all_levels_shown = true + level_caption = 'All levels' + end + + local level_label = list.add({type = 'label', caption = level_caption}) + level_label.style.minimal_width = 100 + level_label.style.font_color = {r = 1, g = 1, b = 1 } + + local buff_caption + local effect_value = effects.value + if name == 'mining_speed' then + buff_caption = format('+ %d mining speed', effect_value) + elseif name == 'inventory_slot' then + buff_caption = format('+ %d inventory slot%s', effect_value, effect_value > 1 and 's' or '') + elseif name == 'health_bonus' then + buff_caption = format('+ %d max health', effect_value) + else + buff_caption = format('+ %d %s', effect_value, name) + end + + local buffs_label = list.add({ type = 'label', caption = buff_caption}) + buffs_label.style.minimal_width = 220 + buffs_label.style.font_color = {r = 1, g = 1, b = 1 } + end +end + +local function toggle(event) + local player = event.player + local left = player.gui.left + local frame = left['Diggy.Experience.Frame'] + + if (frame and event.trigger == nil) then + Gui.destroy(frame) + return + elseif (frame) then + local data = Gui.get_data(frame) + redraw_title(data) + redraw_progressbar(data) + redraw_table(data) + return + end + + frame = left.add({name = 'Diggy.Experience.Frame', type = 'frame', direction = 'vertical'}) + + local experience_progressbars = frame.add({ type = 'flow', direction = 'vertical'}) + local experience_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) + + local experience_scroll_pane = frame.add({ type = 'scroll-pane'}) + experience_scroll_pane.style.maximal_height = 300 + + local buff_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) + + local buff_scroll_pane = frame.add({type = 'scroll-pane'}) + buff_scroll_pane.style.maximal_height = 100 + + frame.add({type = 'button', name = 'Diggy.Experience.Button', caption = 'Close'}) + + local data = { + frame = frame, + experience_progressbars = experience_progressbars, + experience_list_heading = experience_list_heading, + experience_scroll_pane = experience_scroll_pane, + buff_list_heading = buff_list_heading, + buff_scroll_pane = buff_scroll_pane, + } + + redraw_title(data) + redraw_table(data) + + redraw_heading(data, 2) + redraw_buff(data) + + Gui.set_data(frame, data) +end + +local function on_player_created(event) + Game.get_player_by_index(event.player_index).gui.top.add({ + name = 'Diggy.Experience.Button', + type = 'sprite-button', + sprite = 'entity/market', + }) +end + +Gui.on_click('Diggy.Experience.Button', toggle) +Gui.on_custom_close('Diggy.Experience.Frame', function (event) + event.element.destroy() +end) + +---Updates the experience progress gui for every player that has it open +local function update_gui() + for _, p in ipairs(game.connected_players) do + local frame = p.gui.left['Diggy.Experience.Frame'] + + if frame and frame.valid then + local data = {player = p, trigger = 'update_gui'} + toggle(data) + end + end +end function Experience.register(cfg) config = cfg --Adds the function on how to calculate level caps (When to level up) - ForceControl_builder = ForceControl.register(level_up_formula) + local ForceControlBuilder = ForceControl.register(level_up_formula) --Adds a function that'll be executed at every level up - ForceControl_builder.register_on_every_level(function (level_reached, force) + ForceControlBuilder.register_on_every_level(function (level_reached, force) force.print(string_format('%s Leveled up to %d!', '## - ', level_reached)) force.play_sound{path='utility/new_objective', volume_modifier = 1 } local Experience = require 'map_gen.Diggy.Feature.Experience' Experience.update_inventory_slots(force, level_reached) Experience.update_mining_speed(force, level_reached) Experience.update_health_bonus(force, level_reached) - local MarketExchange = require 'map_gen.Diggy.Feature.MarketExchange' - local market = MarketExchange.get_market() - MarketExchange.update_market_contents(market, force) - MarketExchange.update_gui() + Experience.update_market_contents(force) end) -- Events @@ -317,6 +515,8 @@ function Experience.register(cfg) Event.add(defines.events.on_rocket_launched, on_rocket_launched) Event.add(defines.events.on_player_respawned, on_player_respawned) Event.add(defines.events.on_entity_died, on_entity_died) + Event.add(defines.events.on_player_created, on_player_created) + Event.on_nth_tick(61, update_gui) -- Prevents table lookup thousands of times sand_rock_xp = config.XP['sand-rock-big'] diff --git a/map_gen/Diggy/Feature/MarketExchange.lua b/map_gen/Diggy/Feature/MarketExchange.lua deleted file mode 100644 index 3e48546a..00000000 --- a/map_gen/Diggy/Feature/MarketExchange.lua +++ /dev/null @@ -1,386 +0,0 @@ ---[[-- info - Provides the ability to purchase items from the market. -]] - --- dependencies -local Event = require 'utils.event' -local Token = require 'utils.global_token' -local Task = require 'utils.Task' -local Gui = require 'utils.gui' -local Debug = require 'map_gen.Diggy.Debug' -local Template = require 'map_gen.Diggy.Template' -local Game = require 'utils.game' -local insert = table.insert -local force_control = require 'features.force_control' -local Experience = require 'map_gen.Diggy.Feature.Experience' -local max = math.max -local floor = math.floor -local utils = require 'utils.utils' - --- this -local MarketExchange = {} - -local config = {} - -local on_market_timeout_finished = Token.register(function(params) - Template.market(params.surface, params.position, params.player_force) -end) - ----Updates market content with new items if they are to be unlocked ----Primarily used by the force control system at every level up ----@param market LuaEntity The market to be updated ----@param force LuaForce the force which the unlocking requirement should be based of -function MarketExchange.update_market_contents(market, force) - local add_market_item - local item_unlocked = false - - for _, unlockable in pairs(config.unlockables) do - local is_in_range = force_control.get_force_data(force).current_level == unlockable.level - - -- only add the item to the market if it's between the old and new stone range - if (is_in_range and unlockable.type == 'market') then - add_market_item = add_market_item or market.add_market_item - - local name = unlockable.prototype.name - local price = unlockable.prototype.price - if type(price) == 'number' then - add_market_item({ - price = {{config.currency_item, price}}, - offer = {type = 'give-item', item = name, count = 1} - }) - elseif type(price) == 'table' then - add_market_item({ - price = price, - offer = {type = 'give-item', item = name, count = 1} - }) - end - item_unlocked = true - - end - end -end - -local function redraw_title(data) - local force_data = force_control.get_force_data('player') - data.frame.caption = utils.comma_value(force_data.total_experience) .. ' total experience earned!' -end - -local function get_data(unlocks, stone, type) - local result = {} - - for _, data in pairs(unlocks) do - if data.level == stone and data.type == type then - insert(result, data) - end - end - - return result -end - -local tag_label_stone = Gui.uid_name() -local tag_label_buff = Gui.uid_name() -local tag_label_item = Gui.uid_name() - -local function apply_heading_style(style, width) - style.font = 'default-bold' - style.width = width -end - -local function redraw_heading(data, header) - local head_condition = (header == 1) - local frame = (head_condition) and data.market_list_heading or data.buff_list_heading - local header_caption = (head_condition) and 'Reward Item' or 'Reward Buff' - Gui.clear(frame) - - local heading_table = frame.add({type = 'table', column_count = 2}) - apply_heading_style(heading_table.add({type = 'label', name = tag_label_stone, caption = 'Requirement'}).style, 100) - apply_heading_style(heading_table.add({type = 'label', name = tag_label_buff, caption = header_caption}).style, 220) -end - -local function redraw_progressbar(data) - local force_data = force_control.get_force_data('player') - local flow = data.market_progressbars - Gui.clear(flow) - - apply_heading_style(flow.add({type = 'label', tooltip = 'Currently at level: ' .. force_data.current_level .. '\nNext level at: ' .. utils.comma_value((force_data.total_experience - force_data.current_experience) + force_data.experience_level_up_cap) ..' xp\nRemaining xp: ' .. utils.comma_value(force_data.experience_level_up_cap - force_data.current_experience), name = 'Diggy.MarketExchange.Frame.Progress.Level', caption = 'Progress to next level:'}).style) - local level_progressbar = flow.add({type = 'progressbar', tooltip = floor(force_data.experience_percentage*100)*0.01 .. '% xp to next level'}) - level_progressbar.style.width = 350 - level_progressbar.value = force_data.experience_percentage * 0.01 -end - -local function redraw_table(data) - local market_scroll_pane = data.market_scroll_pane - Gui.clear(market_scroll_pane) - - local buffs = {} - local items = {} - local last_stone = 0 - local number_of_rows = 0 - local row = {} - - -- create the progress bars in the window - redraw_progressbar(data) - - -- create table headings - redraw_heading(data, 1) - - -- create table - for i = 1, #config.unlockables do - if config.unlockables[i].level ~= last_stone then - - -- get items and buffs for each stone value - items = get_data(config.unlockables, config.unlockables[i].level, 'market') - - -- get number of rows - number_of_rows = max(#buffs, #items) - - -- loop through buffs and items for number of rows - for j = 1, number_of_rows do - local result = {} - local item = items[j] - local level = item.level - - -- 1st column - result[1] = level - -- 3rd column - if items[j] ~= nil then - result[3] = '+ ' .. item.prototype.name - else - result[3] = '' - end - -- indicator to stop print stone number - if j > 1 then - result[4] = true - else - result[4] = false - end - -- indicator to draw horizontal line - if j == number_of_rows then - result[5] = true - else - result[5] = false - end - - insert(row, result) - end - end - - -- save lastStone - last_stone = config.unlockables[i].level - end - - -- print table - for _, unlockable in pairs(row) do - local is_unlocked = unlockable[1] <= force_control.get_force_data('player').current_level - local list = market_scroll_pane.add {type = 'table', column_count = 2 } - - list.style.horizontal_spacing = 16 - - local caption = '' - if unlockable[4] ~= true then - caption = 'Level ' .. unlockable[1] - else - caption = '' - end - local tag_stone = list.add {type = 'label', name = tag_label_stone, caption = caption, tooltip = 'XP: ' .. utils.comma_value(Experience.calculate_level_xp(unlockable[1]))} - tag_stone.style.minimal_width = 100 - - local tag_items = list.add {type = 'label', name = tag_label_item, caption = unlockable[3]} - tag_items.style.minimal_width = 220 - - -- draw horizontal line - if unlockable[5] == true then - list.draw_horizontal_line_after_headers = true - end - - if (is_unlocked) then - tag_stone.style.font_color = {r = 1, g = 1, b = 1 } - tag_items.style.font_color = {r = 1, g = 1, b = 1 } - else - tag_stone.style.font_color = {r = 0.5, g = 0.5, b = 0.5 } - tag_items.style.font_color = {r = 0.5, g = 0.5, b = 0.5 } - end - end -end - -local function redraw_buff(data) --! Almost equals to the redraw_table() function ! - local buff_scroll_pane = data.buff_scroll_pane - Gui.clear(buff_scroll_pane) - - local buffs = Experience.get_buffs() - local row = {} - local i = 0 - for k, v in pairs(buffs) do - i = i + 1 - local result = {} - - -- 1st column - result[1] = 'All levels' - - -- 2nd column - if k == 'mining_speed' then - result[2] = '+ '.. v.value .. '% mining speed' - elseif k == 'inventory_slot' then - if v.value > 1 then - result[2] = '+ '.. v.value .. ' inventory slots' - else - result[2] = '+ '.. v.value .. ' inventory slot' - end - elseif k == 'health_bonus' then - result[2] = '+ '.. v.value .. ' max health' - else - result[2] = 'Description missing: unknown buff. Please contact admin' - end - - -- 3rd column - result[3] = '' - -- indicator to stop print level number - if i > 1 then - result[4] = true - else - result[4] = false - end - insert(row, result) - end - for _, unlockable in pairs(row) do - local list = buff_scroll_pane.add {type = 'table', column_count = 2 } - list.style.horizontal_spacing = 16 - - local caption = '' - if unlockable[4] ~= true then - caption = unlockable[1] - else - caption = '' - end - local tag_stone = list.add {type = 'label', name = buff_tag_label_stone, caption = caption} - tag_stone.style.minimal_width = 100 - - local tag_buffs = list.add {type = 'label', name = buff_tag_label_buff, caption = unlockable[2]} - tag_buffs.style.minimal_width = 220 - - tag_stone.style.font_color = {r = 1, g = 1, b = 1 } - tag_buffs.style.font_color = {r = 1, g = 1, b = 1 } - end -end - ----Interface for force control system to access the primary market ----@return LuaEntity the primary market (The one at spawn) -function MarketExchange.get_market() - - local markets = game.surfaces.nauvis.find_entities_filtered({name = 'market', position = config.market_spawn_position, limit = 1}) - - if (#markets == 0) then - Debug.print_position(config.market_spawn_position, 'Unable to find a market') - return - end - - return markets[1] -end - -local function on_placed_entity(event) - local market = event.entity - if 'market' ~= market.name then - return - end -end - -function MarketExchange.get_extra_map_info(config) - return 'Market Exchange, come make a deal at the foreman\'s shop' -end - -local function toggle(event) - local player = event.player - local left = player.gui.left - local frame = left['Diggy.MarketExchange.Frame'] - - if (frame and event.trigger == nil) then - Gui.destroy(frame) - return - elseif (frame) then - local data = Gui.get_data(frame) - redraw_title(data) - redraw_progressbar(data) - redraw_table(data) - return - end - - frame = left.add({name = 'Diggy.MarketExchange.Frame', type = 'frame', direction = 'vertical'}) - - local market_progressbars = frame.add({type = 'flow', direction = 'vertical'}) - local market_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) - - local market_scroll_pane = frame.add({type = 'scroll-pane'}) - market_scroll_pane.style.maximal_height = 300 - - local buff_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) - - local buff_scroll_pane = frame.add({type = 'scroll-pane'}) - buff_scroll_pane.style.maximal_height = 100 - - frame.add({ type = 'button', name = 'Diggy.MarketExchange.Button', caption = 'Close'}) - - local data = { - frame = frame, - market_progressbars = market_progressbars, - market_list_heading = market_list_heading, - market_scroll_pane = market_scroll_pane, - buff_list_heading = buff_list_heading, - buff_scroll_pane = buff_scroll_pane, - } - - redraw_title(data) - redraw_table(data) - - redraw_heading(data, 2) - redraw_buff(data) - - Gui.set_data(frame, data) - -end - -local function on_player_created(event) - Game.get_player_by_index(event.player_index).gui.top.add({ - name = 'Diggy.MarketExchange.Button', - type = 'sprite-button', - sprite = 'entity/market', - }) -end - -Gui.on_click('Diggy.MarketExchange.Button', toggle) -Gui.on_custom_close('Diggy.MarketExchange.Frame', function (event) - event.element.destroy() -end) - ----Updates the market progress gui for every player that has it open -function MarketExchange.update_gui() - for _, p in ipairs(game.connected_players) do - local frame = p.gui.left['Diggy.MarketExchange.Frame'] - - if frame and frame.valid then - local data = {player = p, trigger = 'update_gui'} - toggle(data) - end - end -end - -function MarketExchange.on_init() - Task.set_timeout_in_ticks(1, on_market_timeout_finished, { - surface = game.surfaces.nauvis, - position = config.market_spawn_position, - player_force = game.forces.player, - }) -end - ---[[-- - Registers all event handlers. -]] -function MarketExchange.register(cfg) - config = cfg - - --Events - Event.add(Template.events.on_placed_entity, on_placed_entity) - Event.add(defines.events.on_player_created, on_player_created) - Event.on_nth_tick(61, MarketExchange.update_gui) -end - -return MarketExchange diff --git a/map_gen/Diggy/Feature/StartingZone.lua b/map_gen/Diggy/Feature/StartingZone.lua index fb982260..37e17389 100644 --- a/map_gen/Diggy/Feature/StartingZone.lua +++ b/map_gen/Diggy/Feature/StartingZone.lua @@ -6,11 +6,13 @@ local Event = require 'utils.event' local Token = require 'utils.global_token' local Template = require 'map_gen.Diggy.Template' local Debug = require 'map_gen.Diggy.Debug' +local Retailer = require 'features.retailer' local DiggyCaveCollapse = require 'map_gen.Diggy.Feature.DiggyCaveCollapse' local insert = table.insert local random = math.random local sqrt = math.sqrt local floor = math.floor +local raise_event = script.raise_event -- this local StartingZone = {} @@ -67,7 +69,23 @@ function StartingZone.register(config) end end - Template.insert(event.surface, tiles, rocks) + Template.insert(surface, tiles, rocks) + + local position = config.market_spawn_position; + local player_force = game.forces.player; + + local market = surface.create_entity({name = 'market', position = position}) + market.destructible = false + + Retailer.add_market(player_force.name, market) + Retailer.ship_items(player_force.name) + + player_force.add_chart_tag(surface, { + text = 'Market', + position = position, + }) + + raise_event(Template.events.on_placed_entity, {entity = market}) Event.remove_removable(defines.events.on_chunk_generated, callback_token) end @@ -77,5 +95,4 @@ function StartingZone.register(config) Event.add_removable(defines.events.on_chunk_generated, callback_token) end - return StartingZone diff --git a/map_gen/Diggy/FormatMarketItems.lua b/map_gen/Diggy/FormatMarketItems.lua deleted file mode 100644 index ccf0bc06..00000000 --- a/map_gen/Diggy/FormatMarketItems.lua +++ /dev/null @@ -1,45 +0,0 @@ --- dependencies - --- this -local FormatMarketItems = {} - -local market_prototype_items = {} -local insert = table.insert - ---- Returns the correct format for Diggy.Feature.MarketExhange.lua to process --- @param self_level number of the level the given item should be unlocked at --- @param self_price number of the price in the configured currency_item the given item should cost --- @param self_name string of the factorio entity prototype-name --- -local function add(self_level, self_price, self_name) - if (not market_prototype_items[self_level]) then - insert(market_prototype_items, self_level, {}) - end - insert(market_prototype_items[self_level], {price = self_price, name = self_name}) -end - ---- handles the unlockable market items from Config.lua in map_gen.Diggy --- serves as a handler for an array of items and passes it on to FormatMarketItems.add() that returns the correct format for Diggy.Feature.MarketExhange.lua to process. --- @param items table of items where each item is an table with keys: level (integer level it unlocks at), price (price in the configured currency_item) and name (has to be an entity's prototype-name) --- @returns table of items formated in the correct way for Diggy.Feature.MarketExhange.lua to interpret. --- @usage Pass an table with each value being another table with these members: --- @field level number of the level wished to unlock the item --- @field price number of the price in the configured currency_item to buy the item in the market --- @field name string of the factorio prototype-name for the entity to be unlocked --- -function FormatMarketItems.initialize_unlockables(items) - local unlockables = {} - for _, item in ipairs(items) do - add(item.level, item.price, item.name) - end - - for lvl, v in pairs(market_prototype_items) do - for _, w in ipairs(v) do - insert(unlockables, {level = lvl, type = 'market', prototype = w}) - end - end - - return unlockables -end - -return FormatMarketItems diff --git a/map_gen/Diggy/Template.lua b/map_gen/Diggy/Template.lua index 59dc2554..f5681154 100644 --- a/map_gen/Diggy/Template.lua +++ b/map_gen/Diggy/Template.lua @@ -10,8 +10,8 @@ local raise_event = script.raise_event -- this local Template = {} -local tiles_per_call = 5 --how many tiles are inserted with each call of insert_action -local entities_per_call = 5 --how many entities are inserted with each call of insert_action +local tiles_per_call = 256 --how many tiles are inserted with each call of insert_action +local entities_per_call = 8 --how many entities are inserted with each call of insert_action Template.events = { --[[-- @@ -71,7 +71,7 @@ local function insert_next_entities(data) for i = data.entity_iterator, min(data.entity_iterator + entities_per_call - 1, data.entities_n) do local entity = data.entities[i] local created_entity = create_entity(entity) - if (nil == created_entity) then + if not created_entity then error('Failed creating entity ' .. entity.name .. ' on surface.') end @@ -128,7 +128,7 @@ function Template.insert(surface, tiles, entities) } local continue = true - for i = 1, 4 do + for _ = 1, 4 do continue = insert_action(data) if not continue then return @@ -155,24 +155,4 @@ function Template.resources(surface, resources) end end ---[[-- - Designed to spawn a market. - - @param surface LuaSurface - @param position Position - @param force LuaForce - @param market_items Table -]] -function Template.market(surface, position, force) - local market = surface.create_entity({name = 'market', position = position}) - market.destructible = false - - force.add_chart_tag(surface, { - text = 'Market', - position = position, - }) - - raise_event(Template.events.on_placed_entity, {entity = market}) -end - return Template From d80becdc9b46643253b5a68ad21373c5981add4d Mon Sep 17 00:00:00 2001 From: Lynn Date: Sun, 25 Nov 2018 20:24:37 +0100 Subject: [PATCH 30/43] I need Herr Stickler's approval --- features/force_control.lua | 20 ++++++++++---------- features/retailer.lua | 2 -- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/features/force_control.lua b/features/force_control.lua index 07375187..659ad854 100644 --- a/features/force_control.lua +++ b/features/force_control.lua @@ -4,6 +4,8 @@ local Event = require 'utils.event' local raise_event = script.raise_event local ceil = math.ceil local max = math.max +local floor = math.floor +local format = string.format -- this, things that can be done run-time local ForceControl = {} @@ -323,16 +325,14 @@ function ForceControl.get_formatted_force_data(lua_force_or_name) return end - local result = - string.format( - 'Current experience: %d Total experience: %d Current level: %d Next level at: %d Percentage to level up: %d%%', - force_config.current_experience, - force_config.total_experience, - force_config.current_level, - force_config.experience_level_up_cap, - math.floor(force_config.experience_percentage * 100) / 100 - ) - return result + return format( + 'Current experience: %d Total experience: %d Current level: %d Next level at: %d Percentage to level up: %d%%', + force_config.current_experience, + force_config.total_experience, + force_config.current_level, + force_config.experience_level_up_cap, + floor(force_config.experience_percentage * 100) * 0.01 + ) end return ForceControl diff --git a/features/retailer.lua b/features/retailer.lua index 1848f1a1..931b47b8 100644 --- a/features/retailer.lua +++ b/features/retailer.lua @@ -1,6 +1,4 @@ -local Debug = require 'map_gen.Diggy.Debug' local Global = require 'utils.global' -local format = string.format local insert = table.insert local Retailer = {} From 58be972190a93d0908b62b536f8199cae2b7120a Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 26 Nov 2018 20:23:53 +0100 Subject: [PATCH 31/43] Fixed collapse on biters error --- map_gen/Diggy/Feature/Experience.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map_gen/Diggy/Feature/Experience.lua b/map_gen/Diggy/Feature/Experience.lua index 302b231e..12f8f56c 100644 --- a/map_gen/Diggy/Feature/Experience.lua +++ b/map_gen/Diggy/Feature/Experience.lua @@ -259,8 +259,8 @@ local function on_entity_died (event) local text = string_format('+ %d XP', exp) Game.print_floating_text(entity.surface, entity.position, text, {r = 144, g = 202, b = 249}) ForceControl.add_experience(force, exp) - return end + return end if entity.force.name ~= 'enemy' then From a3ff0edd6159eba53a3b90de58beb719262f72d8 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 26 Nov 2018 20:31:10 +0100 Subject: [PATCH 32/43] Minor memory allocation fix --- map_gen/Diggy/Feature/Experience.lua | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/map_gen/Diggy/Feature/Experience.lua b/map_gen/Diggy/Feature/Experience.lua index 12f8f56c..1206a19d 100644 --- a/map_gen/Diggy/Feature/Experience.lua +++ b/map_gen/Diggy/Feature/Experience.lua @@ -50,6 +50,11 @@ end) local config = {} +local gain_xp_color = {r = 144, g = 202, b = 249} +local lose_xp_color = {r = 255, g = 0, b = 0} +local unlocked_color = {r = 255, g = 255, b = 255} +local locked_color = {r = 127, g = 127, b = 127} + local level_up_formula = (function (level_reached) local Config = require 'map_gen.Diggy.Config'.features.Experience local difficulty_scale = floor(Config.difficulty_scale) @@ -173,7 +178,7 @@ local function on_player_mined_entity(event) return end local text = string_format('+%d XP', exp) - Game.print_player_floating_text_position(player_index, text, {r = 144, g = 202, b = 249},0, -0.5) + Game.print_player_floating_text_position(player_index, text, gain_xp_color,0, -0.5) ForceControl.add_experience(force, exp) end @@ -193,7 +198,7 @@ local function on_research_finished(event) local text = string_format('Research completed! +%d XP', exp) for _, p in pairs(game.connected_players) do local player_index = p.index - Game.print_player_floating_text_position(player_index, text, {r = 144, g = 202, b = 249}, -1, -0.5) + Game.print_player_floating_text_position(player_index, text, gain_xp_color, -1, -0.5) end ForceControl.add_experience(force, exp) @@ -223,7 +228,7 @@ local function on_rocket_launched(event) local text = string_format('Rocket launched! +%d XP', exp) for _, p in pairs(game.connected_players) do local player_index = p.index - Game.print_player_floating_text_position(player_index, text, {r = 144, g = 202, b = 249},-1, -0.5) + Game.print_player_floating_text_position(player_index, text, gain_xp_color,-1, -0.5) end end @@ -241,7 +246,7 @@ local function on_entity_died (event) if cause and (cause.name == 'artillery-turret' or cause.name == 'gun-turret' or cause.name == 'laser-turret' or cause.name == 'flamethrower-turret') then exp = config.XP['enemy_killed'] * alien_coin_modifiers[entity.name] local text = string_format('+ %d XP', exp) - Game.print_floating_text(cause.surface, cause.position, text, {r = 144, g = 202, b = 249}) + Game.print_floating_text(cause.surface, cause.position, text, gain_xp_color) ForceControl.add_experience(force, exp) return else @@ -257,7 +262,7 @@ local function on_entity_died (event) end if exp then local text = string_format('+ %d XP', exp) - Game.print_floating_text(entity.surface, entity.position, text, {r = 144, g = 202, b = 249}) + Game.print_floating_text(entity.surface, entity.position, text, gain_xp_color) ForceControl.add_experience(force, exp) end return @@ -269,7 +274,7 @@ local function on_entity_died (event) local exp = config.XP['enemy_killed'] * alien_coin_modifiers[entity.name] local text = string_format('+ %d XP', exp) local player_index = cause.player.index - Game.print_player_floating_text_position(player_index, text, {r = 144, g = 202, b = 249},-1, -0.5) + Game.print_player_floating_text_position(player_index, text, gain_xp_color,-1, -0.5) ForceControl.add_experience(force, exp) end @@ -281,7 +286,7 @@ local function on_player_respawned(event) local exp = ForceControl.remove_experience_percentage(force, config.XP['death-penalty'], 50) local text = string_format('%s resurrected! -%d XP', player.name, exp) for _, p in pairs(game.connected_players) do - Game.print_player_floating_text_position(p.index, text, {r = 255, g = 0, b = 0},-1, -0.5) + Game.print_player_floating_text_position(p.index, text, lose_xp_color, -1, -0.5) end end @@ -350,9 +355,9 @@ local function redraw_table(data) local color if current_force_level >= current_item_level then - color = {r = 1, g = 1, b = 1 } + color = unlocked_color else - color = {r = 0.5, g = 0.5, b = 0.5 } + color = locked_color end local list = experience_scroll_pane.add({type = 'table', column_count = 2}) @@ -398,7 +403,7 @@ local function redraw_buff(data) local level_label = list.add({type = 'label', caption = level_caption}) level_label.style.minimal_width = 100 - level_label.style.font_color = {r = 1, g = 1, b = 1 } + level_label.style.font_color = unlocked_color local buff_caption local effect_value = effects.value @@ -414,7 +419,7 @@ local function redraw_buff(data) local buffs_label = list.add({ type = 'label', caption = buff_caption}) buffs_label.style.minimal_width = 220 - buffs_label.style.font_color = {r = 1, g = 1, b = 1 } + buffs_label.style.font_color = unlocked_color end end From cb9b8e3ecc86259394660f9d4eca2c0435dd69ba Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 26 Nov 2018 19:39:51 +0000 Subject: [PATCH 33/43] changed logic to remove regular's old name --- features/user_groups.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/features/user_groups.lua b/features/user_groups.lua index d93ee1f4..009057c7 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -128,8 +128,11 @@ Event.add( defines.events.on_player_joined_game, function(event) local correctCaseName = Game.get_player_by_index(event.player_index).name - if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then - Server.set_data('regulars', correctCaseName:lower(), nil) + local lowerCaseName = correctCaseName:lower() + if correctCaseName ~= lowerCaseName and global.regulars[lowerCaseName] then + global.regulars[lowerCaseName] = nil + global.regulars[correctCaseName] = true + Server.set_data('regulars', lowerCaseName, nil) Server.set_data('regulars', correctCaseName, true) end end From b142939c5f1caa12b8372889ac92e58e2c53256b Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 26 Nov 2018 19:09:52 -0500 Subject: [PATCH 34/43] Overhaul config and global.scenario usage (#466) --- .luacheckrc | 2 +- config.lua | 46 ++++++++++------------ features/fish_market.lua | 2 +- features/gui/info.lua | 8 ++-- features/gui/paint.lua | 4 +- features/gui/player_list.lua | 2 +- features/nuke_control.lua | 8 ++-- features/player_create.lua | 2 +- map_gen/Diggy/Scenario.lua | 6 +-- map_gen/combined/cave_miner/cave_miner.lua | 18 ++++----- map_gen/presets/crash_site.lua | 2 +- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 797a9089..a4fc9659 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -56,7 +56,7 @@ local STD_BASE_CONTROL = 'lua52c+factorio+factorio_control+factorio_defines+fact --[Assume Factorio Control stage as default]-- ------------------------------------------------------------------------------- std = STD_CONTROL -globals = {'math', 'table', '_DEBUG', '_CHEATS', 'MARKET_ITEM', 'newline'} -- RedMew-specific globals +globals = {'math', 'table', '_DEBUG', '_CHEATS', 'MARKET_ITEM'} -- RedMew-specific globals max_line_length = LINE_LENGTH not_globals = NOT_GLOBALS diff --git a/config.lua b/config.lua index 9ab02e76..f781f919 100644 --- a/config.lua +++ b/config.lua @@ -1,34 +1,30 @@ +-- global: the global table +-- global.scenario: the only segment of global we should touch +-- global. _DEBUG = false _CHEATS = false MARKET_ITEM = 'coin' -global.scenario = {} -global.scenario.variables = {} -global.scenario.variables.player_positions = {} -global.player_walk_distances = {} -global.scenario.variables.player_deaths = {} -global.scenario.config = {} -global.scenario.config.player_list = {} -global.scenario.config.player_list.enable_coin_col = true -global.scenario.config.paint = {} -global.scenario.config.paint.enable = true -global.scenario.config.fish_market = {} -global.scenario.config.fish_market.enable = true -global.scenario.config.nuke_control = {} -global.scenario.config.nuke_control.enable_autokick = true -global.scenario.config.nuke_control.enable_autoban = true -global.scenario.custom_functions = {} -global.scenario.config.nuke_control.nuke_min_time_hours = 3 --how long a player must be on the server to be allowed to use the nuke -global.scenario.config.players_assigned_names = false -- assigns players random names when they first join -global.scenario.config.players_roll_names = false -- allows players to roll random names -global.newline = '\n' -newline = '\n' +global.config = {} +global.config.player_list = {} +global.config.player_list.enable_coin_col = true +global.config.paint = {} +global.config.paint.enable = true +global.config.fish_market = {} +global.config.fish_market.enable = true +global.config.nuke_control = {} +global.config.nuke_control.enable_autokick = true +global.config.nuke_control.enable_autoban = true +global.config.hodor = true +global.config.auto_respond = true +global.config.mentions = true +global.config.nuke_control.nuke_min_time_hours = 3 --how long a player must be on the server to be allowed to use the nuke -- The title of the map -global.scenario.config.map_name_key = 'This Map has no name' +global.config.map_name_key = 'This Map has no name' -- The long description of the map, typically 1 paragraph -global.scenario.config.map_description_key = "By default this section is blank as it's supposed to be filled out on a per map basis. (If you're seeing this message, ping the admin team to get a description added for this map)" +global.config.map_description_key = "By default this section is blank as it's supposed to be filled out on a per map basis. (If you're seeing this message, ping the admin team to get a description added for this map)" -- The feature list of the map -global.scenario.config.map_extra_info_key = 'This map has no extra infomation' +global.config.map_extra_info_key = 'This map has no extra infomation' -- New Scenario Features, appears in the "What's new" tab -global.scenario.config.new_info_key = 'Nothing is new. The world is at peace' +global.config.new_info_key = 'Nothing is new. The world is at peace' diff --git a/features/fish_market.lua b/features/fish_market.lua index eb2e3373..0a8b53cd 100644 --- a/features/fish_market.lua +++ b/features/fish_market.lua @@ -410,7 +410,7 @@ local function fish_player_crafted_item(event) end local function init() - if global.scenario.config.fish_market.enable then + if global.config.fish_market.enable then commands.add_command('market', 'Places a fish market near you. (Admins only)', spawn_market) Event.on_nth_tick(180, on_180_ticks) diff --git a/features/gui/info.lua b/features/gui/info.lua index 3d5ae5cd..05795c32 100644 --- a/features/gui/info.lua +++ b/features/gui/info.lua @@ -21,10 +21,10 @@ local new_info_key = 4 local welcomed_players = {} local editable_info = { - [map_name_key] = global.scenario.config.map_name_key, - [map_description_key] = global.scenario.config.map_description_key, - [map_extra_info_key] = global.scenario.config.map_extra_info_key, - [new_info_key] = global.scenario.config.new_info_key + [map_name_key] = global.config.map_name_key, + [map_description_key] = global.config.map_description_key, + [map_extra_info_key] = global.config.map_extra_info_key, + [new_info_key] = global.config.new_info_key } Global.register( diff --git a/features/gui/paint.lua b/features/gui/paint.lua index fb3068ea..b5119423 100644 --- a/features/gui/paint.lua +++ b/features/gui/paint.lua @@ -41,7 +41,7 @@ local filter_table_close_button_name = Gui.uid_name() global.paint_brushes_by_player = {} local function player_build_tile(event) - if not global.scenario.config.paint.enable then + if not global.config.paint.enable then return end if event.item.name ~= brush_tool then @@ -75,7 +75,7 @@ local function player_build_tile(event) end local function player_joined(event) - if not global.scenario.config.paint.enable then + if not global.config.paint.enable then return end local player = Game.get_player_by_index(event.player_index) diff --git a/features/gui/player_list.lua b/features/gui/player_list.lua index c3a12007..e40dd581 100644 --- a/features/gui/player_list.lua +++ b/features/gui/player_list.lua @@ -448,7 +448,7 @@ local function get_default_player_settings() distance_heading_name } local offset = 6 - if global.scenario.config.player_list.enable_coin_col then + if global.config.player_list.enable_coin_col then columns[6] = coin_heading_name offset = 7 end diff --git a/features/nuke_control.lua b/features/nuke_control.lua index 85a3e006..5dfe4be3 100644 --- a/features/nuke_control.lua +++ b/features/nuke_control.lua @@ -5,7 +5,7 @@ local Game = require 'utils.game' local function allowed_to_nuke(player) if type(player) == 'table' then - return player.admin or UserGroups.is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_control.nuke_min_time_hours) + return player.admin or UserGroups.is_regular(player.name) or ((player.online_time / 216000) > global.config.nuke_control.nuke_min_time_hours) elseif type(player) == 'number' then return allowed_to_nuke(Game.get_player_by_index(player)) end @@ -109,7 +109,7 @@ local function on_capsule_used(event) local item = event.item local player = Game.get_player_by_index(event.player_index) - if not player or not player.valid or (global.scenario.config.nuke_control.enable_autokick and global.scenario.config.nuke_control.enable_autoban) then + if not player or not player.valid or (global.config.nuke_control.enable_autokick and global.config.nuke_control.enable_autoban) then return end @@ -132,12 +132,12 @@ local function on_capsule_used(event) end if count > 8 then if global.players_warned[event.player_index] then - if global.scenario.config.nuke_control.enable_autokick then + if global.config.nuke_control.enable_autokick then game.ban_player(player, string.format('Damaged %i entities with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord.', count, event.item.name)) end else global.players_warned[event.player_index] = true - if global.scenario.config.nuke_control.enable_autoban then + if global.config.nuke_control.enable_autoban then game.print(player, string.format('Damaged %i entities with %s -Antigrief', count, event.item.name)) end end diff --git a/features/player_create.lua b/features/player_create.lua index b889dd62..64842958 100644 --- a/features/player_create.lua +++ b/features/player_create.lua @@ -11,7 +11,7 @@ local function player_created(event) return end - if (global.scenario.config.fish_market.enable) then + if (global.config.fish_market.enable) then player.insert {name = MARKET_ITEM, count = 10} end player.insert {name = 'iron-gear-wheel', count = 8} diff --git a/map_gen/Diggy/Scenario.lua b/map_gen/Diggy/Scenario.lua index c3f16329..3ce7f9fb 100644 --- a/map_gen/Diggy/Scenario.lua +++ b/map_gen/Diggy/Scenario.lua @@ -45,9 +45,9 @@ function Scenario.register(debug, cheats) return end - global.scenario.config.player_list.enable_coin_col = false - if global.scenario.config then - global.scenario.config.fish_market.enable = nil + global.config.player_list.enable_coin_col = false + if global.config then + global.config.fish_market.enable = nil end if debug then diff --git a/map_gen/combined/cave_miner/cave_miner.lua b/map_gen/combined/cave_miner/cave_miner.lua index 0eceaefe..1b3c17b5 100644 --- a/map_gen/combined/cave_miner/cave_miner.lua +++ b/map_gen/combined/cave_miner/cave_miner.lua @@ -41,22 +41,22 @@ But be careful, eating too much might have it´s consequences too... ]]) -if global.scenario and global.scenario.config then - if global.scenario.config.player_list then - global.scenario.config.player_list.enable_coin_col = nil +if global.scenario and global.config then + if global.config.player_list then + global.config.player_list.enable_coin_col = nil end - if global.scenario.config.fish_market then - global.scenario.config.fish_market.enable = nil + if global.config.fish_market then + global.config.fish_market.enable = nil end - if global.scenario.config.paint then - global.scenario.config.paint.enable = nil + if global.config.paint then + global.config.paint.enable = nil end if global.scenario.nuke_control then global.scenario.nuke_control.enable_autokick = nil global.scenario.nuke_control.enable_autoban = nil end - if global.scenario.config.fish_market then - global.scenario.config.fish_market.enable = nil + if global.config.fish_market then + global.config.fish_market.enable = nil end end diff --git a/map_gen/presets/crash_site.lua b/map_gen/presets/crash_site.lua index adea2227..5b79a026 100644 --- a/map_gen/presets/crash_site.lua +++ b/map_gen/presets/crash_site.lua @@ -570,7 +570,7 @@ Global.register_init( tbl.outpost_seed = outpost_seed or seed tbl.ore_seed = ore_seed or seed - global.scenario.config.fish_market.enable = false + global.config.fish_market.enable = false end, function(tbl) outpost_seed = tbl.outpost_seed From 532c1c5bd701622077334eba48cfac59c64dd6e9 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Mon, 26 Nov 2018 21:08:38 -0500 Subject: [PATCH 35/43] Add print as global to luacheckrc --- .luacheckrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 797a9089..86115450 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -56,7 +56,7 @@ local STD_BASE_CONTROL = 'lua52c+factorio+factorio_control+factorio_defines+fact --[Assume Factorio Control stage as default]-- ------------------------------------------------------------------------------- std = STD_CONTROL -globals = {'math', 'table', '_DEBUG', '_CHEATS', 'MARKET_ITEM', 'newline'} -- RedMew-specific globals +globals = {'print', 'math', 'table', '_DEBUG', '_CHEATS', 'MARKET_ITEM', 'newline'} -- RedMew-specific globals max_line_length = LINE_LENGTH not_globals = NOT_GLOBALS From f0ab4be6c9bff5a55643373dd469278f55a235e0 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Tue, 27 Nov 2018 07:26:24 -0500 Subject: [PATCH 36/43] Add on_server_started as field in defines.events --- .luacheckrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 80d77ec0..86eccb12 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -625,7 +625,7 @@ stds.factorio_defines = { "on_gui_closed", "on_gui_value_changed", "on_player_muted", "on_player_unmuted", "on_player_cheat_mode_enabled", "on_player_cheat_mode_disabled", "on_character_corpse_expired", "on_pre_ghost_deconstructed", "on_player_pipette", "on_player_display_resolution_changed", "on_player_display_scale_changed", "on_pre_player_crafted_item", "on_player_cancelled_crafting", "on_chunk_charted", "on_technology_effects_reset", "on_land_mine_armed", "on_forces_merged", - "on_player_trash_inventory_changed", + "on_player_trash_inventory_changed", "on_server_started" }, }, alert_type = { From f010eb0119887a3fbcf75bc4250ec687e378a980 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 27 Nov 2018 12:32:33 +0000 Subject: [PATCH 37/43] moved server and serverCommands module to features + added more documentation to server --- control.lua | 4 +- features/gui/poll.lua | 2 +- server.lua => features/server.lua | 57 +++++++++++++++++++ .../server_commands.lua | 2 +- features/user_groups.lua | 2 +- 5 files changed, 62 insertions(+), 5 deletions(-) rename server.lua => features/server.lua (85%) rename server_commands.lua => features/server_commands.lua (95%) diff --git a/control.lua b/control.lua index 4d5110f0..1657b6a1 100644 --- a/control.lua +++ b/control.lua @@ -8,8 +8,8 @@ require 'map_gen.shared.perlin_noise' require 'map_layout' -- Specific to RedMew hosts, can be disabled safely if not hosting on RedMew servers -require 'server' -require 'server_commands' +require 'features.server' +require 'features.server_commands' -- Library modules which, if missing, will cause other feature modules to fail require 'features.base_data' diff --git a/features/gui/poll.lua b/features/gui/poll.lua index 7bab4608..ed8c1723 100644 --- a/features/gui/poll.lua +++ b/features/gui/poll.lua @@ -5,7 +5,7 @@ local UserGroups = require 'features.user_groups' local Game = require 'utils.game' local math = require 'utils.math' local Utils = require 'utils.utils' -local Server = require 'server' +local Server = require 'features.server' local default_poll_duration = 300 * 60 -- in ticks local duration_max = 3600 -- in seconds diff --git a/server.lua b/features/server.lua similarity index 85% rename from server.lua rename to features/server.lua index 9820b51a..5025ad94 100644 --- a/server.lua +++ b/features/server.lua @@ -1,3 +1,5 @@ +--- See documentation at https://github.com/Refactorio/RedMew/pull/469 + local Token = require 'utils.global_token' local Public = {} @@ -42,6 +44,9 @@ Public.events = {on_server_started = defines.events.on_server_started} --- Sends a message to the linked discord channel. The message is sanitized of markdown server side. -- @param message message to send. +-- @usage +-- local Server = require 'server' +-- Server.to_discord('Hello from scenario script!') function Public.to_discord(message) raw_print(discord_tag .. message) end @@ -96,6 +101,9 @@ end --- Stops and saves the factorio server and starts the named scenario. -- @param scenario_name The name of the scenario as appears in the scenario table on http://redmew.com/admin +-- @usage +-- local Server = require 'server' +-- Server.start_scenario('my_scenario_name') function Public.start_scenario(scenario_name) if type(scenario_name) ~= 'string' then game.print('start_scenario - scenario_name ' .. tostring(scenario_name) .. ' must be a string.') @@ -132,6 +140,14 @@ end -- @param data_set -- @param key -- @param value Any type that is not a function. set to nil to remove the data. +-- @usage +-- local Server = require 'server' +-- Server.set_data('my data set', 'key 1', 123) +-- Server.set_data('my data set', 'key 2', 'abc') +-- Server.set_data('my data set', 'key 3', {'some', 'data', ['is_set'] = true}) +-- +-- Server.set_data('my data set', 'key 1', nil) -- this will remove 'key 1' +-- Server.set_data('my data set', 'key 2', 'def') -- this will change the value for 'key 2' to 'def' function Public.set_data(data_set, key, value) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -179,6 +195,22 @@ end -- @param data_set -- @param key -- @param callback_token +-- @usage +-- local Server = require 'server' +-- local Token = require 'utils.global_token' +-- +-- local callback = +-- Token.register( +-- function(data) +-- local data_set = data.data_set +-- local key = data.key +-- local value = data.value -- will be nil if no data +-- +-- game.print(data_set .. ':' .. key .. ':' .. tostring(value)) +-- end +-- ) +-- +-- Server.try_get_data('my data set', 'key 1', callback) function Public.try_get_data(data_set, key, callback_token) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -203,6 +235,21 @@ end -- If there is no data stored for the data_set entries will be nil. -- @param data_set -- @param callback_token +-- @usage +-- local Server = require 'server' +-- local Token = require 'utils.global_token' +-- +-- local callback = +-- Token.register( +-- function(data) +-- local data_set = data.data_set +-- local entries = data.entries -- will be nil if no data +-- local value2 = entries['key 2'] +-- local value3 = entries['key 3'] +-- end +-- ) +-- +-- Server.try_get_all_data('my data set', callback) function Public.try_get_all_data(data_set, callback_token) if type(data_set) ~= 'string' then error('data_set must be a string') @@ -251,6 +298,16 @@ end -- is in the control stage, i.e before on_init or on_load would be called. -- @param data_set -- @param handler +-- @usage +-- local Server = require 'server' +-- Server.on_data_set_changed( +-- 'my data set', +-- function(data) +-- local data_set = data.data_set +-- local key = data.key +-- local value = data.value -- will be nil if data was removed. +-- end +-- ) function Public.on_data_set_changed(data_set, handler) if type(data_set) ~= 'string' then error('data_set must be a string') diff --git a/server_commands.lua b/features/server_commands.lua similarity index 95% rename from server_commands.lua rename to features/server_commands.lua index 31629b5c..3a34e076 100644 --- a/server_commands.lua +++ b/features/server_commands.lua @@ -1,7 +1,7 @@ local Poll = require 'features.gui.poll' local UserGroups = require 'features.user_groups' local Token = require 'utils.global_token' -local Server = require 'server' +local Server = require 'features.server' --- This module is for the web server to call functions and raise events. -- Not intended to be called by scripts. diff --git a/features/user_groups.lua b/features/user_groups.lua index 009057c7..e35971d9 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -1,6 +1,6 @@ local Event = require 'utils.event' local Utils = require 'utils.utils' -local Server = require 'server' +local Server = require 'features.server' local Donators = require 'resources.donators' local Game = require 'utils.game' local Token = require 'utils.global_token' From 212e34170dfff94aefe939a8754a37dd24b26663 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Tue, 27 Nov 2018 07:26:24 -0500 Subject: [PATCH 38/43] Add on_server_started as field in defines.events and ServerCommands as global --- .luacheckrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 86eccb12..23895768 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -56,7 +56,7 @@ local STD_BASE_CONTROL = 'lua52c+factorio+factorio_control+factorio_defines+fact --[Assume Factorio Control stage as default]-- ------------------------------------------------------------------------------- std = STD_CONTROL -globals = {'print', 'math', 'table', '_DEBUG', '_CHEATS', 'MARKET_ITEM'} -- RedMew-specific globals +globals = {'print', 'math', 'table', '_DEBUG', '_CHEATS', 'MARKET_ITEM', 'ServerCommands'} -- RedMew-specific globals max_line_length = LINE_LENGTH not_globals = NOT_GLOBALS From 7cbf650e638d77b72d36fdb97cbc129935b60183 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Tue, 27 Nov 2018 07:50:07 -0500 Subject: [PATCH 39/43] Add explicit luacheck ignore when defining on_server_started --- features/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/server.lua b/features/server.lua index 5025ad94..e5c62b10 100644 --- a/features/server.lua +++ b/features/server.lua @@ -29,7 +29,7 @@ Public.raw_print = raw_print local data_set_handlers = {} -defines.events.on_server_started = script.generate_event_name() +defines.events.on_server_started = script.generate_event_name() -- luacheck: ignore --- The event id for the on_server_started event. -- The event is raised whenever the server goes from the starting state to the running state. From 031c8b82d9c83a1b7e73c4ac1b118771ca52adca Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 27 Nov 2018 14:47:37 +0000 Subject: [PATCH 40/43] added nil check for regulars and donators fetched from web --- features/user_groups.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/user_groups.lua b/features/user_groups.lua index e35971d9..9a7f5796 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -42,7 +42,7 @@ end local sync_regulars_callback = Token.register( function(data) - global.regulars = data.entries + global.regulars = data.entries or {} end ) @@ -105,7 +105,7 @@ end local sync_donators_callback = Token.register( function(data) - global.donators = data.entries + global.donators = data.entries or {} end ) From 3e56fe32b8c5a92b051017f6969d46c7a2823d67 Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 27 Nov 2018 14:48:45 +0000 Subject: [PATCH 41/43] removed defines.events.on_server_started --- features/server.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/server.lua b/features/server.lua index e5c62b10..fe38fba4 100644 --- a/features/server.lua +++ b/features/server.lua @@ -29,8 +29,6 @@ Public.raw_print = raw_print local data_set_handlers = {} -defines.events.on_server_started = script.generate_event_name() -- luacheck: ignore - --- The event id for the on_server_started event. -- The event is raised whenever the server goes from the starting state to the running state. -- It provides a good opportunity to request data from the web server. @@ -40,7 +38,7 @@ defines.events.on_server_started = script.generate_event_name() -- luacheck: ign -- function() -- Server.try_get_all_data('regulars', callback) -- end) -Public.events = {on_server_started = defines.events.on_server_started} +Public.events = {on_server_started = script.generate_event_name()} --- Sends a message to the linked discord channel. The message is sanitized of markdown server side. -- @param message message to send. From 5585c0357b6e9c28025695f97f4d7e1692cb3d3d Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 27 Nov 2018 16:51:15 +0000 Subject: [PATCH 42/43] fixed printing regulars and donators to all players --- features/user_groups.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/user_groups.lua b/features/user_groups.lua index 9a7f5796..1c8d2763 100644 --- a/features/user_groups.lua +++ b/features/user_groups.lua @@ -57,7 +57,7 @@ Module.print_regulars = function() end result = table.concat(result, ', ') - game.print(result) + Game.player_print(result) end function Module.get_rank(player) @@ -121,7 +121,7 @@ function Module.print_donators() end result = table.concat(result, ', ') - game.print(result) + Game.player_print(result) end Event.add( From 6667ab3e11935236ead822e94f9ef02b11bcb375 Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 27 Nov 2018 16:54:41 +0000 Subject: [PATCH 43/43] updated docs --- features/server.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/features/server.lua b/features/server.lua index fe38fba4..ffd6793b 100644 --- a/features/server.lua +++ b/features/server.lua @@ -34,6 +34,9 @@ local data_set_handlers = {} -- It provides a good opportunity to request data from the web server. -- Note that if the server is stopped then started again, this event will be raised again. -- @usage +-- local Server = require 'features.server' +-- local Event = require 'utils.event' +-- -- Event.add(Server.events.on_server_started, -- function() -- Server.try_get_all_data('regulars', callback) @@ -43,7 +46,7 @@ Public.events = {on_server_started = script.generate_event_name()} --- Sends a message to the linked discord channel. The message is sanitized of markdown server side. -- @param message message to send. -- @usage --- local Server = require 'server' +-- local Server = require 'features.server' -- Server.to_discord('Hello from scenario script!') function Public.to_discord(message) raw_print(discord_tag .. message) @@ -100,7 +103,7 @@ end --- Stops and saves the factorio server and starts the named scenario. -- @param scenario_name The name of the scenario as appears in the scenario table on http://redmew.com/admin -- @usage --- local Server = require 'server' +-- local Server = require 'features.server' -- Server.start_scenario('my_scenario_name') function Public.start_scenario(scenario_name) if type(scenario_name) ~= 'string' then @@ -139,7 +142,7 @@ end -- @param key -- @param value Any type that is not a function. set to nil to remove the data. -- @usage --- local Server = require 'server' +-- local Server = require 'features.server' -- Server.set_data('my data set', 'key 1', 123) -- Server.set_data('my data set', 'key 2', 'abc') -- Server.set_data('my data set', 'key 3', {'some', 'data', ['is_set'] = true}) @@ -194,7 +197,7 @@ end -- @param key -- @param callback_token -- @usage --- local Server = require 'server' +-- local Server = require 'features.server' -- local Token = require 'utils.global_token' -- -- local callback = @@ -234,7 +237,7 @@ end -- @param data_set -- @param callback_token -- @usage --- local Server = require 'server' +-- local Server = require 'features.server' -- local Token = require 'utils.global_token' -- -- local callback = @@ -297,7 +300,7 @@ end -- @param data_set -- @param handler -- @usage --- local Server = require 'server' +-- local Server = require 'features.server' -- Server.on_data_set_changed( -- 'my data set', -- function(data) @@ -320,6 +323,7 @@ function Public.on_data_set_changed(data_set, handler) end end +--- Called by the web server to notify the client that a data_set has changed. Public.raise_data_set = data_set_changed --- Called by the web server to determine which data_sets are being tracked.