<br><br><div class="gmail_quote">On Mon, Apr 16, 2012 at 10:07 AM, 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">
Replaced "get_buddy" function by "lookup_buddy" as suggested the Error message.<br>
<br>
In this version is not allowed to play with more than one player in each XO<br>
(using the gamepad keywords). This is because a known issue [1] and we can not<br>
handle the child's nick properly.<br>
<br>
The "mesh.PARTICIPANT_ADD" event sends something like<br>
"<a href="mailto:6be01ff2bcfaa58eeacc7f10a57b77b65470d413@jabber.sugarlabs.org">6be01ff2bcfaa58eeacc7f10a57b77b65470d413@jabber.sugarlabs.org</a>" in the<br>
"buddy.prosp.nick" variable and the "mesh.broadcast" send the correct child's<br>
name. So, when Maze creates the players uses the mesh.PARTICIPANT_ADD value and<br>
when it reads the messages it find the correct name (the name that the child<br>
chose)<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 | 88 +++++++++++++++++++++++++++++++++++++--------------------------<br>
1 file changed, 52 insertions(+), 36 deletions(-)<br>
<br>
diff --git a/game.py b/game.py<br>
index f710d92..b6319b1 100644<br>
--- a/game.py<br>
+++ b/game.py<br>
@@ -244,37 +244,44 @@ class MazeGame:<br>
self.mouse_in_use = 0<br>
<br>
elif event.type == mesh.CONNECT:<br>
- print "Connected to the mesh."<br>
+ log.debug("Connected to the mesh")<br>
elif event.type == mesh.PARTICIPANT_ADD:<br>
- buddy = mesh.get_buddy(event.handle)<br>
- if event.handle == mesh.my_handle():<br>
- print "Me:", buddy.props.nick, buddy.props.color<br>
- else:<br>
- print "Join:", buddy.props.nick, buddy.props.color<br>
- player = Player(buddy)<br>
- self.remoteplayers[event.handle] = player<br>
- self.allplayers.append(player)<br>
- self.allplayers.extend(player.bonusPlayers())<br>
- self.markPointDirty(player.position)<br>
- # send a test message to the new player<br>
- mesh.broadcast("Welcome %s" % player.nick)<br>
- # tell them which maze we are playing, so they can sync up<br>
- mesh.send_to(event.handle, "maze:%d,%d,%d,%d" % \<br>
- (self.game_running_time(),<br>
- self.maze.seed,<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>
- player.position[0],<br>
- player.position[1],<br>
- player.direction[0],<br>
- player.direction[1]))<br>
+ log.debug('mesh.PARTICIPANT_ADD')<br>
+<br>
+ def withBuddy(buddy):<br>
+ if event.handle == mesh.my_handle():<br>
+ log.debug("Me: %s - %s", buddy.props.nick,<br>
+ buddy.props.color)<br>
+ else:<br>
+ log.debug("Join: %s - %s", buddy.props.nick,<br>
+ buddy.props.color)<br>
+ player = Player(buddy)<br>
+ self.remoteplayers[event.handle] = player<br>
+ self.allplayers.append(player)<br>
+ self.allplayers.extend(player.bonusPlayers())<br>
+ self.markPointDirty(player.position)<br>
+ # send a test message to the new player<br>
+ mesh.broadcast("Welcome %s" % player.nick)<br>
+ # tell them which maze we are playing, so they can sync up<br>
+ mesh.send_to(event.handle, "maze:%d,%d,%d,%d" % \<br>
+ (self.game_running_time(),<br>
+ self.maze.seed,<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>
+ player.position[0],<br>
+ player.position[1],<br>
+ player.direction[0],<br>
+ player.direction[1]))<br>
+<br>
+ mesh.lookup_buddy(event.handle, callback=withBuddy)<br>
elif event.type == mesh.PARTICIPANT_REMOVE:<br>
+ log.debug('mesh.PARTICIPANT_REMOVE')<br>
if event.handle in self.remoteplayers:<br>
player = self.remoteplayers[event.handle]<br>
- print "Leave:", player.nick<br>
+ log.debug("Leave: %s", player.nick)<br>
self.markPointDirty(player.position)<br>
self.allplayers.remove(player)<br>
for bonusplayer in player.bonusPlayers():<br>
@@ -283,9 +290,7 @@ class MazeGame:<br>
del self.remoteplayers[event.handle]<br>
elif event.type == mesh.MESSAGE_UNI or \<br>
event.type == mesh.MESSAGE_MULTI:<br>
- buddy = mesh.get_buddy(event.handle)<br>
- # print "Message from %s / %s: %s" % (buddy.props.nick,<br>
- # event.handle, event.content)<br>
+ log.debug('mesh.MESSAGE_UNI or mesh.MESSAGE_MULTI')<br>
if event.handle == mesh.my_handle():<br>
# ignore messages from ourself<br>
pass<br>
@@ -294,10 +299,10 @@ class MazeGame:<br>
try:<br>
self.handleMessage(player, event.content)<br>
except:<br>
- print "Error handling message: %s\n%s" % \<br>
- (event, sys.exc_info())<br>
+ log.debug("Error handling message: %s\n%s",<br>
+ event, sys.exc_info())<br>
else:<br>
- print "Message from unknown buddy?"<br>
+ log.debug("Message from unknown buddy?")<br>
<br>
elif event.type == pygame.USEREVENT:<br>
# process our buttons<br>
@@ -355,14 +360,26 @@ class MazeGame:<br>
finish: nick, elapsed<br>
A player has finished the maze<br>
"""<br>
+ log.debug('mesh message: %s', message)<br>
+<br>
# ignore messages from myself<br>
if player in self.localplayers:<br>
return<br>
if message.startswith("move:"):<br>
# a player has moved<br>
nick, x, y, dx, dy = message[5:].split(",")[:5]<br>
- player = player.bonusPlayer(nick)<br>
+<br>
+ # README: this function (player.bonusPlayer) sometimes<br>
+ # returns None and the activity doesn't move the players.<br>
+ # This is because the name sent to the server is the<br>
+ # child's name but it returns something like this:<br>
+ # * <a href="mailto:6be01ff2bcfaa58eeacc7f10a57b77b65470d413@jabber.sugarlabs.org">6be01ff2bcfaa58eeacc7f10a57b77b65470d413@jabber.sugarlabs.org</a><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.hidden = False<br>
+<br>
self.markPointDirty(player.position)<br>
player.position = (int(x), int(y))<br>
player.direction = (int(dx), int(dy))<br>
@@ -389,8 +406,7 @@ class MazeGame:<br>
self.markPointDirty(player.position)<br>
else:<br>
# it was something I don't recognize...<br>
- print "Message from %s: %s" % (player.nick, message)<br>
- pass<br>
+ log.debug("Message from %s: %s", player.nick, message)<br>
<br>
def arrowKeysPressed(self):<br>
keys = pygame.key.get_pressed()<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.5<br>
<br>
</font></span></blockquote></div>Ok SL #3296 can be closed after test as it allows collab (other issues should be entered to account OLPC #10750 and to be able to play between two players).<div><br></div><div>Patch applied as:</div>
<div><a href="http://git.sugarlabs.org/maze/mainline/commit/32a8c45503e17ad8b5e8a2f3c756b21cbdbf1d2f">http://git.sugarlabs.org/maze/mainline/commit/32a8c45503e17ad8b5e8a2f3c756b21cbdbf1d2f</a></div><div><br></div><div>Thanks.</div>
<div><br></div>