Skip to content

Commit

Permalink
feat: add events for reporting rule violations and bugs by players
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Nov 20, 2024
1 parent 6f07493 commit d713301
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 79 deletions.
82 changes: 3 additions & 79 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,7 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
return true
end

function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
return true
end
function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder) end

function Player:onMoveCreature(creature, fromPosition, toPosition)
local player = creature:getPlayer()
Expand All @@ -382,82 +380,8 @@ function Player:onMoveCreature(creature, fromPosition, toPosition)
return true
end

local function hasPendingReport(playerGuid, targetName, reportType)
local player = Player(playerGuid)
if not player then
return false
end
local name = player:getName():gsub("%s+", "_")
FS.mkdir_p(string.format("%s/reports/players/%s", CORE_DIRECTORY, name))
local file = io.open(string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType), "r")
if file then
io.close(file)
return true
end
return false
end

function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation)
local name = self:getName()
if hasPendingReport(self:getGuid(), targetName, reportType) then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end

local file = io.open(string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType), "a")
if not file then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return
end

io.output(file)
io.write("------------------------------\n")
io.write("Reported by: " .. name .. "\n")
io.write("Target: " .. targetName .. "\n")
io.write("Type: " .. reportType .. "\n")
io.write("Reason: " .. reportReason .. "\n")
io.write("Comment: " .. comment .. "\n")
if reportType ~= REPORT_TYPE_BOT then
io.write("Translation: " .. translation .. "\n")
end
io.write("------------------------------\n")
io.close(file)
self:sendTextMessage(
MESSAGE_EVENT_ADVANCE,
string.format(
"Thank you for reporting %s. Your report \z
will be processed by %s team as soon as possible.",
targetName,
configManager.getString(configKeys.SERVER_NAME)
)
)
return
end

function Player:onReportBug(message, position, category)
local name = self:getName():gsub("%s+", "_")
FS.mkdir_p(string.format("%s/reports/bugs/%s", CORE_DIRECTORY, name))
local file = io.open(string.format("%s/reports/bugs/%s/report.txt", CORE_DIRECTORY, name), "a")

if not file then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return true
end

io.output(file)
io.write("------------------------------\n")
io.write("Name: " .. name)
if category == BUG_CATEGORY_MAP then
io.write(" [Map position: " .. position.x .. ", " .. position.y .. ", " .. position.z .. "]")
end
local playerPosition = self:getPosition()
io.write(" [Player Position: " .. playerPosition.x .. ", " .. playerPosition.y .. ", " .. playerPosition.z .. "]\n")
io.write("Comment: " .. message .. "\n")
io.close(file)

self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report has been sent to " .. configManager.getString(configKeys.SERVER_NAME) .. ".")
return true
end
function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) end
function Player:onReportBug(message, position, category) end

function Player:onTurn(direction)
if self:getGroup():getAccess() and self:getDirection() == direction then
Expand Down
30 changes: 30 additions & 0 deletions data/scripts/eventcallbacks/player/on_report_bug.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local callback = EventCallback("PlayerOnReportBug")

function callback.playerOnReportBug(player, message, position, category)
local name = player:getName()
local filePath = string.format("%s/reports/bugs/%s.txt", CORE_DIRECTORY, name)
local file = io.open(filePath, "a")

if not file then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return true
end

file:write("------------------------------\n")
file:write(string.format("Name: %s", name))

if category == BUG_CATEGORY_MAP then
file:write(string.format(" [Map position: %d, %d, %d]", position.x, position.y, position.z))
end

local playerPosition = player:getPosition()
file:write(string.format(" [Player Position: %d, %d, %d]\n", playerPosition.x, playerPosition.y, playerPosition.z))
file:write(string.format("Comment: %s\n", message))
file:write("------------------------------\n")
file:close()

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Your report has been sent to %s.", configManager.getString(configKeys.SERVER_NAME)))
return true
end

callback:register()
45 changes: 45 additions & 0 deletions data/scripts/eventcallbacks/player/on_report_rule_violation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local function hasPendingReport(name, targetName, reportType)
local filePath = string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType)
local file = io.open(filePath, "r")
if file then
io.close(file)
return true
end
return false
end

local callback = EventCallback("PlayerOnReportRuleViolation")

function callback.playerOnReportRuleViolation(player, targetName, reportType, reportReason, comment, translation)
local name = player:getName()

if hasPendingReport(name, targetName, reportType) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end

local filePath = string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType)
local file = io.open(filePath, "a")
if not file then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return
end

file:write("------------------------------\n")
file:write(string.format("Reported by: %s\n", name))
file:write(string.format("Target: %s\n", targetName))
file:write(string.format("Type: %d\n", reportType))
file:write(string.format("Reason: %s\n", reportReason))
file:write(string.format("Comment: %s\n", comment))

if reportType ~= REPORT_TYPE_BOT then
file:write(string.format("Translation: %s\n", translation))
end

file:write("------------------------------\n")
file:close()

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Thank you for reporting %s. Your report will be processed by %s team as soon as possible.", targetName, configManager.getString(configKeys.SERVER_NAME)))
end

callback:register()

0 comments on commit d713301

Please sign in to comment.