Beispiel #1
0
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}
Beispiel #2
0
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}
Beispiel #3
0
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}
Beispiel #4
0
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()
Beispiel #5
0
	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()