Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split permissions for moving and moving others #515

Merged
merged 2 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions piqueserver/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ def _handle_command(connection, command, parameters):
msg = 'Command failed'
except CommandError as e:
msg = str(e)
except PermissionDenied:
msg = 'You can\'t use this command'
except PermissionDenied as e:
msg = 'You can\'t do that: {}'.format(str(e))
except ValueError:
msg = 'Invalid parameters'

Expand Down
10 changes: 9 additions & 1 deletion piqueserver/core_commands/movement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pyspades.common import (coordinates, to_coordinates)
from piqueserver.commands import command, CommandError, get_player
from piqueserver.commands import (command, CommandError, get_player,
PermissionDenied)


@command(admin_only=True)
Expand All @@ -25,6 +26,8 @@ def move_silent(connection, *args):
If the z coordinate makes the player appear underground, put them at ground level instead.
If the x/y/z coordinate makes the player appear outside of the world bounds,
take the bound instead

You can only move other players if you are admin or have the move_others right
"""
do_move(connection, args, True)

Expand All @@ -38,6 +41,8 @@ def move(connection, *args):
If the z coordinate makes the player appear underground, put them at ground level instead.
If the x/y/z coordinate makes the player appear outside of the world bounds,
take the bound instead

You can only move other players if you are admin or have the move_others right
"""
if connection not in connection.protocol.players:
raise ValueError()
Expand Down Expand Up @@ -74,6 +79,9 @@ def do_move(connection, args, silent=False):
player = connection.name
# player specified
elif arg_count == 2 or arg_count == 4:
if not (connection.rights.admin or connection.rights.move_others):
raise PermissionDenied(
"moving other players requires the move_others right")
player = args[0]

player = get_player(connection.protocol, player)
Expand Down
2 changes: 1 addition & 1 deletion piqueserver/core_commands/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def kill(connection, value=None):
player = connection
else:
if not connection.rights.kill and not connection.admin:
raise PermissionDenied()
raise PermissionDenied("you can't kill other players")
player = get_player(connection.protocol, value, False)
player.kill()
if connection is not player:
Expand Down