diff src/plugins/plugin_misc_radiocol.py @ 825:e3f4d80f987d

plugins room_games, radiocol: better synchronization after a user joins a running game
author souliane <souliane@mailoo.org>
date Wed, 15 Jan 2014 23:01:23 +0100
parents 1fe00f0c9a91
children 71f8e996f765
line wrap: on
line diff
--- a/src/plugins/plugin_misc_radiocol.py	Mon Feb 17 18:57:53 2014 +0100
+++ b/src/plugins/plugin_misc_radiocol.py	Wed Jan 15 23:01:23 2014 +0100
@@ -224,8 +224,16 @@
             else:
                 error(_('Unmanaged game element: %s') % elt.name)
 
-    def getSyncData(self, room_jid_s):
-        data = self.games[room_jid_s]['queue']
-        if len(data) == QUEUE_LIMIT:
-            data.append(domish.Element((None, 'no_upload')))
+    def getSyncData(self, room_jid_s, force_nicks=[]):
+        data = {}
+        status = self.games[room_jid_s]['status']
+        nicks = [nick for nick in status if status[nick] == 'desync']
+        for nick in force_nicks:
+            if nick not in nicks:
+                nicks.append(nick)
+        for nick in nicks:
+            if len(self.games[room_jid_s]['queue']) > 0:
+                data[nick] = copy.deepcopy(self.games[room_jid_s]['queue'])
+                if len(self.games[room_jid_s]['queue']) == QUEUE_LIMIT:
+                    data[nick].append(domish.Element(('', 'no_upload')))
         return data