MCPcopy Create free account
hub / github.com/Syncplay/syncplay / SyncFactory

Class SyncFactory

syncplay/server.py:25–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion, playlistIsValid, truncateText, getListAsMultilineString, convertMultilineStringToList
24
25class SyncFactory(Factory):
26 def __init__(self, port='', password='', motdFilePath=None, roomsDbFile=None, permanentRoomsFile=None, isolateRooms=False, salt=None,
27 disableReady=False, disableChat=False, maxChatMessageLength=constants.MAX_CHAT_MESSAGE_LENGTH,
28 maxUsernameLength=constants.MAX_USERNAME_LENGTH, statsDbFile=None, tlsCertPath=None):
29 self.isolateRooms = isolateRooms
30 syncplay.messages.setLanguage(syncplay.messages.getInitialLanguage())
31 print(getMessage("welcome-server-notification").format(syncplay.version))
32 self.port = port
33 if password:
34 password = password.encode('utf-8')
35 password = hashlib.md5(password).hexdigest()
36 self.password = password
37 if salt is None:
38 salt = RandomStringGenerator.generate_server_salt()
39 print(getMessage("no-salt-notification").format(salt))
40 self._salt = salt
41 self._motdFilePath = motdFilePath
42 self.roomsDbFile = roomsDbFile
43 self.disableReady = disableReady
44 self.disableChat = disableChat
45 self.maxChatMessageLength = maxChatMessageLength if maxChatMessageLength is not None else constants.MAX_CHAT_MESSAGE_LENGTH
46 self.maxUsernameLength = maxUsernameLength if maxUsernameLength is not None else constants.MAX_USERNAME_LENGTH
47 self.permanentRoomsFile = permanentRoomsFile if permanentRoomsFile is not None and os.path.isfile(permanentRoomsFile) else None
48 self.permanentRooms = self.loadListFromMultilineTextFile(self.permanentRoomsFile) if self.permanentRoomsFile is not None else []
49 if not isolateRooms:
50 self._roomManager = RoomManager(self.roomsDbFile, self.permanentRooms)
51 else:
52 self._roomManager = PublicRoomManager()
53 if statsDbFile is not None:
54 self._statsDbHandle = StatsDBManager(statsDbFile)
55 self._statsRecorder = StatsRecorder(self._statsDbHandle, self._roomManager)
56 statsDelay = 5*(int(self.port)%10 + 1)
57 self._statsRecorder.startRecorder(statsDelay)
58 else:
59 self._statsDbHandle = None
60 if tlsCertPath is not None:
61 self.certPath = tlsCertPath
62 self._TLSattempts = 0
63 self._allowTLSconnections(self.certPath)
64 else:
65 self.certPath = None
66 self.options = None
67 self.serverAcceptsTLS = False
68
69 def loadListFromMultilineTextFile(self, path):
70 if not os.path.isfile(path):
71 return []
72 with open(path) as f:
73 multiline = f.read().splitlines()
74 return multiline
75
76 def loadRoom(self):
77 rooms = self._roomsDbHandle.loadRooms()
78
79 def buildProtocol(self, addr):
80 return SyncServerProtocol(self)
81
82 def sendState(self, watcher, doSeek=False, forcedUpdate=False):

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected