Пример #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:
            bret = mapdata.activate(bid)
            if bret:
                tmpgen = mapdata.getGenAll()
                userstruct.write_redis_dict(userid,
                                            {'mapdata': mapdata.tojson()})
                return {'ret': 1, 'data': tmpgen}
            else:
                return {'ret': 0, 'data': {'des': 'input error'}}
    return {'ret': 0, 'data': {}}
Пример #2
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'}}
Пример #3
0
def handle(param):

    ret = 0

    userid = param.get('userid')
    skey = param.get('skey')
    logger.info("%s,%s", userid, skey)

    if userid and skey:
        tmp = userstruct.read_redis(userid)
        if not tmp or tmp.skey != skey:
            return {'ret': 0, 'data': {'des': 'skey error'}}

        userstruct.write_redis_dict(tmp.userid, {})

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

    return {'ret': 0, 'data': {}}
Пример #4
0
def handle(param):

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

	if userid and skey:
		tmp = userstruct.read_redis(userid)

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

		#myself
		if not otherid:		
			mapdata = tmp.getmap()
			logger.debug('%s, %s', mapdata, type(mapdata))
			if not mapdata:
				mapdata = mapstruct.MapInfo()
				userstruct.write_redis_dict(userid, {'mapdata': mapdata.tojson()})

			logger.debug('%s, %s', mapdata, type(mapdata))
			return {'ret':1, 'data':mapdata.todict()}
		#other	
		else:
			other = userstruct.read_user(otherid)
			if not other:
				return {'ret':0, 'data':{'des': 'otherid error'}}

			mapdata = other.getmap()
			logger.debug('%s, %s', mapdata, type(mapdata))
			if not mapdata:
				mapdata = mapstruct.MapInfo()
				userstruct.write_redis_dict(otherid, {'mapdata': mapdata.tojson()})

			logger.debug('%s, %s', mapdata, type(mapdata))
			return {'ret':1, 'data':mapdata.todict()}


	return {'ret':ret, 'data':{'des': 'skey error'}}