def execute(self, room, client, raw_command_string): command_match = command_pattern.match(raw_command_string) if command_match is None: raise GenericError("Invalid command input.") command_string = command_match.group('command_string') arg_string = command_match.group('arg_string') or "" if command_string is None: raise GenericError("Invalid command input.") command_handler = self._command_finder.find(room, client, command_string) if command_handler is None: raise GenericError("Unknown command.") execute_functionality = command_handler.functionality if not client.allowed(execute_functionality): raise InsufficientPermissions(execute_functionality.denied_message) try: args = shlex.split(arg_string) except ValueError as e: raise GenericError("Invalid input: {error}", error=e.message) d = defer.maybeDeferred(command_handler.execute, self._spyd_server, room, client, command_string, args, arg_string) d.addErrback(client.handle_exception)
def execute(cls, spyd_server, room, client, command_string, arguments, raw_args): if len(arguments) < 1: raise GenericError("Please specify a room name.") room_name = filtertext(arguments[0], True, MAXROOMLEN) target_room = room.manager.get_room(room_name, False) if target_room is not None: raise GenericError( "Room {room#room} already exists, use {action#command} to enter it.", room=target_room.name, command="room") if duel_room_pattern.match(room_name): raise GenericError( "Room {room#room_name} cannot be created for you because room names with the pattern '#x#' are reserved for 1v1 games.", room_name=room_name) room_factory = room.manager.room_factory target_room = room_factory.build_room(room_name, 'temporary') target_room.temporary = True target_room.masters.add(client) room.manager.client_change_room(client, target_room)
def handle(room, client, mastermode): # allowed_set_mastermode = client.allowed(set_mastermode_functionality) or (room.temporary and client.allowed(temporary_set_mastermode_functionality)) # if not allowed_set_mastermode: # raise InsufficientPermissions('Insufficient permissions to change mastermode.') if mastermode == mastermodes.MM_PRIVATE: raise GenericError("Mastermode private not allowed") if mastermode < mastermodes.MM_OPEN or mastermode > mastermodes.MM_PRIVATE: raise GenericError("Mastermode out of allowed range.") room.set_mastermode(mastermode)
def execute(cls, spyd_server, room, client, command_string, arguments, raw_args): try: cn, mode_name, map_name = parse_arguments(raw_args) if mode_name is not None: valid_mode_names = list(gamemodes.keys()) mode_name_match = match_fuzzy(str(mode_name), valid_mode_names) if mode_name_match is None: raise GenericError( 'Could not resolve mode name {value#mode_name} to valid mode. Please try again.', mode_name=mode_name) mode_name = mode_name_match if map_name is not None: map_name = yield resolve_map_name(room, map_name) duel_command_msg = duel_command.format(client=client) challenge_details = get_challenge_details(mode_name, map_name) if cn is not None: target = room.get_client(int(cn)) if target is client: raise GenericError("You can't duel yourself.") existing_challenge = get_existing_challenge(target, client) if existing_challenge is not None: begin_duel(room, client, target, existing_challenge) else: save_specific_challenge(client, target, mode_name, map_name) target.send_server_message( info(cn_chall_msg, client=client, challenge_details=challenge_details, duel_command=duel_command_msg)) client.send_server_message(info(chall_sent_msg)) else: save_general_challenge(client, mode_name, map_name) room.server_message(info(looking_msg, client=client, challenge_details=challenge_details, duel_command=duel_command_msg), exclude=(client, )) client.send_server_message(info(chall_sent_msg)) except: traceback.print_exc()
def client_change_room(client, target_room, announce_follow=True): player = client.get_player() try: room_entry_context = target_room.get_entry_context(client, player) except RoomEntryFailure as e: raise GenericError(e.message) if announce_follow: client.room._broadcaster.server_message(info( "{name#client} is leaving to join {room#room}. Use {action#follow} to go there too.", client=client, room=target_room, follow="follow"), exclude=[client]) old_room = client.room old_room.client_leave(client) old_room.last_destination_room = target_room.name client.room = target_room target_room.client_enter(room_entry_context)
def execute(cls, spyd_server, room, client, command_string, arguments, raw_args): if len(arguments) < 1: raise GenericError("Please specify a room name.") room_name = arguments[0] target_room = room.manager.get_room(room_name, True) if target_room is None: raise GenericError( "Could not resolve {value#room_name} to a room. Perhaps create it with {action#room_create}", room_name=room_name, room_create='room_create') room.manager.client_change_room(client, target_room)
def execute(cls, spyd_server, room, client, command_string, arguments, raw_args): room_name = room.last_destination_room if room_name is None: raise GenericError( "No players have left this room for another recently. Perhaps join another existing room with {action#room}.", room='room') target_room = room.manager.get_room(room_name, True) if target_room is None: raise GenericError( "Could not join {value#room_name}. Room no longer exists. Perhaps create it with {action#room_create}", room_name=room_name, room_create='room_create') room.manager.client_change_room(client, target_room)
def parse_arguments(raw_args): match = form1.search(raw_args) if match is None: match = form2.search(raw_args) if match is None: raise GenericError("No match.") args = match.groupdict() cn = args.get('cn', None) mode_name = args.get('mode_name', None) map_name = args.get('map_name', None) return cn, mode_name, map_name
def execute(cls, spyd_server, room, client, command_string, arguments, raw_args): player_name = arguments[0] if arguments else '' players = dict( map(lambda player: (player.name, player.client), room.players)) if not player_name: raise UsageError("You must provide a player") if player_name not in players.keys(): raise GenericError('The player doesn\'t exist') room.handle_client_event('give_master', client, players[player_name])
def resolve_map_name(room, map_name): valid_map_names = yield room.get_map_names() if not isinstance(map_name, str): map_name = str(map_name, 'utf_8') map_name_match = match_fuzzy(map_name, valid_map_names) if map_name_match is None: raise GenericError( 'Could not resolve map name {value#map_name} to valid map. Please try again.', map_name=map_name) defer.returnValue(map_name_match)
def change_map_mode(self, map_name, mode_name): if mode_name not in gamemodes: raise GenericError("Unsupported game mode.") self._map_name = map_name map_meta_data = yield self._map_meta_data_accessor.get_map_data( self._map_name) map_meta_data = map_meta_data or {} self._gamemode = gamemodes[mode_name](room=self.room, map_meta_data=map_meta_data) self._initialized = True self._new_map_mode_initialize() defer.returnValue(map_meta_data)
def execute(cls, spyd_server, room, client, command_string, arguments, raw_args): if len(arguments): if room.temporary: if not client.allowed(set_temporary_room_timeleft): raise InsufficientPermissions( set_temporary_room_timeleft.denied_message) else: if not client.allowed(set_permanent_room_timeleft): raise InsufficientPermissions( set_permanent_room_timeleft.denied_message) try: modifier, value = timestring.parseTimeString(raw_args) if modifier == '+': new_timeleft = min(MAXTIMELEFT, max(0, room.timeleft + value)) elif modifier == '-': new_timeleft = min(MAXTIMELEFT, max(0, room.timeleft - value)) elif modifier == '=': new_timeleft = min(MAXTIMELEFT, max(0, value)) timeleft = prettytime.createDurationString(new_timeleft) room._broadcaster.server_message( info(timeleft_set_str, client=client, timeleft=timeleft)) room.timeleft = new_timeleft except timestring.MalformedTimeString: raise GenericError("Invalid time string specified.") else: timeleft = prettytime.createDurationString(room.timeleft) client.send_server_message( info(timeleft_get_str, timeleft=timeleft))
def execute(cls, spyd_server, room, client, command_string, arguments): 'Actually run the command.' raise GenericError('Not Implemented.')
def _set_others_privilege(self, client, target, requested_privilege): raise GenericError("Setting other player privileges isn't currently implemented.")