Esempio n. 1
0
    def dismiss_room(self, vote=True):

        # 如果是投票解散房间则进入大结算,否则直接推送房主解散命令

        def _dismiss():
            # 弹出大结算
            from state.table_state.settle_for_room import SettleForRoomState
            self.machine.trigger(SettleForRoomState())
            self.request.load_minus()

        if vote and self.state != "InitState":
            # 房间内游戏中投票解散
            _dismiss()

        else:
            # 0-没开始解散 1-投票 2-外部解散或者游戏进行中房主解散
            vote_flag = 2
            if vote:
                # 房间内投票
                vote_flag = 1
            else:
                if self.state == "InitState":
                    # 房主在游戏未开始时解散
                    vote_flag = 0
            if vote_flag == 2:
                # 到这说明游戏在进行中房主解散
                # 在游戏内部已经做了限制不会走到这里
                # 在游戏外部如果游戏进行中不让解散
                # 这里直接返回吧
                # self.dismiss_flag = 2
                # _dismiss()
                return
            else:

                # 游戏未开始时和游戏外房主解散直接返回0,2。
                # 0代表外开始时解散,2代表外部解散或者游戏进行中房主解散
                # 直接返回一个flag就完事了
                proto = game_pb2.DismissRoomResponse()
                proto.code = 1
                proto.flag = vote_flag
                for k, v in self.player_dict.items():
                    send(DISMISS_ROOM, proto, v.session)
                # 这个位置没-1导致房间数量一直上升
                if vote_flag == 1:
                    self.request.load_minus()
        self.logger.info("room {0} dismiss".format(self.room_id))
        from logic.table_manager import TableMgr
        self.request.dismiss_room(self)
        TableMgr().dismiss(self.room_id)
        for player in self.player_dict.values():
            try:
                player.session.close()
            except Exception:
                pass
            player.delete()

        self.delete()
Esempio n. 2
0
    def dismiss_room(self, vote=True):
        # 如果是投票解散房间则进入大结算,否则直接推送房主解散命令
        def _dismiss():
            from state.table_state.settle_for_room import SettleForRoomState
            self.machine.trigger(SettleForRoomState())
            self.request.load_minus()

        if vote and self.state != "InitState":
            _dismiss()
        else:
            proto = game_pb2.DismissRoomResponse()
            proto.code = 1
            # 0-没开始解散 1-投票 2-游戏内解散
            vote_flag = 2
            if vote:
                vote_flag = 1
            else:
                if self.state == "InitState":
                    vote_flag = 0
            proto.flag = vote_flag
            for k, v in self.player_dict.items():
                send(DISMISS_ROOM, proto, v.session)

            if self.state != "InitState":
                self.dismiss_flag = 2
                _dismiss()

        self.logger.info("room {0} dismiss".format(self.room_id))
        from logic.table_manager import TableMgr
        self.request.dismiss_room(self)
        TableMgr().dismiss(self.room_id)
        for player in self.player_dict.values():
            try:
                player.session.close()
            except Exception:
                pass
            player.delete()

        self.delete()
Esempio n. 3
0
 def dismiss_room(self):
     # 解散房间不重复响应
     if self.table.dismiss_state:
         return
     if self.table.state == "InitState":
         # 房间未开局直接由房主解散
         if self.uuid == self.table.owner:
             self.table.dismiss_room(False)
         else:
             proto = game_pb2.DismissRoomResponse()
             proto.code = 5003
             send(DISMISS_ROOM, proto, self.session)
     else:
         # 如果是房主则直接解散
         if self.uuid == self.table.owner:
             self.table.dismiss_room(False)
             return
         # 房间已开局则直接发起投票
         self.table.dismiss_state = True
         self.table.dismiss_sponsor = self.uuid
         self.table.dismiss_time = time.time()
         self.vote_state = True
         self.dumps()
         proto = game_pb2.SponsorVoteResponse()
         proto.room_id = self.table.room_id
         proto.sponsor = self.table.dismiss_sponsor
         proto.expire_seconds = dismiss_delay
         for player in self.table.player_dict.values():
             send(SPONSOR_VOTE, proto, player.session)
             if player.uuid == self.uuid:
                 continue
             proto_vote = game_pb2.PlayerVoteRequest()
             proto_vote.flag = True
             player.vote_timer = IOLoop().instance().add_timeout(
                 self.table.dismiss_time + dismiss_delay, player.vote,
                 proto_vote)
         self.table.logger.info("player {0} sponsor dismiss room".format(
             self.uuid))