<br><br><div class="gmail_quote">On Mon, Apr 16, 2012 at 10:24 PM, Manuel Kaufmann <span dir="ltr"><<a href="mailto:humitos@gmail.com">humitos@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

This is a workaround to the problem with the real nick on a jabber server[1].<br>
Now, we are using the unique identifier (mesh.my_handle or event.handle) for<br>
each player in the game plus a "-%d" at the end of the uid. This value<br>
(Player.uid) is added only when the Activity is shared otherwise this<br>
field is None.<br>
<br>
This new workaround allow to distinguish between many users (up to 3) for each<br>
XO laptop -using the gamepad keys.<br>
<br>
[1] <a href="http://dev.laptop.org/ticket/10750" target="_blank">http://dev.laptop.org/ticket/10750</a><br>
<br>
Signed-off-by: Manuel Kaufmann <<a href="mailto:humitos@gmail.com">humitos@gmail.com</a>><br>
---<br>
 game.py   |   27 ++++++++++++++++++++-------<br>
 player.py |   24 ++++++++++++++----------<br>
 2 files changed, 34 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/game.py b/game.py<br>
index b6319b1..85f6d7f 100644<br>
--- a/game.py<br>
+++ b/game.py<br>
@@ -33,7 +33,9 @@ import pygame<br>
 import olpcgames<br>
<br>
 import logging<br>
+logging.basicConfig()<br>
 log = logging.getLogger('Maze')<br>
+log.setLevel(logging.DEBUG)<br>
<br>
 import olpcgames.pausescreen as pausescreen<br>
 import olpcgames.mesh as mesh<br>
@@ -195,7 +197,7 @@ class MazeGame:<br>
<br>
                 if len(self.remoteplayers) > 0:<br>
                     mesh.broadcast("move:%s,%d,%d,%d,%d" % \<br>
-                                   (player.nick,<br>
+                                   (player.uid,<br>
                                     player.position[0],<br>
                                     player.position[1],<br>
                                     player.direction[0],<br>
@@ -245,6 +247,7 @@ class MazeGame:<br>
<br>
         elif event.type == mesh.CONNECT:<br>
             log.debug("Connected to the mesh")<br>
+<br>
         elif event.type == mesh.PARTICIPANT_ADD:<br>
             log.debug('mesh.PARTICIPANT_ADD')<br>
<br>
@@ -252,10 +255,19 @@ class MazeGame:<br>
                 if event.handle == mesh.my_handle():<br>
                     log.debug("Me: %s - %s", buddy.props.nick,<br>
                                   buddy.props.color)<br>
+                    # README: this is a workaround to use an unique<br>
+                    # identifier instead the nick of the buddy<br>
+                    # <a href="http://dev.laptop.org/ticket/10750" target="_blank">http://dev.laptop.org/ticket/10750</a><br>
+                    count = ''<br>
+                    for i, player in enumerate(self.localplayers):<br>
+                        if i > 0:<br>
+                            count = '-%d' % i<br>
+                        player.uid = mesh.my_handle() + count<br>
                 else:<br>
                     log.debug("Join: %s - %s", buddy.props.nick,<br>
                                   buddy.props.color)<br>
                     player = Player(buddy)<br>
+                    player.uid = event.handle<br>
                     self.remoteplayers[event.handle] = player<br>
                     self.allplayers.append(player)<br>
                     self.allplayers.extend(player.bonusPlayers())<br>
@@ -269,8 +281,9 @@ class MazeGame:<br>
                                   self.maze.width, self.maze.height))<br>
                     for player in self.localplayers:<br>
                         if not player.hidden:<br>
-                            mesh.send_to(event.handle, "move:%s,%d,%d,%d,%d" % \<br>
-                                         (player.nick,<br>
+                            mesh.send_to(event.handle,<br>
+                                         "move:%s,%d,%d,%d,%d" % \<br>
+                                         (player.uid,<br>
                                           player.position[0],<br>
                                           player.position[1],<br>
                                           player.direction[0],<br>
@@ -367,7 +380,7 @@ class MazeGame:<br>
             return<br>
         if message.startswith("move:"):<br>
             # a player has moved<br>
-            nick, x, y, dx, dy = message[5:].split(",")[:5]<br>
+            uid, x, y, dx, dy = message[5:].split(",")[:5]<br>
<br>
             # README: this function (player.bonusPlayer) sometimes<br>
             # returns None and the activity doesn't move the players.<br>
@@ -377,7 +390,7 @@ class MazeGame:<br>
             # So, we have set remote users with this kind of name but<br>
             # we receive the reald child's name in the mesh message<br>
<br>
-            # player = player.bonusPlayer(nick)<br>
+            player = player.bonusPlayer(uid)<br>
             player.hidden = False<br>
<br>
             self.markPointDirty(player.position)<br>
@@ -400,8 +413,8 @@ class MazeGame:<br>
                 self.reset()<br>
         elif message.startswith("finish:"):<br>
             # someone finished the maze<br>
-            nick, elapsed = message[7:].split(",")[:2]<br>
-            player = player.bonusPlayer(nick)<br>
+            uid, elapsed = message[7:].split(",")[:2]<br>
+            player = player.bonusPlayer(uid)<br>
             player.elapsed = float(elapsed)<br>
             self.markPointDirty(player.position)<br>
         else:<br>
diff --git a/player.py b/player.py<br>
index a6636dc..ee2df37 100644<br>
--- a/player.py<br>
+++ b/player.py<br>
@@ -22,15 +22,12 @@<br>
 #     You should have received a copy of the GNU General Public License<br>
 #     along with Maze.activity.  If not, see <<a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>>.<br>
<br>
-from olpcgames.util import get_bundle_path<br>
-bundlepath = get_bundle_path()<br>
-from sugar.graphics.icon import Icon<br>
-from sugar.graphics.xocolor import XoColor<br>
 import pygame<br>
-import re<br>
-import os<br>
 import unicodedata<br>
<br>
+from olpcgames.util import get_bundle_path<br>
+bundlepath = get_bundle_path()<br>
+<br>
<br>
 class Player:<br>
     def __init__(self, buddy, shape='circle'):<br>
@@ -39,6 +36,11 @@ class Player:<br>
         self.nick = unicodedata.normalize('NFC',name)<br>
         colors = buddy.props.color.split(",")<br>
<br>
+        # this field is None when the activity is not shared and when<br>
+        # the user shared it this field will become to<br>
+        # "olpcgames.mesh.my_handle()"<br>
+        self.uid = None<br>
+<br>
         def string2Color(str):<br>
             return (int(str[1:3], 16), int(str[3:5], 16), int(str[5:7], 16))<br>
         self.colors = map(string2Color, colors)<br>
@@ -123,17 +125,19 @@ class Player:<br>
             self.bonusplayers.append(Player(self.buddy, 'square'))<br>
             self.bonusplayers.append(Player(self.buddy, 'triangle'))<br>
<br>
-            count = 2<br>
+            count = 1<br>
             for player in self.bonusplayers:<br>
                 player.nick = self.nick + "-%d" % count<br>
+                if self.uid is not None:<br>
+                    player.uid = self.uid + "-%d" % count<br>
                 player.hidden = True<br>
                 count += 1<br>
<br>
         return self.bonusplayers<br>
<br>
-    def bonusPlayer(self, nick):<br>
-        if nick == self.nick:<br>
+    def bonusPlayer(self, uid):<br>
+        if uid == self.uid:<br>
             return self<br>
         for bonusplayer in self.bonusPlayers():<br>
-            if bonusplayer.nick == nick:<br>
+            if bonusplayer.uid == uid:<br>
                 return bonusplayer<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.5<br>
<br>
</font></span></blockquote></div>I applied your patch locally (with a little change in an space) on player.py (line 39), it is working very nice even between two XOs, a minor glitch in this case is that the path ( o o o ) is not being draw on the other laptop, i.e I can see the path being draw on my XO but not in the other player XO. In the local case, its very cool that one of the players has a circle and the other one a rectangle, having the same colors this is a optimal way to discriminate.<div>

<br><div>I'm going to apply it mainline, thanks.</div><div><br><div> </div></div></div>