def set_ko_fight(self, player, ko_str): ko_bool = booleanize(ko_str) if ko_bool: if ko_bool > 0: self.ko_fight = True display_str = "^Con^~" else: self.ko_fight = False display_str = "^coff^~" self.channel.broadcast_cc(self.prefix + "^R%s^~ has turned ^Gko fight^~ mode %s.\n" % (player, display_str))
def set_border(self, player, border_str): border_bool = booleanize(border_str) if border_bool: if border_bool > 0: self.has_borders = True display_str = "^Con^~" else: self.has_borders = False display_str = "^coff^~" self.channel.broadcast_cc(self.prefix + "^R%s^~ has turned borders %s.\n" % (player, display_str)) else: player.tell_cc(self.prefix + "Not a valid boolean!\n")
def set_whist(self, player, whist_bits): whist_bool = booleanize(whist_bits) if whist_bool: if whist_bool > 0: self.whist = True display_str = "^Con^~" elif whist_bool < 0: self.whist = False display_str = "^coff^~" self.bc_pre("^R%s^~ has turned whist-style trumps %s.\n" % (player, display_str)) else: self.tell_pre(player, "Not a valid boolean!\n")
def set_positive(self, player, positive_bits): positive_bool = booleanize(positive_bits) if positive_bool: if positive_bool > 0: self.positive = True display_str = "^Crequires^~" elif positive_bool < 0: self.positive = False display_str = "^cdoes not require^~" self.bc_pre("^R%s^~ sets it so that winning %s positive scores.\n" % (player, display_str)) else: self.tell_pre(player, "Not a valid boolean!\n")
def set_ko_fight(self, player, ko_str): ko_bool = booleanize(ko_str) if ko_bool: if ko_bool > 0: self.ko_fight = True display_str = "^Con^~" else: self.ko_fight = False display_str = "^coff^~" self.channel.broadcast_cc( self.prefix + "^R%s^~ has turned ^Gko fight^~ mode %s.\n" % (player, display_str))
def set_master(self, player, master_str): master_bool = booleanize(master_str) if master_bool: if master_bool > 0: self.master = True display_str = "^Con^~" else: self.master = False display_str = "^coff^~" self.channel.broadcast_cc(self.prefix + "^R%s^~ has turned ^GMaster Y^~ mode %s.\n" % (player, display_str)) else: player.tell_cc(self.prefix + "Not a valid boolean!\n")
def quickstart(self, player, qs_str): qs_bool = booleanize(qs_str) if qs_bool: if qs_bool > 0: self.is_quickstart = True display_str = "^Con^~" else: self.is_quickstart = False display_str = "^coff^~" self.channel.broadcast_cc(self.prefix + "^R%s^~ has turned quickstart mode %s.\n" % (player, display_str)) else: player.tell_cc(self.prefix + "Not a valid boolean!\n")
def set_directional(self, player, dir_bits): dir_bool = booleanize(dir_bits) if dir_bool: if dir_bool > 0: if self.goban.height != self.goban.width: player.tell_cc(self.prefix + "Cannot change to directional with uneven sides. Resize first.\n") return self.directional = True display_str = "^Con^~" elif dir_bool < 0: self.directional = False display_str = "^coff^~" self.channel.broadcast_cc(self.prefix + "^R%s^~ has turned directional goals %s.\n" % (player, display_str)) else: player.tell_cc(self.prefix + "Not a valid boolean!\n")
def set_timestamp(self, msg, player): # Returns whether or not it was successful, not the value set. action = booleanize(msg) if not action: return False if action > 0: player.config["timestamps"] = True player.server.log.log("%s turned timestamps on." % player) else: player.config["timestamps"] = False player.server.log.log("%s turned timestamps off." % player) return True
def set_short(self, player, short_bits): if self.mode != 3: self.tell_pre(player, "Cannot set short mode when not in 3-player mode.\n") return False short_bool = booleanize(short_bits) if short_bool: if short_bool > 0: self.short = True display_str = "^Con^~" elif short_bool < 0: self.short = False display_str = "^coff^~" self.bc_pre("^R%s^~ has turned short suits %s.\n" % (player, display_str)) else: self.tell_pre(player, "Not a valid boolean!\n")
def set_color(self, msg, player): # Returns whether or not it was successful, not the value set. action = booleanize(msg) if not action: return False if action > 0: player.config["color"] = True player.client.use_ansi = True player.server.log.log("%s turned color on." % player) else: player.config["color"] = False player.client.use_ansi = False player.server.log.log("%s turned color off." % player) return True
def set_short(self, player, short_bits): if self.mode != 3: self.tell_pre( player, "Cannot set short mode when not in 3-player mode.\n") return False short_bool = booleanize(short_bits) if short_bool: if short_bool > 0: self.short = True display_str = "^Con^~" elif short_bool < 0: self.short = False display_str = "^coff^~" self.bc_pre("^R%s^~ has turned short suits %s.\n" % (player, display_str)) else: self.tell_pre(player, "Not a valid boolean!\n")
def game(self, player, game_bits): primary = game_bits[0].lower() other_bits = game_bits[1:] handled = False if primary in ("reload_all", ): self.server.game_master.reload_all_games() player.tell_cc("You have reloaded all game modules.\n") self.log("%s reloaded all games." % player) handled = True elif primary in ("reload_conf", ): self.server.game_master.unload_all_games() self.server.game_master.load_games_from_conf() player.tell_cc( "You have unloaded all games and reloaded from the conf file.\n" ) self.log("%s unloaded all games and reloaded from the conf file." % player) handled = True elif primary in ("reload", ): if len(other_bits) == 1: game_key = other_bits[0].lower() if self.server.game_master.is_game(game_key): success = self.server.game_master.reload_game(game_key) if success: player.tell_cc("Game %s reloaded successfully.\n" % game_key) self.log("%s reloaded game %s." % (player, game_key)) else: player.tell_cc("Game %s failed to reload.\n" % game_key) self.log( "%s attempted to reload game %s but the reload failed." % (player, game_key)) else: player.tell_cc("No such game %s to reload.\n" % game_key) self.log("%s attempted to reload nonexistent game %s." % (player, game_key)) else: player.tell_cc("Invalid admin game reload command.\n") self.log("%s attempted an invalid admin game reload." % player) handled = True elif primary in ("unload_all", ): self.server.game_master.unload_all_games() player.tell_cc("You have unloaded all game modules.\n") self.log("%s unloaded all games." % player) handled = True elif primary in ("unload", ): if len(other_bits) == 1: game_key = other_bits[0].lower() if self.server.game_master.is_game(game_key): self.server.game_master.unload_game(game_key) player.tell_cc("Game %s unloaded successfully.\n" % game_key) self.log("%s unloaded game %s." % (player, game_key)) else: player.tell_cc("No such game %s to unload.\n" % game_key) self.log("%s attempted to unload nonexistent game %s." % (player, game_key)) else: player.tell_cc("Invalid admin game unload command.\n") self.log("%s attempted an invalid admin game unload." % player) handled = True elif primary in ("load", ): if len(other_bits) == 2 or len(other_bits) == 3: game_key = other_bits[0].lower() class_path = other_bits[1] admin_only = False if len(other_bits) == 3: admin_bool = booleanize(other_bits[2]) if not admin_bool: player.tell_cc( "Invalid admin-only setting. Defaulting to false.\n" ) elif admin_bool > 0: admin_only = True if not self.server.game_master.is_game(game_key): success = self.server.game_master.load_game( game_key, class_path, admin_only) if success: player.tell_cc("Game %s loaded successfully.\n" % game_key) self.log("%s loaded game %s (%s, admin=%s)." % (player, game_key, class_path, admin_only)) else: player.tell_cc( "Game %s failed to load. Check the log.\n" % game_key) self.log( "%s attempted to load game %s (%s) but the load failed." % (player, game_key, class_path)) else: player.tell_cc( "Another game is already loaded with that key.\n") self.log( "%s attempted to load game %s (%s) but the key existed already." % (player, game_key, class_path)) else: player.tell_cc("Invalid admin game load command.\n") self.log("%s attempted an invalid admin game load." % player) handled = True if not handled: player.tell_cc("Invalid admin game command.\n") self.log("%s attempted an invalid admin game command." % player)
def game(self, player, game_bits): primary = game_bits[0].lower() other_bits = game_bits[1:] handled = False if primary in ("reload_all",): self.server.game_master.reload_all_games() player.tell_cc("You have reloaded all game modules.\n") self.log("%s reloaded all games." % player) handled = True elif primary in ("reload_conf",): self.server.game_master.unload_all_games() self.server.game_master.load_games_from_conf() player.tell_cc("You have unloaded all games and reloaded from the conf file.\n") self.log("%s unloaded all games and reloaded from the conf file." % player) handled = True elif primary in ("reload",): if len(other_bits) == 1: game_key = other_bits[0].lower() if self.server.game_master.is_game(game_key): success = self.server.game_master.reload_game(game_key) if success: player.tell_cc("Game %s reloaded successfully.\n" % game_key) self.log("%s reloaded game %s." % (player, game_key)) else: player.tell_cc("Game %s failed to reload.\n" % game_key) self.log("%s attempted to reload game %s but the reload failed." % (player, game_key)) else: player.tell_cc("No such game %s to reload.\n" % game_key) self.log("%s attempted to reload nonexistent game %s." % (player, game_key)) else: player.tell_cc("Invalid admin game reload command.\n") self.log("%s attempted an invalid admin game reload." % player) handled = True elif primary in ("unload_all",): self.server.game_master.unload_all_games() player.tell_cc("You have unloaded all game modules.\n") self.log("%s unloaded all games." % player) handled = True elif primary in ("unload",): if len(other_bits) == 1: game_key = other_bits[0].lower() if self.server.game_master.is_game(game_key): self.server.game_master.unload_game(game_key) player.tell_cc("Game %s unloaded successfully.\n" % game_key) self.log("%s unloaded game %s." % (player, game_key)) else: player.tell_cc("No such game %s to unload.\n" % game_key) self.log("%s attempted to unload nonexistent game %s." % (player, game_key)) else: player.tell_cc("Invalid admin game unload command.\n") self.log("%s attempted an invalid admin game unload." % player) handled = True elif primary in ("load",): if len(other_bits) == 2 or len(other_bits) == 3: game_key = other_bits[0].lower() class_path = other_bits[1] admin_only = False if len(other_bits) == 3: admin_bool = booleanize(other_bits[2]) if not admin_bool: player.tell_cc("Invalid admin-only setting. Defaulting to false.\n") elif admin_bool > 0: admin_only = True if not self.server.game_master.is_game(game_key): success = self.server.game_master.load_game(game_key, class_path, admin_only) if success: player.tell_cc("Game %s loaded successfully.\n" % game_key) self.log("%s loaded game %s (%s, admin=%s)." % (player, game_key, class_path, admin_only)) else: player.tell_cc("Game %s failed to load. Check the log.\n" % game_key) self.log("%s attempted to load game %s (%s) but the load failed." % (player, game_key, class_path)) else: player.tell_cc("Another game is already loaded with that key.\n") self.log("%s attempted to load game %s (%s) but the key existed already." % (player, game_key, class_path)) else: player.tell_cc("Invalid admin game load command.\n") self.log("%s attempted an invalid admin game load." % player) handled = True if not handled: player.tell_cc("Invalid admin game command.\n") self.log("%s attempted an invalid admin game command." % player)