From 98b0d8998128ced09688a485cbb59cc01e759887 Mon Sep 17 00:00:00 2001 From: et0h Date: Sun, 31 Oct 2021 13:32:57 +0000 Subject: [PATCH] Add -temp rooms and persistent room notices --- syncplay/client.py | 2 ++ syncplay/messages_de.py | 1 + syncplay/messages_en.py | 1 + syncplay/messages_es.py | 1 + syncplay/messages_it.py | 1 + syncplay/messages_pt_BR.py | 1 + syncplay/messages_pt_PT.py | 1 + syncplay/messages_ru.py | 1 + syncplay/messages_tr.py | 1 + syncplay/protocols.py | 19 ++++++++++++++++++- syncplay/server.py | 7 +++++-- 11 files changed, 33 insertions(+), 3 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index d3c4c3f..b35c318 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -640,6 +640,7 @@ class SyncplayClient(object): "chat": utils.meetsMinVersion(self.serverVersion, constants.CHAT_MIN_VERSION), "readiness": utils.meetsMinVersion(self.serverVersion, constants.USER_READY_MIN_VERSION), "managedRooms": utils.meetsMinVersion(self.serverVersion, constants.CONTROLLED_ROOMS_MIN_VERSION), + "persistentRooms": False, "maxChatMessageLength": constants.FALLBACK_MAX_CHAT_MESSAGE_LENGTH, "maxUsernameLength": constants.FALLBACK_MAX_USERNAME_LENGTH, "maxRoomNameLength": constants.FALLBACK_MAX_ROOM_NAME_LENGTH, @@ -711,6 +712,7 @@ class SyncplayClient(object): features["featureList"] = True features["readiness"] = True features["managedRooms"] = True + features["persistentRooms"] = True return features diff --git a/syncplay/messages_de.py b/syncplay/messages_de.py index a7ed41d..5716501 100755 --- a/syncplay/messages_de.py +++ b/syncplay/messages_de.py @@ -458,6 +458,7 @@ de = { # Server messages to client "new-syncplay-available-motd-message": "Du nutzt Syncplay Version {}, aber es gibt eine neuere Version auf https://syncplay.pl", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Willkommen zum Syncplay-Server, v. {0}", # version diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index d71ed7d..d1d8569 100755 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -458,6 +458,7 @@ en = { # Server messages to client "new-syncplay-available-motd-message": "You are using Syncplay {} but a newer version is available from https://syncplay.pl", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Welcome to Syncplay server, ver. {0}", # version diff --git a/syncplay/messages_es.py b/syncplay/messages_es.py index 9f2aeb2..b1a29c8 100644 --- a/syncplay/messages_es.py +++ b/syncplay/messages_es.py @@ -457,6 +457,7 @@ es = { # Server messages to client "new-syncplay-available-motd-message": "Estás usando Syncplay {} pero hay una versión más nueva disponible en https://syncplay.pl", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Bienvenido al servidor de Syncplay, ver. {0}", # version diff --git a/syncplay/messages_it.py b/syncplay/messages_it.py index 3ffc168..d3738af 100755 --- a/syncplay/messages_it.py +++ b/syncplay/messages_it.py @@ -457,6 +457,7 @@ it = { # Server messages to client "new-syncplay-available-motd-message": "Stai usando Syncplay {} ma una nuova versione è disponibile presso https://syncplay.pl", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate # Server notifications "welcome-server-notification": "Benvenuto nel server Syncplay, ver. {0}", # version diff --git a/syncplay/messages_pt_BR.py b/syncplay/messages_pt_BR.py index a3ea771..24fe2ba 100644 --- a/syncplay/messages_pt_BR.py +++ b/syncplay/messages_pt_BR.py @@ -458,6 +458,7 @@ pt_BR = { # Server messages to client "new-syncplay-available-motd-message": "Você está usando o Syncplay {}, mas uma versão mais nova está disponível em https://syncplay.pl", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Seja bem-vindo ao servidor de Syncplay, versão {0}", # version diff --git a/syncplay/messages_pt_PT.py b/syncplay/messages_pt_PT.py index 05f899e..3a608b5 100644 --- a/syncplay/messages_pt_PT.py +++ b/syncplay/messages_pt_PT.py @@ -457,6 +457,7 @@ pt_PT = { # Server messages to client "new-syncplay-available-motd-message": "Você está usando o Syncplay {}, mas uma versão mais nova está disponível em https://syncplay.pl", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Seja bem-vindo ao servidor de Syncplay, versão {0}", # version diff --git a/syncplay/messages_ru.py b/syncplay/messages_ru.py index 5ba4d6c..9afeb3e 100755 --- a/syncplay/messages_ru.py +++ b/syncplay/messages_ru.py @@ -455,6 +455,7 @@ ru = { # Server messages to client "new-syncplay-available-motd-message": "Вы используете Syncplay версии {}. Доступна более новая версия на https://syncplay.pl/", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Добро пожаловать на сервер Syncplay версии {0}", # version diff --git a/syncplay/messages_tr.py b/syncplay/messages_tr.py index b0767bd..e68f4e1 100644 --- a/syncplay/messages_tr.py +++ b/syncplay/messages_tr.py @@ -458,6 +458,7 @@ tr = { # Server messages to client "new-syncplay-available-motd-message": "Syncplay {} kullanıyorsunuz ancak daha yeni bir sürüm https://syncplay.pl adresinde mevcut", # ClientVersion + "persistent-rooms-notice": "NOTICE: This server uses persistent rooms, which means that the playlist information is stored between playback sessions. If you want to create a room where information is not saved then put -temp at the end of the room name.", # TO DO: Translate - NOTE: Do not translate the word -temp # Server notifications "welcome-server-notification": "Syncplay sunucusuna hoş geldiniz, ver. {0}", # version diff --git a/syncplay/protocols.py b/syncplay/protocols.py index c4245ae..3070254 100755 --- a/syncplay/protocols.py +++ b/syncplay/protocols.py @@ -131,6 +131,10 @@ class SyncClientProtocol(JSONCommandProtocol): self._client.setUsername(username) self._client.setRoom(roomName) self.logged = True + if self.persistentRoomWarning(featureList): + if len(motd) > 0: + motd += "\n\n" + motd += getMessage("persistent-rooms-notice") if motd: self._client.ui.showMessage(motd, True, True) self._client.ui.showMessage(getMessage("connected-successful-notification")) @@ -138,6 +142,9 @@ class SyncClientProtocol(JSONCommandProtocol): self._client.sendFile() self._client.setServerVersion(version, featureList) + def persistentRoomWarning(self, serverFeatures): + return serverFeatures["persistentRooms"] if "persistentRooms" in serverFeatures else False + def sendHello(self): hello = {} hello["username"] = self._client.getUsername() @@ -441,6 +448,7 @@ class SyncServerProtocol(JSONCommandProtocol): self._features["featureList"] = False self._features["readiness"] = meetsMinVersion(self._version, USER_READY_MIN_VERSION) self._features["managedRooms"] = meetsMinVersion(self._version, CONTROLLED_ROOMS_MIN_VERSION) + self._features["persistentRooms"] = False return self._features def isLogged(self): @@ -496,6 +504,11 @@ class SyncServerProtocol(JSONCommandProtocol): self._logged = True self.sendHello(version) + def persistentRoomWarning(self, clientFeatures, serverFeatures): + serverPersistentRooms = serverFeatures["persistentRooms"] + clientPersistentRooms = clientFeatures["persistentRooms"] if "persistentRooms" in clientFeatures else False + return serverPersistentRooms and not clientPersistentRooms + @requireLogged def handleChat(self, chatMessage): if not self._factory.disableChat: @@ -520,8 +533,12 @@ class SyncServerProtocol(JSONCommandProtocol): hello["room"] = {"name": room.getName()} hello["version"] = clientVersion # Used so 1.2.X client works on newer server hello["realversion"] = syncplay.version - hello["motd"] = self._factory.getMotd(userIp, username, room, clientVersion) hello["features"] = self._factory.getFeatures() + hello["motd"] = self._factory.getMotd(userIp, username, room, clientVersion) + if self.persistentRoomWarning(clientFeatures=self._features, serverFeatures=hello["features"]): + if len(hello["motd"]) > 0: + hello["motd"] += "\n\n" + hello["motd"] += getMessage("persistent-rooms-notice") self.sendMessage({"Hello": hello}) @requireLogged diff --git a/syncplay/server.py b/syncplay/server.py index de9615f..15a0c66 100755 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -24,7 +24,6 @@ from syncplay.messages import getMessage from syncplay.protocols import SyncServerProtocol from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion, playlistIsValid, truncateText, getListAsMultilineString, convertMultilineStringToList - class SyncFactory(Factory): def __init__(self, port='', password='', motdFilePath=None, roomsDbFile=None, permanentRoomsFile=None, isolateRooms=False, salt=None, disableReady=False, disableChat=False, maxChatMessageLength=constants.MAX_CHAT_MESSAGE_LENGTH, @@ -93,6 +92,7 @@ class SyncFactory(Factory): features["isolateRooms"] = self.isolateRooms features["readiness"] = not self.disableReady features["managedRooms"] = True + features["persistentRooms"] = self.roomsDbFile is not None features["chat"] = not self.disableChat features["maxChatMessageLength"] = self.maxChatMessageLength features["maxUsernameLength"] = self.maxUsernameLength @@ -532,7 +532,10 @@ class Room(object): return self._roomsDbHandle is not None def isPersistent(self): - return self.roomsCanPersist() + return self.roomsCanPersist() and not self.isMarkedAsTemporary() + + def isMarkedAsTemporary(self): + return "-temp" in self.getName() def isPlaylistEmpty(self): return len(self._playlist) == 0