Isolated room server is now using inheritance properly
This commit is contained in:
parent
06fd73f6a4
commit
56ea29af72
@ -8,14 +8,13 @@ from syncplay.protocols import SyncServerProtocol
|
||||
import time
|
||||
|
||||
class SyncFactory(Factory):
|
||||
def __init__(self, password = '', isolateRooms = False):
|
||||
def __init__(self, password = ''):
|
||||
print "Welcome to Syncplay server, ver. {0}".format(syncplay.version)
|
||||
if(password):
|
||||
password = hashlib.md5(password).hexdigest()
|
||||
self.password = password
|
||||
self._rooms = {}
|
||||
self._roomStates = {}
|
||||
self.isolateRooms = isolateRooms
|
||||
self._usersCheckupTimer = task.LoopingCall(self._checkUsers)
|
||||
self._usersCheckupTimer.start(4, True)
|
||||
|
||||
@ -53,18 +52,11 @@ class SyncFactory(Factory):
|
||||
return room[watcherProtocol]
|
||||
|
||||
def getAllWatchers(self, watcherProtocol):
|
||||
if(self.isolateRooms):
|
||||
room = self.getWatcher(watcherProtocol).room
|
||||
if(self._rooms.has_key(room)):
|
||||
return self._rooms[room]
|
||||
else:
|
||||
return {}
|
||||
else:
|
||||
watchers = {}
|
||||
for room in self._rooms.itervalues():
|
||||
for watcher in room.itervalues():
|
||||
watchers[watcher.watcherProtocol] = watcher
|
||||
return watchers
|
||||
watchers = {}
|
||||
for room in self._rooms.itervalues():
|
||||
for watcher in room.itervalues():
|
||||
watchers[watcher.watcherProtocol] = watcher
|
||||
return watchers
|
||||
|
||||
def _removeWatcherFromTheRoom(self, watcherProtocol):
|
||||
for room in self._rooms.itervalues():
|
||||
@ -173,9 +165,6 @@ class SyncFactory(Factory):
|
||||
self._roomStates[room]["setBy"] = watcher.name
|
||||
self._roomStates[room]["lastUpdate"] = time.time()
|
||||
self._deleteRoomIfEmpty(oldRoom)
|
||||
if(self.isolateRooms): #this is trick to inform old room about leaving
|
||||
l = lambda w: w.sendUserSetting(watcher.name, oldRoom, None, {"left": True})
|
||||
self.broadcast(watcherProtocol, l)
|
||||
watcher.room = room
|
||||
l = lambda w: w.sendUserSetting(watcher.name, watcher.room, watcher.file, None)
|
||||
self.broadcast(watcherProtocol, l)
|
||||
@ -193,9 +182,6 @@ class SyncFactory(Factory):
|
||||
what(receiver)
|
||||
|
||||
def broadcast(self, sender, what):
|
||||
if(self.isolateRooms):
|
||||
self.broadcastRoom(sender, what)
|
||||
return
|
||||
for room in self._rooms.itervalues():
|
||||
for receiver in room:
|
||||
what(receiver)
|
||||
@ -209,6 +195,24 @@ class SyncFactory(Factory):
|
||||
self._checkUsers() #restart
|
||||
return #end loop
|
||||
|
||||
class SyncIsolatedFactory(SyncFactory):
|
||||
def broadcast(self, sender, what):
|
||||
self.broadcastRoom(sender, what)
|
||||
|
||||
def getAllWatchers(self, watcherProtocol):
|
||||
room = self.getWatcher(watcherProtocol).room
|
||||
if(self._rooms.has_key(room)):
|
||||
return self._rooms[room]
|
||||
else:
|
||||
return {}
|
||||
|
||||
def watcherSetRoom(self, watcherProtocol, room):
|
||||
watcher = self.getWatcher(watcherProtocol)
|
||||
oldRoom = watcher.room
|
||||
l = lambda w: w.sendUserSetting(watcher.name, oldRoom, None, {"left": True})
|
||||
self.broadcast(watcherProtocol, l)
|
||||
SyncFactory.watcherSetRoom(self, watcherProtocol, room)
|
||||
|
||||
|
||||
class Watcher(object):
|
||||
def __init__(self, factory, watcherProtocol, name, room):
|
||||
|
||||
@ -2,10 +2,13 @@
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
from syncplay.server import SyncFactory
|
||||
from syncplay.server import SyncFactory, SyncIsolatedFactory
|
||||
from syncplay.ui.ConfigurationGetter import ServerConfigurationGetter
|
||||
|
||||
argsGetter = ServerConfigurationGetter()
|
||||
args = argsGetter.getConfiguration()
|
||||
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.isolate_rooms))
|
||||
if(not args.isolate_rooms):
|
||||
reactor.listenTCP(int(args.port), SyncFactory(args.password))
|
||||
else:
|
||||
reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password))
|
||||
reactor.run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user