Skip to content

Commit e10ce17

Browse files
Only allow admins to fancy others
1 parent 8850fcd commit e10ce17

2 files changed

Lines changed: 52 additions & 7 deletions

File tree

javascript/features/playground/commands/fancy.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,28 @@ class FancyCommand extends Command {
3131
}
3232

3333
onFancyCommand(player, target, type) {
34-
const subject = target || player;
34+
if(!player.isAdministrator() && player !== target) {
35+
player.sendMessage(Message.COMMAND_ERROR, 'Only administrators can fancy other players.');
36+
return;
37+
}
3538

3639
switch (type) {
3740
case 'none':
38-
this.fancy_.delete(subject);
41+
this.fancy_.delete(target);
3942

40-
pawnInvoke('RemovePlayerAttachedObject', 'ii', subject.id, 0);
43+
pawnInvoke('RemovePlayerAttachedObject', 'ii', target.id, 0);
4144

4245
player.sendMessage(
43-
Message.COMMAND_SUCCESS, subject.name + ' is not fancy anymore :(.');
46+
Message.COMMAND_SUCCESS, target.name + ' is not fancy anymore :(.');
4447
break;
4548

4649
case 'parrot':
4750
case 'cow':
48-
this.fancy_.set(subject, type);
49-
this.onPlayerSpawn({ playerid: subject.id });
51+
this.fancy_.set(target, type);
52+
this.onPlayerSpawn({ playerid: target.id });
5053

5154
player.sendMessage(
52-
Message.COMMAND_SUCCESS, subject.name + ' is now a ' + type + '.');
55+
Message.COMMAND_SUCCESS, target.name + ' is now a ' + type + '.');
5356
break;
5457

5558
default:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020 Las Venturas Playground. All rights reserved.
2+
// Use of this source code is governed by the MIT license, a copy of which can
3+
// be found in the LICENSE file.
4+
5+
import MockPlaygroundCommands from 'features/playground/test/mock_playground_commands.js';
6+
7+
describe('FancyCommand', (it, beforeEach, afterEach) => {
8+
let commands = null;
9+
let gunther = null;
10+
11+
beforeEach(async() => {
12+
commands = new MockPlaygroundCommands();
13+
await commands.loadCommands();
14+
15+
gunther = server.playerManager.getById(0 /* Gunther */);
16+
await gunther.identify();
17+
// Enable |gunther| to use the command by adding an exception.
18+
commands.access.addException('fancy', gunther);
19+
});
20+
21+
afterEach(() => commands.dispose());
22+
23+
it('should not allow players to fancy others', async(assert) => {
24+
const russell = server.playerManager.getById(1 /* Gunther */);
25+
await russell.identify();
26+
27+
assert.isTrue(await gunther.issueCommand('/fancy 1 cow'));
28+
assert.equal(gunther.messages.length, 1);
29+
assert.includes(gunther.messages[0], 'Only administrators can fancy other players.');
30+
});
31+
32+
it('should allow administrators to fancy others', async(assert) => {
33+
const russell = server.playerManager.getById(1 /* Gunther */);
34+
await russell.identify();
35+
36+
gunther.level = Player.LEVEL_ADMINISTRATOR
37+
38+
assert.isTrue(await gunther.issueCommand('/fancy 1 cow'));
39+
assert.equal(gunther.messages.length, 1);
40+
assert.includes(gunther.messages[0], russell.name + ' is now a cow.');
41+
});
42+
});

0 commit comments

Comments
 (0)