예제 #1
0
파일: actions.py 프로젝트: NZem/webgame
def act_uploadMap(data):
    name = data['mapName']
    playersNum = int(data['playersNum'])
    result = list()

    #checkFiles(data['thumbnail'], data['picture'])
    data['thumbnail'] = data[
        'thumbnail'] if 'thumbnail' in data else misc.DEFAULT_THUMB
    data['picture'] = data[
        'picture'] if 'picture' in data else misc.DEFAULT_MAP_PICTURE

    newMap = Map(name, playersNum, data['turnsNum'], data['thumbnail'],
                 data['picture'])
    dbi.addUnique(newMap, 'mapName')
    mapId = newMap.id
    if 'regions' in data:
        regions = data['regions']
        curId = 1
        for regInfo in regions:
            try:
                dbi.addRegion(curId, newMap, regInfo)
            except KeyError, e:
                raise BadFieldException('badRegions')
            curId += 1
        i = 0
        for reg in newMap.regions:
            regInfo = data['regions'][i]
            if reg.id in regInfo['adjacent']:
                raise BadFieldException('badRegions')
            dbi.addAll(
                map(lambda x: Adjacency(reg.id, x, mapId),
                    regInfo['adjacent']))
            i += 1
예제 #2
0
파일: actions.py 프로젝트: NZem/webgame
def act_createGame(data):
    user = dbi.getXbyY('User', 'sid', data['sid'])
    if user.gameId: raise BadFieldException('alreadyInGame')
    map_ = dbi.getXbyY('Map', 'id', data['mapId'])
    descr = None
    if 'gameDescription' in data:
        descr = data['gameDescription']
    randseed = math.trunc(time.time())
    if 'randseed' in data:
        randseed = data['randseed']
    ai = data['ai'] if 'ai' in data else 0
    if ai > map_.playersNum:
        raise BadFieldException('tooManyPlayersForMap')
    newGame = Game(data['gameName'], descr, map_, randseed, data['ai'] if 'ai' in\
     data else None)
    dbi.addUnique(newGame, 'gameName')
    initRegions(map_, newGame)

    if ai < map_.playersNum:
        user.game = newGame
        user.priority = 1
        user.inGame = True
        dbi.flush(user)
        if not misc.TEST_MODE:
            data['randseed'] = randseed
        dbi.updateGameHistory(user.game, data)

    return {'result': 'ok', 'gameId': newGame.id}
예제 #3
0
파일: actions.py 프로젝트: NZem/webgame
def act_createGame(data):
	user = dbi.getXbyY('User', 'sid', data['sid'])
	if user.gameId: raise BadFieldException('alreadyInGame')
	map_ = dbi.getXbyY('Map', 'id', data['mapId'])
	descr = None
	if 'gameDescription' in data:
		descr = data['gameDescription']
	randseed = math.trunc(time.time())
	if 'randseed' in data:
		randseed = data['randseed']
	ai = data['ai'] if 'ai' in data else 0
	if ai > map_.playersNum:
		raise BadFieldException('tooManyPlayersForMap')
	newGame = Game(data['gameName'], descr, map_, randseed, data['ai'] if 'ai' in\
		data else None)
	dbi.addUnique(newGame, 'gameName')
	initRegions(map_, newGame)
	
	if ai < map_.playersNum:
		user.game = newGame
		user.priority = 1
		user.inGame = True
		dbi.flush(user)
		if not misc.TEST_MODE:
			data['randseed'] = randseed
		dbi.updateGameHistory(user.game, data)
		
	return {'result': 'ok', 'gameId': newGame.id}
예제 #4
0
파일: actions.py 프로젝트: NZem/webgame
def act_uploadMap(data):
	name = data['mapName']
	playersNum = int(data['playersNum'])
	result = list()
			
	#checkFiles(data['thumbnail'], data['picture'])
	data['thumbnail'] = data['thumbnail']if 'thumbnail' in data else  misc.DEFAULT_THUMB
	data['picture'] = data['picture']if 'picture' in data else  misc.DEFAULT_MAP_PICTURE

	newMap = Map(name, playersNum, data['turnsNum'], data['thumbnail'], 
		data['picture'])
	dbi.addUnique(newMap, 'mapName')
	mapId = newMap.id
	if 'regions' in data:
		regions = data['regions']
		curId = 1
		for regInfo in regions:
			try:	
				dbi.addRegion(curId, newMap, regInfo)
			except KeyError, e:
				raise BadFieldException('badRegions')
			curId += 1
		i = 0
		for reg in newMap.regions:			
			regInfo = data['regions'][i]
			if reg.id in regInfo['adjacent']:
				raise BadFieldException('badRegions')
			dbi.addAll(map(lambda x: Adjacency(reg.id, x, mapId), regInfo['adjacent']))
			i += 1
예제 #5
0
파일: actions.py 프로젝트: NZem/webgame
def act_register(data):
    username = data['username']
    passwd = data['password']
    if not re.match(misc.usrnameRegexp, username, re.I):
        raise BadFieldException('badUsername')
    if not re.match(misc.pwdRegexp, passwd, re.I):
        raise BadFieldException('badPassword')
    dbi.addUnique(User(username, passwd), 'username')
    return {'result': 'ok'}
예제 #6
0
파일: actions.py 프로젝트: NZem/webgame
def act_register(data):
	username = data['username']
	passwd = data['password']
	if  not re.match(misc.usrnameRegexp, username, re.I):
		raise BadFieldException('badUsername')
	if  not re.match(misc.pwdRegexp, passwd, re.I):
		raise BadFieldException('badPassword')
	dbi.addUnique(User(username, passwd), 'username')	
	return {'result': 'ok'}