示例#1
0
 def get(self):
     for player in Player.all():
         print player.nickname
         
         print player.own_games.filter("status !=", "ABANDONED").count()
         print player.other_games.filter("status !=", "ABANDONED").count()
         
         
         # if it has only abandoned games we delete the player and the games
         if player.own_games.filter("status !=", "ABANDONED").count() == 0 \
             and player.other_games.filter("status !=", "ABANDONED").count() == 0:
             
             # if there are won games we delete them
             for game in player.own_games.filter("status =", "ABANDONED"):
                 game.delete();
                 
             
             # if there are other games we delete them
             for game in player.other_games.filter("status =", "ABANDONED"):
                 game.delete();
                 
             
             # finally delete player
             player.delete()
             
             print "deleted player", player.nickname
     
     print "OK" 
示例#2
0
 def get(self):
     
     for player in Player.all():
         # avoid NoneType problems
         if not player.won:
             player.won = 0
         if not player.lost:
             player.lost = 0
         if not player.created:
             player.created = 0
         if not player.abandoned:
             player.abandoned = 0
             
         # compute score
         player.score = 10 * player.won - 3 * player.lost
         player.put() 
     
     self.response.out.write(template.render(template_path + 'scores.html', 
                                             { 'Scores' : 'active',
                                               'players' : Player.all().order("-score")
                                                    }))
示例#3
0
 def get(self):
     # see who's online now (the last 30 minutes)
     now = datetime.now()
     
     players = []
     
     for player in Player.all().order("nickname"):
         dif = now - player.last_online
         if dif.days * 84000 + dif.seconds > 60:
             player.online = False
         else:
             player.online = True
             
         players.append(player)
     
     self.response.out.write(template.render(template_path + 'players.html', 
                                             { 'Players' : 'active', 
                                               'players' : players, 
                                                    }))
示例#4
0
    def _purge(self):
        """ Purge all dead players (last_online > 30 secs) 
        
        The ping can be efficiently made every 30s in C. 
        """

        # Get players who haven't pinged in more than 30secs and who are currently marked as online
        players = Player.all().filter("last_online < ", datetime.now() - timedelta(seconds=30)).filter("online = ", True)
        for player in players:
            player.online = False # Not online anymore
            player.put() # save
        
            # Get his former game
            player_game = Game.all().filter("creator =", player).filter("status = ", 'PLAYING')
            
            for game in player_game:
                game.status = 'ABANDONED' # game OVER
                game.put() # save
                
                # increment the abandoned counter
                if player.abandoned:
                    player.abandoned = player.abandoned + 1
                else:
                    player.abandoned = 1
                    
                player.put()
                
            # Get his former game
            player_game = Game.all().filter("creator =", player).filter("status = ", 'WAITING')
            
            for game in player_game:
                game.status = 'ABANDONED' # game OVER
                game.put() # save
                
                # increment the abandoned counter
                if player.abandoned:
                    player.abandoned = player.abandoned + 1
                else:
                    player.abandoned = 1
                    
                player.put()