def post(self, path): """Broadcasts all moves.""" message = websocket.Message(self.request.POST) data = simplejson.loads(message.body) state = data.get("state") x = data.get('x') y = data.get('y') players = memcache.get(PLAYERS_INDEX_KEY) or [] if state == PLAYER_MOVED: replace = {path: [x, y]} if path not in players: players.append(path) replace[PLAYERS_INDEX_KEY] = players memcache.replace_multi(replace) response = {'state': PLAYER_MOVED, 'player': path, 'x': x, 'y': y} elif state == PLAYER_LEFT or not data: memcache.delete(path) if path in players: players.remove(path) memcache.replace(PLAYERS_INDEX_KEY, players) response = {'state': PLAYER_LEFT, 'player': path} websocket.broadcast_message(simplejson.dumps(response))
def get(self): players = memcache.get(PLAYERS_INDEX_KEY) or [] for player in players: response = {'state': PLAYER_LEFT, 'player': player} websocket.broadcast_message(simplejson.dumps(response)) memcache.delete(player) players.remove(player) memcache.delete(PLAYERS_INDEX_KEY)
def post(self, path): players = memcache.get(PLAYERS_INDEX_KEY) or [] if path in players: players.remove(path) memcache.replace(PLAYERS_INDEX_KEY, players) memcache.delete(path) response = {'state': PLAYER_LEFT, 'player': path} websocket.broadcast_message(simplejson.dumps(response))