Example #1
0
def sendToAll(msgpack, serverType='', head2=''):
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(msgpack, basestring))
    for stype, sids in gdata.serverTypeMap().items():
        if not serverType or serverType == stype:
            for dst in sids:
                wrapper.send(dst, msgpack, 'S7', head2)
Example #2
0
def sendToAll(msgpack, serverType='', head2=''):
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(msgpack, basestring))
    for stype, sids in gdata.serverTypeMap().items():
        if not serverType or serverType == stype:
            for dst in sids:
                wrapper.send(dst, msgpack, 'S7', head2)
Example #3
0
 def sendToWriter(self, _type, _group, logid, body):
     sid = ftcon.global_config["server_id"]
     svrconf = ftcon.getServerConf(sid)
     try:
         writer = svrconf["writer"]
     except:
         ftlog.error("writer not config!", svrconf)
         return
     header = "%s_%s_%s" % (str(_type), str(_group), str(logid))
     for w in writer:
         ftagent.send(str(w), base64.b64encode(body), header)
Example #4
0
 def sendToWriter(self, _type, _group, logid, body):
     sid = ftcon.global_config["server_id"]
     svrconf = ftcon.getServerConf(sid)
     try:
         writer = svrconf["writer"]
     except:
         ftlog.error("writer not config!", svrconf)
         return
     header = "%s_%s_%s" % (str(_type), str(_group), str(logid))
     for w in writer:
         ftagent.send(str(w), base64.b64encode(body), header)
Example #5
0
def _communicateServer(rsrv,
                       groupId,
                       userId,
                       msgpack,
                       head1,
                       isQuery,
                       timeout=None,
                       notimeoutex=0):
    if timeout == None:
        timeout = _runenv._RPC_TIME_OUT
    if groupId <= 0:
        groupId = rsrv.sididx
        rsrv.sididx += 1
    dst = rsrv.sids[groupId % rsrv.sidlen]
    ftlog.debug('_communicateServer->dst=', dst, 'groupId=', userId,
                'timeout=', timeout, 'msgpack=[' + msgpack + ']')
    if isQuery:
        return wrapper.query(dst,
                             msgpack,
                             head1,
                             str(userId),
                             timeout,
                             notimeoutex=notimeoutex)
    else:
        return wrapper.send(dst, msgpack, head1, str(userId))
Example #6
0
def sendToUsers(msgpack, userIdList):
    '''
    发送消息至一组用户的客户端
    '''
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(msgpack, basestring))
    for userId in userIdList:
        assert (isinstance(userId, (int, long)) and userId > 0)
        if gdata.ENABLIE_DEFENCE_2:
            from poker.entity.dao import sessiondata
            srvId = sessiondata.getConnId(userId)
            ftlog.debug('sendToUser', userId, srvId)
            if srvId in _connServer.sids:
                wrapper.send(srvId, msgpack, 'S0', str(userId))
                continue
        _communicateServer(_connServer, userId, userId, msgpack, 'S0', 0)
Example #7
0
def sendToUsers(msgpack, userIdList):
    '''
    发送消息至一组用户的客户端
    '''
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(msgpack, basestring))
    for userId in userIdList:
        assert (isinstance(userId, (int, long)) and userId > 0)
        if gdata.ENABLIE_DEFENCE_2:
            from poker.entity.dao import sessiondata
            srvId = sessiondata.getConnId(userId)
            ftlog.debug('sendToUser', userId, srvId)
            if srvId in _connServer.sids:
                wrapper.send(srvId, msgpack, 'S0', str(userId))
                continue
        _communicateServer(_connServer, userId, userId, msgpack, 'S0', 0)
Example #8
0
def _communicateTableServer(userId,
                            roomId,
                            msgpack,
                            head1,
                            isQuery,
                            timeout=None,
                            notimeoutex=0):
    if timeout == None:
        timeout = _runenv._RPC_TIME_OUT
    assert (isinstance(msgpack, (MsgPack, basestring)))
    assert (isinstance(roomId, (int, long)) and roomId >= 0)
    assert (isinstance(userId, (int, long)) and userId >= 0)
    allrooms = gdata.roomIdDefineMap()
    if roomId in allrooms:
        roomDef = allrooms[roomId]
        if roomDef.parentId == 0:
            ftlog.warn('ERROR, cat not localtion the roomId of->', userId,
                       roomId, msgpack)
            return
    else:  # this roomId is big roomId
        assert (isinstance(userId, (int, long)) and userId >= 0)
        bigrooms = gdata.bigRoomidsMap()
        if roomId in bigrooms:
            msgpack, shadowRoomId = __getRoomIdByTableId(msgpack)
            ftlog.debug('_communicateTableServer allrooms = ', allrooms,
                        'shadowRoomId =', shadowRoomId)
            if shadowRoomId:
                roomDef = allrooms[shadowRoomId]
            else:
                ftlog.warn('ERROR, cat not localtion the roomId of->', userId,
                           roomId, msgpack)
                return
        else:
            ftlog.warn('ERROR, cat not localtion the roomId of->', userId,
                       roomId, msgpack)
            return
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    dst = roomDef.serverId
    ftlog.debug('_communicateTableServer->dst=', dst, 'head1=', head1,
                'roomId=', str(roomId), 'timeout=', timeout,
                'msgpack=[' + msgpack + ']')

    if isQuery:
        response = wrapper.query(dst,
                                 msgpack,
                                 head1,
                                 str(roomId),
                                 timeout,
                                 notimeoutex=notimeoutex)
        ftlog.debug('_communicateTableServer->dst=', dst, 'head1=', head1,
                    'roomId=', str(roomId), 'response=[' + str(response) + ']')
        return response
    else:
        return wrapper.send(dst, msgpack, head1, str(roomId))
Example #9
0
def sendCenterServer(msgpack, logicName):
    """
    发送消息至CENTER服务
    """
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(msgpack, basestring))
    for dst, logics in gdata.centerServerLogics().items():
        if logicName in logics:
            return wrapper.send(dst, msgpack, 'S7', logicName)
    raise Exception('the center logicName not found !!' + str(logicName))
Example #10
0
def sendCenterServer(msgpack, logicName):
    """
    发送消息至CENTER服务
    """
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(msgpack, basestring))
    for dst, logics in gdata.centerServerLogics().items():
        if logicName in logics:
            return wrapper.send(dst, msgpack, 'S7', logicName)
    raise Exception('the center logicName not found !!' + str(logicName))
Example #11
0
def _communicateServer(rsrv, groupId, userId, msgpack, head1, isQuery, timeout=None, notimeoutex=0):
    if timeout == None:
        timeout = _runenv._RPC_TIME_OUT
    if groupId <= 0:
        groupId = rsrv.sididx
        rsrv.sididx += 1
    dst = rsrv.sids[groupId % rsrv.sidlen]
    ftlog.debug('_communicateServer->dst=', dst, 'groupId=', userId, 'timeout=', timeout, 'msgpack=[' + msgpack + ']')
    if isQuery:
        return wrapper.query(dst, msgpack, head1, str(userId), timeout, notimeoutex=notimeoutex)
    else:
        return wrapper.send(dst, msgpack, head1, str(userId))
Example #12
0
def _communicateRoomServer(userId,
                           roomId,
                           msgpack,
                           head1,
                           isQuery,
                           timeout=None,
                           notimeoutex=0):
    if timeout == None:
        timeout = _runenv._RPC_TIME_OUT
    assert (isinstance(msgpack, (MsgPack, basestring)))
    assert (isinstance(roomId, (int, long)) and roomId >= 0)
    allrooms = gdata.roomIdDefineMap()
    if roomId in allrooms:
        roomDef = allrooms[roomId]
        if roomDef.parentId > 0:  # this roomId is shadowRoomId
            ctrlRoomId = roomDef.parentId
            roomDef = allrooms[ctrlRoomId]
            msgpack = __changeMsgRoomId(msgpack, ctrlRoomId, roomId)
    else:  # this roomId is big roomId
        assert (isinstance(userId, (int, long)) and userId >= 0)
        bigrooms = gdata.bigRoomidsMap()
        if roomId in bigrooms:
            ctrlroomIds = bigrooms[roomId]
            ctrlRoomId = ctrlroomIds[
                userId % len(ctrlroomIds)]  # ctrlRoom0 做为 ctrlRooms 的调度器
            roomDef = allrooms[ctrlRoomId]
            msgpack = __changeMsgRoomId(msgpack, ctrlRoomId, roomId)
        else:
            ftlog.warn('ERROR, cat not localtion the roomId of->', userId,
                       roomId, msgpack)
            return
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    dst = roomDef.serverId
    ftlog.debug('_communicateRoomServer->dst=', dst, 'head1=', head1,
                'roomId=', str(roomId), 'timeout=', timeout,
                'msgpack=[' + msgpack + ']')

    if isQuery:
        response = wrapper.query(dst,
                                 msgpack,
                                 head1,
                                 str(roomId),
                                 timeout,
                                 notimeoutex=notimeoutex)
        ftlog.debug('_communicateRoomServer->dst=', dst, 'head1=', head1,
                    'roomId=', str(roomId), 'response=[' + str(response) + ']')
        return response
    else:
        return wrapper.send(dst, msgpack, head1, str(roomId))
Example #13
0
def sendToUser(msgpack, userId):
    """
    发送消息至用户的客户端
    """
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(userId, (int, long)) and userId > 0)
    assert (isinstance(msgpack, basestring))
    if gdata.ENABLIE_DEFENCE_2:
        from poker.entity.dao import sessiondata
        srvId = sessiondata.getConnId(userId)
        ftlog.debug('sendToUser', userId, srvId)
        if srvId in _connServer.sids:
            return wrapper.send(srvId, msgpack, 'S0', str(userId))
    return _communicateServer(_connServer, userId, userId, msgpack, 'S0', 0)
Example #14
0
def sendToUser(msgpack, userId):
    """
    发送消息至用户的客户端
    """
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    assert (isinstance(userId, (int, long)) and userId > 0)
    assert (isinstance(msgpack, basestring))
    if gdata.ENABLIE_DEFENCE_2:
        from poker.entity.dao import sessiondata
        srvId = sessiondata.getConnId(userId)
        ftlog.debug('sendToUser', userId, srvId)
        if srvId in _connServer.sids:
            return wrapper.send(srvId, msgpack, 'S0', str(userId))
    return _communicateServer(_connServer, userId, userId, msgpack, 'S0', 0)
Example #15
0
def _communicateTableServer(userId, roomId, msgpack, head1, isQuery, timeout=None, notimeoutex=0):
    if timeout == None:
        timeout = _runenv._RPC_TIME_OUT
    assert (isinstance(msgpack, (MsgPack, basestring)))
    assert (isinstance(roomId, (int, long)) and roomId >= 0)
    assert (isinstance(userId, (int, long)) and userId >= 0)
    allrooms = gdata.roomIdDefineMap()
    if roomId in allrooms:
        roomDef = allrooms[roomId]
        if roomDef.parentId == 0:
            ftlog.warn('ERROR, cat not localtion the roomId of->', userId, roomId, msgpack)
            return
    else:  # this roomId is big roomId
        assert (isinstance(userId, (int, long)) and userId >= 0)
        bigrooms = gdata.bigRoomidsMap()
        if roomId in bigrooms:
            msgpack, shadowRoomId = __getRoomIdByTableId(msgpack)
            ftlog.debug('_communicateTableServer allrooms = ', allrooms, 'shadowRoomId =', shadowRoomId)
            if shadowRoomId:
                roomDef = allrooms[shadowRoomId]
            else:
                ftlog.warn('ERROR, cat not localtion the roomId of->', userId, roomId, msgpack)
                return
        else:
            ftlog.warn('ERROR, cat not localtion the roomId of->', userId, roomId, msgpack)
            return
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    dst = roomDef.serverId
    ftlog.debug('_communicateTableServer->dst=', dst, 'head1=', head1, 'roomId=', str(roomId), 'timeout=', timeout,
                'msgpack=[' + msgpack + ']')

    if isQuery:
        response = wrapper.query(dst, msgpack, head1, str(roomId), timeout, notimeoutex=notimeoutex)
        ftlog.debug('_communicateTableServer->dst=', dst, 'head1=', head1, 'roomId=', str(roomId),
                    'response=[' + str(response) + ']')
        return response
    else:
        return wrapper.send(dst, msgpack, head1, str(roomId))
Example #16
0
def _communicateRoomServer(userId, roomId, msgpack, head1, isQuery, timeout=None, notimeoutex=0):
    if timeout == None:
        timeout = _runenv._RPC_TIME_OUT
    assert (isinstance(msgpack, (MsgPack, basestring)))
    assert (isinstance(roomId, (int, long)) and roomId >= 0)
    allrooms = gdata.roomIdDefineMap()
    if roomId in allrooms:
        roomDef = allrooms[roomId]
        if roomDef.parentId > 0:  # this roomId is shadowRoomId
            ctrlRoomId = roomDef.parentId
            roomDef = allrooms[ctrlRoomId]
            msgpack = __changeMsgRoomId(msgpack, ctrlRoomId, roomId)
    else:  # this roomId is big roomId
        assert (isinstance(userId, (int, long)) and userId >= 0)
        bigrooms = gdata.bigRoomidsMap()
        if roomId in bigrooms:
            ctrlroomIds = bigrooms[roomId]
            ctrlRoomId = ctrlroomIds[userId % len(ctrlroomIds)]  # ctrlRoom0 做为 ctrlRooms 的调度器
            roomDef = allrooms[ctrlRoomId]
            msgpack = __changeMsgRoomId(msgpack, ctrlRoomId, roomId)
        else:
            ftlog.warn('ERROR, cat not localtion the roomId of->', userId, roomId, msgpack)
            return
    if isinstance(msgpack, MsgPack):
        msgpack = msgpack.pack()
    dst = roomDef.serverId
    ftlog.debug('_communicateRoomServer->dst=', dst, 'head1=', head1, 'roomId=', str(roomId), 'timeout=', timeout,
                'msgpack=[' + msgpack + ']')

    if isQuery:
        response = wrapper.query(dst, msgpack, head1, str(roomId), timeout, notimeoutex=notimeoutex)
        ftlog.debug('_communicateRoomServer->dst=', dst, 'head1=', head1, 'roomId=', str(roomId),
                    'response=[' + str(response) + ']')
        return response
    else:
        return wrapper.send(dst, msgpack, head1, str(roomId))
Example #17
0
 def sendToAllCoServer(cls, mo):
     ''' 发送消息到所有TCP管理服务器'''
     msgpack = mo.pack()
     coSrvIds = gdata.serverTypeMap()[gdata.SRV_TYPE_CONN]
     for coSrvId in coSrvIds:
         wrapper.send(coSrvId, msgpack, "S1", "")
Example #18
0
    if markParams['syncCall']:
        if future:
            # TODO: Future RPC CALL 1
            return _FutureResultRemote(rpc, dstSid, mi, rpcid, str(groupVal), _runenv._RPC_TIME_OUT)
        else:
            try:
                jstr = wrapper.query(dstSid, mi, rpcid, str(groupVal), _runenv._RPC_TIME_OUT)
            except FTMsgPackException, e:
                raise e
            except Exception, e:
                ftlog.warn('RpcException msg=', mi)
                raise RpcException('RpcException ' + rpc + ' ! query remote false, ' + str(e))
            return _parseRpcResult(mi, jstr, rpc)
    else:
        try:
            wrapper.send(dstSid, mi, rpcid, str(groupVal))
        except Exception, e:
            ftlog.warn('RpcException msg=', mi)
            raise RpcException('RpcException ' + rpc + ' ! send to remote false, ' + str(e))
        return None


def _parseRpcResult(mi, jstr, rpc):
    if jstr:
        try:
            modict = strutil.loads(jstr)
        except:
            ftlog.warn('RpcException msg=', mi)
            raise RpcException('RpcException ' + rpc + ' ! remote return format false, json=[' + repr(jstr) + ']')
    else:
        raise RpcException('RpcException ' + rpc + ' ! remote return is Empty !')