diff --git a/game/engines/default/engine/UserChat.lua b/game/engines/default/engine/UserChat.lua index 0b7a83f70d2f9eacfa225c55dd16c1d410419b31..9f762f4886ba2438c643a31f05519a820ca5be9d 100644 --- a/game/engines/default/engine/UserChat.lua +++ b/game/engines/default/engine/UserChat.lua @@ -248,6 +248,16 @@ function _M:whisper(to, msg) if type(game) == "table" and game.logChat then game.logChat("#GOLD#<Whisper to %s> %s", to, msg) end end +function _M:reportUser(to, msg) + if not profile.auth then return end + if not to or not msg or msg == "" then return end + msg = msg:removeColorCodes() + core.profile.pushOrder(string.format("o='ReportUser' target=%q msg=%q", to, msg)) + + self:addMessage("report", self.cur_channel, to, to, "#VIOLET#Report for "..to.." sent.#LAST#") + if type(game) == "table" and game.logChat then game.logChat("#VIOLET#Report for %s sent.#LAST#", to) end +end + function _M:achievement(name) if not profile.auth then return end core.profile.pushOrder(string.format("o='ChatAchievement' channel=%q msg=%q", self.cur_channel, name)) @@ -320,6 +330,26 @@ function _M:showUserInfo(login) game:registerDialog(UserInfo.new(data)) end +--- Get user infos +function _M:getUserInfo(login) + if not profile.auth then return end + + local popup = Dialog:simpleWaiter("Requesting...", "Requesting user info...") + core.display.forceRedraw() + + core.profile.pushOrder(string.format("o='ChatUserInfo' login=%q", login)) + local data = nil + profile:waitEvent("UserInfo", function(e) data=e.data end, 5000) + + popup:done() + + if not data then + return + end + data = zlib.decompress(data):unserialize() + return data +end + ---------------------------------------------------------------- -- UI Section ---------------------------------------------------------------- diff --git a/game/modules/tome/class/uiset/Minimalist.lua b/game/modules/tome/class/uiset/Minimalist.lua index 930d5832d3be6c6ff59747c34c44755a7d916178..59314981f813ffd02f82b0ff1968580b1befa310 100644 --- a/game/modules/tome/class/uiset/Minimalist.lua +++ b/game/modules/tome/class/uiset/Minimalist.lua @@ -1949,7 +1949,15 @@ function _M:setupMouse(mouse) else extra.log_str = str if button == "right" and event == "button" then - extra.add_map_action = { name="Show chat user", fct=function() profile.chat:showUserInfo(user.login) end } + extra.add_map_action = { + { name="Show chat user", fct=function() profile.chat:showUserInfo(user.login) end }, + { name="Report user for bad behavior", fct=function() + game:registerDialog(require('engine.dialogs.GetText').new("Reason to report: "..user.login, "Reason", 4, 500, function(text) + profile.chat:reportUser(user.login, text) + game.log("#VIOLET#", "Report sent.") + end)) + end }, + } end end game.tooltip.old_tmx = -100 diff --git a/game/modules/tome/dialogs/MapMenu.lua b/game/modules/tome/dialogs/MapMenu.lua index 048df9e8c41808682298f60b8c9e8d437e11bfab..dc1c14cdd6196d726a8a84bac1deaac8f59d50e6 100644 --- a/game/modules/tome/dialogs/MapMenu.lua +++ b/game/modules/tome/dialogs/MapMenu.lua @@ -27,9 +27,9 @@ module(..., package.seeall, class.inherit(engine.ui.Dialog)) function _M:init(mx, my, tmx, tmy, extra) self.tmx, self.tmy = util.bound(tmx, 0, game.level.map.w - 1), util.bound(tmy, 0, game.level.map.h - 1) if tmx == game.player.x and tmy == game.player.y then self.on_player = true end + self.extra = extra self:generateList() - if extra then table.insert(self.list, 1, {name=extra.name, action="extra", action_fct=extra.fct, color=extra.color}) end self.__showup = false local name = "Actions" @@ -180,6 +180,16 @@ function _M:generateList() for i = 1, #tals do list[#list+1] = tals[i] end end + if self.extra then + if self.extra.name then + table.insert(list, 1, {name=self.extra.name, action="extra", action_fct=self.extra.fct, color=self.extra.color}) + else + for i, extra in ipairs(self.extra) do + table.insert(list, i, {name=extra.name, action="extra", action_fct=extra.fct, color=extra.color}) + end + end + end + self.max = 0 self.maxh = 0 for i, v in ipairs(list) do diff --git a/game/modules/tome/dialogs/ShowChatLog.lua b/game/modules/tome/dialogs/ShowChatLog.lua index 20116b6bcafc85e9ce47171d609780cfe987e825..ffc020f9a9beedc70cff3ba8bf85bf8944f0848b 100644 --- a/game/modules/tome/dialogs/ShowChatLog.lua +++ b/game/modules/tome/dialogs/ShowChatLog.lua @@ -165,6 +165,30 @@ function _M:mouseEvent(button, x, y, xrel, yrel, bx, by, event) end end end + + if citem and citem.login then + local data = profile.chat:getUserInfo(citem.login) + if data then + local list = {{name="Show infos", ui="show"}, {name="Open profile(in brower)", ui="profile"}, {name="Report for bad behavior", ui="report"}} + if data.char_link then table.insert(list, 3, {name="Open charsheet(in brower)", ui="charsheet"}) end + Dialog:listPopup("User: "..citem.login, "Action", list, 300, 200, function(sel) + if not sel or not sel.ui then return end + if sel.ui == "show" then + local UserInfo = require "engine.dialogs.UserInfo" + game:registerDialog(UserInfo.new(data)) + elseif sel.ui == "profile" then + util.browserOpenUrl(data.profile) + elseif sel.ui == "charsheet" then + util.browserOpenUrl(data.char_link) + elseif sel.ui == "report" then + game:registerDialog(require('engine.dialogs.GetText').new("Reason to report: "..citem.login, "Reason", 4, 500, function(text) + profile.chat:reportUser(citem.login, text) + game.log("#VIOLET#", "Report sent.") + end)) + end + end) + end + end end end end diff --git a/game/profile-thread/Client.lua b/game/profile-thread/Client.lua index 4f7b2b65a025ac1848bd4e2e01f38e89051e925e..2584ff256f11fd35ef686d9b6e98fa8ad27b246a 100644 --- a/game/profile-thread/Client.lua +++ b/game/profile-thread/Client.lua @@ -23,7 +23,7 @@ local UserChat = require "profile-thread.UserChat" module(..., package.seeall, class.make) -local debug = false +local debug = true local mport = debug and 2259 or 2257 local pport = debug and 2260 or 2258 @@ -400,6 +400,11 @@ function _M:orderChatWhisper(o) self:read("200") end +function _M:orderReportUser(o) + self:command("RPTU", o.target..":=:"..o.msg) + self:read("200") +end + function _M:orderChatAchievement(o) self:command("ACHV", o.channel, o.msg) self:read("200")