-
-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add events for reporting rule violations and bugs by players
- Loading branch information
1 parent
6f07493
commit d713301
Showing
3 changed files
with
78 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
data/scripts/eventcallbacks/player/on_report_rule_violation.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |