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 connect_received(self, message): '''Create the main player instance for this client and join room.''' if not self.connect_timeout_deferred.called: self.connect_timeout_deferred.cancel() name = filtertext(message['name'], False, MAXNAMELEN) playermodel = message['playermodel'] player = Player(self, self.cn, name, playermodel) self.add_player(player) pwdhash = message['pwdhash'] authdomain = message['authdomain'] authname = message['authname'] if len(authname) > 0: deferred = self.auth(authdomain, authname) deferred.addCallbacks(self.connection_auth_finished, lambda e: self.connection_auth_finished(None, pwdhash), (pwdhash,)) else: self.connection_auth_finished(None, pwdhash)
def handle(client, room, message): player = client.get_player(-1) name = filtertext(message['name'], False, MAXNAMELEN) if len(name) <= 0: name = "unnamed" room.handle_player_event('switch_name', player, name)
def handle(client, room, message): team_name = filtertext(message['team'], False, MAXTEAMLEN) room.handle_client_event('set_team', client, message['target_cn'], team_name)
def test_removes_whitespace(self): self.assertEqual(filtertext('a b c', False, 30), 'abc')
def test_truncates(self): self.assertEqual(filtertext('abc', True, 2), 'ab')
def test_removes_cube_format_chars(self): self.assertEqual(filtertext('\fs\f3a \f2b c\fr', True, 30), 'a b c')
def handle(client, room, message): player = client.get_player(-1) team_name = filtertext(message['team'], False, MAXTEAMLEN) room.handle_player_event('switch_team', player, team_name)