Skip to content

Commit

Permalink
Merge c758a09 into 5ef52df
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Walladge committed Aug 10, 2019
2 parents 5ef52df + c758a09 commit 92b9a37
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 57 deletions.
6 changes: 3 additions & 3 deletions piqueserver/core_commands/game.py
Expand Up @@ -28,7 +28,7 @@ def reset_game(connection):
"""
resetting_player = connection
# irc compatibility
if resetting_player not in connection.protocol.players:
if resetting_player not in connection.protocol.players.values():
for player in connection.protocol.players.values():
resetting_player = player
if player.admin:
Expand Down Expand Up @@ -78,7 +78,7 @@ def switch(connection, player=None, team=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
Expand All @@ -96,7 +96,7 @@ def switch(connection, player=None, team=None):
player.on_team_changed(old_team)
player.spawn(player.world_object.position.get())
player.send_chat('Switched to %s team' % player.team.name)
if connection is not player and connection in protocol.players:
if connection is not player and connection in protocol.players.values():
connection.send_chat('Switched %s to %s team' % (player.name,
player.team.name))
protocol.irc_say('* %s silently switched teams' % player.name)
Expand Down
10 changes: 4 additions & 6 deletions piqueserver/core_commands/info.py
@@ -1,14 +1,13 @@
from piqueserver.commands import command, _commands, has_permission, get_player, get_command_help
from piqueserver.commands import command, _commands, has_permission, get_player, get_command_help, player_only


@command()
@player_only
def streak(connection):
"""
Tell your current kill streak
/streak
"""
if connection not in connection.protocol.players:
raise KeyError()
return ('Your current kill streak is %s. Best is %s kills' %
(connection.streak, connection.best_streak))

Expand All @@ -20,7 +19,7 @@ def ping(connection, value=None):
/ping
"""
if value is None:
if connection not in connection.protocol.players:
if connection not in connection.protocol.players.values():
raise ValueError()
player = connection
else:
Expand All @@ -32,13 +31,12 @@ def ping(connection, value=None):


@command()
@player_only
def rules(connection):
"""
Show you the server rules
/rules
"""
if connection not in connection.protocol.players:
raise KeyError()
lines = connection.protocol.rules
if lines is None:
return
Expand Down
14 changes: 7 additions & 7 deletions piqueserver/core_commands/moderation.py
Expand Up @@ -207,7 +207,7 @@ def ip(connection, value=None):
/ip [player]
"""
if value is None:
if connection not in connection.protocol.players:
if connection not in connection.protocol.players.values():
raise ValueError()
player = connection
else:
Expand Down Expand Up @@ -245,7 +245,7 @@ def invisible(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
Expand Down Expand Up @@ -300,7 +300,7 @@ def invisible(connection, player=None):
protocol.broadcast_contained(set_color, sender=player, save=True)
protocol.broadcast_contained(input_data, sender=player)
protocol.broadcast_contained(weapon_input, sender=player)
if connection is not player and connection in protocol.players:
if connection is not player and connection in protocol.players.values():
if player.invisible:
return '%s is now invisible' % player.name
else:
Expand All @@ -315,7 +315,7 @@ def godsilent(connection, player=None):
"""
if player is not None:
connection = get_player(connection.protocol, player)
elif connection not in connection.protocol.players:
elif connection not in connection.protocol.players.values():
return 'Unknown player: ' + player

connection.god = not connection.god # toggle godmode
Expand Down Expand Up @@ -351,7 +351,7 @@ def god(connection, player=None):
"""
if player:
connection = get_player(connection.protocol, player)
elif connection not in connection.protocol.players:
elif connection not in connection.protocol.players.values():
return 'Unknown player'

connection.god = not connection.god # toggle godmode
Expand All @@ -372,7 +372,7 @@ def god_build(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
Expand All @@ -382,6 +382,6 @@ def god_build(connection, player=None):
message = ('now placing god blocks' if player.god_build else
'no longer placing god blocks')
player.send_chat("You're %s" % message)
if connection is not player and connection in protocol.players:
if connection is not player and connection in protocol.players.values():
connection.send_chat('%s is %s' % (player.name, message))
protocol.irc_say('* %s is %s' % (player.name, message))
16 changes: 8 additions & 8 deletions piqueserver/core_commands/movement.py
@@ -1,6 +1,6 @@
from pyspades.common import (coordinates, to_coordinates)
from piqueserver.commands import (command, CommandError, get_player,
PermissionDenied)
PermissionDenied, player_only)


@command(admin_only=True)
Expand Down Expand Up @@ -33,6 +33,7 @@ def move_silent(connection, *args):


@command(admin_only=True)
@player_only
def move(connection, *args):
"""
Move yourself or a given player to the specified x/y/z coordinates or sector
Expand All @@ -44,8 +45,6 @@ def move(connection, *args):
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()
do_move(connection, args)


Expand Down Expand Up @@ -74,7 +73,8 @@ def do_move(connection, args, silent=False):

# no player specified
if arg_count == 1 or arg_count == 3:
if connection not in connection.protocol.players:
# must be run by a player in this case because moving self
if connection not in connection.protocol.players.values():
raise ValueError()
player = connection.name
# player specified
Expand Down Expand Up @@ -111,7 +111,7 @@ def where(connection, player=None):
"""
if player is not None:
connection = get_player(connection.protocol, player)
elif connection not in connection.protocol.players:
elif connection not in connection.protocol.players.values():
raise ValueError()
x, y, z = connection.get_location()
return '%s is in %s (%s, %s, %s)' % (
Expand All @@ -137,7 +137,7 @@ def teleport(connection, player1, player2=None, silent=False):
else:
return 'No administrator rights!'
else:
if connection not in connection.protocol.players:
if connection not in connection.protocol.players.values():
raise ValueError()
player, target = connection, player1
silent = silent or player.invisible
Expand Down Expand Up @@ -171,14 +171,14 @@ def fly(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
player.fly = not player.fly

message = 'now flying' if player.fly else 'no longer flying'
player.send_chat("You're %s" % message)
if connection is not player and connection in protocol.players:
if connection is not player and connection in protocol.players.values():
connection.send_chat('%s is %s' % (player.name, message))
protocol.irc_say('* %s is %s' % (player.name, message))
7 changes: 3 additions & 4 deletions piqueserver/core_commands/player.py
@@ -1,4 +1,4 @@
from piqueserver.commands import command, get_player, PermissionDenied
from piqueserver.commands import command, get_player, PermissionDenied, player_only

@command("client", "cli")
def client(connection, target=None):
Expand Down Expand Up @@ -31,13 +31,12 @@ def weapon(connection, value):


@command()
@player_only
def intel(connection):
"""
Inform you of who has the enemy intel
/intel
"""
if connection not in connection.protocol.players:
raise KeyError()
flag = connection.team.other.flag
if flag.player is not None:
if flag.player is connection:
Expand Down Expand Up @@ -75,7 +74,7 @@ def heal(connection, player=None):
player = get_player(connection.protocol, player, False)
message = '%s was healed by %s' % (player.name, connection.name)
else:
if connection not in connection.protocol.players:
if connection not in connection.protocol.players.values():
raise ValueError()
player = connection
message = '%s was healed' % (connection.name)
Expand Down
4 changes: 2 additions & 2 deletions piqueserver/core_commands/server.py
Expand Up @@ -21,7 +21,7 @@ def server_name(connection, *arg):
message = "%s changed servername to '%s'" % (connection.name, name)
log.info(message)
connection.protocol.irc_say("* " + message)
if connection in connection.protocol.players:
if connection in connection.protocol.players.values():
return message
return None

Expand Down Expand Up @@ -73,5 +73,5 @@ def toggle_master(connection):
message = ("toggled master broadcast %s" % ['OFF', 'ON'][
int(protocol.master)])
protocol.irc_say("* %s " % connection.name + message)
if connection in connection.protocol.players:
if connection in connection.protocol.players.values():
return "You " + message
2 changes: 1 addition & 1 deletion piqueserver/scripts/afk.py
Expand Up @@ -63,7 +63,7 @@ def kick_afk(connection, minutes, amount=None):
num_connections=amount - kicks,
time=minutes_s)
protocol.irc_say('* ' + message)
if connection in protocol.players:
if connection in protocol.players.values():
return message


Expand Down
7 changes: 3 additions & 4 deletions piqueserver/scripts/airstrike2.py
Expand Up @@ -17,7 +17,7 @@
from pyspades.common import to_coordinates, Vertex3
from pyspades.world import Grenade
from pyspades.constants import UPDATE_FREQUENCY, WEAPON_TOOL
from piqueserver.commands import command, admin, get_player
from piqueserver.commands import command, admin, get_player, player_only

STREAK_REQUIREMENT = 8

Expand All @@ -44,9 +44,8 @@


@command('airstrike', 'a')
@player_only
def airstrike(connection, *args):
if connection not in connection.protocol.players:
raise ValueError()
player = connection

if player.airstrike:
Expand All @@ -64,7 +63,7 @@ def give_strike(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
Expand Down
2 changes: 1 addition & 1 deletion piqueserver/scripts/analyze.py
Expand Up @@ -83,7 +83,7 @@ def on_hit(self, hit_amount, hit_player, type, grenade):
for name in list(self.protocol.analyzers.keys()):
if self.protocol.analyzers[name] == self.name:
analyzer = get_player(self.protocol, name)
if analyzer not in self.protocol.players:
if analyzer not in self.protocol.players.values():
raise ValueError()
else:
if body_part == "HEADSHOT":
Expand Down
4 changes: 2 additions & 2 deletions piqueserver/scripts/badmin.py
@@ -1,5 +1,5 @@
"""
Badmin is an bot admin.
Badmin is an bot admin.
It automates common admin tasks such as:
Expand Down Expand Up @@ -98,7 +98,7 @@ def investigate(connection, player):

def score_grief(connection, player, time=None): # 302 = blue (0), #303 = green (1)
print("start score grief")
color = connection not in connection.protocol.players and connection.colors
color = connection not in connection.protocol.players.values() and connection.colors
minutes = float(time or 2)
if minutes < 0.0:
raise ValueError()
Expand Down
2 changes: 1 addition & 1 deletion piqueserver/scripts/blockinfo.py
Expand Up @@ -36,7 +36,7 @@
def grief_check(connection, player, minutes=2):
player = get_player(connection.protocol, player)
protocol = connection.protocol
color = connection not in protocol.players and connection.colors
color = connection not in protocol.players.values() and connection.colors
minutes = float(minutes)
if minutes <= 0.0:
raise ValueError('minutes must be number greater than 0')
Expand Down
2 changes: 1 addition & 1 deletion piqueserver/scripts/geoip.py
Expand Up @@ -36,7 +36,7 @@
def where_from(connection, value=None):
# Get player IP address
if value is None:
if connection not in connection.protocol.players:
if connection not in connection.protocol.players.values():
raise ValueError()
player = connection
else:
Expand Down
8 changes: 3 additions & 5 deletions piqueserver/scripts/markers.py
Expand Up @@ -43,7 +43,7 @@
from pyspades.contained import BlockAction, BlockLine, SetColor, ChatMessage
from pyspades.common import make_color, to_coordinates
from pyspades.constants import *
from piqueserver.commands import command, admin, get_player
from piqueserver.commands import command, admin, get_player, player_only

SHADOW_INTEL = True # if True, shows where the intel used to be before taken
REVEAL_ENEMIES = True # if True, mimics old intel reveal behavior when captured
Expand Down Expand Up @@ -73,9 +73,8 @@


@command(admin_only=True)
@player_only
def clear(connection):
if connection not in connection.protocol.players:
raise ValueError()
connection.destroy_markers()
return S_CLEARED

Expand All @@ -96,9 +95,8 @@ def toggle_markers(connection, player=None):


@command()
@player_only
def markers(connection):
if connection not in connection.protocol.players:
raise ValueError()
connection.send_lines(S_HELP)


Expand Down
4 changes: 2 additions & 2 deletions piqueserver/scripts/paint.py
Expand Up @@ -24,7 +24,7 @@ def paint(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
Expand All @@ -33,7 +33,7 @@ def paint(connection, player=None):

message = 'now painting' if player.painting else 'no longer painting'
player.send_chat("You're %s" % message)
if connection is not player and connection in protocol.players:
if connection is not player and connection in protocol.players.values():
connection.send_chat('%s is %s' % (player.name, message))
protocol.irc_say('* %s is %s' % (player.name, message))

Expand Down
4 changes: 2 additions & 2 deletions piqueserver/scripts/rapid.py
Expand Up @@ -28,7 +28,7 @@ def toggle_rapid(connection, player=None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
elif connection in protocol.players.values():
player = connection
else:
raise ValueError()
Expand All @@ -44,7 +44,7 @@ def toggle_rapid(connection, player=None):

message = 'now rapid' if rapid else 'no longer rapid'
player.send_chat("You're %s" % message)
if connection is not player and connection in protocol.players:
if connection is not player and connection in protocol.players.values():
connection.send_chat('%s is %s' % (player.name, message))
protocol.irc_say('* %s is %s' % (player.name, message))

Expand Down

0 comments on commit 92b9a37

Please sign in to comment.