Пример #1
0
    def post(self):
        user = users.get_current_user()
        gameKeyStr = self.request.get('id')
        move = self.request.get('move')
        moveNum = int(self.request.get('moveNum'))
        logging.info("state: %s" % self.request.get('state'))
        state = int(self.request.get('state'))
        if gameKeyStr and move:
            game = db.get(gameKeyStr)
            if game:
                if len(game.moves
                       ) == moveNum - 1 and game.state == models.NOT_FINISHED:
                    game.moves.append(move)
                    game.whiteMove = not game.whiteMove
                    game.state = state
                    game.put()

                    if game.whiteMove:
                        movePlayer = game.whitePlayer
                        otherPlayer = game.blackPlayer
                    else:
                        movePlayer = game.blackPlayer
                        otherPlayer = game.whitePlayer
                    if game.state == models.NOT_FINISHED:
                        notify.sendYourMove(movePlayer, otherPlayer,
                                            str(game.key()))
                else:
                    logging.warn(
                        'Out of sync move, move list length: %s, move number: %s, state: %s'
                        % (len(game.moves), moveNum, game.state))
                    self.error(409)
            else:
                self.error(404)
        else:
            self.error(500)
Пример #2
0
 def post(self):
   user = users.get_current_user()
   gameKeyStr = self.request.get('id')
   move = self.request.get('move')
   moveNum = int(self.request.get('moveNum'))
   logging.info("state: %s" % self.request.get('state'))
   state = int(self.request.get('state'))
   if gameKeyStr and move:
     game = db.get(gameKeyStr)
     if game:
       if len(game.moves) == moveNum - 1 and game.state == models.NOT_FINISHED:
         game.moves.append(move)
         game.whiteMove = not game.whiteMove
         game.state = state
         game.put()
         
         if game.whiteMove:
           movePlayer = game.whitePlayer
           otherPlayer = game.blackPlayer
         else:
           movePlayer = game.blackPlayer
           otherPlayer = game.whitePlayer
         if game.state == models.NOT_FINISHED:
           notify.sendYourMove(movePlayer, otherPlayer, str(game.key()))
       else:
         logging.warn('Out of sync move, move list length: %s, move number: %s, state: %s' % (len(game.moves), moveNum, game.state))
         self.error(409)
     else:
       self.error(404)
   else:
     self.error(500)
Пример #3
0
 def post(self):
     user = users.get_current_user()
     toEmail = self.request.get('invited')
     if toEmail:
         prefs = models.Prefs.gql('where userEmail = :1', toEmail).get()
         if prefs:
             invite = models.Invite(toUser=prefs.user, toEmail=toEmail)
             invite.put()
             notify.sendInvite(user, invite)
         else:
             invite = models.Invite(toEmail=toEmail)
             invite.put()
             notify.sendInviteEmail(user, invite)
     if self.request.get('submit') == 'Delete':
         invites = self.request.get_all('select')
         for i in invites:
             invite = db.get(i)
             invite.delete()
     if self.request.get('submit') == 'Accept':
         invites = self.request.get_all('select')
         for i in invites:
             invite = db.get(i)
             if invite:
                 invite.status = models.INVITE_ACCEPTED
                 if invite.fromPlayAs == models.PLAYAS_RANDOM:
                     invite.fromPlayAs = random.choice(
                         [models.PLAYAS_WHITE, models.PLAYAS_BLACK])
                 invite.put()
                 if invite.fromPlayAs == models.PLAYAS_WHITE:
                     game = models.Game(whitePlayer=invite.fromUser,
                                        blackPlayer=invite.toUser)
                 else:
                     game = models.Game(whitePlayer=invite.toUser,
                                        blackPlayer=invite.fromUser)
                 game.put()
                 notify.sendYourMove(game.whitePlayer, game.blackPlayer,
                                     str(game.key()))
     if self.request.get('submit') == 'Reject':
         invites = self.request.get_all('select')
         for i in invites:
             invite = db.get(i)
             if invite:
                 invite.status = models.INVITE_REJECTED
                 invite.put()
     self.redirect('/')
Пример #4
0
 def post(self):
   user = users.get_current_user()
   toEmail = self.request.get('invited')
   if toEmail:
     prefs = models.Prefs.gql('where userEmail = :1', toEmail).get()
     if prefs:
       invite = models.Invite(toUser = prefs.user, toEmail = toEmail)
       invite.put()
       notify.sendInvite(user, invite)
     else:
       invite = models.Invite(toEmail = toEmail)
       invite.put()
       notify.sendInviteEmail(user, invite)
   if self.request.get('submit') == 'Delete':
     invites = self.request.get_all('select')
     for i in invites:
       invite = db.get(i)
       invite.delete()
   if self.request.get('submit') == 'Accept':
     invites = self.request.get_all('select')
     for i in invites:
       invite = db.get(i)
       if invite:
         invite.status = models.INVITE_ACCEPTED
         if invite.fromPlayAs == models.PLAYAS_RANDOM:
           invite.fromPlayAs = random.choice([models.PLAYAS_WHITE, models.PLAYAS_BLACK])
         invite.put()
         if invite.fromPlayAs == models.PLAYAS_WHITE:
           game = models.Game(whitePlayer = invite.fromUser, blackPlayer = invite.toUser)
         else:
           game = models.Game(whitePlayer = invite.toUser, blackPlayer = invite.fromUser)
         game.put()
         notify.sendYourMove(game.whitePlayer, game.blackPlayer, str(game.key()))
   if self.request.get('submit') == 'Reject':
     invites = self.request.get_all('select')
     for i in invites:
       invite = db.get(i)
       if invite:
         invite.status = models.INVITE_REJECTED
         invite.put()
   self.redirect('/')