@expcluster/legacy 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/browser/package.json +40 -0
- package/dist/browser/tsconfig.browser.tsbuildinfo +1 -0
- package/dist/browser/web/index.d.ts +1 -0
- package/dist/browser/web/index.d.ts.map +1 -0
- package/dist/browser/web/index.js +2 -0
- package/dist/browser/web/index.js.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +10 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/instance.d.ts +4 -0
- package/dist/node/instance.d.ts.map +1 -0
- package/dist/node/instance.js +8 -0
- package/dist/node/instance.js.map +1 -0
- package/dist/node/tsconfig.node.tsbuildinfo +1 -0
- package/dist/web/manifest.json +7 -0
- package/dist/web/static/exp_legacy.9b6538559ed5e689539c.js +355 -0
- package/dist/web/static/index_ts.8f9d451c8d3f7f293da6.js +22 -0
- package/dist/web/static/main.94e1b48804112ca8bdfc.js +118 -0
- package/dist/web/static/package_json.a83729efdb0697b12396.js +22 -0
- package/dist/web/static/web_index_tsx.e5a01ac0e4b0a6f6517f.js +21 -0
- package/index.ts +8 -0
- package/instance.ts +7 -0
- package/module/config/_file_loader.lua +29 -0
- package/module/config/advanced_start.lua +112 -0
- package/module/config/afk_kick.lua +14 -0
- package/module/config/bonus.lua +105 -0
- package/module/config/chat_reply.lua +136 -0
- package/module/config/compilatron.lua +25 -0
- package/module/config/death_logger.lua +15 -0
- package/module/config/deconlog.lua +11 -0
- package/module/config/discord_alerts.lua +25 -0
- package/module/config/expcore/permission_groups.lua +143 -0
- package/module/config/graftorio.lua +7 -0
- package/module/config/gui/autofill.lua +129 -0
- package/module/config/gui/player_list_actions.lua +201 -0
- package/module/config/gui/rockets.lua +47 -0
- package/module/config/gui/science.lua +21 -0
- package/module/config/gui/tasks.lua +13 -0
- package/module/config/gui/warps.lua +52 -0
- package/module/config/inventory_clear.lua +9 -0
- package/module/config/join_messages.lua +8 -0
- package/module/config/lawnmower.lua +6 -0
- package/module/config/logging.lua +30 -0
- package/module/config/miner.lua +8 -0
- package/module/config/module.lua +86 -0
- package/module/config/nukeprotect.lua +30 -0
- package/module/config/pollution_grading.lua +9 -0
- package/module/config/popup_messages.lua +10 -0
- package/module/config/preset_player_colours.lua +33 -0
- package/module/config/preset_player_quickbar.lua +6 -0
- package/module/config/protection.lua +17 -0
- package/module/config/repair.lua +8 -0
- package/module/config/research.lua +179 -0
- package/module/config/scorched_earth.lua +116 -0
- package/module/config/spawn_area.lua +255 -0
- package/module/config/station_auto_name.lua +11 -0
- package/module/config/statistics.lua +46 -0
- package/module/config/vlayer.lua +180 -0
- package/module/config/warnings.lua +38 -0
- package/module/control.lua +46 -0
- package/module/expcore/datastore.lua +884 -0
- package/module/expcore/external.lua +146 -0
- package/module/expcore/permission_groups.lua +355 -0
- package/module/expcore/player_data.lua +152 -0
- package/module/locale/en/addons.cfg +31 -0
- package/module/locale/en/data.cfg +114 -0
- package/module/locale/en/expcore.cfg +16 -0
- package/module/locale/en/gui.cfg +114 -0
- package/module/locale/zh-CN/addons.cfg +31 -0
- package/module/locale/zh-CN/data.cfg +114 -0
- package/module/locale/zh-CN/expcore.cfg +16 -0
- package/module/locale/zh-CN/gui.cfg +122 -0
- package/module/locale/zh-TW/addons.cfg +31 -0
- package/module/locale/zh-TW/data.cfg +114 -0
- package/module/locale/zh-TW/expcore.cfg +16 -0
- package/module/locale/zh-TW/gui.cfg +122 -0
- package/module/module.json +14 -0
- package/module/module_exports.lua +3 -0
- package/module/modules/control/jail.lua +119 -0
- package/module/modules/control/protection.lua +204 -0
- package/module/modules/control/reports.lua +225 -0
- package/module/modules/control/spectate.lua +173 -0
- package/module/modules/control/vlayer.lua +807 -0
- package/module/modules/control/warnings.lua +331 -0
- package/module/modules/control/warps.lua +488 -0
- package/module/modules/data/alt-view.lua +26 -0
- package/module/modules/data/greetings.lua +45 -0
- package/module/modules/data/language.lua +21 -0
- package/module/modules/data/player-colours.lua +63 -0
- package/module/modules/data/quickbar.lua +72 -0
- package/module/modules/data/statistics.lua +181 -0
- package/module/modules/data/tag.lua +82 -0
- package/module/modules/data/toolbar.lua +31 -0
- package/module/modules/graftorio/forcestats.lua +196 -0
- package/module/modules/graftorio/general.lua +63 -0
- package/module/modules/graftorio/require.lua +28 -0
- package/module/modules/graftorio/statics.lua +36 -0
- package/module/modules/gui/vlayer.lua +547 -0
- package/module/modules/gui/warp-list.lua +909 -0
- package/module/utils/event.lua +86 -0
- package/package.json +38 -0
- package/tsconfig.browser.json +4 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +5 -0
- package/web/index.tsx +0 -0
- package/webpack.config.js +29 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--[[-- Core Module - External
|
|
2
|
+
- A module used to make accessing externally set data easier.
|
|
3
|
+
@core External
|
|
4
|
+
@alias External
|
|
5
|
+
|
|
6
|
+
@usage-- Printing all server to chat
|
|
7
|
+
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
|
|
8
|
+
|
|
9
|
+
local message = 'id: %s name: %s version: %s status: %s'
|
|
10
|
+
for server_id, server in pairs(External.get_servers()) do
|
|
11
|
+
local status = External.get_server_status(server_id)
|
|
12
|
+
game.print(message:format(server_id, server.name, server.version, status))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
]]
|
|
16
|
+
|
|
17
|
+
local ext --- @type table<string, any>
|
|
18
|
+
local var --- @type table<string, any>
|
|
19
|
+
local concat = table.concat
|
|
20
|
+
|
|
21
|
+
local External = {}
|
|
22
|
+
|
|
23
|
+
--[[-- Checks that local links are valid, will try to add the links if invalid
|
|
24
|
+
@treturn boolean If the external data is valid, if false you should not call any other methods from External
|
|
25
|
+
|
|
26
|
+
@usage-- Check that external data is valid
|
|
27
|
+
if not External.valid() then
|
|
28
|
+
-- error code here
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
]]
|
|
32
|
+
function External.valid()
|
|
33
|
+
local stored = storage.ext
|
|
34
|
+
if stored == nil then return false end
|
|
35
|
+
if ext == stored and var == ext.var then
|
|
36
|
+
return var ~= nil
|
|
37
|
+
else
|
|
38
|
+
ext = stored
|
|
39
|
+
var = stored.var
|
|
40
|
+
return var ~= nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
--[[-- Gets a table of all the servers, key is the server id, value is the server details
|
|
45
|
+
@treturn table A table containing all the servers, key is the server id, value is the server details
|
|
46
|
+
|
|
47
|
+
@usage-- Get all servers
|
|
48
|
+
local servers = External.get_servers()
|
|
49
|
+
|
|
50
|
+
]]
|
|
51
|
+
function External.get_servers()
|
|
52
|
+
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
|
53
|
+
return (assert(ext.servers, "No server list was found, please ensure that the external service is running"))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
--[[-- Gets a table of all the servers filtered by name, key is the server id, value is the server details
|
|
57
|
+
@tparam string search The string to search for, names, short_names and ids are checked for this string.
|
|
58
|
+
@treturn table A table containing all the servers filtered by name, key is the server id, value is the server details
|
|
59
|
+
|
|
60
|
+
@usage-- Get all servers with public in the name
|
|
61
|
+
local servers = External.get_servers_filtered(public)
|
|
62
|
+
|
|
63
|
+
]]
|
|
64
|
+
function External.get_servers_filtered(search)
|
|
65
|
+
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
|
66
|
+
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
|
67
|
+
local found_servers = {}
|
|
68
|
+
search = search:lower()
|
|
69
|
+
for server_id, server in pairs(servers) do
|
|
70
|
+
local str = concat{ server.name, server.short_name, server.id }
|
|
71
|
+
if str:lower():find(search, 1, true) then found_servers[server_id] = server end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
return found_servers
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
--[[-- Gets the details of the current server
|
|
78
|
+
@treturn table The details of the current server
|
|
79
|
+
|
|
80
|
+
@usage-- Get the details of the current server
|
|
81
|
+
local server = External.get_current_server()
|
|
82
|
+
|
|
83
|
+
]]
|
|
84
|
+
function External.get_current_server()
|
|
85
|
+
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
|
86
|
+
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
|
87
|
+
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
|
88
|
+
return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
--[[-- Gets the details of the given server
|
|
92
|
+
@tparam string server_id The internal server if for the server you want the details of
|
|
93
|
+
@treturn table The details of the given server
|
|
94
|
+
|
|
95
|
+
@usage-- Get the details of the given server
|
|
96
|
+
local server = External.get_server_details('eu-01')
|
|
97
|
+
|
|
98
|
+
]]
|
|
99
|
+
function External.get_server_details(server_id)
|
|
100
|
+
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
|
101
|
+
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
|
102
|
+
return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
--[[-- Gets the status of the given server
|
|
106
|
+
@tparam string server_id The internal server if for the server you want the status of
|
|
107
|
+
@tparam boolean raw When true Current will not be returned as status but rather the raw status for the server
|
|
108
|
+
@treturn string The status of the given server, one of: Online, Modded, Protected, Current, Offline
|
|
109
|
+
|
|
110
|
+
@usage-- Get the status of the given server
|
|
111
|
+
local status = External.get_server_status('eu-01')
|
|
112
|
+
|
|
113
|
+
]]
|
|
114
|
+
function External.get_server_status(server_id, raw)
|
|
115
|
+
assert(var, "No external data was found, use External.valid() to ensure external data exists.")
|
|
116
|
+
local servers = assert(var.status, "No server status was found, please ensure that the external service is running")
|
|
117
|
+
local current = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
|
118
|
+
return not raw and server_id == current and "Current" or assert(servers[server_id], "No status found for server with id: " .. tostring(server_id))
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
--[[-- Connect a player to the given server
|
|
122
|
+
@tparam LuaPlayer player The player that you want to request to join a different server
|
|
123
|
+
@tparam string server_id The internal id of the server to connect to, can also be any address but this will show Unknown Server
|
|
124
|
+
@tparam[opt=false] boolean self_requested If the player requested the join themself, this will hide the message about being asked to switch
|
|
125
|
+
|
|
126
|
+
@usage-- Request that a player joins a different server
|
|
127
|
+
External.request_connection(player, 'eu-01')
|
|
128
|
+
|
|
129
|
+
@usage-- Request that a player joins a different server, by own request
|
|
130
|
+
External.request_connection(player, 'eu-01', true)
|
|
131
|
+
|
|
132
|
+
]]
|
|
133
|
+
function External.request_connection(player, server_id, self_requested)
|
|
134
|
+
local server = { address = server_id, name = "Unknown Server", description = "This server is not ran by us, please check the address of the server." }
|
|
135
|
+
if ext and ext.servers and ext.servers[server_id] then server = ext.servers[server_id] end
|
|
136
|
+
local message = "Please press the connect button below to join."
|
|
137
|
+
if not self_requested then message = "You have been asked to switch to a different server.\n" .. message end
|
|
138
|
+
player.connect_to_server{
|
|
139
|
+
address = server.address,
|
|
140
|
+
name = "\n[color=orange][font=heading-1]" .. server.name .. "[/font][/color]\n",
|
|
141
|
+
description = server.description .. "\n" .. message,
|
|
142
|
+
}
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
--- Module return
|
|
146
|
+
return External
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
--[[-- Core Module - Permission Groups
|
|
2
|
+
- Permission group making for factorio so you never have to make one by hand again
|
|
3
|
+
@core Groups
|
|
4
|
+
@alias Permissions_Groups
|
|
5
|
+
|
|
6
|
+
@usage--- Example Group (Allow All)
|
|
7
|
+
-- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups
|
|
8
|
+
Permission_Groups.new_group('Admin') -- this defines a new group called "Admin"
|
|
9
|
+
:allow_all() -- this makes the default to allow any input action unless set other wise
|
|
10
|
+
:disallow{ -- here we disallow the input action we don't want them to use
|
|
11
|
+
'add_permission_group',
|
|
12
|
+
'delete_permission_group',
|
|
13
|
+
'import_permissions_string',
|
|
14
|
+
'map_editor_action',
|
|
15
|
+
'toggle_map_editor'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@usage--- Example Group (Disallow All)
|
|
19
|
+
-- here we will create a group that cant do anything but talk in chat
|
|
20
|
+
Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted"
|
|
21
|
+
:disallow_all() -- this makes the default to disallow any input action unless set other wise
|
|
22
|
+
:allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action
|
|
23
|
+
|
|
24
|
+
]]
|
|
25
|
+
|
|
26
|
+
local Event = require("modules/exp_legacy/utils/event")
|
|
27
|
+
local Async = require("modules/exp_util/async")
|
|
28
|
+
|
|
29
|
+
local PermissionsGroups = {
|
|
30
|
+
groups = {}, -- store for the different groups that are created
|
|
31
|
+
_prototype = {}, -- stores functions that are used on group instances
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
-- Async function to add players to permission groups
|
|
35
|
+
local add_to_permission_group_async =
|
|
36
|
+
Async.register(function(permission_group, player)
|
|
37
|
+
permission_group.add_player(player)
|
|
38
|
+
end)
|
|
39
|
+
PermissionsGroups.add_to_permission_group_async = add_to_permission_group_async
|
|
40
|
+
|
|
41
|
+
-- Async function to remove players from permission groups
|
|
42
|
+
local remove_from_permission_group_async =
|
|
43
|
+
Async.register(function(permission_group, player)
|
|
44
|
+
permission_group.remove_player(player)
|
|
45
|
+
end)
|
|
46
|
+
PermissionsGroups.remove_from_permission_group_async = remove_from_permission_group_async
|
|
47
|
+
|
|
48
|
+
--- Getters.
|
|
49
|
+
-- Functions that get permission groups
|
|
50
|
+
-- @section getters
|
|
51
|
+
|
|
52
|
+
--[[-- Defines a new permission group that can have it actions set in the config
|
|
53
|
+
@tparam string name the name of the new group
|
|
54
|
+
@treturn Permissions_Groups._prototype the new group made with function to allow and disallow actions
|
|
55
|
+
|
|
56
|
+
@usage-- Defining a new permission group
|
|
57
|
+
Groups.new_group('Admin')
|
|
58
|
+
|
|
59
|
+
]]
|
|
60
|
+
function PermissionsGroups.new_group(name)
|
|
61
|
+
local group = setmetatable({
|
|
62
|
+
name = name,
|
|
63
|
+
actions = {},
|
|
64
|
+
allow_all_actions = true,
|
|
65
|
+
}, {
|
|
66
|
+
__index = PermissionsGroups._prototype,
|
|
67
|
+
})
|
|
68
|
+
PermissionsGroups.groups[name] = group
|
|
69
|
+
return group
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
--[[-- Returns the group with the given name, case sensitive
|
|
73
|
+
@tparam string name the name of the group to get
|
|
74
|
+
@treturn ?Permissions_Groups._prototype|nil the group with that name or nil if non found
|
|
75
|
+
|
|
76
|
+
@usage-- Getting a permision group
|
|
77
|
+
local admin_group = Groups.get_group_by_name('Admin')
|
|
78
|
+
|
|
79
|
+
]]
|
|
80
|
+
function PermissionsGroups.get_group_by_name(name)
|
|
81
|
+
return PermissionsGroups.groups[name]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
--[[-- Returns the group that a player is in
|
|
85
|
+
@tparam LuaPlayer player the player to get the group of can be name index etc
|
|
86
|
+
@treturn ?Permissions_Groups._prototype|nil the group with that player or nil if non found
|
|
87
|
+
|
|
88
|
+
@usage-- Get your permission group
|
|
89
|
+
local group = Groups.get_group_from_player(game.player)
|
|
90
|
+
|
|
91
|
+
]]
|
|
92
|
+
function PermissionsGroups.get_group_from_player(player)
|
|
93
|
+
local group = player.permission_group
|
|
94
|
+
if group then
|
|
95
|
+
return PermissionsGroups.groups[group.name]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
--- Setters.
|
|
100
|
+
-- Functions that control all groups
|
|
101
|
+
-- @section players
|
|
102
|
+
|
|
103
|
+
--[[-- Reloads/creates all permission groups and sets them to they configured state
|
|
104
|
+
|
|
105
|
+
@usage-- Reload the permission groups, used internally
|
|
106
|
+
Groups.reload_permissions()
|
|
107
|
+
|
|
108
|
+
]]
|
|
109
|
+
function PermissionsGroups.reload_permissions()
|
|
110
|
+
for _, group in pairs(PermissionsGroups.groups) do
|
|
111
|
+
group:create()
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
--[[-- Sets a player's group to the one given, a player can only have one group at a time
|
|
116
|
+
@tparam LuaPlayer player the player to effect can be name index etc
|
|
117
|
+
@tparam string group the name of the group to give to the player
|
|
118
|
+
@treturn boolean true if the player was added successfully, false other wise
|
|
119
|
+
|
|
120
|
+
@usage-- Set your permission group
|
|
121
|
+
Groups.set_player_group(game.player, 'Admin')
|
|
122
|
+
|
|
123
|
+
]]
|
|
124
|
+
function PermissionsGroups.set_player_group(player, group)
|
|
125
|
+
group = PermissionsGroups.get_group_by_name(group)
|
|
126
|
+
if not group or not player then return false end
|
|
127
|
+
group:add_player(player)
|
|
128
|
+
return true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
--- Actions.
|
|
132
|
+
-- Functions that control group actions
|
|
133
|
+
-- @section actions
|
|
134
|
+
|
|
135
|
+
--[[-- Sets the allow state of an action for this group, used internally but is safe to use else where
|
|
136
|
+
@tparam ?string|defines.input_action action the action that you want to set the state of
|
|
137
|
+
@tparam boolean state the state that you want to set it to, true = allow, false = disallow
|
|
138
|
+
@treturn Permissions_Groups._prototype returns self so function can be chained
|
|
139
|
+
|
|
140
|
+
@usage-- Set an action to be disallowed
|
|
141
|
+
group:set_action('toggle_map_editor', false)
|
|
142
|
+
|
|
143
|
+
]]
|
|
144
|
+
function PermissionsGroups._prototype:set_action(action, state)
|
|
145
|
+
local input_action = defines.input_action[action] --[[@as defines.input_action?]]
|
|
146
|
+
if input_action == nil then input_action = action end
|
|
147
|
+
assert(type(input_action) == "number", tostring(action) .. " is not a valid input action")
|
|
148
|
+
self.actions[input_action] = state
|
|
149
|
+
return self
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
--[[-- Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime
|
|
153
|
+
@tparam string|Array<string> actions the action or actions that you want to allow for this group
|
|
154
|
+
@treturn Permissions_Groups._prototype returns self so function can be chained
|
|
155
|
+
|
|
156
|
+
@usage-- Allow some actions
|
|
157
|
+
group:allow{
|
|
158
|
+
'write_to_console'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
]]
|
|
162
|
+
function PermissionsGroups._prototype:allow(actions)
|
|
163
|
+
if type(actions) ~= "table" then
|
|
164
|
+
actions = { actions }
|
|
165
|
+
end
|
|
166
|
+
for _, action in pairs(actions) do
|
|
167
|
+
self:set_action(action, true)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
return self
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
--[[-- Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime
|
|
174
|
+
@tparam string|Array<string> actions the action or actions that you want to disallow for this group
|
|
175
|
+
@treturn Permissions_Groups._prototype returns self so function can be chained
|
|
176
|
+
|
|
177
|
+
@usage-- Disalow some actions
|
|
178
|
+
group:disallow{
|
|
179
|
+
'add_permission_group',
|
|
180
|
+
'delete_permission_group',
|
|
181
|
+
'import_permissions_string',
|
|
182
|
+
'map_editor_action',
|
|
183
|
+
'toggle_map_editor'
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
]]
|
|
187
|
+
function PermissionsGroups._prototype:disallow(actions)
|
|
188
|
+
if type(actions) ~= "table" then
|
|
189
|
+
actions = { actions }
|
|
190
|
+
end
|
|
191
|
+
for _, action in pairs(actions) do
|
|
192
|
+
self:set_action(action, false)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
return self
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
--[[-- Sets the default state for any actions not given to be allowed, useful with :disallow
|
|
199
|
+
@treturn Permissions_Groups._prototype returns self so function can be chained
|
|
200
|
+
|
|
201
|
+
@usage-- Allow all actions unless given by disallow
|
|
202
|
+
group:allow_all()
|
|
203
|
+
|
|
204
|
+
]]
|
|
205
|
+
function PermissionsGroups._prototype:allow_all()
|
|
206
|
+
self.allow_all_actions = true
|
|
207
|
+
return self
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
--[[-- Sets the default state for any action not given to be disallowed, useful with :allow
|
|
211
|
+
@treturn Permissions_Groups._prototype returns self so function can be chained
|
|
212
|
+
|
|
213
|
+
@usage-- Disallow all actions unless given by allow
|
|
214
|
+
group:disallow_all()
|
|
215
|
+
|
|
216
|
+
]]
|
|
217
|
+
function PermissionsGroups._prototype:disallow_all()
|
|
218
|
+
self.allow_all_actions = false
|
|
219
|
+
return self
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
--[[-- Returns if an input action is allowed for this group
|
|
223
|
+
@tparam ?string|defines.input_action action the action that you want to test for
|
|
224
|
+
@treturn boolean true if the group is allowed the action, false other wise
|
|
225
|
+
|
|
226
|
+
@usage-- Test if a group is allowed an action
|
|
227
|
+
local allowed = group:is_allowed('write_to_console')
|
|
228
|
+
|
|
229
|
+
]]
|
|
230
|
+
function PermissionsGroups._prototype:is_allowed(action)
|
|
231
|
+
if type(action) == "string" then
|
|
232
|
+
action = defines.input_action[action]
|
|
233
|
+
end
|
|
234
|
+
local state = self.actions[action]
|
|
235
|
+
if state == nil then
|
|
236
|
+
state = self.allow_all_actions
|
|
237
|
+
end
|
|
238
|
+
return state
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
--- Players.
|
|
242
|
+
-- Functions that control group players
|
|
243
|
+
-- @section players
|
|
244
|
+
|
|
245
|
+
--[[-- Creates or updates the permission group with the configured actions, used internally
|
|
246
|
+
@treturn LuaPermissionGroup the permission group that was created
|
|
247
|
+
|
|
248
|
+
@usage-- Create the permission group so players can be added, used internally
|
|
249
|
+
group:create()
|
|
250
|
+
|
|
251
|
+
]]
|
|
252
|
+
function PermissionsGroups._prototype:create()
|
|
253
|
+
local group = self:get_raw()
|
|
254
|
+
if not group then
|
|
255
|
+
group = game.permissions.create_group(self.name) --[[@as LuaPermissionGroup]]
|
|
256
|
+
end
|
|
257
|
+
for _, action in pairs(defines.input_action) do
|
|
258
|
+
group.set_allows_action(action, self:is_allowed(action))
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
return group
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
--[[-- Returns the LuaPermissionGroup that was created with this group object, used internally
|
|
265
|
+
@treturn LuaPermissionGroup the raw lua permission group
|
|
266
|
+
|
|
267
|
+
@usage-- Get the factorio api permision group, used internally
|
|
268
|
+
local permission_group = group:get_raw()
|
|
269
|
+
|
|
270
|
+
]]
|
|
271
|
+
function PermissionsGroups._prototype:get_raw()
|
|
272
|
+
return game.permissions.get_group(self.name)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
--[[-- Adds a player to this group
|
|
276
|
+
@tparam LuaPlayer player LuaPlayer the player you want to add to this group can be name or index etc
|
|
277
|
+
@treturn boolean true if the player was added successfully, false other wise
|
|
278
|
+
|
|
279
|
+
@usage-- Add a player to this permission group
|
|
280
|
+
group:add_player(game.player)
|
|
281
|
+
|
|
282
|
+
]]
|
|
283
|
+
function PermissionsGroups._prototype:add_player(player)
|
|
284
|
+
local group = self:get_raw()
|
|
285
|
+
if not group or not player then return false end
|
|
286
|
+
add_to_permission_group_async(group, player)
|
|
287
|
+
return true
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
--[[-- Removes a player from this group
|
|
291
|
+
@tparam LuaPlayer player LuaPlayer the player you want to remove from this group can be name or index etc
|
|
292
|
+
@treturn boolean true if the player was removed successfully, false other wise
|
|
293
|
+
|
|
294
|
+
@usage-- Remove a player from this permission group
|
|
295
|
+
group:remove_player(game.player)
|
|
296
|
+
|
|
297
|
+
]]
|
|
298
|
+
function PermissionsGroups._prototype:remove_player(player)
|
|
299
|
+
local group = self:get_raw()
|
|
300
|
+
if not group or not player then return false end
|
|
301
|
+
remove_from_permission_group_async(group, player)
|
|
302
|
+
return true
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
--[[-- Returns all player that are in this group with the option to filter to online/offline only
|
|
306
|
+
@tparam[opt] boolean online if nil returns all players, if true online players only, if false returns online players only
|
|
307
|
+
@treturn table a table of players that are in this group; filtered if online param is given
|
|
308
|
+
|
|
309
|
+
@usage-- Get all players in this group
|
|
310
|
+
local online_players = group:get_players()
|
|
311
|
+
|
|
312
|
+
@usage-- Get all online players in this group
|
|
313
|
+
local online_players = group:get_players(true)
|
|
314
|
+
|
|
315
|
+
]]
|
|
316
|
+
function PermissionsGroups._prototype:get_players(online)
|
|
317
|
+
local players = {}
|
|
318
|
+
local group = self:get_raw()
|
|
319
|
+
if group then
|
|
320
|
+
if online == nil then
|
|
321
|
+
return group.players
|
|
322
|
+
else
|
|
323
|
+
for _, player in pairs(group.players) do
|
|
324
|
+
if player.connected == online then
|
|
325
|
+
table.insert(player, player)
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
return players
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
--[[-- Prints a message to every player in this group
|
|
334
|
+
@tparam string message the message that you want to send to the players
|
|
335
|
+
@treturn number the number of players that received the message
|
|
336
|
+
|
|
337
|
+
@usage-- Print a message to all players in thie group
|
|
338
|
+
group:print('Hello, World!')
|
|
339
|
+
|
|
340
|
+
]]
|
|
341
|
+
function PermissionsGroups._prototype:print(message)
|
|
342
|
+
local players = self:get_players(true)
|
|
343
|
+
for _, player in pairs(players) do
|
|
344
|
+
player.print(message)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
return #players
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
-- when the game starts it will make the permission groups
|
|
351
|
+
Event.on_init(function()
|
|
352
|
+
PermissionsGroups.reload_permissions()
|
|
353
|
+
end)
|
|
354
|
+
|
|
355
|
+
return PermissionsGroups
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
--[[-- Core Module - PlayerData
|
|
2
|
+
- A module used to store player data in a central datastore to minimize data requests and saves.
|
|
3
|
+
@core PlayerData
|
|
4
|
+
|
|
5
|
+
@usage-- Adding a colour setting for players
|
|
6
|
+
local PlayerData = require("modules.exp_legacy.expcore.player_data")
|
|
7
|
+
local PlayerColors = PlayerData.Settings:combine('Color')
|
|
8
|
+
|
|
9
|
+
-- Set the players color when their data is loaded
|
|
10
|
+
PlayerColors:on_load(function(player_name, color)
|
|
11
|
+
local player = game.players[player_name]
|
|
12
|
+
player.color = color
|
|
13
|
+
end)
|
|
14
|
+
|
|
15
|
+
-- Overwrite the saved color with the players current color
|
|
16
|
+
PlayerColors:on_save(function(player_name, _)
|
|
17
|
+
local player = game.players[player_name]
|
|
18
|
+
return player.color -- overwrite existing data with the current color
|
|
19
|
+
end)
|
|
20
|
+
|
|
21
|
+
@usage-- Add a playtime statistic for players
|
|
22
|
+
local Event = require("modules/exp_legacy/utils/event")
|
|
23
|
+
local PlayerData = require("modules.exp_legacy.expcore.player_data")
|
|
24
|
+
local Playtime = PlayerData.Statistics:combine('Playtime')
|
|
25
|
+
|
|
26
|
+
-- When playtime reaches an hour interval tell the player and say thanks
|
|
27
|
+
Playtime:on_update(function(player_name, playtime)
|
|
28
|
+
if playtime % 60 == 0 then
|
|
29
|
+
local hours = playtime / 60
|
|
30
|
+
local player = game.players[player_name]
|
|
31
|
+
player.print('Thanks for playing on our servers, you have played for '..hours..' hours!')
|
|
32
|
+
end
|
|
33
|
+
end)
|
|
34
|
+
|
|
35
|
+
-- Update playtime for players, data is only loaded for online players so update_all can be used
|
|
36
|
+
Event.add_on_nth_tick(3600, function()
|
|
37
|
+
Playtime:update_all(function(player_name, playtime)
|
|
38
|
+
return playtime + 1
|
|
39
|
+
end)
|
|
40
|
+
end)
|
|
41
|
+
|
|
42
|
+
]]
|
|
43
|
+
|
|
44
|
+
local Async = require("modules/exp_util/async")
|
|
45
|
+
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
|
46
|
+
local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expcore.datastore
|
|
47
|
+
local Commands = require("modules/exp_commands")
|
|
48
|
+
|
|
49
|
+
local table_to_json = helpers.table_to_json
|
|
50
|
+
local write_file = helpers.write_file
|
|
51
|
+
|
|
52
|
+
--- Common player data that acts as the root store for player data
|
|
53
|
+
local PlayerData = Datastore.connect("PlayerData", true) -- saveToDisk
|
|
54
|
+
PlayerData:set_serializer(Datastore.name_serializer) -- use player name
|
|
55
|
+
|
|
56
|
+
--- Store and enum for the data saving preference
|
|
57
|
+
local DataSavingPreference = PlayerData:combine("DataSavingPreference")
|
|
58
|
+
local PreferenceEnum = { "All", "Statistics", "Settings", "Required" } --- @type table<string | number, string | number>
|
|
59
|
+
for k, v in ipairs(PreferenceEnum) do PreferenceEnum[v] = k end
|
|
60
|
+
|
|
61
|
+
DataSavingPreference:set_default("All")
|
|
62
|
+
DataSavingPreference:set_metadata{
|
|
63
|
+
name = { "expcore-data.preference" },
|
|
64
|
+
tooltip = { "expcore-data.preference-tooltip" },
|
|
65
|
+
value_tooltip = { "expcore-data.preference-value-tooltip" },
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
--- Sets your data saving preference
|
|
69
|
+
Commands.new("data-preference", { "expcore-data.description-preference" })
|
|
70
|
+
:optional("option", { "expcore-data.arg-option" }, Commands.types.enum(PreferenceEnum))
|
|
71
|
+
:register(function(player, option)
|
|
72
|
+
--- @cast option "All" | "Statistics" | "Settings" | "Required" | nil
|
|
73
|
+
if option then
|
|
74
|
+
DataSavingPreference:set(player, option)
|
|
75
|
+
return Commands.status.success{ "expcore-data.set-preference", option }
|
|
76
|
+
else
|
|
77
|
+
return Commands.status.success{ "expcore-data.get-preference", DataSavingPreference:get(player) }
|
|
78
|
+
end
|
|
79
|
+
end)
|
|
80
|
+
|
|
81
|
+
--- Gets your data and writes it to a file
|
|
82
|
+
Commands.new("save-data", { "expcore-data.description-data" })
|
|
83
|
+
:register(function(player)
|
|
84
|
+
player.print{ "expcore-data.get-data" }
|
|
85
|
+
write_file("expgaming_player_data.json", table_to_json(PlayerData:get(player, {})), false, player.index)
|
|
86
|
+
end)
|
|
87
|
+
|
|
88
|
+
--- Async function called after 5 seconds with no player data loaded
|
|
89
|
+
local check_data_loaded_async =
|
|
90
|
+
Async.register(function(player)
|
|
91
|
+
local player_data = PlayerData:get(player)
|
|
92
|
+
if not player_data or not player_data.valid then
|
|
93
|
+
player.print{ "expcore-data.data-failed" }
|
|
94
|
+
Datastore.ingest("request", "PlayerData", player.name, '{"valid":false}')
|
|
95
|
+
end
|
|
96
|
+
end)
|
|
97
|
+
|
|
98
|
+
--- When player data loads tell the player if the load had failed previously
|
|
99
|
+
PlayerData:on_load(function(player_name, player_data, existing_data)
|
|
100
|
+
if not player_data or player_data.valid == false then return end
|
|
101
|
+
if existing_data and existing_data.valid == false then
|
|
102
|
+
game.players[player_name].print{ "expcore-data.data-restore" }
|
|
103
|
+
end
|
|
104
|
+
player_data.valid = true
|
|
105
|
+
end)
|
|
106
|
+
|
|
107
|
+
--- Remove data that the player doesnt want to have stored
|
|
108
|
+
PlayerData:on_save(function(player_name, player_data)
|
|
109
|
+
local data_preference = DataSavingPreference:get(player_name)
|
|
110
|
+
data_preference = PreferenceEnum[data_preference]
|
|
111
|
+
if data_preference == PreferenceEnum.All then
|
|
112
|
+
player_data.valid = nil
|
|
113
|
+
return player_data
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
local saved_player_data = { PlayerRequired = player_data.PlayerRequired, DataSavingPreference = PreferenceEnum[data_preference] }
|
|
117
|
+
if data_preference <= PreferenceEnum.Settings then saved_player_data["PlayerSettings"] = player_data.PlayerSettings end
|
|
118
|
+
if data_preference <= PreferenceEnum.Statistics then saved_player_data["PlayerStatistics"] = player_data.PlayerStatistics end
|
|
119
|
+
|
|
120
|
+
return saved_player_data
|
|
121
|
+
end)
|
|
122
|
+
|
|
123
|
+
--- Display your data preference when your data loads
|
|
124
|
+
DataSavingPreference:on_load(function(player_name, data_preference)
|
|
125
|
+
game.players[player_name].print{ "expcore-data.get-preference", data_preference or DataSavingPreference.default }
|
|
126
|
+
end)
|
|
127
|
+
|
|
128
|
+
--- Load player data when they join
|
|
129
|
+
Event.add(defines.events.on_player_joined_game, function(event)
|
|
130
|
+
local player = game.players[event.player_index]
|
|
131
|
+
check_data_loaded_async:start_after(300, player)
|
|
132
|
+
PlayerData:request(player)
|
|
133
|
+
end)
|
|
134
|
+
|
|
135
|
+
--- Unload player data when they leave
|
|
136
|
+
Event.add(defines.events.on_player_left_game, function(event)
|
|
137
|
+
local player = game.players[event.player_index]
|
|
138
|
+
local player_data = PlayerData:get(player)
|
|
139
|
+
if player_data and player_data.valid == true then
|
|
140
|
+
PlayerData:unload(player)
|
|
141
|
+
end
|
|
142
|
+
end)
|
|
143
|
+
|
|
144
|
+
----- Module Return -----
|
|
145
|
+
return {
|
|
146
|
+
All = PlayerData, -- Root for all of a players data
|
|
147
|
+
Statistics = PlayerData:combine("Statistics"), -- Common place for stats
|
|
148
|
+
Settings = PlayerData:combine("Settings"), -- Common place for settings
|
|
149
|
+
Required = PlayerData:combine("Required"), -- Common place for required data
|
|
150
|
+
DataSavingPreference = DataSavingPreference, -- Stores what data groups will be saved
|
|
151
|
+
PreferenceEnum = PreferenceEnum, -- Enum for the allowed options for data saving preference
|
|
152
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[links]
|
|
2
|
+
discord=https://discord.explosivegaming.nl
|
|
3
|
+
website=https://www.explosivegaming.nl
|
|
4
|
+
status=https://status.explosivegaming.nl
|
|
5
|
+
github=https://github.com/explosivegaming/ExpCluster
|
|
6
|
+
patreon=https://www.patreon.com/ExpGaming
|
|
7
|
+
|
|
8
|
+
[info]
|
|
9
|
+
players-online=There are __1__ players online
|
|
10
|
+
total-map-time=This map has been on for __1__
|
|
11
|
+
discord=Join us on our discord at: https://discord.explosivegaming.nl
|
|
12
|
+
website=Please visit our website at: https://www.explosivegaming.nl
|
|
13
|
+
status=Want to check if out servers are down? Visit: https://status.explosivegaming.nl
|
|
14
|
+
github=Want to help improve our server with some extra features? Help us at: https://github.com/explosivegaming/ExpCluster
|
|
15
|
+
patreon=Consider supporting our server at: https://www.patreon.com/ExpGaming
|
|
16
|
+
custom-commands=We use custom commands, such as /tag and /me, use /chelp for more info.
|
|
17
|
+
read-readme=Make sure you have read the information gui (It can be found through the info mark on the top left)
|
|
18
|
+
softmod=We run a softmod on our servers. A softmod is a custom scenario that runs on this server, an example is the player list.
|
|
19
|
+
redmew=We don't talk about redmew here; they beat us to 1000 members ;-;
|
|
20
|
+
lhd=All trains must be LHD! This is a long standing rule on our servers, please respect this.
|
|
21
|
+
|
|
22
|
+
[warnings]
|
|
23
|
+
received=You received a warning from __1__. You have __2__ warnings. __3__
|
|
24
|
+
pre-kick=This is your last warning before you are kicked.
|
|
25
|
+
kick=You were kicked for having too many warnings; you may rejoin if you wish.
|
|
26
|
+
pre-pre-ban=You are close to receiving a ban; successful ban appeals are unlikely.
|
|
27
|
+
pre-ban=This your LAST warning before you are BANNED! Successful ban appeals are unlikely.
|
|
28
|
+
ban=You were banned for having too many warnings; visit __1__ to request a ban appeal.
|
|
29
|
+
script-warning=You are receiving script warnings; if you recive too many you will receive a permanent warning (__1__/__2__)
|
|
30
|
+
script-warning-removed=A script warning has expired (__1__/__2__)
|
|
31
|
+
script-warning-limit=__1__ has received a permanent warning from the script.
|