mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-21 23:33:12 +09:00
Add the exp_reports plugin and move the scenario onto it
Reports were the last legacy control module, kept in the lua state of each instance. They are now an exp_reports plugin which stores them on the controller: a report is immutable and holds the reported player, who made it, the reason, the instance name and when it was made, and the only operations are get, list, create and delete. In game nothing is stored. The lua module sends each request over ipc, the instance plugin asks the controller and hands the answer back with rcon, and the module prints it to whoever asked if they are still online. Answers are dropped if the instance stopped meanwhile. The module raises on_player_reported with the count and reporters of every report against the player, which report_jail and discord_alerts use, and the commands and player list button call into it. The web ui gets a /reports page: a table with search on the player, reporter and reason, a filter on the instance, delete per row and a create form which reports in the name of the web user. New reports are posted to two optional webhooks configured on the controller, a Discord channel hook as an embed and a generic JSON hook. Failures are logged rather than failing the report. Tests cover the messages, the controller against a real Controller, the instance plugin against a real Instance, and the lua module through the shared harness.
This commit is contained in:
1 parent
142d296a02
commit
bad98c5013
35 files changed
+1707
-350
No files matched your search
@@ -3,13 +3,12 @@ Adds a commands that allow players to report other players
|
||||
]]
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local format_player_name = Commands.format_player_name_locale
|
||||
local parse_input = Commands.parse_input
|
||||
|
||||
local Roles = require("modules/exp_roles")
|
||||
local player_has_permission = Roles.player_has_permission
|
||||
|
||||
local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports
|
||||
local Reports = require("modules/exp_reports")
|
||||
|
||||
--- @param input string
|
||||
--- @param player LuaPlayer
|
||||
@@ -29,7 +28,7 @@ local function reportable_player(input, player)
|
||||
end
|
||||
end
|
||||
|
||||
--- Reports a player and notifies admins
|
||||
--- Reports a player and notifies admins, the outcome is printed once the controller answers
|
||||
Commands.new("create-report", { "exp-commands_reports.description-create" })
|
||||
:argument("player", { "exp-commands_reports.arg-player-create" }, reportable_player)
|
||||
:argument("reason", { "exp-commands_reports.arg-reason" }, Commands.types.string)
|
||||
@@ -38,50 +37,20 @@ Commands.new("create-report", { "exp-commands_reports.description-create" })
|
||||
:register(function(player, other_player, reason)
|
||||
--- @cast other_player LuaPlayer
|
||||
--- @cast reason string
|
||||
local player_name = format_player_name(player)
|
||||
local other_player_name = format_player_name(other_player)
|
||||
if Reports.report_player(other_player, player.name, reason) then
|
||||
local user_message = { "exp-commands_reports.response", other_player_name, reason }
|
||||
local admin_message = { "exp-commands_reports.response-admin", other_player_name, player_name, reason }
|
||||
for _, connected_player in ipairs(game.connected_players) do
|
||||
if connected_player.admin then
|
||||
connected_player.print(admin_message)
|
||||
else
|
||||
connected_player.print(user_message)
|
||||
end
|
||||
end
|
||||
else
|
||||
return Commands.status.invalid_input{ "exp-commands_reports.already-reported" }
|
||||
end
|
||||
Reports.create_report(player, other_player, reason)
|
||||
end)
|
||||
|
||||
--- Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.
|
||||
--- Lists the reports against a player, or the number against every player, printed once the controller answers
|
||||
Commands.new("get-reports", { "exp-commands_reports.description-get" })
|
||||
:optional("player", { "exp-commands_reports.arg-player-get" }, Commands.types.player)
|
||||
:add_aliases{ "reports" }
|
||||
:add_flags{ "admin_only" }
|
||||
:register(function(player, other_player)
|
||||
--- @cast other_player LuaPlayer?
|
||||
if other_player then
|
||||
local reports = Reports.get_reports(other_player)
|
||||
local other_player_name = format_player_name(other_player)
|
||||
Commands.print{ "exp-commands_reports.player-title", other_player_name, #reports }
|
||||
for by_player_name, reason in pairs(reports) do
|
||||
local by_player_name_formatted = format_player_name(by_player_name)
|
||||
Commands.print{ "exp-commands_reports.list-element", by_player_name_formatted, reason }
|
||||
end
|
||||
else
|
||||
local reports = Reports.user_reports
|
||||
Commands.print{ "exp-commands_reports.reports-title" }
|
||||
for player_name in pairs(reports) do
|
||||
local player_name_formatted = format_player_name(player_name)
|
||||
local report_count = Reports.count_reports(player_name)
|
||||
Commands.print{ "exp-commands_reports.list-element", player_name_formatted, report_count }
|
||||
end
|
||||
end
|
||||
Reports.list_reports(player, other_player)
|
||||
end)
|
||||
|
||||
--- Clears all reports from a player or just the report from one player.
|
||||
--- Clears all reports from a player or just the report from one player, printed once the controller answers
|
||||
Commands.new("clear-reports", { "exp-commands_reports.description-clear" })
|
||||
:argument("player", { "exp-commands_reports.arg-player-clear" }, Commands.types.player)
|
||||
:optional("from-player", { "exp-commands_reports.arg-from-player" }, Commands.types.player)
|
||||
@@ -89,22 +58,5 @@ Commands.new("clear-reports", { "exp-commands_reports.description-clear" })
|
||||
:register(function(player, other_player, from_player)
|
||||
--- @cast other_player LuaPlayer
|
||||
--- @cast from_player LuaPlayer?
|
||||
local player_name = format_player_name(player)
|
||||
local other_player_name = format_player_name(other_player)
|
||||
if from_player then
|
||||
if not Reports.remove_report(other_player, from_player.name, player.name) then
|
||||
local from_player_name = format_player_name(other_player)
|
||||
return Commands.status.invalid_input{ "exp-commands_reports.not-reported-by", from_player_name }
|
||||
else
|
||||
game.print{ "exp-commands_reports.removed", other_player_name, player_name }
|
||||
return Commands.status.success()
|
||||
end
|
||||
else
|
||||
if not Reports.remove_all(other_player, player.name) then
|
||||
return Commands.status.invalid_input{ "exp-commands_reports.not-reported" }
|
||||
else
|
||||
game.print{ "exp-commands_reports.removed-all", other_player_name, player_name }
|
||||
return Commands.status.success()
|
||||
end
|
||||
end
|
||||
Reports.delete_reports(player, other_player, from_player and from_player.name)
|
||||
end)
|
||||
@@ -99,10 +99,10 @@ end
|
||||
|
||||
--- Reports added and removed
|
||||
if config.player_reports then
|
||||
local Reports = require("modules.exp_legacy.modules.control.reports")
|
||||
events[Reports.events.on_player_reported] = function(event)
|
||||
local Reports = require("modules/exp_reports")
|
||||
--- @param event EventData.ExpReports.on_player_reported
|
||||
events[Reports.on_player_reported] = function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
local player = assert(game.get_player(player_name))
|
||||
emit_event{
|
||||
title = "Report",
|
||||
description = "A player was reported",
|
||||
@@ -110,22 +110,22 @@ if config.player_reports then
|
||||
fields = {
|
||||
{ name = "Player", inline = true, value = append_playtime(player_name) },
|
||||
{ name = "By", inline = true, value = append_playtime(by_player_name) },
|
||||
{ name = "Report Count", inline = true, value = Reports.count_reports(player) },
|
||||
{ name = "Report Count", inline = true, value = tostring(event.report_count) },
|
||||
{ name = "Reason", value = event.reason },
|
||||
},
|
||||
}
|
||||
end
|
||||
events[Reports.events.on_report_removed] = function(event)
|
||||
if event.batch ~= 1 then return end
|
||||
local player_name = get_player_name(event)
|
||||
--- @param event EventData.ExpReports.on_reports_deleted
|
||||
events[Reports.on_reports_deleted] = function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title = "Reports Removed",
|
||||
description = "A player has a report removed",
|
||||
description = "A player has reports removed",
|
||||
color = Colors.green,
|
||||
fields = {
|
||||
{ name = "Player", inline = true, value = append_playtime(player_name) },
|
||||
{ name = "By", inline = true, value = append_playtime(event.removed_by_name) },
|
||||
{ name = "Report Count", inline = true, value = tostring(event.batch_count) },
|
||||
{ name = "By", inline = true, value = append_playtime(by_player_name) },
|
||||
{ name = "Report Count", inline = true, value = tostring(event.count) },
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
@@ -4,28 +4,24 @@ When a player is reported, the player is automatically jailed if the combined pl
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Jail = require("modules/exp_scenario/control/jail")
|
||||
local Reports = require("modules.exp_legacy.modules.control.reports")
|
||||
local Reports = require("modules/exp_reports")
|
||||
|
||||
local max = math.max
|
||||
local format_player_name = ExpUtil.format_player_name_locale
|
||||
|
||||
--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters
|
||||
--- @param player LuaPlayer
|
||||
--- @param by_player_name string
|
||||
--- @param reason string
|
||||
--- @return number
|
||||
local function reporter_playtime(player, by_player_name, reason)
|
||||
local by_player = game.get_player(by_player_name)
|
||||
return by_player and by_player.online_time or 0
|
||||
end
|
||||
|
||||
--- Check if the player has too many reports against them (based on playtime)
|
||||
--- Check if the player has too many reports against them, weighed by the playtime of the reporters
|
||||
--- @param event EventData.ExpReports.on_player_reported
|
||||
local function on_player_reported(event)
|
||||
local player = assert(game.get_player(event.player_index))
|
||||
local total_playtime = Reports.count_reports(player, reporter_playtime)
|
||||
|
||||
local total_playtime = 0
|
||||
for _, by_player_name in ipairs(event.by_player_names) do
|
||||
local by_player = game.get_player(by_player_name)
|
||||
total_playtime = total_playtime + (by_player and by_player.online_time or 0)
|
||||
end
|
||||
|
||||
-- Total time greater than the players own time, or 30 minutes, which ever is greater
|
||||
if Reports.count_reports(player) > 1 and total_playtime > max(player.online_time * 2, 108000) then
|
||||
if event.report_count > 1 and total_playtime > max(player.online_time * 2, 108000) then
|
||||
Jail.jail_player(player, "<reports>", "Reported by too many players, please wait for a moderator.")
|
||||
game.print{ "exp_report-jail.chat-jailed", format_player_name(player) }
|
||||
end
|
||||
@@ -33,6 +29,6 @@ end
|
||||
|
||||
return {
|
||||
events = {
|
||||
[Reports.events.on_player_reported] = on_player_reported,
|
||||
[Reports.on_player_reported] = on_player_reported,
|
||||
}
|
||||
}
|
||||
@@ -172,16 +172,6 @@ arg-reason=Reason you want to report this player.
|
||||
arg-from-player=Only remove the report from this player.
|
||||
player-immune=This player can not be reported.
|
||||
self-report=You cannot report yourself.
|
||||
response=__1__ was reported for __2__.
|
||||
response-admin=__1__ was reported by __2__ for __3__.
|
||||
already-reported=You can only report a player once, you can ask a moderator to clear this report.
|
||||
not-reported=The player had no reports on them.
|
||||
not-reported-by=The player had no reports on them from __1__.
|
||||
reports-title=The following players have reports against them:
|
||||
player-title=__1__ has __2__ __plural_for_parameter__2__{1=report|rest=reports}__ against them:
|
||||
list-element=__1__: __2__
|
||||
removed-all=__1__ has has all of their reports removed by __2__.
|
||||
removed=__1__ has a report removed by __2__.
|
||||
|
||||
[exp-commands_roles]
|
||||
description-assign=Assigns a role to a player.
|
||||
|
||||
@@ -173,16 +173,6 @@ arg-reason=原因
|
||||
arg-from-player=用戶
|
||||
player-immune=用戶不能被舉報
|
||||
self-report=你不能舉報自己
|
||||
response=__1__ 因 __2__ 被舉報了。
|
||||
response-admin=__1__ 因 __3__ 被 __2__ 舉報了。
|
||||
already-reported=你已經舉報過該用戶了,你可以讓管理員清除報告來重寫
|
||||
not-reported=該用戶沒有被舉報的紀錄。
|
||||
not-reported-by=該用戶沒有被 __1__ 舉報的紀錄。
|
||||
reports-title==該用戶現在的被舉報紀錄:
|
||||
player-title=__1__ 有 __2__ 項被舉報的紀錄:
|
||||
list-element=__1__: __2__
|
||||
removed-all=__1__ 被舉報的所有紀錄已被 __2__ 清除。
|
||||
removed=__1__ 被舉報的一個紀錄已被 __2__ 清除。
|
||||
|
||||
[exp-commands_roles]
|
||||
description-assign=為用戶指配用戶組
|
||||
|
||||
@@ -173,16 +173,6 @@ arg-reason=原因
|
||||
arg-from-player=用戶
|
||||
player-immune=用戶不能被舉報
|
||||
self-report=你不能舉報自己
|
||||
response=__1__ 因 __2__ 被舉報了。
|
||||
response-admin=__1__ 因 __3__ 被 __2__ 舉報了。
|
||||
already-reported=你已經舉報過該用戶了,你可以讓管理員清除報告來重寫
|
||||
not-reported=該用戶沒有被舉報的紀錄。
|
||||
not-reported-by=該用戶沒有被 __1__ 舉報的紀錄。
|
||||
reports-title==該用戶現在的被舉報紀錄:
|
||||
player-title=__1__ 有 __2__ 項被舉報的紀錄:
|
||||
list-element=__1__: __2__
|
||||
removed-all=__1__ 被舉報的所有紀錄已被 __2__ 清除。
|
||||
removed=__1__ 被舉報的一個紀錄已被 __2__ 清除。
|
||||
|
||||
[exp-commands_roles]
|
||||
description-assign=為用戶指配用戶組
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"clusterio": "*",
|
||||
"exp_util": "*",
|
||||
"exp_roles": "*",
|
||||
"exp_reports": "*",
|
||||
"exp_gui": "*",
|
||||
"exp_commands": "*"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user