def handler(cls, attacker, victim_codename): logging.info("SNIPE start.") victim = Util.get_victim(victim_codename) logging.info("Attacker {}".format(attacker)) logging.info("Victim {}".format(victim)) """ validation """ outgoing = [] try: Kill.validate_kill(attacker, victim) if attacker.role != "SNIPER": raise MeError("not SNIPER") except (TeamError, MeError, TargetError) as message: outgoing.append((WEI_HAN, message.message)) outgoing.append((attacker.key.id(), message.message)) return outgoing except: message = "[ERR] Unknown Error in SNIPE" outgoing.append((WEI_HAN, message)) outgoing.append((attacker.key.id(), message)) return outgoing action = Action() action.attacker = attacker.key.id() action.action = "SNIPE" action.victim = victim.key.id() action.datetime = datetime.now() action_key = action.put() attacker = Player.get_by_id(action.attacker) attacker.killed.append(str(action_key.id())) attacker.put() victim.state = "DEAD" victim.killed_by = str(action_key.id()) victim.put() message = "{} has been SNIPED.".format(victim_codename) outgoing.append((victim.key.id(), "You have been SNIPED. (Ref {}).".\ format(action_key.id()))) outgoing.append(("*", message)) outgoing += Team.push(Team.get_by_id(victim.team)) return outgoing
def handler(cls, attacker, victim_codename): logging.info("SNIPE start.") victim = Util.get_victim(victim_codename) logging.info("Attacker {}".format(attacker)) logging.info("Victim {}".format(victim)) """ validation """ outgoing = [] try: Kill.validate_kill(attacker, victim) if attacker.role != "SNIPER": raise MeError("not SNIPER") except (TeamError, MeError, TargetError) as message: outgoing.append((WEI_HAN, message.message)) outgoing.append((attacker.key.id(), message.message)) return outgoing except: message = "[ERR] Unknown Error in SNIPE" outgoing.append((WEI_HAN, message)) outgoing.append((attacker.key.id(), message)) return outgoing action = Action() action.attacker = attacker.key.id() action.action = "SNIPE" action.victim = victim.key.id() action.datetime = datetime.now() action_key = action.put() attacker = Player.get_by_id(action.attacker) attacker.killed.append(str(action_key.id())) attacker.put() victim.state = "DEAD" victim.killed_by = str(action_key.id()) victim.put() message = "{} has been SNIPED.".format(victim_codename) outgoing.append((victim.key.id(), "You have been SNIPED. (Ref {}).".\ format(action_key.id()))) outgoing.append(("*", message)) outgoing += Team.push(Team.get_by_id(victim.team)) return outgoing
def handler(cls, ref, params, From): logging.debug("REPLY {}".format(ref)) lookup = Action.get_by_id(int(ref)) if not lookup: raise ReplyError("ref num", ref) response = params[0] if response != "Y" and response != "y" and response != "N" and response != "n": raise ReplyError(response, ref) if lookup.action == "DISARM": return Disarm.reply_handler(lookup, response) else: output_msg = [] if lookup.action == "KILL": output_msg += Kill.reply_handler(lookup, response) elif lookup.action == "BOMB": output_msg += Bomb.reply_handler(lookup, response, From) """ Generate push if necessary """ output_msg += Team.push(Team.get_by_id(From.team)) return output_msg raise ReplyError(response, ref)