Skip to content

Commit

Permalink
Don't send dummy users to new console clients (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
Et0h committed Nov 7, 2021
1 parent 37b9384 commit 07499aa
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions syncplay/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions syncplay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions syncplay/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions syncplay/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ 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):
if watcher and watcher.getRoom():
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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions syncplay/ui/consoleUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions syncplay/ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,3 +2081,4 @@ def __init__(self, passedBar=None):
self.show()
self.setAcceptDrops(True)
self.clearedPlaylistNote = False
self.uiMode = constants.GRAPHICAL_UI_MODE

0 comments on commit 07499aa

Please sign in to comment.