Beispiel #1
0
 def enter(self, room_id, player_id, info, session):
     #print "player {0} enter room {1}, session {2}".format(player_id, room_id, session.uuid)
     table = self.room_dict.get(room_id)
     #if not table:
         #self.create(room_id,'asdfasdfsaf', player_id,
                     #'{"game_type":163,"max_rounds":6,"play_type":100,"has_zhong":0,"app_id":47,"has_niao":0,"chips":null,"options":604005382,"ren_shu":4,"qiang_gang":0,"bao_gang":0,"hu_pai":1,"create_type":2,"aa":0}')
         #table = self.room_dict.get(room_id)
     if not table:
         # 给前端返回房间不存在的错误
         proto = game_pb2.EnterRoomResponse()
         proto.code = 5001
         send(ENTER_ROOM, proto, session)
         print("room {0} not exist, player {1} enter failed".format(room_id, player_id))
         return
     if table.room_id != room_id:
         self.room_dict[table.room_id] = table
         del self.room_dict[room_id]
         proto = game_pb2.EnterRoomResponse()
         proto.code = 5001
         send(ENTER_ROOM, proto, session)
         table.logger.fatal("room id map error: proto {0} actually {1}".format(room_id, table.room_id))
         return
     player = table.player_dict.get(player_id)
     if player:
         # 服务重启后player没有session
         if player.session:
             player.table.logger.info("player {0} cancel old session {1}".format(player_id, player.session.uuid))
             # SessionMgr().cancel(player.session)
             player.session.close()
         SessionMgr().register(player, session)
         player.table.logger.info("player {0} register new session {1}".format(player_id, player.session.uuid))
         player.reconnect()
         player.online_status(True)
     else:
         table.enter_room(player_id, info, session)
Beispiel #2
0
    def enter_room(self, player_id, info, session):
        if not self.owner_info and player_id == self.owner:
            self.owner_info = info
        proto = game_pb2.EnterRoomResponse()
        proto.room_id = self.room_id
        proto.owner = self.owner

        if len(self.player_dict.keys()) >= self.chairs:
            proto.code = 5002
            send(ENTER_ROOM, proto, session)
            if self.conf.is_aa():
                self.request.aa_refund(player_id, 0)
            self.logger.warn(
                "room {0} is full, player {1} enter failed".format(
                    self.room_id, player_id))
            return

        player = Player(player_id, info, session, self)
        from state.player_state.init import InitState
        player.machine.trigger(InitState())
        seat = -1
        for seat in range(self.chairs):
            if seat in self.seat_dict.keys():
                continue
            break
        player.seat = seat
        self.player_dict[player_id] = player
        self.seat_dict[seat] = player
        proto.code = 1
        proto.kwargs = self.kwargs
        proto.rest_cards = self.cards_total
        for k, v in self.seat_dict.items():
            p = proto.player.add()
            p.seat = k
            p.player = v.uuid
            p.info = v.info
            p.status = player_state_code_map[v.state]
            p.is_online = v.is_online
            p.total_score = v.total
        SessionMgr().register(player, session)

        send(ENTER_ROOM, proto, session)
        # print 'player cnt:', len(self.player_dict.keys())
        proto = game_pb2.EnterRoomOtherResponse()
        proto.code = 1
        proto.player = player_id
        player = self.player_dict[player_id]
        proto.info = player.info
        proto.seat = player.seat

        for i in self.player_dict.values():
            if i.uuid == player_id:
                continue
            send(ENTER_ROOM_OTHER, proto, i.session)
        player.dumps()
        self.dumps()
        self.request.enter_room(player_id)
        self.logger.info("player {0} enter room".format(player_id))
        if self.conf.is_aa():
            self.request.aa_cons(player_id)