Example #1
0
def __initializeRooms(gdatas):
    '''
    初始化所有的房间对象
    '''
    if _DEBUG:
        debug('initializeRooms begin')
    from poker.entity.game.rooms import getInstance
    srvid = gdata.serverId()
    roomids = gdata.srvIdRoomIdListMap().get(srvid, None)
    if roomids:
        tyrooms = {}
        gdatas['tyrooms.instance.dict'] = tyrooms
        allrooms = gdata.roomIdDefineMap()
        for roomid in roomids:
            roomdefine = allrooms[roomid]
            roomins = getInstance(roomdefine)
            assert (isinstance(roomins, TYRoom))
            tyrooms[roomid] = roomins
        gdatas['tyrooms.instance.dict'] = makeReadonly(tyrooms)
    if _DEBUG:
        debug('initializeRooms end')
Example #2
0
def __initializeRooms(gdatas):
    '''
    初始化所有的房间对象
    '''
    if _DEBUG:
        debug('initializeRooms begin')
    from poker.entity.game.rooms import getInstance
    srvid = gdata.serverId()
    roomids = gdata.srvIdRoomIdListMap().get(srvid, None)
    if roomids:
        tyrooms = {}
        gdatas['tyrooms.instance.dict'] = tyrooms
        allrooms = gdata.roomIdDefineMap()
        for roomid in roomids:
            roomdefine = allrooms[roomid]
            roomins = getInstance(roomdefine)
            assert (isinstance(roomins, TYRoom))
            tyrooms[roomid] = roomins
        gdatas['tyrooms.instance.dict'] = makeReadonly(tyrooms)
    if _DEBUG:
        debug('initializeRooms end')
Example #3
0
def _loadTYGames(gdatas):
    '''
    装载挂接的游戏PLUGIN, 挂接多少PLUGIN由配置: poker:global中的game_packages决定
    '''
    if _DEBUG:
        debug('loadTYGames begin')
    tygames = {}
    gdatas['tygame.instance.dict'] = tygames
    gdatas['tygame.instance.ids'] = set(tygames.keys())
    tygamelist = []
    mpkgs = set()
    for pkg in gdata.gamePackages():
        if _DEBUG:
            debug('load TYGame package:', pkg)
        assert (not pkg in mpkgs)
        mpkgs.add(pkg)

        initfun = None
        exec 'from %s.game import getInstance as initfun' % (pkg)
        assert (callable(initfun))
        tygame = initfun()

        assert (isinstance(tygame, TYGame))
        tygame._packageName = pkg  # hall、dizhu、texas、

        gameid = tygame.gameId()  # 44
        assert (isinstance(gameid, int))
        assert (gameid > 0 and gameid <= 9999)
        assert (not gameid in tygames)
        tygames[gameid] = tygame  # 44: getInstance() 各种游戏插件的实例
        tygamelist.append(tygame)  # 各种插件游戏实例的激活
        if _DEBUG:
            debug('load TYGame of ', gameid, tygame)

    tygamelist.sort(key=lambda x: x.gameId(), reverse=True)
    gdatas['tygame.instance.ids'] = set(tygames.keys())
    gdatas['tygame.instance.dict'] = makeReadonly(tygames)
    if _DEBUG:
        debug('loadTYGames end')
    return tygamelist
Example #4
0
def __loadTYGames(gdatas):
    '''
    装载挂接的游戏PLUGIN, 挂接多少PLUGIN由配置: poker:global中的game_packages决定
    '''
    if _DEBUG:
        debug('loadTYGames begin')
    tygames = {}
    gdatas['tygame.instance.dict'] = tygames
    gdatas['tygame.instance.ids'] = set(tygames.keys())
    tygamelist = []
    mpkgs = set()
    for pkg in gdata.gamePackages():
        if _DEBUG:
            debug('load TYGame package :', pkg)
        assert (not pkg in mpkgs)
        mpkgs.add(pkg)

        initfun = None
        exec 'from %s.game import getInstance as initfun' % (pkg)
        assert (callable(initfun))
        tygame = initfun()

        assert (isinstance(tygame, TYGame))
        tygame._packageName = pkg

        gameid = tygame.gameId()
        assert (isinstance(gameid, int))
        assert (gameid > 0 and gameid <= 9999)
        assert (not gameid in tygames)
        tygames[gameid] = tygame
        tygamelist.append(tygame)
        if _DEBUG:
            debug('load TYGame of ', gameid, tygame)

    gdatas['tygame.instance.ids'] = set(tygames.keys())
    gdatas['tygame.instance.dict'] = makeReadonly(tygames)
    if _DEBUG:
        debug('loadTYGames end')
    return tygamelist
Example #5
0
def _initializeRooms(gdatas):
    '''
    初始化所有的房间对象
    '''
    if _DEBUG:
        debug('initializeRooms begin')
    from poker.entity.game.rooms import getInstance  # 获取房间实例
    srvid = gdata.serverId()
    roomids = gdata.srvIdRoomIdListMap().get(srvid, None)  # 获取所有房间ids
    if _DEBUG:
        debug('initializeRooms srvid=', srvid, 'roomids=', roomids)
    if roomids:
        tyrooms = {}
        gdatas['tyrooms.instance.dict'] = tyrooms  # 房间实例dict
        allrooms = gdata.roomIdDefineMap()  # 房间定义的映射
        if _DEBUG:
            debug('initializeRooms allroomsid=', allrooms.keys())
        for roomid in roomids:
            roomdefine = allrooms[roomid]
            roomins = getInstance(roomdefine)  # 房间实例子
            tyrooms[roomid] = roomins  # 房间id: 实例
        gdatas['tyrooms.instance.dict'] = makeReadonly(tyrooms)
    if _DEBUG:
        debug('initializeRooms end')
Example #6
0
def _loadRoomDefines(gdatas):
    '''
    需要整理一个全局的 serverid-roomid-roombaseinfo的大集合
    取得server_rooms.json的配置内容, key为服务ID, value为房间配置内容
    '''
    if _DEBUG:
        debug('loadRoomDefines begin')
    # 首先整理进程ID, 展开多房间进程的进程ID
    srvid_rooms_map = {}
    srvidmap = {}
    allserver = gdata.allServersMap()
    for k in allserver:
        srvid_rooms_map[k] = []
        if k.find('-') > 0:
            assert (k.find(gdata.SRV_TYPE_ROOM) == 0
                    or k.find(gdata.SRV_TYPE_TABLE) == 0)
            tail = '000'
            if k.find(gdata.SRV_TYPE_TABLE) == 0:
                tail = '001'
            ks = k.split('-')
            ps = int(ks[1])
            pe = int(ks[2])
            assert (ps > 0 and ps < 999)
            assert (pe > 0 and pe < 999)
            assert (ps < pe)
            for x in xrange(ps, pe + 1):
                playid = '%03d' % (x)
                sid = ks[0] + playid + ks[3]
                srvidmap[sid + tail] = k
        else:
            if k.find(gdata.SRV_TYPE_ROOM) == 0:
                srvidmap[k + '000'] = k
            if k.find(gdata.SRV_TYPE_TABLE) == 0:
                srvidmap[k] = k

    clsRoomDefine = namedtuple('RoomDefine', [
        'bigRoomId', 'parentId', 'roomId', 'gameId', 'configId', 'controlId',
        'shadowId', 'serverId', 'tableCount', 'shadowRoomIds', 'configure'
    ])

    roomid_define_map = {}
    big_roomids_map = {}
    gameid_big_roomids_map = {}
    # 取得说有挂接的游戏ID, 取得对应GAMEID的房间配置
    gameids = gdata.games().keys()
    if _DEBUG:
        debug('the game ids=', gameids)
    for gid in gameids:
        gameid_big_roomids_map[gid] = []
        roomdict = ftcon.getConfNoCache('GET', 'game:' + str(gid) + ':room:0')
        if roomdict:
            roomdict = strutil.loads(roomdict)
        if not isinstance(roomdict, dict):
            if _DEBUG:
                debug('the game of', gid, 'have no room !')
            continue
        for roomIdStr, configure in roomdict.items():
            bigRoomId = int(roomIdStr)
            gameid, configid = strutil.parseBigRoomId(bigRoomId)

            configure = _auto_change_room_count(configure)
            controlServerCount = int(configure['controlServerCount'])
            controlTableCount = int(configure['controlTableCount'])
            gameServerCount = int(configure['gameServerCount'])
            gameTableCount = int(configure['gameTableCount'])

            assert (gameid == gid)
            assert (configid > 0
                    and configid < 999), '%s,%s' % (roomIdStr, str(configure))
            assert (controlServerCount > 0
                    and controlServerCount < 9), '%s,%s' % (roomIdStr,
                                                            str(configure))
            assert (controlTableCount >= 0
                    and controlTableCount < 9999), '%s,%s' % (roomIdStr,
                                                              str(configure))
            assert (gameServerCount >= 0
                    and gameServerCount < 999), '%s,%s' % (roomIdStr,
                                                           str(configure))
            assert (gameTableCount > 0
                    and gameTableCount < 9999), '%s,%s' % (roomIdStr,
                                                           str(configure))
            assert (not bigRoomId in big_roomids_map)

            extconfig = ftcon.getConfNoCache(
                'GET', 'game:' + str(gid) + ':room:' + str(bigRoomId))
            if extconfig:
                extconfig = strutil.loads(extconfig)
            if isinstance(extconfig, dict):
                configure.update(extconfig)
            gameid_big_roomids_map[gid].append(bigRoomId)
            big_roomids_map[bigRoomId] = []
            for m in xrange(controlServerCount):
                # 自动计算controlId, 重1开始
                controlId = m + 1
                controlRoomId = (bigRoomId * 10 + controlId) * 1000
                shadowRooms = []
                assert (not controlRoomId in big_roomids_map)
                assert (not controlRoomId in roomid_define_map)
                for n in xrange(gameServerCount):
                    # 自动计算shadowId, 重1开始, 此处为桌子运行的房间
                    shadowId = n + 1
                    shadowRoomId = controlRoomId + shadowId
                    assert (not shadowRoomId in roomid_define_map)
                    processId = gdata.SRV_TYPE_TABLE + str(shadowRoomId)
                    serverId = srvidmap[processId]
                    srvid_rooms_map[serverId].append(shadowRoomId)
                    shadowRooms.append(shadowRoomId)
                    roomid_define_map[shadowRoomId] = clsRoomDefine(
                        bigRoomId, controlRoomId, shadowRoomId, gameid,
                        configid, controlId, shadowId, serverId,
                        gameTableCount, tuple([]), configure)
                    if _DEBUG:
                        debug('load room define->bigRoomId=', bigRoomId,
                              'parentId=', controlRoomId, 'roomId=',
                              shadowRoomId, 'gameId=', gameid, 'configId=',
                              configid, 'controlId=', controlId, 'shadowId=',
                              shadowId, 'tableCount=', gameTableCount,
                              'serverId=', serverId)

                # 此处为控制房间
                processId = gdata.SRV_TYPE_ROOM + str(controlRoomId)
                serverId = srvidmap[processId]
                srvid_rooms_map[serverId].append(controlRoomId)
                big_roomids_map[bigRoomId].append(controlRoomId)
                roomid_define_map[controlRoomId] = clsRoomDefine(
                    bigRoomId, 0, controlRoomId, gameid, configid,
                    controlId, 0, serverId, controlTableCount,
                    tuple(shadowRooms), configure)

                if _DEBUG:
                    debug('load room define->bigRoomId=', bigRoomId,
                          'parentId=', 0, 'roomId=', controlRoomId, 'gameId=',
                          gameid, 'configId=', configid, 'controlId=',
                          controlId, 'shadowId=', 0, 'tableCount=',
                          controlTableCount, 'serverId=', serverId,
                          'shadowRooms=', shadowRooms)
        gameid_big_roomids_map[gid].sort()

    # 整理打印配置的内容
    if _DEBUG:
        debug('find big roomids=', big_roomids_map.keys())
    for k, v in big_roomids_map.items():
        if _DEBUG:
            debug('find big room id ', k, 'has childs:', v)
    for k in srvid_rooms_map.keys():
        if not srvid_rooms_map[k]:
            del srvid_rooms_map[k]
        else:
            if _DEBUG:
                debug('find server', k, 'has roomids:', srvid_rooms_map[k])

    gdatas['srvid_roomid_map'] = makeReadonly(srvid_rooms_map)
    gdatas['roomid_define_map'] = makeReadonly(roomid_define_map)
    gdatas['big_roomids_map'] = makeReadonly(big_roomids_map)
    gdatas['gameid_big_roomids_map'] = makeReadonly(gameid_big_roomids_map)
    if _DEBUG:
        debug('loadRoomDefines end')
Example #7
0
def __loadRoomDefines(gdatas):
    '''
    需要整理一个全局的 serverid-roomid-roombaseinfo的大集合
    取得server_rooms.json的配置内容, key为服务ID, value为房间配置内容
    '''
    if _DEBUG:
        debug('loadRoomDefines begin')
    # 首先整理进程ID, 展开多房间进程的进程ID
    srvid_rooms_map = {}
    srvidmap = {}
    allserver = gdata.allServersMap()
    for k in allserver:
        srvid_rooms_map[k] = []
        if k.find('-') > 0:
            assert (k.find(gdata.SRV_TYPE_ROOM) == 0 or k.find(gdata.SRV_TYPE_TABLE) == 0)
            tail = '000'
            if k.find(gdata.SRV_TYPE_TABLE) == 0:
                tail = '001'
            ks = k.split('-')
            ps = int(ks[1])
            pe = int(ks[2])
            assert (ps > 0 and ps < 999)
            assert (pe > 0 and pe < 999)
            assert (ps < pe)
            for x in xrange(ps, pe + 1):
                playid = '%03d' % (x)
                sid = ks[0] + playid + ks[3]
                srvidmap[sid + tail] = k
        else:
            if k.find(gdata.SRV_TYPE_ROOM) == 0:
                srvidmap[k + '000'] = k
            if k.find(gdata.SRV_TYPE_TABLE) == 0:
                srvidmap[k] = k

    clsRoomDefine = namedtuple('RoomDefine', ['bigRoomId', 'parentId', 'roomId', 'gameId',
                                              'configId', 'controlId', 'shadowId', 'serverId',
                                              'tableCount', 'shadowRoomIds', 'configure'])
    roomid_define_map = {}
    big_roomids_map = {}
    gameid_big_roomids_map = {}
    # 取得说有挂接的游戏ID, 取得对应GAMEID的房间配置
    gameids = gdata.games().keys()
    if _DEBUG:
        debug('the game ids=', gameids)
    for gid in gameids:
        gameid_big_roomids_map[gid] = []
        roomdict = ftcon.getConfNoCache('GET', 'game:' + str(gid) + ':room:0')
        if roomdict:
            roomdict = strutil.loads(roomdict)
        if not isinstance(roomdict, dict):
            if _DEBUG:
                debug('the game of', gid, 'have no room !')
            continue
        for roomIdStr, configure in roomdict.items():
            bigRoomId = int(roomIdStr)
            gameid, configid = strutil.parseBigRoomId(bigRoomId)

            configure = __auto_change_room_count(configure)
            controlServerCount = int(configure['controlServerCount'])
            controlTableCount = int(configure['controlTableCount'])
            gameServerCount = int(configure['gameServerCount'])
            gameTableCount = int(configure['gameTableCount'])

            assert (gameid == gid)
            assert (configid > 0 and configid < 999), '%s,%s' % (roomIdStr, str(configure))
            assert (controlServerCount > 0 and controlServerCount < 9), '%s,%s' % (roomIdStr, str(configure))
            assert (controlTableCount >= 0 and controlTableCount < 9999), '%s,%s' % (roomIdStr, str(configure))
            assert (gameServerCount >= 0 and gameServerCount < 999), '%s,%s' % (roomIdStr, str(configure))
            assert (gameTableCount > 0 and gameTableCount < 9999), '%s,%s' % (roomIdStr, str(configure))
            assert (not bigRoomId in big_roomids_map)

            extconfig = ftcon.getConfNoCache('GET', 'game:' + str(gid) + ':room:' + str(bigRoomId))
            if extconfig:
                extconfig = strutil.loads(extconfig)
            if isinstance(extconfig, dict):
                configure.update(extconfig)

            gameid_big_roomids_map[gid].append(bigRoomId)
            big_roomids_map[bigRoomId] = []
            for m in xrange(controlServerCount):
                # 自动计算controlId, 重1开始
                controlId = m + 1
                controlRoomId = (bigRoomId * 10 + controlId) * 1000
                shadowRooms = []
                assert (not controlRoomId in big_roomids_map)
                assert (not controlRoomId in roomid_define_map)
                for n in xrange(gameServerCount):
                    # 自动计算shadowId, 重1开始, 此处为桌子运行的房间
                    shadowId = n + 1
                    shadowRoomId = controlRoomId + shadowId
                    assert (not shadowRoomId in roomid_define_map)
                    processId = gdata.SRV_TYPE_TABLE + str(shadowRoomId)
                    serverId = srvidmap[processId]
                    srvid_rooms_map[serverId].append(shadowRoomId)
                    shadowRooms.append(shadowRoomId)
                    roomid_define_map[shadowRoomId] = clsRoomDefine(bigRoomId, controlRoomId, shadowRoomId, gameid,
                                                                    configid, controlId, shadowId, serverId,
                                                                    gameTableCount, tuple([]), configure)
                    if _DEBUG:
                        debug('load room define->bigRoomId=', bigRoomId, 'parentId=', controlRoomId,
                              'roomId=', shadowRoomId, 'gameId=', gameid, 'configId=', configid,
                              'controlId=', controlId, 'shadowId=', shadowId, 'tableCount=', gameTableCount,
                              'serverId=', serverId)

                # 此处为控制房间
                processId = gdata.SRV_TYPE_ROOM + str(controlRoomId)
                serverId = srvidmap[processId]
                srvid_rooms_map[serverId].append(controlRoomId)
                big_roomids_map[bigRoomId].append(controlRoomId)
                roomid_define_map[controlRoomId] = clsRoomDefine(bigRoomId, 0, controlRoomId, gameid,
                                                                 configid, controlId, 0, serverId,
                                                                 controlTableCount, tuple(shadowRooms), configure)
                if _DEBUG:
                    debug('load room define->bigRoomId=', bigRoomId, 'parentId=', 0,
                          'roomId=', controlRoomId, 'gameId=', gameid, 'configId=', configid,
                          'controlId=', controlId, 'shadowId=', 0, 'tableCount=', controlTableCount,
                          'serverId=', serverId, 'shadowRooms=', shadowRooms)
        gameid_big_roomids_map[gid].sort()

    # 整理打印配置的内容
    if _DEBUG:
        debug('find big roomids=', big_roomids_map.keys())
    for k, v in big_roomids_map.items():
        if _DEBUG:
            debug('find big room id ', k, 'has childs :', v)
    for k in srvid_rooms_map.keys():
        if not srvid_rooms_map[k]:
            del srvid_rooms_map[k]
        else:
            if _DEBUG:
                debug('find server', k, 'has roomids :', srvid_rooms_map[k])

    gdatas['srvid_roomid_map'] = makeReadonly(srvid_rooms_map)
    gdatas['roomid_define_map'] = makeReadonly(roomid_define_map)
    gdatas['big_roomids_map'] = makeReadonly(big_roomids_map)
    gdatas['gameid_big_roomids_map'] = makeReadonly(gameid_big_roomids_map)
    if _DEBUG:
        debug('loadRoomDefines end')