Exemplo n.º 1
0
def handle(param):

    ret = 0
    userid = param.get('userid')
    skey = param.get('skey')
    bid = param.get('bid')
    if userid and skey and bid != None:
        tmp = userstruct.read_redis(userid)

        if not tmp or tmp.skey != skey:
            return {'ret': 0, 'data': {'des': 'skey error'}}

        mapdata = tmp.getmap()
        logger.info(mapdata)

        if mapdata:
            upoint = mapdata.getUpgrade(bid)
            if upoint > 0 and tmp.gamepoint > upoint and mapdata.upgrade(bid):

                logger.info('change point:%s,%s', tmp.gamepoint,
                            tmp.gamepoint - upoint)

                rds = rdsmanager.get_client(userid)
                rkey = 'hashuser:%s' % userid
                pipe = rds.pipeline()
                pipe.hset(rkey, 'mapdata', mapdata.tojson())
                pipe.hincrby(rkey, 'gamepoint', -upoint)
                pipe.execute()

                userstruct.write_redis_updateuser(userid)

                return {'ret': 1, 'data': mapdata.todict()}

    return {'ret': ret, 'data': {'des': 'input error'}}
Exemplo n.º 2
0
def handle(param):

	ret = 0
	userid = param.get('userid')
	skey = param.get('skey')
	bid = param.get('bid')
	if userid and skey and bid != None:
		tmp = userstruct.read_redis(userid)

		if not tmp or tmp.skey != skey: 
			return {'ret':0, 'data':{'des': 'skey error'}}

		mapdata = tmp.getmap()
		logger.info('mapdata:%s', mapdata)

		if mapdata:
			gentmp = mapdata.getGen(bid)

			logger.info('gentmp:%s', gentmp)
			if gentmp['genflag']:
				mapdata.updatetime[bid] = time.time()


				if gentmp['buildstate'] == 2:
					mapdata.buildstate[bid] = 0

				logger.info('%s,%s', gentmp['buildstate'], mapdata.buildstate[bid])

				mapdata.delAttack(bid)

				logger.info('after:%s', mapdata)

				rds = rdsmanager.get_client(userid)
				rkey = 'hashuser:%s' % userid
				pipe = rds.pipeline()
				pipe.hset(rkey, 'mapdata', mapdata.tojson())
				pipe.hincrby(rkey, 'gamepoint', gentmp['gen'])
				pipe.hincrby(rkey, 'exp', gentmp['gen'])
				pipe.execute()

				userstruct.write_redis_updateuser(userid)

				logger.info('mapdata:%s', mapdata)

				return {'ret':1, 'data':gentmp}
			
			return {'ret':1, 'data':gentmp}
		
	return {'ret':ret, 'data':{}}
Exemplo n.º 3
0
def handle(param):

    ret = 0
    userid = param.get('userid')
    skey = param.get('skey')

    attackuserid = param.get('attackuserid')
    attackid = param.get('attackid')
    bid = param.get('attackbid')
    if userid and skey and attackuserid and attackid and bid != None:
        tmp = userstruct.read_redis(userid)

        if not tmp or tmp.skey != skey:
            return {'ret': 0, 'data': {'des': 'skey error'}}

        if userid == attackuserid:
            return {'ret': 0, 'data': {'des': 'not can attac youself'}}

        apoint = mapstruct.getAttacPoint(attackid)
        if apoint <= 0:
            return {'ret': 0, 'data': {'des': 'attackid input error'}}

        if tmp.gamepoint < apoint:
            return {'ret': 0, 'data': {'des': 'you point not enough'}}

        attackuser = userstruct.read_user(attackuserid)
        if not attackuser:
            return {'ret': 0, 'data': {'des': 'attackbid error'}}

        mapdata = attackuser.getmap()
        aret = mapdata.addAttack(bid, attackid)
        if not aret:
            return {'ret': 0, 'data': {'des': 'aret error'}}

        logger.info('mapdata:%s, apoint:%s', mapdata, apoint)

        userstruct.write_redis_dict(attackuserid,
                                    {'mapdata': mapdata.tojson()})

        rds = rdsmanager.get_client(userid)
        rkey = 'hashuser:%s' % userid
        rds.hincrby(rkey, 'gamepoint', -apoint)

        return {'ret': 1, 'data': {'des': 'attac ok'}}

    return {'ret': 0, 'data': {'des': 'input error'}}
Exemplo n.º 4
0
def handle(param):

    ret = 0
    userid = param.get('userid')
    skey = param.get('skey')

    guardid = param.get('guardid')
    bid = param.get('guardbid')

    if userid and skey and guardid and bid != None:
        tmp = userstruct.read_redis(userid)

        if not tmp or tmp.skey != skey:
            return {'ret': 0, 'data': {'des': 'skey error'}}

        apoint = mapstruct.getGuardPoint(guardid)
        if apoint <= 0:
            return {'ret': 0, 'data': {'des': 'attackid input error'}}

        if tmp.gamepoint < apoint:
            return {'ret': 0, 'data': {'des': 'you point not enough'}}

        mapdata = tmp.getmap()
        aret = mapdata.guard(bid, guardid)
        if not aret:
            return {'ret': 0, 'data': {'des': 'aret error'}}

        logger.info('mapdata:%s, apoint:%s', mapdata, apoint)

        rds = rdsmanager.get_client(userid)
        rkey = 'hashuser:%s' % userid
        pipe = rds.pipeline()
        pipe.hset(rkey, 'mapdata', mapdata.tojson())
        pipe.hincrby(rkey, 'gamepoint', -apoint)
        pipe.execute()

        userstruct.write_redis_updateuser(userid)

        return {'ret': 1, 'data': {'des': 'attac ok'}}

    return {'ret': 0, 'data': {'des': 'input error'}}