Ejemplo n.º 1
0
def execute(userId, message, messageHandle):
    redis = gl.get_v("redis")
    redis.lock("match")
    if redis.exists(str(userId) + "_room"):
        reconnection_cmd.execute(userId, message, messageHandle)
        redis.unlock("match")
        return
    reqApplyEnterMatch = ReqApplyEnterMatch()
    reqApplyEnterMatch.ParseFromString(message.data)
    try:
        if redis.exists("7_rooms"):
            rooms = redis.get("7_rooms")
        else:
            rooms = []
        join = False
        for r in rooms:
            if redis.exists("room_" + str(r)):
                redis.lock("lockroom_" + str(r))
                room = redis.getobj("room_" + str(r))
                if room.roomNo != reqApplyEnterMatch.reject and room.matchLevel == reqApplyEnterMatch.level and (
                        room.count == -1 or 0 < len(room.seatNos)):
                    join_match_room_cmd.execute(userId, message, messageHandle,
                                                room)
                    redis.unlock("lockroom_" + str(r))
                    join = True
                    break
                redis.unlock("lockroom_" + str(r))
        if not join:
            create_match_room_cmd.execute(userId, message, messageHandle)
    except:
        print traceback.print_exc()
    redis.unlock("match")
Ejemplo n.º 2
0
def execute(userId, message, messageHandle, room):
    redis = gl.get_v("redis")
    if redis.exists(str(userId) + "_room"):
        return

    reqApplyEnterMatch = ReqApplyEnterMatch()
    reqApplyEnterMatch.ParseFromString(message.data)

    recMatchGame = RecMatchGame()
    recMatchGame.allocId = 2
    recMatchGame.level = reqApplyEnterMatch.level

    account = data_account.query_account_by_id(None, userId)
    if account.gold < room.inScore:
        recMatchGame.state = 1
        messageHandle.send_to_gateway(GAME_SVR_MATCH, recMatchGame)
        return

    if len(room.seatNos) == 0:
        recMatchGame.state = 3
        messageHandle.send_to_gateway(GAME_SVR_MATCH, recMatchGame)
        return

    messageHandle.send_to_gateway(GAME_SVR_MATCH, recMatchGame)

    if room.getSeatByUserId(userId) is None:
        douniuSeat = DouniuSeat()
        douniuSeat.seatNo = room.seatNos[0]
        room.seatNos.remove(room.seatNos[0])
        douniuSeat.userId = account.id
        douniuSeat.account = account.account_name
        douniuSeat.createDate = account.create_time
        douniuSeat.nickname = account.nick_name
        douniuSeat.head = account.head_url
        douniuSeat.sex = account.sex
        douniuSeat.score = int(account.gold.quantize(Decimal('0')))
        douniuSeat.ip = account.last_address
        douniuSeat.gpsInfo = ""
        douniuSeat.total_count = account.total_count
        douniuSeat.introduce = account.introduce
        douniuSeat.phone = account.phone
        douniuSeat.level = account.level
        douniuSeat.experience = account.experience
        douniuSeat.intoDate = int(time.time())
        douniuSeat.guanzhan = room.gameStatus > GameStatus.WAITING
        room.seats.append(douniuSeat)

        threading.Thread(target=ready_timeout.execute,
                         args=(room.gameCount, room.roomNo, messageHandle,
                               userId, douniuSeat.intoDate),
                         name='ready_timeout').start()  # 线程对象.

    room.recUpdateGameInfo(messageHandle)
    room.recUpdateScore(messageHandle, 0)
    if room.gameStatus == GameStatus.PLAYING:
        room.recReEnterGameInfo(messageHandle, userId)
    redis.set(str(userId) + "_room", room.roomNo)
    room.save(redis)
Ejemplo n.º 3
0
def execute(userId, message, messageHandle, room):
    redis = gl.get_v("redis")
    if redis.exists(str(userId) + "_room"):
        return

    account = data_account.query_account_by_id(None, userId)

    reqApplyEnterMatch = ReqApplyEnterMatch()
    reqApplyEnterMatch.ParseFromString(message.data)

    recMatchGame = RecMatchGame()
    recMatchGame.allocId = 7
    recMatchGame.level = reqApplyEnterMatch.level

    messageHandle.send_to_gateway(GAME_SVR_MATCH, recMatchGame)

    if room.getWatchSeatByUserId(userId) is None:
        tuitongziSeat = TuitongziSeat()
        tuitongziSeat.seatNo = 0
        tuitongziSeat.userId = account.id
        tuitongziSeat.account = account.account_name
        tuitongziSeat.createDate = account.create_time
        tuitongziSeat.nickname = account.nick_name
        tuitongziSeat.head = account.head_url
        tuitongziSeat.sex = account.sex
        tuitongziSeat.score = int(account.gold.quantize(Decimal('0')))
        tuitongziSeat.ip = account.last_address
        tuitongziSeat.gpsInfo = ""
        tuitongziSeat.total_count = account.total_count
        tuitongziSeat.introduce = account.introduce
        tuitongziSeat.phone = account.phone
        tuitongziSeat.level = account.level
        tuitongziSeat.experience = account.experience
        tuitongziSeat.intoDate = int(time.time())
        room.watchSeats.append(tuitongziSeat)
    room.sendBetScore(messageHandle)

    room.recUpdateGameInfo(messageHandle)
    room.recUpdateScore(messageHandle, userId)
    room.updateBankerList(messageHandle, userId)
    room.updateWatchSize(messageHandle, 0)
    room.updateTrend(messageHandle, userId)
    if 0 == room.gameStatus == GameStatus.PLAYING or room.started:
        room.recReEnterGameInfo(messageHandle, userId)
        if room.gameStatus == GameStatus.PLAYING:
            room.executeAsk(messageHandle, userId, 2)
        else:
            room.executeAsk(messageHandle, userId, 1)
    redis.set(str(userId) + "_room", room.roomNo)
    room.save(redis)
Ejemplo n.º 4
0
def execute(userId, message, messageHandle):
    redis = gl.get_v("redis")
    if redis.exists(str(userId) + "_room"):
        return
    reqApplyEnterMatch = ReqApplyEnterMatch()
    reqApplyEnterMatch.ParseFromString(message.data)
    account = data_account.query_account_by_id(None, userId)
    match_infos = gl.get_v("match_info")
    for match_info in match_infos:
        m = MatchInfo()
        m.__dict__ = match_info
        if m.level == reqApplyEnterMatch.level:
            if m.inScore <= account.gold:
                room = DouniuRoom(0, m.playerNum, 26 if m.level > 20 else 24,
                                  m.level, m.baseScore, m.inScore,
                                  m.leaveScore, 0, 1)
                redis.lock("lock2_rooms")
                try:
                    if redis.exists("2_rooms"):
                        rooms = redis.get("2_rooms")
                    else:
                        rooms = []
                    roomNo = random.randint(100000, 999999)
                    while roomNo in rooms:
                        roomNo = random.randint(100000, 999999)
                    rooms.append(roomNo)
                    room.roomNo = roomNo
                    room.save(redis)
                    redis.set(str(roomNo) + "_gameId", 2)
                    redis.set("2_rooms", rooms)
                    redis.lock("lockroom_" + str(roomNo))
                    join_match_room_cmd.execute(userId, message, messageHandle,
                                                room)
                    redis.unlock("lockroom_" + str(roomNo))
                except:
                    traceback.print_exc()
                redis.unlock("lock2_rooms")
                return
            else:
                recMatchGame = RecMatchGame()
                recMatchGame.allocId = 2
                recMatchGame.level = reqApplyEnterMatch.level
                recMatchGame.state = 1
                messageHandle.send_to_gateway(GAME_SVR_MATCH, recMatchGame)
            break
Ejemplo n.º 5
0
def execute(userId, message, messageHandle):
    redis = gl.get_v("redis")
    if redis.exists(str(userId) + "_room"):
        return
    reqApplyEnterMatch = ReqApplyEnterMatch()
    reqApplyEnterMatch.ParseFromString(message.data)
    account = data_account.query_account_by_id(None, userId)
    match_infos = gl.get_v("match_info")
    for match_info in match_infos:
        m = MatchInfo()
        m.__dict__ = match_info
        if m.level == reqApplyEnterMatch.level:
            if m.inScore <= account.gold:
                room = NiuniuRoom(0, m.playerNum, 0, m.level, m.baseScore,
                                  m.inScore, m.leaveScore)
                redis.lock("lock10_rooms")
                try:
                    if redis.exists("10_rooms"):
                        rooms = redis.get("10_rooms")
                    else:
                        rooms = []
                    roomNo = random.randint(100000, 999999)
                    while roomNo in rooms:
                        roomNo = random.randint(100000, 999999)
                    rooms.append(roomNo)
                    room.roomNo = roomNo
                    room.save(redis)
                    redis.set(str(roomNo) + "_gameId", 10)
                    redis.set("10_rooms", rooms)
                    redis.lock("lockroom_" + str(roomNo))
                    join_match_room_cmd.execute(userId, message, messageHandle,
                                                room)
                    gamestart_cmd.execute(room, messageHandle)
                    room.save(redis)
                    redis.unlock("lockroom_" + str(roomNo))
                except:
                    traceback.print_exc()
                redis.unlock("lock10_rooms")
                return
            break
Ejemplo n.º 6
0
 def intoRoom(self):
     reqApplyEnterMatch = ReqApplyEnterMatch()
     reqApplyEnterMatch.allocId = self.allocId
     reqApplyEnterMatch.level = 11
     self.send_data(APPLY_ENTER_MATCH, reqApplyEnterMatch)