Skip to content

Commit 5a2d730

Browse files
committed
Make it possible to add exceptions again
1 parent 40dc794 commit 5a2d730

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

data/messages.json

+2
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@
400400
"LOCATION_NO_TELEPORT": "@error Sorry, the owner has locked the door because %s!",
401401

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

javascript/features/playground/playground_commands.js

+61
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,68 @@ export class PlaygroundCommands {
317317
// Displays a dialog to the |player| which allows them to add a new exception to the given
318318
// |command|. Exceptions can only be issued to registered players.
319319
async displayCommandExceptionDialog(player, command) {
320+
const target = await Question.ask(player, {
321+
question: command.command,
322+
message: 'Which player do you want to give access to this command?',
323+
constraints: {
324+
validation: input => !!server.playerManager.find({ nameOrId: input }),
325+
explanation: `Sorry, I don't know which player you mean by that. Try again?`,
326+
abort: `Sorry, you need to tell me which player to add the exception for.`
327+
}
328+
});
329+
330+
if (!target)
331+
return; // the |player| aborted
332+
333+
const targetPlayer = server.playerManager.find({ nameOrId: target });
334+
if (!targetPlayer)
335+
return; // validation succeeded, but now fails.. race condition?
320336

337+
// (1) If the |targetPlayer| is not registered, we cannot add an exception for them.
338+
if (!targetPlayer.account.isIdentified()) {
339+
return await alert(player, {
340+
title: command.command,
341+
message: `Sorry, exceptions can only be added for registered players.`
342+
});
343+
}
344+
345+
// (2) If the |targetPlayer| is the current |player|, tell them to stop being silly.
346+
if (targetPlayer === player) {
347+
return await alert(player, {
348+
title: command.command,
349+
message: `Sorry, you're being silly so computer says no.`
350+
});
351+
}
352+
353+
// (3) If the |targetPlayer| already has access, let's not bother adding an exception.
354+
if (this.permissionDelegate_.canExecuteCommand(targetPlayer, null, command, false)) {
355+
return await alert(player, {
356+
title: command.command,
357+
message: `Sorry, ${targetPlayer.name} can already execute the command and thus\n` +
358+
`does not need an exception. Are you trying to be sneaky? :D`
359+
});
360+
}
361+
362+
// (3) Add the exception for the |targetPlayer| with the given |command|.
363+
this.permissionDelegate_.addException(targetPlayer, command);
364+
365+
// (4) Tell the |targetPlayer| about the exception that has been added.
366+
targetPlayer.sendMessage(
367+
Message.LVP_ACCESS_EXCEPTION_ADDED_FYI, player.name, player.id, command.command);
368+
369+
// (5) Tell in-game administrators about the exception having been added, except when the
370+
// original |command| requirement is Management-only, in which case it's silent.
371+
if (command.restrictLevel !== Player.LEVEL_MANAGEMENT) {
372+
this.announce_().announceToAdministrators(
373+
Message.LVP_ACCESS_EXCEPTION_ADDED_ADMIN, player.name, player.id, targetPlayer.name,
374+
targetPlayer.id, command.command);
375+
}
376+
377+
// (6) Tell the |player| that the exception has been added.
378+
return await alert(player, {
379+
title: command.command,
380+
message: `An exception has been added for ${targetPlayer.name}`
381+
});
321382
}
322383

323384
// Handles the flow where the |player| wants to remove an exception issued for |exceptedPlayer|

javascript/features/playground/playground_commands.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ describe('PlaygroundCommands', (it, beforeEach) => {
9191
assert.equal(delegate.getCommandLevel(command).restrictLevel, Player.LEVEL_MANAGEMENT);
9292

9393
// (3) Gunther should be able to add an exception to the "/lvp" command.
94+
assert.isFalse(delegate.canExecuteCommand(russell, null, command, false));
95+
assert.isFalse(delegate.hasException(russell, command));
96+
97+
gunther.respondToDialog({ listitem: 0 /* /lvp */ }).then(
98+
() => gunther.respondToDialog({ listitem: 0 /* /lvp */ })).then(
99+
() => gunther.respondToDialog({ listitem: 1 /* add exception */ })).then(
100+
() => gunther.respondToDialog({ inputtext: 'Russ' })).then(
101+
() => gunther.respondToDialog({ response: 0 /* dismiss */ }));
102+
103+
assert.isTrue(await gunther.issueCommand('/lvp access'));
104+
assert.includes(gunther.lastDialog, `has been added for Russell`);
105+
106+
assert.isTrue(delegate.canExecuteCommand(russell, null, command, false));
107+
assert.isTrue(delegate.hasException(russell, command));
94108

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

0 commit comments

Comments
 (0)