@@ -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|
0 commit comments