def start_votekick(connection, *args): protocol = connection.protocol if connection not in protocol.players: raise KeyError() player = connection if not args: if protocol.votekick: # player requested votekick info protocol.votekick.send_chat_update(player) return raise ValueError() value = args[0] try: # vanilla aos behavior victim = get_player(protocol, '#' + value) except InvalidPlayer: victim = get_player(protocol, value) reason = join_arguments(args[1:]) try: # attempt to start votekick votekick = Votekick.start(player, victim, reason) protocol.votekick = votekick except VotekickFailure as err: return str(err)
def togglevotekick(connection, *args): protocol = connection.protocol if len(args) == 0: protocol.votekick_enabled = not protocol.votekick_enabled return "Votekicking globally %s." % ['disabled', 'enabled'][protocol.votekick_enabled] try: player = get_player(protocol, '#' + args[0]) except InvalidPlayer: player = get_player(protocol, args[0]) player.votekick_enabled = not player.votekick_enabled return "Votekicking is %s for %s." % (['disabled', 'enabled'][player.votekick_enabled], player.name)
def togglevotekick(connection, *args): protocol = connection.protocol if len(args) == 0: protocol.votekick_enabled = not protocol.votekick_enabled return "Votekicking globally %s." % ['disabled', 'enabled' ][protocol.votekick_enabled] try: player = get_player(protocol, '#' + args[0]) except InvalidPlayer: player = get_player(protocol, args[0]) player.votekick_enabled = not player.votekick_enabled return "Votekicking is %s for %s." % ( ['disabled', 'enabled'][player.votekick_enabled], player.name)
def ratio(connection, user=None): msg = "Tu hai" if user != None: connection = get_player(connection.protocol, user) msg = "%s ha" if connection not in connection.protocol.players: raise KeyError() msg %= connection.name if connection not in connection.protocol.players: raise KeyError() kills = connection.ratio_kills deaths = float(max(1,connection.ratio_deaths)) headshotkills = connection.ratio_headshotkills meleekills = connection.ratio_meleekills grenadekills = connection.ratio_grenadekills msg += " un rapporto uccisioni-morti di %.2f" % (kills/deaths) if HEADSHOT_RATIO: msg += ", rapporto headshot-morti di %.2f" % (headshotkills/deaths) msg += " (%s uccisioni, %s morti" % (kills, connection.ratio_deaths) if EXTENDED_RATIO: msg += ", %s headshot, %s melee, %s grenade" % (headshotkills, meleekills, grenadekills) msg += ")." return msg
def on_hit(self, hit_amount, hit_player, type, grenade): body_damage_values = [49, 29, 27] limb_damage_values = [33, 18, 16] dist = int(distance_3d_vector(self.world_object.position, hit_player.world_object.position)) weap = self.weapon_object.name self.pres_time = seconds() if self.prev_time is None: dt = None else: dt = (self.pres_time - self.prev_time) * 1000 self.prev_time = seconds() if weap == "SMG" or weap == "Rifle": if dt is not None and dt < 5: self.illegal_dt_count = self.illegal_dt_count + 1 if weap == "Shotgun": if dist > 20: if dt < 8: if hit_amount == self.spread_hit_amount and hit_player.name == self.spread_hit_player: if type == HEADSHOT_KILL: self.spread_hs_count = self.spread_hs_count +1 elif hit_amount in body_damage_values: self.spread_hs_count = self.spread_bs_count +1 elif hit_amount in limb_damage_values: self.spread_ls_count = self.spread_ls_count +1 else: self.spread_hs_count, self.spread_bs_count, self.spread_ls_count = 0, 0, 0 self.spread_hit_amount, self.spread_hit_player = None, None else: self.spread_hs_count, self.spread_bs_count, self.spread_ls_count = 0, 0, 0 self.spread_hit_amount, self.spread_hit_player = hit_amount, hit_player.name else: self.spread_hs_count, self.spread_bs_count, self.spread_ls_count = 0, 0, 0 self.spread_hit_amount, self.spread_hit_player = None, None self.local_variable = self.shots_analyzed_by for names in self.local_variable: adminz = get_player(self.protocol, names) if type == HEADSHOT_KILL: adminz.hs = adminz.hs + 1 if dt is not None: adminz.send_chat('%s shot %s dist: %d blocks dT: %.0f ms %s HEADSHOT(%d)' % (self.name, hit_player.name, dist, dt, weap, adminz.hs)) else: adminz.send_chat('%s shot %s dist: %d blocks dT: NA %s HEADSHOT(%d)' % (self.name, hit_player.name, dist, weap, adminz.hs)) if hit_amount in body_damage_values: adminz.bs = adminz.bs + 1 if dt is not None: adminz.send_chat('%s shot %s dist: %d blocks dT: %.0f ms %s Body(%d)' % (self.name, hit_player.name, dist, dt, weap, adminz.bs)) else: adminz.send_chat('%s shot %s dist: %d blocks dT: NA %s Body(%d)' % (self.name, hit_player.name, dist, weap, adminz.bs)) if hit_amount in limb_damage_values: adminz.ls = adminz.ls + 1 if dt is not None: adminz.send_chat('%s shot %s dist: %d blocks dT: %.0f ms %s Limb(%d)' % (self.name, hit_player.name, dist, dt, weap, adminz.ls)) else: adminz.send_chat('%s shot %s dist: %d blocks dT: NA %s Limb(%d)' % (self.name, hit_player.name, dist, weap, adminz.ls)) if self.illegal_dt_count >= 5: self.ban('Hack Detected - Multiple Bullets', 10080) return False if self.spread_hs_count >= 7 or self.spread_bs_count >= 7 or self.spread_ls_count >=7: self.ban('Hack Detected - No Spread', 10080) return False return connection.on_hit(self, hit_amount, hit_player, type, grenade)
def investigate(connection, player): player = get_player(connection.protocol, player) score = score_grief(connection, player) kdr = round(player.ratio_kills / float(max(1, player.ratio_deaths))) percent = round(check_percent(player)) message = "Results for %s: Grief Score - %s / KDR - %s / Hit Acc. - %s" % ( player.name, score, kdr, percent)
def aimbotcheck(connection, user, minutes): connection = commands.get_player(connection.protocol, user) if connection not in connection.protocol.players: raise KeyError() kills = connection.tally_kill_log(reactor.seconds() - int(minutes)*60) return ('Player %s did %s kills in the last %s minutes.' % (connection.name, kills, minutes))
def start_votekick(connection, *args): protocol = connection.protocol if connection not in protocol.players: raise KeyError() player = connection if protocol.votekick_enabled == False: return "Votekicking disabled" if player.votekick_enabled == False: return "You are not allowed to initiate a votekick." if not args: if protocol.votekick: # player requested votekick info protocol.votekick.send_chat_update(player) return raise ValueError() value = args[0] victim = get_player(protocol, value) reason = join_arguments(args[1:]) try: # attempt to start votekick votekick = Votekick.start(player, victim, reason) protocol.votekick = votekick except VotekickFailure as err: return str(err)
def analyze_shot(connection, player=None): protocol = connection.protocol if player is None: connection.local_variable = protocol.players for people in connection.local_variable.itervalues(): if connection.name in people.shots_analyzed_by: people.shots_analyzed_by.remove(connection.name) connection.send_chat("You are no longer analyzing anyone.") else: player = get_player(protocol, player) if player not in protocol.players: raise ValueError() else: if not player.shots_analyzed_by: player.shots_analyzed_by = [] connection.local_variable = protocol.players for person in connection.local_variable.itervalues(): if person.name is None: continue if person != player and connection.name in person.shots_analyzed_by: person.shots_analyzed_by.remove(connection.name) connection.send_chat("You are no longer analyzing %s." % (person.name)) print person.shots_analyzed_by if connection.name not in player.shots_analyzed_by: connection.send_chat("You are now analyzing %s." % (player.name)) player.shots_analyzed_by.append(connection.name) connection.hs, connection.bs, connection.ls = 0, 0, 0 print player.shots_analyzed_by elif connection.name in player.shots_analyzed_by: connection.send_chat("You are no longer analyzing anyone.") player.shots_analyzed_by.remove(connection.name) print player.shots_analyzed_by
def toggle_pause(connection, player = None): protocol = connection.protocol if player is None: protocol.paused = paused = not protocol.paused for player in protocol.players.itervalues(): if not player.admin: player.paused = paused if not paused: # immediately send orientation packets protocol.update_network() message = S_GAME_PAUSED if paused else S_GAME_UNPAUSED protocol.send_chat(message, irc = True) else: player = get_player(protocol, player) player.paused = paused = not player.paused irc_message = S_PAUSED_IRC if paused else S_UNPAUSED_IRC protocol.irc_say(irc_message.format(admin = connection.name, player = player.name)) self_message = S_PAUSED_SELF if paused else S_UNPAUSED_SELF if connection is player: return self_message elif connection in protocol.players: player.send_chat(self_message) other_message = S_PAUSED if paused else S_UNPAUSED return other_message.format(player = player.name)
def lightning(connection, player = None): # And I will strike down upon thee with great vengeance and furious anger # those who would attempt to poison and destroy My brothers protocol = connection.protocol if player: player = get_player(protocol, player) is_spectator = player.team and player.team.spectator if is_spectator: return S_SPECTATING.format(player = player.name) if player.hp < 0: return S_NOT_ALIVE.format(player = player.name) callLater(0.1, player.kill) callLater(0.1, create_explosion_effect_at_player, player) message = S_LIGHTNING.format(player = player.name) protocol.send_chat(message, sender = player) player.send_chat(S_LIGHTNING_SELF) if connection in protocol.players: message = S_LIGHTNING_IRC.format(admin = connection.name, player = player.name) else: message = '* ' + message protocol.irc_say(message) effects = [ FogHold(0.05, (0, 0, 0)), FogGradient(0.8, (255, 255, 255), (0, 0, 0), ease_in), FogHold(1.0, (0, 0, 0)), FogGradient(4.0, (0, 0, 0), protocol.get_real_fog_color, ease_out) ] protocol.set_fog_effects(effects)
def analyze_shot(connection, player = None): protocol = connection.protocol if player is None: for people in protocol.players.itervalues(): if people.name is None: continue if connection.name in people.shots_analyzed_by: people.shots_analyzed_by.remove(connection.name) connection.send_chat("You are no longer analyzing anyone.") else: player = get_player(protocol, player) if player not in protocol.players: raise ValueError() else: if not player.shots_analyzed_by: player.shots_analyzed_by = [] for person in protocol.players.itervalues(): if person.name is None: continue if person != player and connection.name in person.shots_analyzed_by: person.shots_analyzed_by.remove(connection.name) connection.send_chat("You are no longer analyzing %s." % (person.name)) print person.shots_analyzed_by if connection.name not in player.shots_analyzed_by: connection.send_chat("You are now analyzing %s." % (player.name)) player.shots_analyzed_by.append(connection.name) connection.hs, connection.bs, connection.ls = 0, 0, 0 print player.shots_analyzed_by elif connection.name in player.shots_analyzed_by: connection.send_chat("You are no longer analyzing anyone.") player.shots_analyzed_by.remove(connection.name) print player.shots_analyzed_by
def ratio(connection, user=None): msg = "You have" if user != None: connection = get_player(connection.protocol, user) msg = "%s has" if connection not in connection.protocol.players: raise KeyError() msg %= connection.name if connection not in connection.protocol.players: raise KeyError() kills = connection.ratio_kills deaths = float(max(1,connection.ratio_deaths)) headshotkills = connection.ratio_headshotkills meleekills = connection.ratio_meleekills grenadekills = connection.ratio_grenadekills msg += " a kill-death ratio of %.2f" % (kills/deaths) if HEADSHOT_RATIO: msg += ", headshot-death ratio of %.2f" % (headshotkills/deaths) msg += " (%s kills, %s deaths" % (kills, connection.ratio_deaths) if EXTENDED_RATIO: msg += ", %s headshot, %s melee, %s grenade" % (headshotkills, meleekills, grenadekills) if KILLS_PER_MINUTE: dt = (seconds() - connection.time_login) /60 msg += ", %.2f kills per minute" % (kills/dt) msg += ")." return msg
def on_weapon_set(self, value): if self.name in analyzers.values(): for name in analyzers: if analyzers[name] == self.name: analyzer = get_player(self.protocol, name) analyzer.hs, analyzer.bs, analyzer.ls = 0, 0, 0 return connection.on_weapon_set(self, value)
def analyze_shot(connection, player=None): global analyzers protocol = connection.protocol if not analyzers: analyzers = {} if player is None: if analyzers.has_key(connection.name): del analyzers[connection.name] connection.send_chat('You are no longer analyzing anyone.') else: connection.send_chat('Please enter a target player to analyze.') elif player is not None: player = get_player(protocol, player) if player not in protocol.players: raise ValueError() else: if analyzers.has_key(connection.name) and player.name == analyzers[ connection.name]: del analyzers[connection.name] connection.send_chat('You are no longer analyzing anyone.') elif analyzers.has_key( connection.name ) and player.name != analyzers[connection.name]: connection.send_chat( 'You are no longer analyzing %s. You are now analyzing %s.' % (analyzers[connection.name], player.name)) analyzers[connection.name] = player.name connection.hs, connection.bs, connection.ls = 0, 0, 0 elif not analyzers.has_key(connection.name): analyzers[connection.name] = player.name connection.send_chat('You are now analyzing %s' % (player.name)) connection.hs, connection.bs, connection.ls = 0, 0, 0
def analyze_shot(connection, player=None): global analyzers protocol = connection.protocol if not analyzers: analyzers = {} if player is None: if analyzers.has_key(connection.name): del analyzers[connection.name] connection.send_chat("You are no longer analyzing anyone.") else: connection.send_chat("Please enter a target player to analyze.") elif player is not None: player = get_player(protocol, player) if player not in protocol.players: raise ValueError() else: if analyzers.has_key(connection.name) and player.name == analyzers[connection.name]: del analyzers[connection.name] connection.send_chat("You are no longer analyzing anyone.") elif analyzers.has_key(connection.name) and player.name != analyzers[connection.name]: connection.send_chat( "You are no longer analyzing %s. You are now analyzing %s." % (analyzers[connection.name], player.name) ) analyzers[connection.name] = player.name connection.hs, connection.bs, connection.ls = 0, 0, 0 elif not analyzers.has_key(connection.name): analyzers[connection.name] = player.name connection.send_chat("You are now analyzing %s" % (player.name)) connection.hs, connection.bs, connection.ls = 0, 0, 0
def lightning(connection, player=None): # And I will strike down upon thee with great vengeance and furious anger # those who would attempt to poison and destroy My brothers protocol = connection.protocol if player: player = get_player(protocol, player) is_spectator = player.team and player.team.spectator if is_spectator: return S_SPECTATING.format(player=player.name) if player.hp < 0: return S_NOT_ALIVE.format(player=player.name) callLater(0.1, player.kill) callLater(0.1, create_explosion_effect_at_player, player) message = S_LIGHTNING.format(player=player.name) protocol.send_chat(message, sender=player) player.send_chat(S_LIGHTNING_SELF) if connection in protocol.players: message = S_LIGHTNING_IRC.format(admin=connection.name, player=player.name) else: message = '* ' + message protocol.irc_say(message) effects = [ FogHold(0.05, (0, 0, 0)), FogGradient(0.8, (255, 255, 255), (0, 0, 0), ease_in), FogHold(1.0, (0, 0, 0)), FogGradient(4.0, (0, 0, 0), protocol.get_real_fog_color, ease_out) ] protocol.set_fog_effects(effects)
def ratio(connection, user=None): msg = "You have" if user != None: connection = get_player(connection.protocol, user) msg = "%s has" if connection not in connection.protocol.players: raise KeyError() msg %= connection.name if connection not in connection.protocol.players: raise KeyError() kills = connection.ratio_kills deaths = float(max(1, connection.ratio_deaths)) headshotkills = connection.ratio_headshotkills meleekills = connection.ratio_meleekills grenadekills = connection.ratio_grenadekills msg += " a kill-death ratio of %.2f" % (kills / deaths) if HEADSHOT_RATIO: msg += ", headshot-death ratio of %.2f" % (headshotkills / deaths) msg += " (%s kills, %s deaths" % (kills, connection.ratio_deaths) if EXTENDED_RATIO: msg += ", %s headshot, %s melee, %s grenade" % ( headshotkills, meleekills, grenadekills) if KILLS_PER_MINUTE: dt = (seconds() - connection.time_login) / 60 msg += ", %.2f kills per minute" % (kills / dt) msg += ")." return msg
def refill_mines(connection, *args): protocol = connection.protocol try: player = args[0] except IndexError: player = None if player is not None: if player == "*": for _pList in protocol.players: for player in _pList: if player.mine_amount <= 5: player.mine_amount = 5 player.send_chat("Mines refilled! %s mines available." % player.mine_amount) protocol.irc_say("* %s refilled all players' mines" % (connection.name)) connection.send_chat("Refilled all players' mines!" % player.name) else: player = get_player(protocol, player) if player.mine_amount <= 5: player.mine_amount = 5 player.send_chat("Mines refilled! %s mines available." % player.mine_amount) connection.send_chat("Refilled %s's mines!" % player.name) protocol.irc_say("* %s refilled %s's mines" % (connection.name, player.name)) else: player = connection if player.mine_amount <= 5: player.mine_amount = 5 player.send_chat("Mines refilled! %s mines available." % player.mine_amount) protocol.irc_say("* %s refilled %s's mines" % (connection.name, connection.name))
def toggle_spy(connection, player = None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) elif connection in protocol.players: player = connection else: raise ValueError() player.spy = spy = not player.spy player.killing = not spy if spy and player.invisible: # spy and invisibility don't get along nicely, the latter doesn't know # about the multiteaming when sending out create_player packets result = commands.invisible(connection, player.name) if result: connection.send_chat(result) if player.world_object and not player.world_object.dead: team = player.team.other if player.spy else player.team fill_create_player(player, team) protocol.send_contained(create_player, team = team, sender = player, save = True) other_message = S_SPY if spy else S_NO_SPY other_message = other_message.format(player = player.name) protocol.irc_say('* ' + other_message) self_message = S_SPY_SELF if spy else S_NO_SPY_SELF if connection is player: return self_message elif connection in protocol.players: player.send_chat(self_message) return other_message
def carpet(connection, player = None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) elif connection in protocol.players: player = connection else: raise ValueError() player.carpet = not player.carpet if player.carpet: player.carpet_blocks = deque() if player.carpet_loop is None: player.carpet_loop = LoopingCall(carpet_cycle, protocol, player) player.carpet_loop.start(CARPET_INTERVAL) else: while player.carpet_blocks: destroy_block(protocol, *player.carpet_blocks.pop()) player.carpet_loop.stop() message = 'now carpetwalking' if player.carpet else 'no longer carpetwalking' player.send_chat("You're %s" % message) if connection is not player and connection in protocol.players: connection.send_chat('%s is %s' % (player.name, message)) protocol.irc_say('* %s is %s' % (player.name, message))
def aimbotcheck(connection, user, minutes): connection = commands.get_player(connection.protocol, user) if connection not in connection.protocol.players: raise KeyError() kills = connection.tally_kill_log(reactor.seconds() - int(minutes)*60) return ('Il giocatore %s ha fatto %s uccisioni negli ultimi %s minuti.' % (connection.name, kills, minutes))
def whois(connection, player): player = commands.get_player(connection.protocol, player) username = player.username if username is None: message = ' is not logged in.' else: message = ' is logged in as ' + username return player.name + message
def hp(connection, player_name): try: player = get_player(connection.protocol, player_name, False) except InvalidPlayer: return 'Invalid player' except InvalidSpectator: return 'Player is a spectator' return "%s's HP is: %i" % (player.name, player.hp)
def free_all(connection): protocol = connection.protocol for playersJailed in jail_list: player = get_player(protocol, playersJailed) player.kill() player.jailed = False player.reason = None jail_list.remove(playersJailed) return 'All players freed.'
def remove_squad(self, player_name): player = get_player(self.protocol, player_name) if player.squad is not None: player.squad = None player.squad_pref = None player.join_squad(None, None) return 'Removed player %s from their squad.' % player.name else: return 'Player %s is not in a squad!' % player.name
def on_disconnect(self): if self.name in analyzers.values(): for name in analyzers.keys(): if analyzers[name] == self.name: del analyzers[name] analyzer = get_player(self.protocol, name) if name != self.name: analyzer.send_chat("You are no longer analyzing %s. Player disconnected." % (self.name)) if analyzers.has_key(self.name): del analyzers[self.name] return connection.on_disconnect(self)
def estrogen(connection, player = None): if player is not None: player = get_player(connection.protocol, player) else: player = connection x, y, z = player.get_location() num = random.randrange(125, 150) connection.protocol.spawn_estrogen(x, y, z, num) player.send_chat('Let the female part of you emerge!') connection.protocol.send_chat('%s has been surrounded by a ' 'cloud of estrogen.' % (player.name), irc = True)
def estrogen(connection, player=None): if player is not None: player = get_player(connection.protocol, player) else: player = connection x, y, z = player.get_location() num = random.randrange(125, 150) connection.protocol.spawn_estrogen(x, y, z, num) player.send_chat('Let the female part of you emerge!') connection.protocol.send_chat('%s has been surrounded by a ' 'cloud of estrogen.' % (player.name), irc=True)
def toggle_headshot(connection, player): protocol = connection.protocol player = get_player(connection.protocol, player) player.headshots = not player.headshots message = S_HS_ENABLED_IRC if player.headshots else S_HS_DISABLED_IRC message = message.format(admin = connection.name, victim = player.name) protocol.irc_say(message) if connection in protocol.players: message = S_HS_ENABLED if player.headshots else S_HS_DISABLED return message.format(victim = player.name)
def toggle_markers(connection, player=None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) player.allow_markers = not player.allow_markers message = S_PLAYER_ENABLED if player.allow_markers else S_PLAYER_DISABLED message = message.format(player=player.name) protocol.send_chat(message, irc=True) else: protocol.allow_markers = not protocol.allow_markers message = S_ENABLED if protocol.allow_markers else S_DISABLED connection.protocol.send_chat(message, irc=True)
def changename(connection, new_name, old_name=None): if old_name is None: old_name = connection.name try: player = commands.get_player(connection.protocol, old_name, False) except InvalidPlayer: return 'Invalid player' except InvalidSpectator: return 'Player is a spectator' msg = "Changed %s's name to %s" % (player.name, new_name) player.name = new_name return msg
def toggle_markers(connection, player = None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) player.allow_markers = not player.allow_markers message = S_PLAYER_ENABLED if player.allow_markers else S_PLAYER_DISABLED message = message.format(player = player.name) protocol.send_chat(message, irc = True) else: protocol.allow_markers = not protocol.allow_markers message = S_ENABLED if protocol.allow_markers else S_DISABLED connection.protocol.send_chat(message, irc = True)
def togglecaps(connection, player = None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) elif connection in protocol.players: player = connection else: raise ValueError() player.no_caps = not player.no_caps status = "no longer" if player.no_caps else "now" protocol.irc_say("%s can %s use caps" % (player.name, status))
def on_disconnect(self): self.illegal_dt_count = 0 if self.shots_analyzed_by: for names in self.shots_analyzed_by: adminz = get_player(self.protocol, names) if names != self.name: adminz.send_chat("No longer analyzing %s. Player has disconnected." % (self.name)) self.shots_analyzed_by = [] self.prev_time = None for player in self.protocol.players.itervalues(): if self.name in player.shots_analyzed_by: player.shots_analyzed_by.remove(self.name) return connection.on_disconnect(self)
def ratio(connection, user=None): has_msg = "You have" if user != None: connection = get_player(connection.protocol, user) has_msg = "%s has" if connection not in connection.protocol.players: raise KeyError() has_msg %= connection.name if connection not in connection.protocol.players: raise KeyError() ratio = connection.ratio_kills / float(max(1, connection.ratio_deaths)) ratio_msg = has_msg + (" a kill-death ratio of %.2f" % (ratio)) return "%s (%s kills, %s deaths)." % (ratio_msg, connection.ratio_kills, connection.ratio_deaths)
def on_disconnect(self): if self.name in analyzers.values(): for name in analyzers.keys(): if analyzers[name] == self.name: del analyzers[name] analyzer = get_player(self.protocol, name) if name != self.name: analyzer.send_chat( 'You are no longer analyzing %s. Player disconnected.' % (self.name)) if analyzers.has_key(self.name): del analyzers[self.name] return connection.on_disconnect(self)
def whois(connection, player): """ Gets the user that a player is logged in as usage: \whois playername """ player = commands.get_player(connection.protocol, player) username = player.username if username is None: message = ' is not logged in.' else: message = ' is logged in as ' + username return player.name + message
def on_hit(self, hit_amount, hit_player, type, grenade): if self.name in analyzers.values(): body_damage_values = [49, 29, 27] limb_damage_values = [33, 18, 16] if type == HEADSHOT_KILL or hit_amount in body_damage_values or hit_amount in limb_damage_values: if not grenade: dist = int( distance_3d_vector( self.world_object.position, hit_player.world_object.position)) weap = self.weapon_object.name self.pres_time = seconds() if self.prev_time is None: dt = None else: dt = (self.pres_time - self.prev_time) * 1000 self.prev_time = seconds() if type == HEADSHOT_KILL: body_part = "HEADSHOT" elif hit_amount in body_damage_values: body_part = "Body" elif hit_amount in limb_damage_values: body_part = "Limb" for name in analyzers.keys(): if analyzers[name] == self.name: analyzer = get_player(self.protocol, name) if analyzer not in self.protocol.players: raise ValueError() else: if body_part == "HEADSHOT": analyzer.hs += 1 counter = analyzer.hs elif body_part == "Body": analyzer.bs += 1 counter = analyzer.bs elif body_part == "Limb": analyzer.ls += 1 counter = analyzer.ls if dt is not None: analyzer.send_chat( '%s shot %s dist: %d blocks dT: %.0f ms %s %s(%d)' % (self.name, hit_player.name, dist, dt, weap, body_part, counter)) else: analyzer.send_chat( '%s shot %s dist: %d blocks dT: NA %s %s(%d)' % (self.name, hit_player.name, dist, weap, body_part, counter)) return connection.on_hit(self, hit_amount, hit_player, type, grenade)
def toggle_mine(connection, player=None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) player.canPlaceMines = placemine = not player.canPlaceMines message = 'now place mines' if placemine else 'no longer place mines' connection.send_chat("%s can %s" % (player.name, message)) protocol.irc_say('* %s can %s' % (player.name, message)) else: protocol.mine_place = placemine = not protocol.mine_place message = 'enabled' if placemine else 'disabled' connection.send_chat("Mine placing is now %s" % (message)) protocol.irc_say('* Mine placing is now %s' % (message))
def ratio(connection, user=None): has_msg = "You have" if user != None: connection = get_player(connection.protocol, user) has_msg = "%s has" if connection not in connection.protocol.players: raise KeyError() has_msg %= connection.name if connection not in connection.protocol.players: raise KeyError() ratio = connection.ratio_kills / float(max(1, connection.ratio_deaths)) ratio_msg = has_msg + (" a kill-death ratio of %.2f" % (ratio)) return ('%s (%s kills, %s deaths).' % (ratio_msg, connection.ratio_kills, connection.ratio_deaths))
def free_from_jail(connection, value): protocol = connection.protocol # Meh player = get_player(protocol, value) # Get player if player not in protocol.players: raise ValueError() # Errors again else: if not player.jailed: # If player isn't jailed return 'Player ' + player.name + ' is not jailed!' # Message elif player.jailed: # If player is jailed player.jailed = False # Player is not jailed anymore player.kill() # Kill the player connection.protocol.send_chat("%s was freed from jail by %s" % (player.name, connection.name)) # Message connection.protocol.irc_say('* %s was freed from jail by %s' % (player.name, connection.name)) # Message jail_list.remove(player.name)
def follow(self, playerkey=None): if playerkey is None: squad_pref = None squad = self.squad else: squad_pref = get_player(self.protocol, playerkey) squad = squad_pref.squad if squad_pref.team is not self.team: return "%s is not on your team!" % (squad_pref.name) if squad_pref is self: return "You can't follow yourself!" if squad_pref.squad is None: return "%s is not in a squad and cannot be followed." % squad_pref.name return self.join_squad(squad, squad_pref)
def language(connection, player, lang = None): protocol = connection.protocol player = get_player(protocol, player) if lang is None: if player.language_detected: lang = player.language_pair[:2] return S_LANGUAGE.format(player = player.name, lang = lang) else: return S_NOT_DETECTED_YET.format(player = player.name) else: player.language_detected = True player.language_pair = lang + '|en' player.translating = lang != 'en' return S_LANGUAGE_SET.format(player = player.name, lang = lang)
def timed_mute(connection, *args): protocol = connection.protocol nick = args[0] time = int(args[1]) reason = join_arguments(args[2:]) player = get_player(protocol, nick) if time < 0: raise ValueError() if not player.mute: TimedMute(player, time, reason) else: return '%s is already muted!' % nick
def on_disconnect(self): self.illegal_dt_count = 0 if self.shots_analyzed_by: for names in self.shots_analyzed_by: adminz = get_player(self.protocol, names) if names != self.name: adminz.send_chat( "No longer analyzing %s. Player has disconnected." % (self.name)) self.shots_analyzed_by = [] self.prev_time = None for player in self.protocol.players.itervalues(): if self.name in player.shots_analyzed_by: player.shots_analyzed_by.remove(self.name) return connection.on_disconnect(self)
def language(connection, player, lang=None): protocol = connection.protocol player = get_player(protocol, player) if lang is None: if player.language_detected: lang = player.language_pair[:2] return S_LANGUAGE.format(player=player.name, lang=lang) else: return S_NOT_DETECTED_YET.format(player=player.name) else: player.language_detected = True player.language_pair = lang + '|en' player.translating = lang != 'en' return S_LANGUAGE_SET.format(player=player.name, lang=lang)
def is_jailed(connection, value = None): if value is None: if not jail_list: return 'No jailed players.' else: return "Jailed players: " + ", ".join(jail_list) elif value is not None: protocol = connection.protocol player = get_player(protocol, value) if player not in protocol.players: raise ValueError() else: if player.jailed: return 'Player %s jailed for: %s' % (player.name, player.reason) else: return 'Player %s is not jailed.' % (player.name)
def invisible(connection, player = None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) elif connection in protocol.players: player = connection else: raise ValueError() if not player.invisible and player.spy: # disable spy before going invisible result = toggle_spy(connection, player.name) if result: connection.send_chat(result) commands.invisible(connection, player.name)