def findFreeUsername(self, username): username = truncateText(username,constants.MAX_USERNAME_LENGTH) allnames = [] for room in self._rooms.itervalues(): for watcher in room.getWatchers(): allnames.append(watcher.getName().lower()) while username.lower() in allnames: username += '_' return username
def setWatcherRoom(self, watcher, roomName, asJoin=False): roomName = truncateText(roomName, constants.MAX_ROOM_NAME_LENGTH) self._roomManager.moveWatcher(watcher, roomName) if asJoin: self.sendJoinMessage(watcher) else: self.sendRoomSwitchMessage(watcher) room = watcher.getRoom() roomSetByName = room.getSetBy().getName() if room.getSetBy() else None watcher.setPlaylist(roomSetByName, room.getPlaylist()) watcher.setPlaylistIndex(roomSetByName, room.getPlaylistIndex()) if RoomPasswordProvider.isControlledRoom(roomName): for controller in room.getControllers(): watcher.sendControlledRoomAuthStatus(True, controller, roomName)
def loadRooms(self, rooms): roomsLoaded = [] for roomDetails in rooms: roomName = truncateText(roomDetails[0], constants.MAX_ROOM_NAME_LENGTH) room = Room(roomDetails[0], self._roomsDbHandle) room.loadRoom(roomDetails) if roomName in self._permanentRooms: room.setPermanent(True) self._rooms[roomName] = room roomsLoaded.append(roomName) for roomName in self._permanentRooms: if roomName not in roomsLoaded: roomDetails = (roomName, "", 0, 0, 0) room = Room(roomName, self._roomsDbHandle) room.loadRoom(roomDetails) room.setPermanent(True) self._rooms[roomName] = room
def addWatcher(self, watcherProtocol, username, roomName): roomName = truncateText(roomName, constants.MAX_ROOM_NAME_LENGTH) username = self._roomManager.findFreeUsername(username) watcher = Watcher(self, watcherProtocol, username) self.setWatcherRoom(watcher, roomName, asJoin=True)
def setFile(self, file_): print file_ if file_ and file_.has_key("name"): file_["name"] = truncateText(file_["name"],constants.MAX_FILENAME_LENGTH) self._file = file_ self._server.sendFileUpdate(self)
def moveWatcher(self, watcher, roomName): roomName = truncateText(roomName, constants.MAX_ROOM_NAME_LENGTH) self.removeWatcher(watcher) room = self._getRoom(roomName) room.addWatcher(watcher)
def sendChat(self,watcher,message): message = truncateText(message, constants.MAX_CHAT_MESSAGE_LENGTH) messageDict={"message":message,"username" : watcher.getName()} self._roomManager.broadcastRoom(watcher, lambda w: w.sendChatMessage(messageDict))
def setFile(self, file_): if file_ and "name" in file_: file_["name"] = truncateText(file_["name"], constants.MAX_FILENAME_LENGTH) self._file = file_ self._server.sendFileUpdate(self)
def sendChat(self, watcher, message): message = truncateText(message, self.maxChatMessageLength) messageDict = {"message": message, "username": watcher.getName()} self._roomManager.broadcastRoom( watcher, lambda w: w.sendChatMessage(messageDict))
def sendChat(self, watcher, message): message = truncateText(message, self.maxChatMessageLength) messageDict = {"message": message, "username": watcher.getName()} self._roomManager.broadcastRoom(watcher, lambda w: w.sendChatMessage(messageDict))