Skip to content
Permalink
Browse files
Make it possible to add exceptions again
  • Loading branch information
RussellLVP committed Jul 31, 2020
1 parent 40dc794 commit 5a2d7309615db2f86ffef500ee8432eb159d7098
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
@@ -400,6 +400,8 @@
"LOCATION_NO_TELEPORT": "@error Sorry, the owner has locked the door because %s!",

"LVP_ACCESS_ADMIN_NOTICE": "%s (Id:%d) has changed the \"%s\" command to %s.",
"LVP_ACCESS_EXCEPTION_ADDED_ADMIN": "%s (Id:%d) has allowed %s (Id:%d) to use the \"%s\" command.",
"LVP_ACCESS_EXCEPTION_ADDED_FYI": "{80CBC4}*** %s (Id:%d) has allowed you to use the \"%s\" command.",
"LVP_ACCESS_PLAYERS_GRANTED": "%s has made the command \"%s\" available to all players.",
"LVP_ACCESS_PLAYERS_REVOKED": "%s has revoked the \"%s\" command from players.",

@@ -317,7 +317,68 @@ export class PlaygroundCommands {
// Displays a dialog to the |player| which allows them to add a new exception to the given
// |command|. Exceptions can only be issued to registered players.
async displayCommandExceptionDialog(player, command) {
const target = await Question.ask(player, {
question: command.command,
message: 'Which player do you want to give access to this command?',
constraints: {
validation: input => !!server.playerManager.find({ nameOrId: input }),
explanation: `Sorry, I don't know which player you mean by that. Try again?`,
abort: `Sorry, you need to tell me which player to add the exception for.`
}
});

if (!target)
return; // the |player| aborted

const targetPlayer = server.playerManager.find({ nameOrId: target });
if (!targetPlayer)
return; // validation succeeded, but now fails.. race condition?

// (1) If the |targetPlayer| is not registered, we cannot add an exception for them.
if (!targetPlayer.account.isIdentified()) {
return await alert(player, {
title: command.command,
message: `Sorry, exceptions can only be added for registered players.`
});
}

// (2) If the |targetPlayer| is the current |player|, tell them to stop being silly.
if (targetPlayer === player) {
return await alert(player, {
title: command.command,
message: `Sorry, you're being silly so computer says no.`
});
}

// (3) If the |targetPlayer| already has access, let's not bother adding an exception.
if (this.permissionDelegate_.canExecuteCommand(targetPlayer, null, command, false)) {
return await alert(player, {
title: command.command,
message: `Sorry, ${targetPlayer.name} can already execute the command and thus\n` +
`does not need an exception. Are you trying to be sneaky? :D`
});
}

// (3) Add the exception for the |targetPlayer| with the given |command|.
this.permissionDelegate_.addException(targetPlayer, command);

// (4) Tell the |targetPlayer| about the exception that has been added.
targetPlayer.sendMessage(
Message.LVP_ACCESS_EXCEPTION_ADDED_FYI, player.name, player.id, command.command);

// (5) Tell in-game administrators about the exception having been added, except when the
// original |command| requirement is Management-only, in which case it's silent.
if (command.restrictLevel !== Player.LEVEL_MANAGEMENT) {
this.announce_().announceToAdministrators(
Message.LVP_ACCESS_EXCEPTION_ADDED_ADMIN, player.name, player.id, targetPlayer.name,
targetPlayer.id, command.command);
}

// (6) Tell the |player| that the exception has been added.
return await alert(player, {
title: command.command,
message: `An exception has been added for ${targetPlayer.name}`
});
}

// Handles the flow where the |player| wants to remove an exception issued for |exceptedPlayer|
@@ -91,6 +91,20 @@ describe('PlaygroundCommands', (it, beforeEach) => {
assert.equal(delegate.getCommandLevel(command).restrictLevel, Player.LEVEL_MANAGEMENT);

// (3) Gunther should be able to add an exception to the "/lvp" command.
assert.isFalse(delegate.canExecuteCommand(russell, null, command, false));
assert.isFalse(delegate.hasException(russell, command));

gunther.respondToDialog({ listitem: 0 /* /lvp */ }).then(
() => gunther.respondToDialog({ listitem: 0 /* /lvp */ })).then(
() => gunther.respondToDialog({ listitem: 1 /* add exception */ })).then(
() => gunther.respondToDialog({ inputtext: 'Russ' })).then(
() => gunther.respondToDialog({ response: 0 /* dismiss */ }));

assert.isTrue(await gunther.issueCommand('/lvp access'));
assert.includes(gunther.lastDialog, `has been added for Russell`);

assert.isTrue(delegate.canExecuteCommand(russell, null, command, false));
assert.isTrue(delegate.hasException(russell, command));

// (4) Gunther should be able to remove an exception from the "/lvp" command.

0 comments on commit 5a2d730

Please sign in to comment.