Added --rooms-timer option that limits the max lifespan of persistent rooms
This commit is contained in:
parent
11653ec8bb
commit
cc4b936076
@ -79,7 +79,11 @@ Path to a file from which motd (Message Of The Day) will be read.
|
||||
|
||||
.TP
|
||||
.B \-\-rooms\-dir [directory]
|
||||
Path to a directory from where room data will be written to and read from. This will enable rooms to persist without watchers and through restarts. Will not work if using \fB--isolate-rooms\fP.
|
||||
Path to a directory from where room data will be written to and read from. This will enable rooms to persist without watchers and through restarts. Will not work if using \fB\-\-isolate\-rooms\fP.
|
||||
|
||||
.TP
|
||||
.B \-\-rooms\-timer [directory]
|
||||
Requires \fB\-\-rooms\-timer\fP. Time in seconds that rooms will persist without users. \fB0\fP disables the timer, meaning rooms persist permanently.
|
||||
|
||||
.TP
|
||||
.B \-\-max\-chat\-message\-length [maxChatMessageLength]
|
||||
|
||||
@ -35,6 +35,7 @@ def main():
|
||||
args.password,
|
||||
args.motd_file,
|
||||
args.rooms_dir,
|
||||
args.rooms_timer,
|
||||
args.isolate_rooms,
|
||||
args.salt,
|
||||
args.disable_ready,
|
||||
|
||||
@ -473,6 +473,7 @@ de = {
|
||||
"server-disable-ready-argument": "Bereitschaftsfeature deaktivieren",
|
||||
"server-motd-argument": "Pfad zur Datei, von der die Nachricht des Tages geladen wird",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "Soll Chat deaktiviert werden?",
|
||||
"server-chat-maxchars-argument": "Maximale Zeichenzahl in einer Chatnachricht (Standard ist {})",
|
||||
"server-maxusernamelength-argument": "Maximale Zeichenzahl in einem Benutzernamen (Standard ist {})",
|
||||
|
||||
@ -474,6 +474,7 @@ en = {
|
||||
"server-disable-ready-argument": "disable readiness feature",
|
||||
"server-motd-argument": "path to file from which motd will be fetched",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts",
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning",
|
||||
"server-chat-argument": "Should chat be disabled?",
|
||||
"server-chat-maxchars-argument": "Maximum number of characters in a chat message (default is {})", # Default number of characters
|
||||
"server-maxusernamelength-argument": "Maximum number of characters in a username (default is {})",
|
||||
|
||||
@ -473,6 +473,7 @@ es = {
|
||||
"server-disable-ready-argument": "deshabilitar la función de preparación",
|
||||
"server-motd-argument": "ruta al archivo del cual se obtendrá el texto motd",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "¿Debería deshabilitarse el chat?",
|
||||
"server-chat-maxchars-argument": "Número máximo de caracteres en un mensaje de chat (el valor predeterminado es {})", # Default number of characters
|
||||
"server-maxusernamelength-argument": "Número máximo de caracteres para el nombre de usuario (el valor predeterminado es {})",
|
||||
|
||||
@ -473,6 +473,7 @@ it = {
|
||||
"server-disable-ready-argument": "disabilita la funzionalità \"pronto\"",
|
||||
"server-motd-argument": "percorso del file da cui verrà letto il messaggio del giorno",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "abilita o disabilita la chat",
|
||||
"server-chat-maxchars-argument": "Numero massimo di caratteri in un messaggio di chat (default è {})", # Default number of characters
|
||||
"server-maxusernamelength-argument": "Numero massimo di caratteri in un nome utente (default è {})",
|
||||
|
||||
@ -474,6 +474,7 @@ pt_BR = {
|
||||
"server-disable-ready-argument": "desativar recurso de prontidão",
|
||||
"server-motd-argument": "caminho para o arquivo o qual o motd será obtido",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "O chat deve ser desativado?",
|
||||
"server-chat-maxchars-argument": "Número máximo de caracteres numa mensagem do chat (o padrão é {})", # Default number of characters
|
||||
"server-maxusernamelength-argument": "Número máximos de caracteres num nome de usuário (o padrão é {})",
|
||||
|
||||
@ -473,6 +473,7 @@ pt_PT = {
|
||||
"server-disable-ready-argument": "desativar recurso de prontidão",
|
||||
"server-motd-argument": "caminho para o arquivo o qual o motd será obtido",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "O chat deve ser desativado?",
|
||||
"server-chat-maxchars-argument": "Número máximo de caracteres numa mensagem do chat (o padrão é {})", # Default number of characters
|
||||
"server-maxusernamelength-argument": "Número máximos de caracteres num nome de utilizador (o padrão é {})",
|
||||
|
||||
@ -470,6 +470,7 @@ ru = {
|
||||
"server-disable-ready-argument": "отключить статусы готов/не готов",
|
||||
"server-motd-argument": "путь к файлу, из которого будет извлекаться MOTD-сообщение",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "Должен ли чат быть отключён?",
|
||||
"server-chat-maxchars-argument": "Максимальное число символов в сообщениях в чате (по умолчанию {})",
|
||||
"server-maxusernamelength-argument": "Максимальное число символов в именах пользователей (по умолчанию {})",
|
||||
|
||||
@ -474,6 +474,7 @@ tr = {
|
||||
"server-disable-ready-argument": "hazır olma özelliğini devre dışı bırak",
|
||||
"server-motd-argument": "motd alınacak dosyanın yolu",
|
||||
"server-rooms-argument": "path to directory to store/fetch room data. Enables rooms to persist without watchers and through restarts", # TODO: Translate
|
||||
"server-timer-argument": "time in seconds before a persistent room with no watchers is pruned. 0 disables pruning", # TODO: Translate
|
||||
"server-chat-argument": "Sohbet devre dışı bırakılmalı mı?",
|
||||
"server-chat-maxchars-argument": "Bir sohbet mesajındaki maksimum karakter sayısı (varsayılan: {})", # Default number of characters
|
||||
"server-maxusernamelength-argument": "Bir kullanıcı adındaki maksimum karakter sayısı (varsayılan {})",
|
||||
|
||||
@ -26,7 +26,7 @@ from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomString
|
||||
|
||||
|
||||
class SyncFactory(Factory):
|
||||
def __init__(self, port='', password='', motdFilePath=None, roomsDirPath=None, isolateRooms=False, salt=None,
|
||||
def __init__(self, port='', password='', motdFilePath=None, roomsDirPath=None, roomsTimer=31558149, isolateRooms=False, salt=None,
|
||||
disableReady=False, disableChat=False, maxChatMessageLength=constants.MAX_CHAT_MESSAGE_LENGTH,
|
||||
maxUsernameLength=constants.MAX_USERNAME_LENGTH, statsDbFile=None, tlsCertPath=None):
|
||||
self.isolateRooms = isolateRooms
|
||||
@ -42,12 +42,13 @@ class SyncFactory(Factory):
|
||||
self._salt = salt
|
||||
self._motdFilePath = motdFilePath
|
||||
self._roomsDirPath = roomsDirPath if roomsDirPath is not None and os.path.isdir(roomsDirPath) else None
|
||||
self._roomsTimer = roomsTimer if roomsDirPath is not None and isinstance(roomsTimer, int) and roomsTimer > 0 else 0
|
||||
self.disableReady = disableReady
|
||||
self.disableChat = disableChat
|
||||
self.maxChatMessageLength = maxChatMessageLength if maxChatMessageLength is not None else constants.MAX_CHAT_MESSAGE_LENGTH
|
||||
self.maxUsernameLength = maxUsernameLength if maxUsernameLength is not None else constants.MAX_USERNAME_LENGTH
|
||||
if not isolateRooms:
|
||||
self._roomManager = RoomManager(self._roomsDirPath)
|
||||
self._roomManager = RoomManager(self._roomsDirPath, self._roomsTimer)
|
||||
else:
|
||||
self._roomManager = PublicRoomManager()
|
||||
if statsDbFile is not None:
|
||||
@ -313,8 +314,9 @@ class DBManager(object):
|
||||
|
||||
|
||||
class RoomManager(object):
|
||||
def __init__(self, roomsDir=None):
|
||||
def __init__(self, roomsDir=None, timer=0):
|
||||
self._roomsDir = roomsDir
|
||||
self._timer = timer
|
||||
self._rooms = {}
|
||||
if self._roomsDir is not None:
|
||||
for root, dirs, files in os.walk(self._roomsDir):
|
||||
@ -323,7 +325,7 @@ class RoomManager(object):
|
||||
room = Room('', self._roomsDir)
|
||||
room.loadFromFile(os.path.join(root, file))
|
||||
roomName = truncateText(room.getName(), constants.MAX_ROOM_NAME_LENGTH)
|
||||
if len(room.getPlaylist()) == 0:
|
||||
if len(room.getPlaylist()) == 0 or room.isStale(self._timer):
|
||||
os.remove(os.path.join(root, file))
|
||||
else:
|
||||
self._rooms[roomName] = room
|
||||
@ -356,16 +358,18 @@ class RoomManager(object):
|
||||
oldRoom = watcher.getRoom()
|
||||
if oldRoom:
|
||||
oldRoom.removeWatcher(watcher)
|
||||
if self._roomsDir is None:
|
||||
if self._roomsDir is None or oldRoom.isStale(self._timer):
|
||||
self._deleteRoomIfEmpty(oldRoom)
|
||||
|
||||
def _getRoom(self, roomName):
|
||||
if roomName in self._rooms:
|
||||
if roomName in self._rooms and not self._rooms[roomName].isStale(self._timer):
|
||||
return self._rooms[roomName]
|
||||
else:
|
||||
if RoomPasswordProvider.isControlledRoom(roomName):
|
||||
room = ControlledRoom(roomName)
|
||||
else:
|
||||
if roomName in self._rooms:
|
||||
self._deleteRoomIfEmpty(self._rooms[roomName])
|
||||
room = Room(roomName, self._roomsDir)
|
||||
self._rooms[roomName] = room
|
||||
return room
|
||||
@ -416,6 +420,7 @@ class Room(object):
|
||||
self._playlist = []
|
||||
self._playlistIndex = None
|
||||
self._lastUpdate = time.time()
|
||||
self._lastSavedUpdate = 0
|
||||
self._position = 0
|
||||
|
||||
def __str__(self, *args, **kwargs):
|
||||
@ -444,6 +449,7 @@ class Room(object):
|
||||
data['playlist'] = self._playlist
|
||||
data['playlistIndex'] = self._playlistIndex
|
||||
data['position'] = self._position
|
||||
data['lastSavedUpdate'] = self._lastSavedUpdate
|
||||
with open(os.path.join(self._roomsDir, self.sanitizeFilename(self._name)+'.room'), "w") as outfile:
|
||||
json.dump(data, outfile)
|
||||
|
||||
@ -454,6 +460,12 @@ class Room(object):
|
||||
self._playlist = data['playlist']
|
||||
self._playlistIndex = data['playlistIndex']
|
||||
self._position = data['position']
|
||||
self._lastSavedUpdate = data['lastSavedUpdate']
|
||||
|
||||
def isStale(self, timer):
|
||||
if timer == 0 or self._lastSavedUpdate == 0:
|
||||
return False
|
||||
return time.time() - self._lastSavedUpdate > timer
|
||||
|
||||
def getName(self):
|
||||
return self._name
|
||||
@ -464,7 +476,7 @@ class Room(object):
|
||||
watcher = min(self._watchers.values())
|
||||
self._setBy = watcher
|
||||
self._position = watcher.getPosition()
|
||||
self._lastUpdate = time.time()
|
||||
self._lastSavedUpdate = self._lastUpdate = time.time()
|
||||
return self._position
|
||||
elif self._position is not None:
|
||||
return self._position + (age if self._playState == self.STATE_PLAYING else 0)
|
||||
@ -743,6 +755,7 @@ class ConfigurationGetter(object):
|
||||
self._argparser.add_argument('--salt', metavar='salt', type=str, nargs='?', help=getMessage("server-salt-argument"), default=os.environ.get('SYNCPLAY_SALT'))
|
||||
self._argparser.add_argument('--motd-file', metavar='file', type=str, nargs='?', help=getMessage("server-motd-argument"))
|
||||
self._argparser.add_argument('--rooms-dir', metavar='rooms', type=str, nargs='?', help=getMessage("server-rooms-argument"))
|
||||
self._argparser.add_argument('--rooms-timer', metavar='timer', type=int, nargs='?',default=31558149, help=getMessage("server-timer-argument"))
|
||||
self._argparser.add_argument('--max-chat-message-length', metavar='maxChatMessageLength', type=int, nargs='?', help=getMessage("server-chat-maxchars-argument").format(constants.MAX_CHAT_MESSAGE_LENGTH))
|
||||
self._argparser.add_argument('--max-username-length', metavar='maxUsernameLength', type=int, nargs='?', help=getMessage("server-maxusernamelength-argument").format(constants.MAX_USERNAME_LENGTH))
|
||||
self._argparser.add_argument('--stats-db-file', metavar='file', type=str, nargs='?', help=getMessage("server-stats-db-file-argument"))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user