mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-21 15: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
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user