def at_server_start(): """ This is called every time the server starts up, regardless of how it was shut down. """ # reset settings from muddery.utils.game_settings import GAME_SETTINGS GAME_SETTINGS.reset() # reload local strings from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER LOCALIZED_STRINGS_HANDLER.reload() # reset default locations from muddery.utils import builder builder.reset_default_locations() # clear dialogues from muddery.utils.dialogue_handler import DIALOGUE_HANDLER DIALOGUE_HANDLER.clear() # reload equipment types from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER EQUIP_TYPE_HANDLER.reload() # localize model fields from muddery.utils.localiztion_handler import localize_model_fields localize_model_fields() # load condition descriptions from muddery.utils.desc_handler import DESC_HANDLER DESC_HANDLER.reload()
def at_server_start(): """ This is called every time the server starts up, regardless of how it was shut down. """ # reset settings GAME_SETTINGS.reset() CLIENT_SETTINGS.reset() # reload keys OBJECT_KEY_HANDLER.reload() # reset default locations builder.reset_default_locations() # clear dialogues DIALOGUE_HANDLER.clear() # clear quest dependencies QUEST_DEP_HANDLER.clear() # reload equipment types EQUIP_TYPE_HANDLER.reload() # reload local strings LOCALIZED_STRINGS_HANDLER.reload() # localize model fields localize_model_fields()
def at_server_start(): """ This is called every time the server starts up, regardless of how it was shut down. """ # reset settings GAME_SETTINGS.reset() # reload keys OBJECT_KEY_HANDLER.reload() # reset default locations builder.reset_default_locations() # clear dialogues DIALOGUE_HANDLER.clear() # clear quest dependencies QUEST_DEP_HANDLER.clear() # reload equipment types EQUIP_TYPE_HANDLER.reload() # reload local strings LOCALIZED_STRINGS_HANDLER.reload() # localize model fields localize_model_fields()
def __init__(self): """ Initialize the handler. """ self.can_close_dialogue = GAME_SETTINGS.get("can_close_dialogue") self.single_sentence_mode = GAME_SETTINGS.get("single_dialogue_sentence") self.dialogue_storage = {}
def apply_changes(request): """ Apply the game world's data. """ try: # reload localized strings LOCALIZED_STRINGS_HANDLER.reload() # rebuild the world build_all() # send client settings CLIENT_SETTINGS.reset() client_settings = CLIENT_SETTINGS.all_values() client_settings["game_name"] = GAME_SETTINGS.get("game_name") client_settings["show_social_box"] = not GAME_SETTINGS.get("solo_mode") text = json.dumps({"settings": client_settings}) SESSIONS.announce_all(text) # restart the server SESSIONS.announce_all(" Server restarting ...") SESSIONS.server.shutdown(mode='reload') except Exception, e: message = "Can't build world: %s" % e logger.log_tracemsg(message) return render(request, 'fail.html', {"message": message})
def func(self): "Send settings to the client." client_settings = GAME_SETTINGS.get_client_settings() self.caller.msg({"settings": client_settings}) "Show the connect screen." connection_screen = GAME_SETTINGS.get("connection_screen") if not connection_screen: connection_screen = "No connection screen found. Please contact an admin." self.caller.msg({"msg": connection_screen})
def after_data_loaded(self): """ """ super(MudderyPlayerCharacter, self).after_data_loaded() self.reborn_cd = GAME_SETTINGS.get("player_reborn_cd") self.solo_mode = GAME_SETTINGS.get("solo_mode") # refresh data self.refresh_data()
def at_initial_setup(): """ Build up the default world and set default locations. """ try: # load world data import_local_data() print("Import local data.") # load game settings GAME_SETTINGS.reset() print("Reset game settings.") # build world builder.build_all() print("Builder build all.") # set limbo's desc limbo_obj = search.search_object("#2", exact=True) if limbo_obj: limbo_obj[0].db.desc = LIMBO_DESC limbo_obj[0].position = None print("Set limbo object.") # set default locations builder.reset_default_locations() print("Set default locations.") superuser = search.search_object("#1", exact=True) if superuser: superuser = superuser[0] # move the superuser to the start location start_location = search.search_object(settings.START_LOCATION, exact=True) if start_location: start_location = start_location[0] superuser.move_to(start_location, quiet=True) # set superuser's data superuser.set_data_key( GAME_SETTINGS.get("default_player_character_key")) superuser.set_level(1) superuser.set_nickname("superuser") # set superuser's honour to -1 HONOURS_MAPPER.set_honour(superuser, -1) print("Set supervisor.") except Exception, e: ostring = "Can't set initial data: %s" % e print(ostring) print(traceback.format_exc())
def func(self): "Send settings to the client." client_settings = CLIENT_SETTINGS.all_values() client_settings["game_name"] = GAME_SETTINGS.get("game_name") client_settings["show_social_box"] = not GAME_SETTINGS.get("solo_mode") self.caller.msg({"settings": client_settings}) "Show the connect screen." connection_screen = GAME_SETTINGS.get("connection_screen") if not connection_screen: connection_screen = "No connection screen found. Please contact an admin." self.caller.msg({"msg": connection_screen})
def at_object_creation(self): """ Called once, when this object is first created. This is the normal hook to overload for most object types. """ super(MudderyCharacter, self).at_object_creation() # set default values if not self.attributes.has("level"): self.db.level = 0 if not self.attributes.has("exp"): self.db.exp = 0 if not self.attributes.has("hp"): self.db.hp = 1 if not self.attributes.has("team"): self.db.team = 0 # init equipments if not self.attributes.has("equipments"): self.db.equipments = {} if not self.attributes.has("position_names"): self.db.position_names = {} self.reset_equip_positions() if not self.attributes.has("skills"): self.db.skills = {} # set quests if not self.attributes.has("finished_quests"): self.db.finished_quests = set() if not self.attributes.has("current_quests"): self.db.current_quests = {} # set closed events if not self.attributes.has("closed_events"): self.db.closed_events = set() # skill's gcd self.skill_gcd = GAME_SETTINGS.get("global_cd") self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd") self.gcd_finish_time = 0 # loop for auto cast skills self.auto_cast_loop = None self.target = None self.reborn_time = 0 # A temporary character will be deleted after the combat finished. self.is_temp = False
def at_server_start(): """ This is called every time the server starts up, regardless of how it was shut down. """ # reset settings from muddery.utils.game_settings import GAME_SETTINGS GAME_SETTINGS.reset() # reload local strings from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER LOCALIZED_STRINGS_HANDLER.reload() # reload attributes from muddery.utils.attributes_info_handler import CHARACTER_ATTRIBUTES_INFO CHARACTER_ATTRIBUTES_INFO.reload() from muddery.utils.attributes_info_handler import EQUIPMENT_ATTRIBUTES_INFO EQUIPMENT_ATTRIBUTES_INFO.reload() from muddery.utils.attributes_info_handler import FOOD_ATTRIBUTES_INFO FOOD_ATTRIBUTES_INFO.reload() # reset default locations from muddery.utils import builder builder.reset_default_locations() # clear dialogues from muddery.utils.dialogue_handler import DIALOGUE_HANDLER DIALOGUE_HANDLER.clear() # reload equipment types from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER EQUIP_TYPE_HANDLER.reload() # localize model fields from muddery.utils.localiztion_handler import localize_model_fields localize_model_fields() # set character attribute field names CHARACTER_ATTRIBUTES_INFO.set_model_fields() EQUIPMENT_ATTRIBUTES_INFO.set_model_fields() FOOD_ATTRIBUTES_INFO.set_model_fields() # load condition descriptions from muddery.utils.desc_handler import DESC_HANDLER DESC_HANDLER.reload() # load honours from muddery.dao.honours_mapper import HONOURS_MAPPER HONOURS_MAPPER.reload()
def __init__(self, owner): """ Initialize handler. """ self.owner = owner self.skills = {} if owner: self.skills = owner.db.skills self.gcd = GAME_SETTINGS.get("global_cd") self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd") self.can_auto_cast = False self.gcd_finish_time = 0
def at_initial_setup(): """ Build up the default world and set default locations. """ try: # load world data import_local_data() print("Import local data.") # load game settings GAME_SETTINGS.reset() print("Reset game settings.") # build world builder.build_all() print("Builder build all.") # set limbo's desc limbo_obj = search.search_object("#2", exact=True) if limbo_obj: limbo_obj[0].db.desc = LIMBO_DESC limbo_obj[0].position = None print("Set limbo object.") # set default locations builder.reset_default_locations() print("Set default locations.") superuser = search.search_object("#1", exact=True) if superuser: superuser = superuser[0] # move the superuser to the start location start_location = search.search_object(settings.START_LOCATION, exact=True) if start_location: start_location = start_location[0] superuser.move_to(start_location, quiet=True) # set superuser's data superuser.set_data_key(GAME_SETTINGS.get("default_player_character_key")) superuser.set_level(1) superuser.set_nickname("superuser") print("Set supervisor.") except Exception, e: ostring = "Can't set initial data: %s" % e print(ostring) print(traceback.format_exc())
def func(self): "Show the connect screen." game_name = GAME_SETTINGS.get("game_name") connection_screen = GAME_SETTINGS.get("connection_screen") records = EQUIPMENT_POSITIONS.all() equipment_pos = [{ "key": r.key, "name": r.name, "desc": r.desc } for r in records] self.caller.msg({ "game_name": game_name, "conn_screen": connection_screen, "equipment_pos": equipment_pos, })
def continue_dialogue(self, npc, dialogue, sentence): """ Continue current dialogue. Args: npc: (optional) NPC's object. dialogue: current dialogue's key. sentence: current sentence's ordinal. Returns: None """ if GAME_SETTINGS.get("auto_resume_dialogues"): # Check current dialogue. if not self.db.current_dialogue: return if (dialogue, sentence) not in self.db.current_dialogue["sentences_all"]: # Can not find specified dialogue in current dialogues. return try: # Finish current sentence DIALOGUE_HANDLER.finish_sentence(self, npc, dialogue, sentence) except Exception, e: ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e) logger.log_tracemsg(ostring)
def save_current_dialogue(self, dialogue, npc): """ Save player's current dialogues. Args: dialogue: the current dialogue npc: NPC whom the player is talking to. Returns: None """ if not GAME_SETTINGS.get("auto_resume_dialogues"): # Can not auto resume dialogues. return if not dialogue: self.clear_current_dialogue() return # Save dialogue's id and sentence's ordinal. sentences = [(d["dialogue"], d["sentence"]) for d in dialogue] npc_key = None if npc: npc_key = npc.get_data_key() location_key = None if self.location: location_key = self.location.get_data_key() self.db.current_dialogue = {"sentences": sentences, "npc": npc_key, "location": location_key} return
def reborn(self): """ Reborn after being killed. """ # Reborn at its home. home = None if not home: default_home_key = GAME_SETTINGS.get("default_player_home_key") if default_home_key: rooms = utils.search_obj_data_key(default_home_key) if rooms: home = rooms[0] if not home: rooms = search.search_object(settings.DEFAULT_HOME) if rooms: home = rooms[0] if home: self.move_to(home, quiet=True) # Recover properties. self.recover() self.show_status() self.msg( {"msg": _("You are reborn at {C%s{n.") % self.home.get_name()})
def func(self, args, request): try: # reload system data # import_syetem_data() # reload localized strings # LOCALIZED_STRINGS_HANDLER.reload() # rebuild the world build_all() # send client settings client_settings = GAME_SETTINGS.get_client_settings() text = json.dumps({"settings": client_settings}) SESSIONS.announce_all(text) # restart the server SESSIONS.announce_all("Server restarting ...") SESSIONS.portal_restart_server() except Exception as e: message = "Can not build the world: %s" % e logger.log_tracemsg(message) raise MudderyError(ERR.build_world_error, message) return success_response("success")
def at_object_receive(self, moved_obj, source_location): """ Called after an object has been moved into this object. Args: moved_obj (Object): The object moved into this one source_location (Object): Where `moved_object` came from. """ super(MudderyRoom, self).at_object_receive(moved_obj, source_location) if not GAME_SETTINGS.get("solo_mode"): # send surrounding changes to player type = self.get_surrounding_type(moved_obj) if type: change = { type: [{ "dbref": moved_obj.dbref, "name": moved_obj.get_name() }] } self.msg_contents({"obj_moved_in": change}, exclude=moved_obj) # trigger event if moved_obj.has_account: self.event.at_character_move_in(moved_obj)
def reset_default_locations(): """ Reset default home and start location, get new positions from settings.DEFAULT_HOME_KEY and settings.START_LOCATION_KEY. If they are empty, set them to to the first room in settings.WORLD_ROOMS. """ # Set default home. default_home_key = GAME_SETTINGS.get("default_home_key") if not default_home_key: # If does not have the default_home_key, get the first room in WORLD_ROOMS. try: rooms = CM.WORLD_ROOMS.all() if rooms: default_home_key = rooms[0].key except Exception as e: ostring = "Can not find default_home_key: %s" % e print(ostring) print(traceback.print_exc()) if default_home_key: # If get default_home_key. default_home = utils.search_obj_data_key(default_home_key) if default_home: # Set default home. settings.DEFAULT_HOME = default_home[0].dbref print("settings.DEFAULT_HOME set to: %s" % settings.DEFAULT_HOME) # Set start location. start_location_key = GAME_SETTINGS.get("start_location_key") if not start_location_key: # If does not have the start_location_key, get the first room in WORLD_ROOMS try: rooms = CM.WORLD_ROOMS.all() if rooms: start_location_key = rooms[0].key except Exception as e: ostring = "Can not find start_location_key: %s" % e print(ostring) print(traceback.print_exc()) if start_location_key: # If get start_location_key. start_location = utils.search_obj_data_key(start_location_key) if start_location: settings.START_LOCATION = start_location[0].dbref print("settings.START_LOCATION set to: %s" % settings.START_LOCATION)
def create_guest_player(session): """ Creates a guest player/character for this session, if one is available. Args: session (Session): the session which will use the guest player/character. Returns: GUEST_ENABLED (boolean), player (Player): the boolean is whether guest accounts are enabled at all. the Player which was created from an available guest name. """ # check if guests are enabled. if not settings.GUEST_ENABLED: return False, None # Check IP bans. bans = ServerConfig.objects.conf("server_bans") if bans and any(tup[2].match(session.address) for tup in bans if tup[2]): # this is a banned IP! string = "{rYou have been banned and cannot continue from here." \ "\nIf you feel this ban is in error, please email an admin.{x" session.msg(string) session.sessionhandler.disconnect(session, "Good bye! Disconnecting.") return True, None try: # Find an available guest name. for playername in settings.GUEST_LIST: if not PlayerDB.objects.filter(username__iexact=playername): break playername = None if playername == None: session.msg( "All guest accounts are in use. Please try again later.") return True, None password = "******" % getrandbits(64) home = ObjectDB.objects.get_id(settings.GUEST_HOME) permissions = settings.PERMISSION_GUEST_DEFAULT typeclass = settings.BASE_CHARACTER_TYPECLASS ptypeclass = settings.BASE_GUEST_TYPECLASS new_player = _create_player(session, playername, password, permissions, ptypeclass) if new_player: _create_character(GAME_SETTINGS.get("default_player_model_key"), 1, session, new_player, typeclass, home, home, permissions, playername) except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, # we won't see any errors at all. session.msg( "An error occurred. Please e-mail an admin if the problem persists." ) logger.log_trace() finally: return True, new_player
def func(self): "Show the connect screen." self.caller.msg({"settings": CLIENT_SETTINGS.all_values()}) connection_screen = GAME_SETTINGS.get("connection_screen") if not connection_screen: connection_screen = "No connection screen found. Please contact an admin." self.caller.msg({"msg": connection_screen})
def at_initial_setup(): """ Build up the default world and set default locations. """ try: # load world data importer.import_local_all() # load game settings GAME_SETTINGS.reset() # reload skill modules MudderySkill.load_skill_modules() # build world builder.build_all() # set limbo's desc limbo_obj = search.search_object("#2", exact=True) if limbo_obj: limbo_obj[0].db.desc = LIMBO_DESC limbo_obj[0].position = None # set default locations builder.reset_default_locations() superuser = search.search_object("#1", exact=True) if superuser: superuser = superuser[0] # move the superuser to the start location start_location = search.search_object(settings.START_LOCATION, exact=True) if start_location: start_location = start_location[0] superuser.move_to(start_location, quiet=True) # set superuser's data superuser.set_data_key(GAME_SETTINGS.get("default_player_model_key")) superuser.set_level(1) superuser.set_nickname("superuser") except Exception, e: ostring = "Can't build world: %s" % e print(ostring) print(traceback.format_exc())
def get_available_commands(self, caller): """ This returns a list of available commands. """ commands = [] if GAME_SETTINGS.get("can_give_up_quests"): commands.append({"name": _("Give Up"), "cmd": "giveup_quest", "args": self.get_data_key()}) return commands
def get_available_commands(self, caller): """ This returns a list of available commands. """ commands = [] if GAME_SETTINGS.get("can_give_up_quests"): commands.append({"name": LS("Give Up"), "cmd": "giveup_quest", "args": self.get_data_key()}) return commands
def after_data_loaded(self): """ Init the character. """ super(MudderyCharacter, self).after_data_loaded() # get level if not self.db.level: self.db.level = getattr(self.system, "level", 1) # friendly self.friendly = getattr(self.system, "friendly", 0) # skill's ai ai_choose_skill_class = class_from_module(settings.AI_CHOOSE_SKILL) self.ai_choose_skill = ai_choose_skill_class() # skill's gcd self.skill_gcd = GAME_SETTINGS.get("global_cd") self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd") self.gcd_finish_time = 0 # loop for auto cast skills self.auto_cast_loop = None # clear target self.target = None # set reborn time self.reborn_time = getattr(self.system, "reborn_time", 0) # A temporary character will be deleted after the combat finished. self.is_temp = False # update equipment positions self.reset_equip_positions() # load default skills self.load_default_skills() # load default objects self.load_default_objects() # refresh the character's properties. self.refresh_properties()
def after_data_loaded(self): """ Init the character. """ super(MudderyCharacter, self).after_data_loaded() # get level if not self.db.level: self.db.level = getattr(self.dfield, "level", 1) # friendly self.friendly = getattr(self.dfield, "friendly", 0) # skill's ai ai_choose_skill_class = class_from_module(settings.AI_CHOOSE_SKILL) self.ai_choose_skill = ai_choose_skill_class() # skill's gcd self.skill_gcd = GAME_SETTINGS.get("global_cd") self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd") self.gcd_finish_time = 0 # loop for auto cast skills self.auto_cast_loop = None # clear target self.target = None # set reborn time self.reborn_time = getattr(self.dfield, "reborn_time", 0) # A temporary character will be deleted after the combat finished. self.is_temp = False # update equipment positions self.reset_equip_positions() # load default skills self.load_default_skills() # load default objects self.load_default_objects() # refresh data self.refresh_data()
def __init__(self, owner): """ Initialize handler. """ self.owner = owner # TICKER_HANDLER needs pk. self.pk = "SKILL" self.skills = {} if owner: self.skills = owner.db.skills self.gcd = GAME_SETTINGS.get("global_cd") self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd") self.can_auto_cast = False self.skill_target = None self.gcd_finish_time = 0
def at_server_start(): """ This is called every time the server starts up, regardless of how it was shut down. """ # reset settings GAME_SETTINGS.reset() # reload keys OBJECT_KEY_HANDLER.reload() # reload attributes CHARACTER_ATTRIBUTES_INFO.reload() EQUIPMENT_ATTRIBUTES_INFO.reload() FOOD_ATTRIBUTES_INFO.reload() # reset default locations builder.reset_default_locations() # clear dialogues DIALOGUE_HANDLER.clear() # clear quest dependencies QUEST_DEP_HANDLER.clear() # reload equipment types EQUIP_TYPE_HANDLER.reload() # reload local strings LOCALIZED_STRINGS_HANDLER.reload() # localize model fields localize_model_fields() # set character attribute field names CHARACTER_ATTRIBUTES_INFO.set_model_fields() EQUIPMENT_ATTRIBUTES_INFO.set_model_fields() FOOD_ATTRIBUTES_INFO.set_model_fields() # load condition descriptions DESC_HANDLER.reload() # load honours HONOURS_MAPPER.reload()
def create_guest_player(session): """ Creates a guest player/character for this session, if one is available. Args: session (Session): the session which will use the guest player/character. Returns: GUEST_ENABLED (boolean), player (Player): the boolean is whether guest accounts are enabled at all. the Player which was created from an available guest name. """ # check if guests are enabled. if not settings.GUEST_ENABLED: return False, None # Check IP bans. bans = ServerConfig.objects.conf("server_bans") if bans and any(tup[2].match(session.address) for tup in bans if tup[2]): # this is a banned IP! string = "{rYou have been banned and cannot continue from here." \ "\nIf you feel this ban is in error, please email an admin.{x" session.msg(string) session.sessionhandler.disconnect(session, "Good bye! Disconnecting.") return True, None try: # Find an available guest name. for playername in settings.GUEST_LIST: if not PlayerDB.objects.filter(username__iexact=playername): break playername = None if playername == None: session.msg("All guest accounts are in use. Please try again later.") return True, None password = "******" % getrandbits(64) home = ObjectDB.objects.get_id(settings.GUEST_HOME) permissions = settings.PERMISSION_GUEST_DEFAULT typeclass = settings.BASE_CHARACTER_TYPECLASS ptypeclass = settings.BASE_GUEST_TYPECLASS new_player = _create_player(session, playername, password, permissions, ptypeclass) if new_player: _create_character(GAME_SETTINGS.get("default_player_character_key"), 1, session, new_player, typeclass, home, home, permissions, playername) except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, # we won't see any errors at all. session.msg("An error occurred. Please e-mail an admin if the problem persists.") logger.log_trace() finally: return True, new_player
def get_surroundings(self, caller): """ This is a convenient hook for a 'look' command to call. """ # get name, description, commands and all objects in it info = { "exits": [], "npcs": [], "things": [], "players": [], "offlines": [] } visible = (cont for cont in self.contents if cont != caller and cont.access(caller, "view")) if GAME_SETTINGS.get("solo_mode"): visible = (cont for cont in visible if not cont.has_player) for cont in visible: # only show objects that match the condition condition = getattr(cont.dfield, "condition", None) if condition: if not STATEMENT_HANDLER.match_condition( condition, caller, self): continue type = self.get_surrounding_type(cont) if type: appearance = {} if type == "npcs": # add quest status if hasattr(cont, "have_quest"): provide_quest, complete_quest = cont.have_quest(caller) appearance["provide_quest"] = provide_quest appearance["complete_quest"] = complete_quest elif type == "exits": # get exits destination if cont.destination: dest = { "name": cont.destination.get_name(), "position": cont.destination.position } appearance["destination"] = dest elif type == "offlines": continue appearance["dbref"] = cont.dbref appearance["name"] = cont.get_name() appearance["key"] = cont.get_data_key() info[type].append(appearance) return info
def load_data(self): """ Init the character. """ super(MudderyMonster, self).load_data() # set home self.home = self.location self.reborn_cd = GAME_SETTINGS.get("npc_reborn_cd")
def after_data_loaded(self): """ """ super(MudderyPlayerCharacter, self).after_data_loaded() self.solo_mode = GAME_SETTINGS.get("solo_mode") self.available_channels = {} # refresh data self.refresh_data()
def load_data(self): """ Init the character. """ super(MudderyNPC, self).load_data() # set home self.home = self.location # load dialogues. self.load_dialogues() self.reborn_cd = GAME_SETTINGS.get("npc_reborn_cd")
def get_data_key(self, default=""): """ Get data's key. Args: default: (string) default value if can not find the data key. """ key = GAME_SETTINGS.get("default_player_character_key") if not key: key = self.attributes.get(key="key", category=settings.DATA_KEY_CATEGORY, strattr=True) if not key: key = default return key
def set_owner(self, owner): """ Set the owner of the skill. Args: owner: (object) skill's owner Returns: None """ self.db.owner = owner if not self.passive: # Set skill cd. Add gcd to new the skill. gcd = GAME_SETTINGS.get("global_cd") if gcd > 0: self.db.cd_finish_time = time.time() + gcd
def at_object_leave(self, moved_obj, target_location, **kwargs): """ Called when an object leaves this object in any fashion. Args: moved_obj (Object): The object leaving target_location (Object): Where `moved_obj` is going. """ super(MudderyRoom, self).at_object_leave(moved_obj, target_location) if not GAME_SETTINGS.get("solo_mode"): # send surrounding changes to player type = self.get_surrounding_type(moved_obj) if type: change = {type: [{"dbref": moved_obj.dbref, "name": moved_obj.get_name()}]} self.msg_contents({"obj_moved_out": change}, exclude=moved_obj)
def at_object_receive(self, moved_obj, source_location, **kwargs): """ Called after an object has been moved into this object. Args: moved_obj (Object): The object moved into this one source_location (Object): Where `moved_object` came from. """ super(MudderyRoom, self).at_object_receive(moved_obj, source_location, **kwargs) if not GAME_SETTINGS.get("solo_mode"): # send surrounding changes to player type = self.get_surrounding_type(moved_obj) if type: change = {type: [{"dbref": moved_obj.dbref, "name": moved_obj.get_name()}]} self.msg_contents({"obj_moved_in": change}, exclude=moved_obj)
def reset_default_locations(): """ Reset default home and start location, get new positions from settings.DEFAULT_HOME_KEY and settings.START_LOCATION_KEY. If they are empty, set them to to the first room in settings.WORLD_ROOMS. """ # Set default home. default_home_key = GAME_SETTINGS.get("default_home_key") if not default_home_key: # If does not have the default_home_key, get the first room in WORLD_ROOMS. try: rooms = DATA_SETS.world_rooms.objects.all() if rooms: default_home_key = rooms[0].key except Exception, e: ostring = "Can not find default_home_key: %s" % e print(ostring) print(traceback.print_exc())
def get_surroundings(self, caller): """ This is a convenient hook for a 'look' command to call. """ # get name, description, commands and all objects in it info = {"exits": [], "npcs": [], "things": [], "players": [], "offlines": []} visible = (cont for cont in self.contents if cont != caller and cont.access(caller, "view")) if GAME_SETTINGS.get("solo_mode"): visible = (cont for cont in visible if not cont.has_account) for cont in visible: # only show objects that match the condition if not cont.is_visible(caller): continue type = self.get_surrounding_type(cont) if type: appearance = {} if type == "npcs": # add quest status if hasattr(cont, "have_quest"): provide_quest, complete_quest = cont.have_quest(caller) appearance["provide_quest"] = provide_quest appearance["complete_quest"] = complete_quest elif type == "offlines": continue appearance["dbref"] = cont.dbref appearance["name"] = cont.get_name() appearance["key"] = cont.get_data_key() info[type].append(appearance) return info
def at_post_unpuppet(self, player, session=None, **kwargs): """ We stove away the character when the player goes ooc/logs off, otherwise the character object will remain in the room also after the player logged off ("headless", so to say). Args: player (Player): The player object that just disconnected from this object. session (Session): Session controlling the connection that just disconnected. """ if not self.sessions.count(): # only remove this char from grid if no sessions control it anymore. if self.location: # have to check, in case of multiple connections closing if not GAME_SETTINGS.get("solo_mode"): # Notify other players in this location. self.location.msg_contents("%s has left the game." % self.name, exclude=[self]) # Save last location. self.db.prelogout_location = self.location self.location = None
def resume_last_dialogue(self): """ Restore player's dialogues when he return to game. Returns: None """ if not GAME_SETTINGS.get("auto_resume_dialogues"): # Can not auto resume dialogues. return if not self.db.current_dialogue: return current = self.db.current_dialogue if not current["sentences_begin"]: return # Check dialogue's location if self.location.get_data_key() != current["location"]: # If player's location has changed, return. return # Check npc. npc_talking = None if current["npc"]: npc_list = utils.search_obj_data_key(current["npc"]) npc_in_location = [npc for npc in npc_list if npc.location == self.location] if not npc_in_location: # If the NPC has left it's location, return. return npc_talking = npc_in_location[0] sentences_list = [DIALOGUE_HANDLER.get_sentence(s[0], s[1]) for s in current["sentences_begin"]] output = DIALOGUE_HANDLER.create_output_sentences(sentences_list, self, npc_talking) self.msg({"dialogues_list": [output]}) return
def func(self, args, request): try: # reload system data # import_syetem_data() # reload localized strings # LOCALIZED_STRINGS_HANDLER.reload() # rebuild the world build_all() # send client settings client_settings = GAME_SETTINGS.get_client_settings() text = json.dumps({"settings": client_settings}) SESSIONS.announce_all(text) # restart the server SESSIONS.announce_all("Server restarting ...") SESSIONS.portal_restart_server() except Exception, e: message = "Can not build the world: %s" % e logger.log_tracemsg(message) raise MudderyError(ERR.build_world_error, message)
def apply_changes(request): """ Apply the game world's data. """ try: # reload localized strings LOCALIZED_STRINGS_HANDLER.reload() # rebuild the world build_all() # send client settings client_settings = GAME_SETTINGS.get_client_settings() text = json.dumps({"settings": client_settings}) SESSIONS.announce_all(text) # restart the server SESSIONS.announce_all(" Server restarting ...") SESSIONS.server.shutdown(mode='reload') except Exception, e: message = "Can't build world: %s" % e logger.log_tracemsg(message) return render(request, 'fail.html', {"message": message})
def say(self, channel, message): """ Say something in the channel. Args: channel: (string) channel's key. message: (string) message to say. Returns: None """ if not (channel in self.available_channels): self.msg({"alert":_("You can not say here.")}) return # Build the string to emit to neighbors. emit_string = "%s: %s" % (self.get_name(), message) if not channel: # Say in the room. solo_mode = GAME_SETTINGS.get("solo_mode") if solo_mode: self.msg(emit_string) else: self.location.msg_contents(emit_string) else: channels = ChannelDB.objects.filter(db_key=channel) if not channels: self.msg(_("You can not talk in this channel.")) return channel_obj = channels[0] if not channel_obj.access(self, channel, "send"): self.msg(_("You can not access this channel.")) return channel_obj.msg(emit_string)
def save_current_dialogue(self, sentences_list, npc): """ Save player's current dialogues. Args: sentences_list: the list of current dialogues npc: NPC whom the player is talking to. Returns: None """ if not GAME_SETTINGS.get("auto_resume_dialogues"): # Can not auto resume dialogues. return if not sentences_list: self.clear_current_dialogue() return # Save dialogue's id and sentence's ordinal. sentences_begin = [(s["dialogue"], s["sentence"]) for s in sentences_list[0]] sentences_all = [(s["dialogue"], s["sentence"]) for s_list in sentences_list for s in s_list] npc_key = None if npc: npc_key = npc.get_data_key() location_key = None if self.location: location_key = self.location.get_data_key() self.db.current_dialogue = {"sentences_begin": sentences_begin, "sentences_all": sentences_all, "npc": npc_key, "location": location_key} return
def give_up(self, quest_key): """ Accept a quest. Args: quest_key: (string) quest's key Returns: None """ if not GAME_SETTINGS.get("can_give_up_quests"): logger.log_tracemsg("Can not give up quests.") raise MudderyError(_("Can not give up this quest.")) if quest_key not in self.current_quests: raise MudderyError(_("Can not find this quest.")) self.current_quests[quest_key].delete() del(self.current_quests[quest_key]) if quest_key in self.finished_quests: self.finished_quests.remove(quest_key) self.show_quests()
def func(self): "Do checks, create account and login." session = self.caller try: playername = self.args["playername"] nickname = self.args["nickname"] password = self.args["password"] except Exception: string = 'Syntax error!' string += '\nUsage:' string += '\n {"cmd":"create_connect",' string += '\n "args":{' string += '\n "playername":<playername>,' string += '\n "nickname":<nickname>,' string += '\n "password":<password>' string += '\n }' logger.log_errmsg(string) self.caller.msg({"alert":string}) return # sanity checks if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): # this echoes the restrictions made by django's auth # module (except not allowing spaces, for convenience of # logging in). string = "\n\r Playername can max be 30 characters or fewer. Letters, spaces, digits and @/./+/-/_ only." session.msg({"alert":string}) return # strip excessive spaces in playername playername = re.sub(r"\s+", " ", playername).strip() if PlayerDB.objects.filter(username__iexact=playername): # player already exists (we also ignore capitalization here) session.msg({"alert":_("Sorry, there is already a player with the name '%s'.") % playername}) return # Reserve playernames found in GUEST_LIST if settings.GUEST_LIST and playername.lower() in (guest.lower() for guest in settings.GUEST_LIST): string = "\n\r That name is reserved. Please choose another Playername." session.msg({"alert":string}) return # sanity checks if not (0 < len(nickname) <= 30): # Nickname's length string = "\n\r Nickname can max be 30 characters or fewer." session.msg({"alert":string}) return # strip excessive spaces in playername nickname = re.sub(r"\s+", " ", nickname).strip() if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)): string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." \ "\nFor best security, make it longer than 8 characters. You can also use a phrase of" \ "\nmany words if you enclose the password in quotes." session.msg({"alert":string}) return # Check IP and/or name bans bans = ServerConfig.objects.conf("server_bans") if bans and (any(tup[0]==playername.lower() for tup in bans) or any(tup[2].match(session.address) for tup in bans if tup[2])): # this is a banned IP or name! string = "{rYou have been banned and cannot continue from here." \ "\nIf you feel this ban is in error, please email an admin.{x" session.msg({"alert":string}) session.execute_cmd('{"cmd":"quit","args":""}') return # everything's ok. Create the new player account. try: permissions = settings.PERMISSION_PLAYER_DEFAULT typeclass = settings.BASE_CHARACTER_TYPECLASS new_player = _create_player(session, playername, password, permissions) if new_player: if MULTISESSION_MODE < 2: default_home = settings.DEFAULT_HOME try: default_home_key = GAME_SETTINGS.get("default_player_home_key") if default_home_key: rooms = search_obj_data_key(default_home_key) default_home = rooms[0] except: pass start_location = default_home try: start_location_key = GAME_SETTINGS.get("start_location_key") if start_location_key: rooms = search_obj_data_key(start_location_key) start_location = rooms[0] except: pass _create_character(GAME_SETTINGS.get("default_player_character_key"), 1, session, new_player, typeclass, start_location, default_home, permissions, nickname) # tell the caller everything went well. # string = "A new account '%s' was created. Welcome!" # if " " in playername: # string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'." # else: # string += "\n\nYou can now log with the command 'connect %s <your password>'." # session.msg(string % (playername, playername)) # actually do the login. This will call all other hooks: # session.at_login() # player.at_init() # always called when object is loaded from disk # player.at_pre_login() # player.at_first_login() # only once # player.at_post_login(sessid=sessid) session.msg({"login":{"name": playername, "dbref": new_player.dbref}}) session.sessionhandler.login(session, new_player) except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, # we won't see any errors at all. string = "%s\nThis is a bug. Please e-mail an admin if the problem persists." session.msg({"alert":string % (traceback.format_exc())}) logger.log_tracemsg()
default_home_key = rooms[0].key except Exception, e: ostring = "Can not find default_home_key: %s" % e print(ostring) print(traceback.print_exc()) if default_home_key: # If get default_home_key. default_home = utils.search_obj_data_key(default_home_key) if default_home: # Set default home. settings.DEFAULT_HOME = default_home[0].dbref print("settings.DEFAULT_HOME set to: %s" % settings.DEFAULT_HOME) # Set start location. start_location_key = GAME_SETTINGS.get("start_location_key") if not start_location_key: # If does not have the start_location_key, get the first room in WORLD_ROOMS try: rooms = DATA_SETS.world_rooms.objects.all() if rooms: start_location_key = rooms[0].key except Exception, e: ostring = "Can not find start_location_key: %s" % e print(ostring) print(traceback.print_exc()) if start_location_key: # If get start_location_key. start_location = utils.search_obj_data_key(start_location_key) if start_location:
def func(self): "Show the connect screen." connection_screen = GAME_SETTINGS.get("connection_screen") if not connection_screen: connection_screen = "No connection screen found. Please contact an admin." self.caller.msg({"msg":connection_screen})
def load_data(self): """ """ super(MudderyPlayerCharacter, self).load_data() self.reborn_cd = GAME_SETTINGS.get("player_reborn_cd") self.solo_mode = GAME_SETTINGS.get("solo_mode")
def create_character(new_player, nickname, permissions=None, character_key=None, level=1, typeclass=None, location=None, home=None): """ Helper function, creates a character based on a player's name. """ if not character_key: character_key = GAME_SETTINGS.get("default_player_character_key") if not typeclass: typeclass = settings.BASE_PLAYER_CHARACTER_TYPECLASS if not permissions: permissions = settings.PERMISSION_ACCOUNT_DEFAULT if not home: home = settings.DEFAULT_HOME try: default_home_key = GAME_SETTINGS.get("default_player_home_key") if default_home_key: rooms = utils.search_obj_data_key(default_home_key) home = rooms[0] except: pass if not location: location = home try: start_location_key = GAME_SETTINGS.get("start_location_key") if start_location_key: rooms = utils.search_obj_data_key(start_location_key) location = rooms[0] except: pass new_character = create.create_object(typeclass, key=new_player.key, location=location, home=home, permissions=permissions) # set character info new_character.set_data_key(character_key) new_character.set_level(level) # set playable character list new_player.db._playable_characters.append(new_character) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # Add nickname if not nickname: nickname = character_key new_character.set_nickname(nickname) # We need to set this to have @ic auto-connect to this character new_player.db._last_puppet = new_character return new_character
default_home_key = rooms[0].key except Exception, e: ostring = "Can not find default_home_key: %s" % e print(ostring) print(traceback.print_exc()) if default_home_key: # If get default_home_key. default_home = utils.search_obj_data_key(default_home_key) if default_home: # Set default home. settings.DEFAULT_HOME = default_home[0].dbref print("settings.DEFAULT_HOME set to: %s" % settings.DEFAULT_HOME) # Set player's default home. default_player_home_key = GAME_SETTINGS.get("default_player_home_key") if not default_player_home_key: # If does not have the default_player_home_key, set to the DEFAULT_HOME settings.DEFAULT_PLAYER_HOME = settings.DEFAULT_HOME else: default_player_home = utils.search_obj_data_key(default_player_home_key) if default_player_home: # Set player's default home. settings.DEFAULT_PLAYER_HOME = default_player_home[0].dbref print("settings.DEFAULT_PLAYER_HOME set to: %s" % settings.DEFAULT_PLAYER_HOME) # Set start location. start_location_key = GAME_SETTINGS.get("start_location_key") if not start_location_key: # If does not have the start_location_key, get the first room in WORLD_ROOMS try: