Skip to content

Commit

Permalink
Port more commands to use target_player
Browse files Browse the repository at this point in the history
/from
/paint
/unlink
  • Loading branch information
godwhoa committed Aug 16, 2019
1 parent dea3f70 commit 51755da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
19 changes: 6 additions & 13 deletions piqueserver/scripts/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'''

import os
from piqueserver.commands import command, restrict, get_player
from piqueserver.commands import (command, restrict, get_player, target_player)
from piqueserver.config import config

# optional commands
Expand All @@ -31,25 +31,18 @@
)
finally:

@restrict('admin')
@command('from')
def where_from(connection, value=None):
# Get player IP address
if value is None:
if connection not in connection.protocol.players.values():
raise ValueError()
player = connection
else:
player = get_player(connection.protocol, value)

@command('from', admin_only=True)
@target_player
def where_from(connection, player):
# Query database
try:
record = database.city(player.address[0])
except geoip2.errors.GeoIP2Error:
return 'Player location could not be determined.'

# Extract info
raw_items = (record.city, *reversed(record.subdivisions), record.country)
raw_items = (record.city, *reversed(record.subdivisions),
record.country)

items = (raw_item.name for raw_item in raw_items if raw_item.name is not None)

Expand Down
9 changes: 2 additions & 7 deletions piqueserver/scripts/paint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@
from pyspades.contained import BlockAction
from pyspades.common import Vertex3
from pyspades.constants import *
from piqueserver.commands import command, admin, get_player
from piqueserver.commands import command, admin, get_player, target_player

PAINT_RAY_LENGTH = 32.0


@command(admin_only=True)
@target_player
def paint(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()

player.painting = not player.painting

Expand Down
12 changes: 3 additions & 9 deletions piqueserver/scripts/runningman.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pyspades.collision import distance_3d_vector
from pyspades.constants import *
from pyspades.common import Vertex3
from piqueserver.commands import command, admin, get_player
from piqueserver.commands import (command, admin, get_player, target_player)

ENABLED_AT_START = False

Expand Down Expand Up @@ -61,18 +61,12 @@ def relink(connection):


@command(admin_only=True)
@target_player
def unlink(connection, player=None):
protocol = connection.protocol
if not protocol.running_man:
return S_NOT_ENABLED

if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()

player.drop_link()
player.linkable = not player.linkable
player.send_chat(S_LINKABLE_SELF if player.linkable else S_UNLINKABLE_SELF)
Expand Down Expand Up @@ -154,7 +148,7 @@ def can_be_linked_to(self, player):

def get_new_link(self):
available = list(filter(self.can_be_linked_to,
self.team.get_players()))
self.team.get_players()))
if not available:
return
self.drop_link(force_message=True)
Expand Down

0 comments on commit 51755da

Please sign in to comment.