Skip to content
Permalink
Browse files
Block PMs to muted target. Fixes #750 (#751)
* Block PMs to muted target. Fixes #750

* Fix feedback regarding imports and MuteManager

* Fix line length based on feedback

Co-authored-by: Jonathan Trolin <jonathan.trolin@visma.com>
  • Loading branch information
JTrolin and Jonathan Trolin committed Jun 22, 2020
1 parent 8835fbf commit ff1a5494f81b87ba7ea979aa72e8a75ece2085df
Showing 3 changed files with 29 additions and 0 deletions.
@@ -107,6 +107,7 @@
"COMMUNICATION_PM_RECEIVER": "{FFDC18}* PM from %s (Id:%d): {FFFFFF}%s",
"COMMUNICATION_PM_SELF": "@error You cannot send messages to yourself.",
"COMMUNICATION_PM_SENDER": "{FCF545}* PM to %s (Id:%d): {FFFFFF}%s",
"COMMUNICATION_PM_TARGET_MUTED": "@error Your message has been blocked because %s (Id: %d) is muted for another %s.",
"COMMUNICATION_PSAY_SENT": "@success The message has been sent, but mind that it's still subject to filters.",
"COMMUNICATION_REPLY_DISCONNECTED": "@error %s has disconnected from the server.",
"COMMUNICATION_REPLY_NONE": "@error You haven't received messages you can respond to yet.",
@@ -5,6 +5,8 @@
import { CommandBuilder } from 'components/command_manager/command_builder.js';
import { ScopedCallbacks } from 'base/scoped_callbacks.js';

import { relativeTime } from 'base/time.js';

// Id of the sound to play when a player has received a message.
const kMessageReceivedSoundId = 1058;

@@ -139,6 +141,19 @@ export class DirectCommunicationCommands {
if (!message)
return; // the message was blocked

// Check if the recieving |target| is muted and not allowed to recieved PMs.
// And that the sending |player| is NOT an administrator.
let muteTime = this.communication_().muteManager_.getPlayerRemainingMuteTime(target);
if (muteTime !== null && !player.isAdministrator()) {
const durationText = relativeTime({
date1: new Date(),
date2: new Date(Date.now() + muteTime * 1000)
}).text;
player.sendMessage(Message.COMMUNICATION_PM_TARGET_MUTED, target.name, target.id,
durationText);
return;
}

player.sendMessage(Message.COMMUNICATION_PM_SENDER, target.name, target.id, message);

if (!this.visibilityManager.isPlayerOnIgnoreList(target, player)) {
@@ -158,6 +158,19 @@ describe('DirectCommunicationCommands', (it, beforeEach) => {
assert.equal(gunther.messages.length, 1); // unchanged
});

it('cannot send to muted targets unless sender is an admin', async (assert) => {
const playground = server.featureManager.loadFeature('playground');

// Set up by Russell muting themselves
assert.isTrue(await russell.issueCommand('/mute Russell 5'));

// (1) It should not be possible for Gunther to PM Russell who's muted
assert.isTrue(await gunther.issueCommand('/pm Russell Hello world'));
assert.equal(gunther.messages.length, 1);
assert.equal(gunther.messages[0],Message.format(Message.COMMUNICATION_PM_TARGET_MUTED,
russell.name, russell.id, "5 minutes"));
});

it('should be able to send secret private messages', async (assert) => {
const playground = server.featureManager.loadFeature('playground');

0 comments on commit ff1a549

Please sign in to comment.