diff --git a/lib/world.js b/lib/world.js index dbd446d..6b7cdaa 100644 --- a/lib/world.js +++ b/lib/world.js @@ -318,6 +318,11 @@ const login = (session, msg) => { // and the items staff have made (lib/customitems.js), for a game started // before they were. customItems.sendAll(session); + // staff: their role and what it allows, for the patched client's staff + // window (AJClient.onStaff). nobody else is sent anything. + if (roles.isActiveStaff(account)) { + session.sendXt("xsp", -1, roles.roleOf(account), roles.permissionsOf(account).join(",")); + } sendFilter(session); buddies.announce(account); }; @@ -459,6 +464,8 @@ const sendUserVars = session => { }; const findOnline = username => online.get(String(username).toLowerCase()); +const STAFF_WINDOW_COMMANDS = ["warn", "message", "silence", "kick", "summon", "goto", "warnings"]; +const MAX_STAFF_WINDOW_WORDS = 3; // username, then a reason, hours or the message (each one field) // a custom colour (lib/colours.js) for these four RGB values, made if it is // new and the account has not made its day's worth; everyone online is told @@ -809,6 +816,15 @@ const handlers = { session.sendXt("fra", -1, fileReport(session, username, reason, "", about) ? 1 : 0); }, + // the staff's window of the patched client (AJClient.openModerate): + // [command, username, ...words], one of the staff commands about a player, + // run as if typed (lib/commands.js checks the permission and logs it). + xmd(session, roomId, [command, ...words]) { + if (roles.isActiveStaff(session.account) && STAFF_WINDOW_COMMANDS.includes(command) && words.length > 0 && words.length <= MAX_STAFF_WINDOW_WORDS) { + commands.run(session, `!${command} ${words.join(" ")}`); + } + }, + // the patched report window (gui.ReportAPlayer), just before its "fr" or // "fra": [username, reasonId, what the reporter typed]. xrd(session, roomId, [username, reason, ...text]) { diff --git a/swf-src/AJClient.as b/swf-src/AJClient.as index 587ce64..32475fa 100644 --- a/swf-src/AJClient.as +++ b/swf-src/AJClient.as @@ -91,6 +91,24 @@ package private var _finderKind:int; private var _finderColourInput:TextField; + + // the staff's window for one player (openModerate), and what the + // signed-in role may do ("xsp" from the server; empty for players). + private var _moderate:Sprite; + + private var _moderateContent:MovieClip; + + private var _moderateName:String; + + private var _moderateReason:int; + + private var _moderateMessageBar:MovieClip; + + private var _moderateButtons:Array; + + public static var staffRole:String = ""; + + public static var staffPermissions:Array = []; // the items drawn on the rows shown, by row number private var _finderIcons:Object = {}; @@ -516,6 +534,41 @@ package } } + // "xsp": [.., .., role, permissions]. sent at login to staff only: their + // role and what it allows, comma separated (the server's lib/roles.js). + public static function onStaff(param1:Object) : void + { + staffRole = String(param1[2]); + staffPermissions = String(param1[3]).length > 0 ? String(param1[3]).split(",") : []; + } + + public static function staffMay(param1:String) : Boolean + { + return staffPermissions.indexOf(param1) != -1; + } + + // whether a player's card offers the staff's window instead of a report. + public static function canModerate() : Boolean + { + return _toolsInstance != null && (staffMay("player.warn") || staffMay("player.kick") || staffMay("chat.silence") || staffMay("player.summon") || staffMay("player.goto")); + } + + public static function openModerate(param1:String) : void + { + if(_toolsInstance == null) + { + return; + } + try + { + _toolsInstance.showModerate(param1); + } + catch(e:Error) + { + GlobalErrorCatch.reportToServer("moderate: " + e + "\n" + e.getStackTrace()); + } + } + // "xtl": [.., .., text]. A plain message box; what a chat command says. public static function showMessage(param1:Object) : void { @@ -1978,6 +2031,162 @@ package param1.stopPropagation(); showItemFinder(false); } + + // ---- the staff's window for one player, from the report button of + // their card. each button is a staff command for that player ("xmd", + // which the server runs as if typed: lib/commands.js, its permission + // checks and log included); only the ones the role allows are shown. + // the window closes and the server's answer comes as a message box. + private static const MODERATE_REASONS:Array = ["behavior","bullying","personal","scamming"]; + + private static const MODERATE_REASON_NAMES:Array = ["Inappropriate behavior","Bullying","Personal information","Scamming"]; + + private function buildModerate() : void + { + var _loc1_:MovieClip = GETDEFINITIONBYNAME("ReportRulesPopupSkin"); + var _loc2_:int = 1; + _moderate = new Sprite(); + _moderate.graphics.beginFill(0,0.45); + _moderate.graphics.drawRect(0,0,900,550); + _moderate.graphics.endFill(); + var _loc3_:Sprite = new Sprite(); + _loc3_.x = 450; + _loc3_.y = 275; + _moderate.addChild(_loc3_); + _loc3_.addChild(_loc1_); + _moderateContent = GETDEFINITIONBYNAME("ReportRulesPopupContent"); + _moderateContent.x = _loc1_.c.x; + _moderateContent.y = _loc1_.c.y; + _loc3_.addChild(_moderateContent); + _loc1_.bx.addEventListener("mouseDown",onModerateCloseClick); + while(_loc2_ <= 5) + { + _moderateContent["ruleTxt" + _loc2_].visible = false; + _moderateContent["ruleBodyTxt" + _loc2_].visible = false; + _loc2_++; + } + var _loc4_:TextField = _moderateContent.ruleBodyTxt1; + _loc4_.visible = true; + _loc4_.wordWrap = true; + _loc4_.x = -245; + _loc4_.y = -150; + _loc4_.width = 490; + _loc4_.height = 40; + _loc4_.text = "What you do here is written down under your name, as in the moderator panel."; + _moderateButtons = []; + // a row each: warn (the reason cycles), a message, chat, moving them. + moderateButton("reason","",-150,-88,"player.warn"); + moderateButton("warn","Warn",90,-88,"player.warn"); + _moderateMessageBar = finderSearchBar(-247,-56,330,"Message to show them",null,200,false); + _moderateContent.addChild(_moderateMessageBar); + moderateButton("message","Send",150,-52,"player.warn"); + moderateButton("silence 1","Silence 1 hour",-160,12,"chat.silence"); + moderateButton("silence 24","Silence 1 day",0,12,"chat.silence"); + moderateButton("silence off","Lift silence",160,12,"chat.silence"); + moderateButton("summon","Bring here",-160,72,"player.summon"); + moderateButton("goto","Go to them",0,72,"player.goto"); + moderateButton("kick","Disconnect",160,72,"player.kick"); + moderateButton("warnings","Warnings",0,132,"player.warn"); + _moderate.addEventListener("mouseDown",onFinderMouse); + _moderate.addEventListener("mouseUp",onFinderMouse); + _moderate.addEventListener("click",onFinderMouse); + _moderate.addEventListener("mouseWheel",onFinderMouse); + _moderate.visible = false; + addChild(_moderate); + } + + private function moderateButton(param1:String, param2:String, param3:Number, param4:Number, param5:String) : void + { + var _loc6_:MovieClip = GETDEFINITIONBYNAME("introBtnCont"); + _loc6_.x = param3; + _loc6_.y = param4; + _loc6_.name = param1; + finderButtonText(_loc6_,param2); + _loc6_.addEventListener("mouseDown",onModerateButton); + _moderateContent.addChild(_loc6_); + _moderateButtons.push({ + "clip":_loc6_, + "permission":param5 + }); + } + + private function showModerate(param1:String) : void + { + if(_moderate == null) + { + buildModerate(); + } + _moderateName = param1; + _moderateReason = 0; + _moderateContent.titleTxt.text = "Moderate " + param1; + _moderateMessageBar.searchTxt.text = ""; + _moderateMessageBar.txt.visible = true; + for each(var _loc2_:Object in _moderateButtons) + { + _loc2_.clip.visible = staffMay(_loc2_.permission); + } + _moderateMessageBar.visible = staffMay("player.warn"); + showModerateReason(); + _moderate.visible = true; + setChildIndex(_moderate,numChildren - 1); + } + + private function showModerateReason() : void + { + finderButtonText(_moderateContent.getChildByName("reason") as MovieClip,MODERATE_REASON_NAMES[_moderateReason]); + } + + private function hideModerate() : void + { + if(_moderate != null) + { + _moderate.visible = false; + } + gMainFrame.stage.focus = null; + } + + private function onModerateCloseClick(param1:MouseEvent) : void + { + param1.stopPropagation(); + hideModerate(); + } + + private function onModerateButton(param1:MouseEvent) : void + { + param1.stopPropagation(); + var _loc2_:String = MovieClip(param1.currentTarget).name; + var _loc3_:String = null; + if(_loc2_ == "reason") + { + _moderateReason = (_moderateReason + 1) % MODERATE_REASONS.length; + showModerateReason(); + return; + } + if(_loc2_ == "warn") + { + gMainFrame.server.setXtObject_Str("xmd",["warn",_moderateName,MODERATE_REASONS[_moderateReason]]); + } + else if(_loc2_ == "message") + { + // "%" ends a field of the message: left out. + _loc3_ = _moderateMessageBar.searchTxt.text.split("%").join("").replace(/^\s+|\s+$/g,""); + if(_loc3_.length == 0) + { + gMainFrame.stage.focus = _moderateMessageBar.searchTxt; + return; + } + gMainFrame.server.setXtObject_Str("xmd",["message",_moderateName,_loc3_]); + } + else if(_loc2_.indexOf("silence ") == 0) + { + gMainFrame.server.setXtObject_Str("xmd",["silence",_moderateName,_loc2_.substr(8)]); + } + else + { + gMainFrame.server.setXtObject_Str("xmd",[_loc2_,_moderateName]); + } + hideModerate(); + } private function onFinderKey(param1:KeyboardEvent) : void { diff --git a/swf-src/BuddyCard.as b/swf-src/BuddyCard.as index 84605ba..c1944cb 100644 --- a/swf-src/BuddyCard.as +++ b/swf-src/BuddyCard.as @@ -3325,6 +3325,12 @@ package buddy private function reportDownHandler(param1:MouseEvent) : void { param1.stopPropagation(); + // staff get their window for this player instead (AJClient.openModerate). + if(!param1.currentTarget.isGray && AJClient.canModerate()) + { + AJClient.openModerate(_currUserName); + return; + } if(!param1.currentTarget.isGray) { if(_reportAPlayer) @@ -3344,7 +3350,7 @@ package buddy param1.stopPropagation(); if(!param1.currentTarget.isGray) { - GuiManager.toolTip.init(_popupLayer,LocalizationManager.translateIdOnly(14633),845,210); + GuiManager.toolTip.init(_popupLayer,AJClient.canModerate() ? "Moderate" : LocalizationManager.translateIdOnly(14633),845,210); GuiManager.toolTip.startTimer(param1); } } diff --git a/swf-src/XtReplyDemuxer.as b/swf-src/XtReplyDemuxer.as index 05dd361..a825ebc 100644 --- a/swf-src/XtReplyDemuxer.as +++ b/swf-src/XtReplyDemuxer.as @@ -84,6 +84,11 @@ package PaletteHelper.handleCustomColors(param1.obj); return; } + if(param1.obj[0] == "xsp") + { + AJClient.onStaff(param1.obj); + return; + } if(param1.obj[0] == "xdi") { AJClient.onItemDefs(param1.obj); diff --git a/test/staff.js b/test/staff.js index a7e5859..227b29a 100644 --- a/test/staff.js +++ b/test/staff.js @@ -61,8 +61,9 @@ const webSession = () => { const say = (client, roomId, text) => client.send(``); -// logs in (with a 2FA code when given) and walks into `room`. -const arrive = async (username, password, room, totp) => { +// logs in (with a 2FA code when given) and walks into `room`. `onLogin` +// sees what comes with the login, before joining skips past it. +const arrive = async (username, password, room, totp, onLogin = async () => {}) => { const res = await postJson(`${BASE}/authenticate`, {username, password, ...(totp ? {totp} : {})}); const auth = await res.json(); assert.strictEqual(res.status, 200, `${username} could not sign in: ${JSON.stringify(auth)}`); @@ -70,6 +71,7 @@ const arrive = async (username, password, room, totp) => { await client.connect(); const login = await client.logIn(username, auth.auth_token); assert.strictEqual(login.status, "1"); + await onLogin(client); client.xt("rj", 1, room, 1, 0, 0); const rj = await client.untilXt("rj"); await client.untilXt("rp"); @@ -134,7 +136,13 @@ const run = async () => { // --- the game: the login reply carries your own role, and nobody else's usedStep.Mira++; - const mira = await arrive("Mira", people.Mira, TOWNSHIP, codeAt(secrets.Mira, usedStep.Mira)); + // and the patched client's staff window is told the same ("xsp") + let staffSaid = null; + const mira = await arrive("Mira", people.Mira, TOWNSHIP, codeAt(secrets.Mira, usedStep.Mira), async client => { + staffSaid = await client.untilXt("xsp"); + }); + assert.strictEqual(staffSaid[2], "moderator"); + assert.ok(staffSaid[3].split(",").includes("player.summon")); assert.strictEqual(mira.login.params.staffRole, "moderator"); assert.ok(mira.login.params.staffPermissions.split(",").includes("player.summon")); usedStep.Hal++; @@ -186,6 +194,20 @@ const run = async () => { assert.strictEqual(await nextBox(mira.client), "Shown to Ann."); say(mira.client, ann.roomId, "!warnings Ann"); assert.match(await nextBox(mira.client), /^Ann has 2 warnings\. Latest: \S+ behavior by Mira; \S+ bullying by Mira \(called names\)$/); + // the client's staff window ("xmd"): the same commands, one field each + mira.client.xt("xmd", ann.roomId, "warn", "Ann", "personal"); + assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fw", "3"]); + assert.strictEqual(await nextBox(mira.client), "Ann warned (personal): warning 3."); + mira.client.xt("xmd", ann.roomId, "message", "Ann", "hello there"); + assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fp", "hello there"]); + assert.strictEqual(await nextBox(mira.client), "Shown to Ann."); + mira.client.xt("xmd", ann.roomId, "ban", "Ann"); // not one the window has: nothing + // and from a player, nothing at all: Ann warns Mira + ann.client.xt("xmd", ann.roomId, "warn", "Mira", "bullying"); + mira.client.xt("xmd", ann.roomId, "warnings", "Ann"); + assert.match(await nextBox(mira.client), /^Ann has 3 warnings\. /); + say(mira.client, ann.roomId, "!warnings Mira"); + assert.strictEqual(await nextBox(mira.client), "Mira has no warnings."); say(mira.client, ann.roomId, "!kick Ann"); assert.strictEqual((await ann.client.untilXt("fd"))[2], "fk"); assert.strictEqual(await nextBox(mira.client), "Ann was disconnected.");