<s> from lampost . comm . channel import Channel <EOL> from lampost . context . config import m_configured <EOL> from lampost . context . resource import m_requires <EOL> from lampost . env . room import Room , safe_room <EOL> from lampost . gameops . action import ActionError <EOL> from lampost . mud . action import mud_action , imm_actions <EOL> m_requires ( __name__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> m_configured ( __name__ , '<STR_LIT>' ) <EOL> _init_priority = <NUM_LIT> <EOL> def _post_init ( ) : <EOL> global shout_channel , imm_channel <EOL> shout_channel = Channel ( '<STR_LIT>' , general = True ) <EOL> imm_channel = Channel ( '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , _player_create ) <EOL> register ( '<STR_LIT>' , _baptise , priority = - <NUM_LIT:100> ) <EOL> register ( '<STR_LIT>' , _imm_baptise , priority = - <NUM_LIT:100> ) <EOL> register ( '<STR_LIT>' , _start_env ) <EOL> def _player_create ( player , user ) : <EOL> if len ( user . player_ids ) == <NUM_LIT:1> and not player . imm_level : <EOL> player . imm_level = perm_level ( '<STR_LIT>' ) <EOL> update_immortal_list ( player ) <EOL> dispatch ( '<STR_LIT>' , player , <NUM_LIT:0> ) <EOL> message_service . add_message ( '<STR_LIT>' , "<STR_LIT>" , player . dbo_id ) <EOL> player . room_id = default_start_room <EOL> def _baptise ( player ) : <EOL> player . baptise ( ) <EOL> shout_channel . add_sub ( player ) <EOL> if player . imm_level : <EOL> dispatch ( "<STR_LIT>" , player ) <EOL> player . change_env ( _start_env ( player ) ) <EOL> def _imm_baptise ( player ) : <EOL> player . can_die = False <EOL> player . immortal = True <EOL> imm_channel . add_sub ( player ) <EOL> for cmd in imm_actions : <EOL> if player . imm_level >= perm_level ( cmd . imm_level ) : <EOL> player . enhance_soul ( cmd ) <EOL> else : <EOL> player . diminish_soul ( cmd ) <EOL> def _start_env ( player ) : <EOL> instance = instance_manager . get ( player . instance_id ) <EOL> instance_room = load_object ( player . instance_room_id , Room , silent = True ) <EOL> player_room = load_object ( player . room_id , Room , silent = True ) <EOL> if instance and instance_room : <EOL> return instance . get_room ( player . instance_room_id ) <EOL> if instance_room and not player_room : <EOL> instance = instance_manager . next_instance ( ) <EOL> return instance . get_room ( player . instance_room_id ) <EOL> del player . instance_id <EOL> del player . instance_room_id <EOL> if player_room : <EOL> return player_room <EOL> default_start = load_object ( default_start_room , Room ) <EOL> if default_start : <EOL> return default_start <EOL> error ( "<STR_LIT>" , stack_info = True ) <EOL> del player . room_id <EOL> save_object ( player ) <EOL> return safe_room <EOL> @ mud_action ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def quit_action ( source , ** _ ) : <EOL> source . check_logout ( ) <EOL> dispatch ( '<STR_LIT>' , source . session ) <EOL> @ mud_action ( ( "<STR_LIT>" , "<STR_LIT:l>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def look ( target_method , ** kwargs ) : <EOL> return target_method ( ** kwargs ) <EOL> @ mud_action ( '<STR_LIT>' ) <EOL> def friends ( source , ** _ ) : <EOL> friend_list = friend_service . friend_list ( source . dbo_id ) <EOL> return "<STR_LIT>" . format ( friend_list ) if friend_list else "<STR_LIT>" <EOL> @ mud_action ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def friend ( source , target , ** _ ) : <EOL> if source == target or friend_service . is_friend ( source . dbo_id , target . dbo_id ) : <EOL> return "<STR_LIT>" . format ( target . name ) <EOL> try : <EOL> friend_service . friend_request ( source , target ) <EOL> except ClientError as exp : <EOL> return str ( exp ) <EOL> return "<STR_LIT>" <EOL> @ mud_action ( '<STR_LIT>' ) <EOL> def unfriend ( source , args , ** _ ) : <EOL> if not args or len ( args ) > <NUM_LIT:1> : <EOL> raise ActionError ( "<STR_LIT>" ) <EOL> unfriend_id = user_manager . name_to_id ( args [ <NUM_LIT:0> ] ) <EOL> friend_name = user_manager . id_to_name ( unfriend_id ) <EOL> if friend_service . is_friend ( source . dbo_id , unfriend_id ) : <EOL> friend_service . del_friend ( source . dbo_id , unfriend_id ) <EOL> message_service . add_message ( '<STR_LIT>' , "<STR_LIT>" . format ( friend_name ) , source . dbo_id ) <EOL> message_service . add_message ( '<STR_LIT>' , "<STR_LIT>" . format ( source . name ) , unfriend_id ) <EOL> else : <EOL> raise ActionError ( "<STR_LIT>" . format ( args [ <NUM_LIT:0> ] ) ) <EOL> @ mud_action ( '<STR_LIT:message>' ) <EOL> def message ( source , args , command , ** _ ) : <EOL> if not args : <EOL> raise ActionError ( "<STR_LIT>" ) <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> raise ActionError ( "<STR_LIT>" ) <EOL> target_id = user_manager . name_to_id ( args [ <NUM_LIT:0> ] ) <EOL> if not user_manager . player_exists ( target_id ) : <EOL> raise ActionError ( "<STR_LIT>" . format ( args [ <NUM_LIT:0> ] ) ) <EOL> message_service . add_message ( '<STR_LIT>' , command . partition ( args [ <NUM_LIT:0> ] ) [ <NUM_LIT:2> ] [ <NUM_LIT:1> : ] , target_id , source . dbo_id ) <EOL> return "<STR_LIT>" <EOL> @ mud_action ( '<STR_LIT>' ) <EOL> def block ( source , args , ** _ ) : <EOL> if not args or len ( args ) > <NUM_LIT:1> : <EOL> raise ActionError ( "<STR_LIT>" ) <EOL> block_id = user_manager . name_to_id ( args [ <NUM_LIT:0> ] ) <EOL> block_name = user_manager . id_to_name ( block_id ) <EOL> if not user_manager . player_exists ( block_id ) : <EOL> raise ActionError ( "<STR_LIT>" . format ( block_name ) ) <EOL> if message_service . is_blocked ( source , block_id ) : <EOL> return "<STR_LIT>" . format ( block_name ) <EOL> message_service . block_messages ( source . dbo_id , block_id ) <EOL> return "<STR_LIT>" . format ( block_name ) <EOL> @ mud_action ( '<STR_LIT>' ) <EOL> def unblock ( source , args , ** _ ) : <EOL> if not args or len ( args ) > <NUM_LIT:1> : <EOL> raise ActionError ( "<STR_LIT>" ) <EOL> block_id = user_manager . name_to_id ( args [ <NUM_LIT:0> ] ) <EOL> if message_service . is_blocked ( source . dbo_id , block_id ) : <EOL> message_service . unblock_messages ( source . dbo_id , block_id ) <EOL> return "<STR_LIT>" . format ( block_id ) <EOL> return "<STR_LIT>" . format ( block_id ) <EOL> @ mud_action ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def follow ( source , target , target_method , ** _ ) : <EOL> if hasattr ( source , '<STR_LIT>' ) : <EOL> return "<STR_LIT>" . format ( source . following . name ) <EOL> target_method ( source ) <EOL> source . following = target <EOL> @ mud_action ( '<STR_LIT>' ) <EOL> def unfollow ( source , args , ** _ ) : <EOL> if not hasattr ( source , '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> if args and args [ <NUM_LIT:0> ] . lower ( ) != source . following . name . lower ( ) : <EOL> return "<STR_LIT>" . format ( args [ <NUM_LIT:0> ] ) <EOL> source . unfollow ( ) <EOL> @ mud_action ( '<STR_LIT>' ) <EOL> def abandon ( source , ** _ ) : <EOL> if source . dead : <EOL> source . resurrect ( ) <EOL> else : <EOL> source . display_line ( "<STR_LIT>" ) </s>
