From 07499aaef45a23aa14df840faeef29d72f6e7b19 Mon Sep 17 00:00:00 2001 From: et0h Date: Sun, 7 Nov 2021 15:47:57 +0000 Subject: [PATCH] Don't send dummy users to new console clients (#434) --- syncplay/client.py | 4 ++++ syncplay/constants.py | 5 +++++ syncplay/protocols.py | 12 +++++++----- syncplay/server.py | 22 ++++++++++++++++++---- syncplay/ui/consoleUI.py | 1 + syncplay/ui/gui.py | 1 + 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index b35c3183..cc6fc836 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -707,6 +707,7 @@ def getFeatures(self): # Can change during runtime: features["sharedPlaylists"] = self.sharedPlaylistIsEnabled() # Can change during runtime features["chat"] = self.chatIsEnabled() # Can change during runtime + features["uiMode"] = self.ui.getUIMode() # Static for this version/release of Syncplay: features["featureList"] = True @@ -1595,6 +1596,9 @@ def __init__(self, client, ui): self.lastAlertOSDEndTime = None self.lastError = "" + def getUIMode(self): + return self.__ui.uiMode + def addFileToPlaylist(self, newPlaylistItem): self.__ui.addFileToPlaylist(newPlaylistItem) diff --git a/syncplay/constants.py b/syncplay/constants.py index ddb2f73e..148de977 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -349,3 +349,8 @@ def getValueForOS(constantDict): TRUSTABLE_WEB_PROTOCOLS = ["http", "https"] PRIVATE_FILE_FIELDS = ["path"] + +CONSOLE_UI_MODE = "CLI" +GRAPHICAL_UI_MODE = "GUI" +UNKNOWN_UI_MODE = "Unknown" +FALLBACK_ASSUMED_UI_MODE = GRAPHICAL_UI_MODE diff --git a/syncplay/protocols.py b/syncplay/protocols.py index 30702540..53cdaf34 100755 --- a/syncplay/protocols.py +++ b/syncplay/protocols.py @@ -11,7 +11,7 @@ from zope.interface.declarations import implementer import syncplay -from syncplay.constants import PING_MOVING_AVERAGE_WEIGHT, CONTROLLED_ROOMS_MIN_VERSION, USER_READY_MIN_VERSION, SHARED_PLAYLIST_MIN_VERSION, CHAT_MIN_VERSION +from syncplay.constants import PING_MOVING_AVERAGE_WEIGHT, CONTROLLED_ROOMS_MIN_VERSION, USER_READY_MIN_VERSION, SHARED_PLAYLIST_MIN_VERSION, CHAT_MIN_VERSION, UNKNOWN_UI_MODE from syncplay.messages import getMessage from syncplay.utils import meetsMinVersion @@ -143,7 +143,7 @@ def handleHello(self, hello): self._client.setServerVersion(version, featureList) def persistentRoomWarning(self, serverFeatures): - return serverFeatures["persistentRooms"] if "persistentRooms" in serverFeatures else False + return serverFeatures["persistentRooms"] if "persistentRooms" in serverFeatures else False def sendHello(self): hello = {} @@ -449,6 +449,7 @@ def getFeatures(self): self._features["readiness"] = meetsMinVersion(self._version, USER_READY_MIN_VERSION) self._features["managedRooms"] = meetsMinVersion(self._version, CONTROLLED_ROOMS_MIN_VERSION) self._features["persistentRooms"] = False + self._features["uiMode"] = UNKNOWN_UI_MODE return self._features def isLogged(self): @@ -652,9 +653,10 @@ def sendList(self): dummyCount = 0 for watcher in watchers: self._addUserOnList(userlist, watcher) - for emptyRoom in self._factory.getEmptyPersistentRooms(): - dummyCount += 1 - self._addDummyUserOnList(userlist, emptyRoom, dummyCount) + if self._watcher.isGUIUser(self.getFeatures()): + for emptyRoom in self._factory.getEmptyPersistentRooms(): + dummyCount += 1 + self._addDummyUserOnList(userlist, emptyRoom, dummyCount) self.sendMessage({"List": userlist}) @requireLogged diff --git a/syncplay/server.py b/syncplay/server.py index 7fcf11ac..149be128 100755 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -150,7 +150,7 @@ def sendRoomSwitchMessage(self, watcher): self._roomManager.broadcast(watcher, l) self._roomManager.broadcastRoom(watcher, lambda w: w.sendSetReady(watcher.getName(), watcher.isReady(), False)) if self.roomsDbFile: - l = lambda w: w.sendList() + l = lambda w: w.sendList(toGUIOnly=True) self._roomManager.broadcast(watcher, l) def removeWatcher(self, watcher): @@ -158,7 +158,7 @@ def removeWatcher(self, watcher): self.sendLeftMessage(watcher) self._roomManager.removeWatcher(watcher) if self.roomsDbFile: - l = lambda w: w.sendList() + l = lambda w: w.sendList(toGUIOnly=True) self._roomManager.broadcast(watcher, l) def sendLeftMessage(self, watcher): @@ -170,7 +170,7 @@ def sendJoinMessage(self, watcher): self._roomManager.broadcast(watcher, l) self._roomManager.broadcastRoom(watcher, lambda w: w.sendSetReady(watcher.getName(), watcher.isReady(), False)) if self.roomsDbFile: - l = lambda w: w.sendList() + l = lambda w: w.sendList(toGUIOnly=True) self._roomManager.broadcast(watcher, l) def sendFileUpdate(self, watcher): @@ -781,9 +781,23 @@ def sendChatMessage(self, message): if self._connector.meetsMinVersion(constants.CHAT_MIN_VERSION): self._connector.sendMessage({"Chat": message}) - def sendList(self): + def sendList(self, toGUIOnly=False): + if toGUIOnly and self.isGUIUser(self._connector.getFeatures()): + clientFeatures = self._connector.getFeatures() + if "uiMode" in clientFeatures: + if clientFeatures["uiMode"] == constants.CONSOLE_UI_MODE: + return + else: + return self._connector.sendList() + def isGUIUser(self, clientFeatures): + clientFeatures = self._connector.getFeatures() + uiMode = clientFeatures["uiMode"] if "uiMode" in clientFeatures else constants.UNKNOWN_UI_MODE + if uiMode == constants.UNKNOWN_UI_MODE: + uiMode = constants.FALLBACK_ASSUMED_UI_MODE + return uiMode == constants.GRAPHICAL_UI_MODE + def sendSetReady(self, username, isReady, manuallyInitiated=True): self._connector.sendSetReady(username, isReady, manuallyInitiated) diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index 00a00035..f7cec734 100755 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -18,6 +18,7 @@ def __init__(self): self.PromptResult = "" self.promptMode.set() self._syncplayClient = None + self.uiMode = constants.CONSOLE_UI_MODE threading.Thread.__init__(self, name="ConsoleUI") def addClient(self, client): diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 2669885b..071f56f3 100755 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -2081,3 +2081,4 @@ def __init__(self, passedBar=None): self.show() self.setAcceptDrops(True) self.clearedPlaylistNote = False + self.uiMode = constants.GRAPHICAL_UI_MODE