diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 67f663fd1a8..d7f1eb786fd 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -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() @@ -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 diff --git a/data/scripts/eventcallbacks/player/on_report_bug.lua b/data/scripts/eventcallbacks/player/on_report_bug.lua new file mode 100644 index 00000000000..49526f66383 --- /dev/null +++ b/data/scripts/eventcallbacks/player/on_report_bug.lua @@ -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() diff --git a/data/scripts/eventcallbacks/player/on_report_rule_violation.lua b/data/scripts/eventcallbacks/player/on_report_rule_violation.lua new file mode 100644 index 00000000000..8c92c84b8ee --- /dev/null +++ b/data/scripts/eventcallbacks/player/on_report_rule_violation.lua @@ -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()