From 4b1d0971a830d367e1091ebdc8b4a9e9d46b8469 Mon Sep 17 00:00:00 2001 From: Uriziel Date: Sun, 30 Sep 2012 17:15:36 +0200 Subject: [PATCH] Who's lagging behind fix --- syncplay/client.py | 22 +++++++++++++--------- syncplay/server.py | 13 ++++++------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index 30df7af..46794da 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -78,14 +78,14 @@ class SyncClientProtocol(CommandProtocol): message = '%s is present in the room: \'%s\'' % (who, where) self.__syncplayClient.ui.showMessage(message) - @argumentCount(4, 5) + @argumentCount(4, 6) def state(self, args): args = self.__parseState(args) if not args: self.dropWithError('Malformed state attributes') return - counter, ctime, paused, position, name = args - self.__syncplayClient.updateGlobalState(counter, ctime, paused, position, name) + counter, ctime, paused, position, lagger, name = args + self.__syncplayClient.updateGlobalState(counter, ctime, paused, position, lagger, name) @argumentCount(3) def seek(self, args): @@ -136,10 +136,12 @@ class SyncClientProtocol(CommandProtocol): if len(args) == 4: counter, ctime, state, position = args who_changed_state = None + lagger = None elif len(args) == 5: - counter, ctime, state, position, who_changed_state = args + counter, ctime, state, position, lagger = args + who_changed_state = None else: - return + counter, ctime, state, position, lagger, who_changed_state = args if not state in ('paused', 'playing'): return paused = state == 'paused' @@ -151,7 +153,7 @@ class SyncClientProtocol(CommandProtocol): return ctime /= 1000.0 position /= 1000.0 - return counter, ctime, paused, position, who_changed_state + return counter, ctime, paused, position, lagger, who_changed_state class _MessagesSender(object): def __init__(self, protocol): @@ -400,7 +402,7 @@ class SyncplayClientManager(object): self.users.currentUser.filesize = unicode(os.path.getsize(path)) self.sendPlaying() - def updateGlobalState(self, counter, ctime, paused, position, name): + def updateGlobalState(self, counter, ctime, paused, position, lagger, name): self.counter_recv = max(self.counter_recv, counter) counter_valid = self.counter and counter >= self.counter @@ -432,8 +434,10 @@ class SyncplayClientManager(object): diff = self.getPlayerPosition() - position if abs(diff) > 4: self.player.set_position(position) - #self.player.set_paused(True) - message = "Rewinded due to time difference with %s" % name + if lagger <> self.users.currentUser.name: + message = "Rewinded due to time difference with %s" % lagger + else: + message = "You can't seek closer than 8 seconds from where you are" self.ui.showMessage(message) if self.player_paused and not paused: diff --git a/syncplay/server.py b/syncplay/server.py index f3f6999..611f867 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -173,14 +173,11 @@ class SyncServerProtocol(CommandProtocol): def __init__(self, protocol): self.__protocol = protocol - def send_state(self, counter, ctime, paused, position, who_last_changed): + def send_state(self, counter, ctime, paused, position, whosLagging, who_last_changed): ctime = int(ctime*1000) paused = 'paused' if paused else 'playing' position = int(position*1000) - if who_last_changed is None: - self.__protocol.sendMessage('state', counter, ctime, paused, position) - else: - self.__protocol.sendMessage('state', counter, ctime, paused, position, who_last_changed) + self.__protocol.sendMessage('state', counter, ctime, paused, position, whosLagging, who_last_changed) def send_seek(self, ctime, position, who_seeked): self.__protocol.sendMessage('seek', int(ctime*1000), int(position*1000), who_seeked) @@ -332,12 +329,14 @@ class SyncFactory(Factory): if position is None: position, minWatcher = self.find_position(watcher.room) minWatcher = minWatcher.name if minWatcher else None + if minWatcher is None and self.pause_change_by is not None: + minWatcher = self.pause_change_by.name curtime = time.time() ctime = curtime - watcher.time_offset if self.pause_change_by: - watcher.watcher_proto.sender.send_state(watcher.counter, ctime, self.paused[watcher.room], position, self.pause_change_by.name) + watcher.watcher_proto.sender.send_state(watcher.counter, ctime, self.paused[watcher.room], position, minWatcher, self.pause_change_by.name) else: - watcher.watcher_proto.sender.send_state(watcher.counter, ctime, self.paused[watcher.room], position, minWatcher) + watcher.watcher_proto.sender.send_state(watcher.counter, ctime, self.paused[watcher.room], position, minWatcher, None) watcher.last_update_sent = curtime def find_position(self, room):