def act_aiExecute(data): user = dbi.getXbyY('User', 'sid', data['sid']) gameId = user.game.id res = None for act in data['actions']: res = doAction(act, False) if res['result'] != 'ok': break gameState = getGameState(user.game) dbi.rollback() return {'result': res, 'gameState' : gameState}
def doAction(data, check=True): try: dbi.session = dbi.Session() func = 'act_%s' % data['action'] if not (func in globals()): raise BadFieldException('badAction') if check: checkFieldsCorrectness(data) res = globals()[func](data) dbi.commit() return res except BadFieldException, e: print e dbi.rollback() return {'result': e.value}
def doAction(data, check = True): try: dbi.session = dbi.Session() func = 'act_%s' % data['action'] if not(func in globals()): raise BadFieldException('badAction') if check: checkFieldsCorrectness(data) res = globals()[func](data) dbi.commit() return res except BadFieldException, e: print e dbi.rollback() return {'result': e.value}
def doAction(data, check=True): try: dbi.session = dbi.Session() func = 'act_%s' % data['action'] if not (func in globals()): raise BadFieldException('badAction') if check: checkFieldsCorrectness(data) res = globals()[func](data) dbi.commit() return res except BadFieldException, e: print e dbi.rollback() return {'result': e.value} except (DatabaseError, DBAPIError, OperationalError), e: print e dbi.rollback() return { 'result': 'databaseError', 'statement': str(e.statement) if ('statement' in e) else None, 'params': str(e.params) if ('params' in e) else None, 'orig': str(e.orig) if ('orig' in e) else None } except Exception, e: print e dbi.rollback() raise e finally: dbi.Session.remove()
readyPlayersNum = dbi.query(User).filter(User.gameId == game.id).filter(User.isReady==True).count() if maxPlayersNum == readyPlayersNum: misc_game.startGame(game, ai, data) return {'result': 'ok', 'sid' : ai.sid, 'id' : ai.id} def doAction(data, check = True): try: dbi.session = dbi.Session() func = 'act_%s' % data['action'] if not(func in globals()): raise BadFieldException('badAction') if check: checkFieldsCorrectness(data) res = globals()[func](data) dbi.commit() return res except BadFieldException, e: print e dbi.rollback() return {'result': e.value} except (DatabaseError, DBAPIError, OperationalError), e: print e dbi.rollback() return {'result': 'databaseError', 'statement': str(e.statement) if ('statement' in e) else None, 'params': str(e.params) if ('params' in e) else None, 'orig': str(e.orig) if ('orig' in e) else None} except Exception, e: print e dbi.rollback() raise e finally: dbi.Session.remove()