Example #1
0
class EntityManager(object, ):
    '\n\t\xe7\xae\xa1\xe7\x90\x86\xe6\x89\x80\xe6\x9c\x89\xe7\x9a\x84Entity\xe7\x9a\x84\xe7\xae\xa1\xe7\x90\x86\xe5\x8d\x95\xe4\xbb\xb6\xe7\xb1\xbb\xe3\x80\x82\n\t'
    _logger = LogManager.get_logger('server.EntityManager')
    _entities = {}

    @staticmethod
    def hasentity(entityid):
        '\n\t\t\xe5\x88\xa4\xe5\xae\x9a\xe6\x98\xaf\xe5\x90\xa6\xe5\xad\x98\xe5\x9c\xa8entity\n\n\t\t:param entityid: Entity ID\xe3\x80\x82\n\t\t:type entityid: entityid\n\t\t:returns: \xe8\x8b\xa5ID\xe6\x8c\x87\xe5\xae\x9a\xe7\x9a\x84Enitity\xe5\xad\x98\xe5\x9c\xa8\xef\xbc\x8c\xe5\x88\x99\xe8\xbf\x94\xe5\x9b\x9eTrue\xef\xbc\x9b\xe5\x90\xa6\xe5\x88\x99\xef\xbc\x8c\xe8\xbf\x94\xe5\x9b\x9eFalse\xe3\x80\x82\n\t\t:rtype: bool\n\t\t'
        return (entityid in EntityManager._entities)

    @staticmethod
    def getentity(entityid):
        '\n\t\t\xe8\x8e\xb7\xe5\x8f\x96Entity\xe3\x80\x82\n\n\t\t:param entityid: \xe6\xac\xb2\xe8\x8e\xb7\xe5\x8f\x96\xe7\x9a\x84Entity ID\xe3\x80\x82\n\t\t:type entityid: entityid\n\t\t:returns: \xe8\x8b\xa5ID\xe6\x8c\x87\xe5\xae\x9a\xe7\x9a\x84Enitity\xe5\xad\x98\xe5\x9c\xa8\xef\xbc\x8c\xe5\x88\x99\xe8\xbf\x94\xe5\x9b\x9e\xe8\xaf\xa5Entity\xef\xbc\x9b\xe5\x90\xa6\xe5\x88\x99\xef\xbc\x8c\xe8\xbf\x94\xe5\x9b\x9eNone\xe3\x80\x82\n\t\t:rtype: entity/None\n\t\t'
        return EntityManager._entities.get(entityid, None)

    @staticmethod
    def delentity(entityid):
        '\n\t\t\xe5\x88\xa0\xe9\x99\xa4entity\n\n\t\t:param entityid: \xe5\xbe\x85\xe5\x88\xa0\xe9\x99\xa4\xe7\x9a\x84Entity ID\xe3\x80\x82\n\t\t:type entityid: entityid\n\t\t'
        try:
            del EntityManager._entities[entityid]
        except KeyError:
            EntityManager._logger.warn(" entity id %s didn't exist", entityid)

    @staticmethod
    def addentity(entityid, entity, override=True):
        '\n\t\t\xe6\xb7\xbb\xe5\x8a\xa0\xe6\x96\xb0\xe7\x9a\x84entity\n\n\t\t:param entityid: \xe6\xac\xb2\xe6\xb7\xbb\xe5\x8a\xa0\xe7\x9a\x84\xe7\x9a\x84Entity ID\xe3\x80\x82\n\t\t:type entityid: entityid\n\t\t:param entityid: \xe6\xac\xb2\xe6\xb7\xbb\xe5\x8a\xa0\xe7\x9a\x84\xe7\x9a\x84Entity\xe3\x80\x82\n\t\t:type entity: entity\n\t\t:param override: \xe8\x8b\xa5\xe4\xb8\xbaTrue\xef\xbc\x8c\xe5\x88\x99\xe5\xbd\x93\xe6\xac\xb2\xe6\xb7\xbb\xe5\x8a\xa0\xe7\x9a\x84Entity ID\xe5\xb7\xb2\xe7\xbb\x8f\xe5\xad\x98\xe5\x9c\xa8\xe6\x97\xb6\xef\xbc\x8c\xe5\x88\x99\xe5\xb0\x86\xe8\xa6\x86\xe7\x9b\x96\xe5\x8e\x9f\xe6\x9c\x89\xe7\x9a\x84Entity\xef\xbc\x9b\xe5\x90\xa6\xe5\x88\x99\xef\xbc\x8c\xe4\xb8\x8d\xe6\x89\xa7\xe8\xa1\x8c\xe5\x8a\xa8\xe4\xbd\x9c\xe3\x80\x82\n\t\t:type override: bool\n\t\t'
        if (entityid in EntityManager._entities):
            EntityManager._logger.warn('%s (%s) Already Exist', EntityManager._entities[entityid].__class__.__name__, entityid)
            (override and EntityManager._entities[entityid].destroyObject())
        EntityManager._entities[entityid] = entity
Example #2
0
 def __new__(cls, name, bases, dct):
     entityclass = super(EntityMetaClass,
                         cls).__new__(cls, name, bases, dct)
     entityclass.logger = LogManager.get_logger(entityclass.__name__)
     EntityMetaClass.replaceDestroy(entityclass)
     EntityMetaClass.replaceInitFromDict(entityclass)
     return entityclass
Example #3
0
class GameServerConsole(
        asiocore.telnet_server, ):
    logger = LogManager.get_logger('Telnet')

    def __init__(self, ip='127.0.0.1', port=9113):
        super(GameServerConsole, self).__init__()
        while 1:
            try:
                if self.bind(ip, port):
                    break
            except Exception as e:
                self.logger.error('Failed To Bind Port %s:%d For %s', ip, port,
                                  e)
            port += 1
            if (port > 65535):
                raise IOError(
                    'Telnet Server Failed To Find A Usable Port To Bind!')
        self.logger.info('Telnet Server Binded on Port %s:%d', ip, port)
        self.ip = ip
        self.port = port

    def start(self):
        self.listen(5)

    @property
    def handler(self):
        import __main__
        return getattr(__main__, '_telnet_handler', None)

    @handler.setter
    def handler(self, handler):
        import __main__
        __main__._telnet_handler = handler
 def __init__(self,
              logic_service,
              channel_handler,
              processlagerbuf='True',
              max_data_len=0):
     super(RpcChannelCreator, self).__init__()
     self.logger = LogManager.get_logger("mobilerpc.RpcChannelCreator")
     # 保存rpc的service和stub
     self.rpc_service = logic_service
     self.channel_handler = channel_handler
     self.max_data_len = max_data_len
     self.processlagerbuf = processlagerbuf
Example #5
0
    def __init__(self, ip, port, con_handler=None, reuse_addr=False):
        self.ip = ip
        self.port = port
        self.con_handler = con_handler
        asyncore.dispatcher.__init__(self)

        # log
        self.logger = LogManager.get_logger("mobilerpc.TcpServer")
        # begin to listen
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        if reuse_addr:
            self.set_reuse_addr()
        self.started = False
        self.try_bind()
        self.logger.info('__init__: Server Listen on: %s, %d', self.ip,
                         self.port)
        self.listen(50)
Example #6
0
	def __init__(self, stub, spaceno):
		self.logger = LogManager.get_logger(self.__class__.__name__)
		self.spaceno = spaceno
		self.stub = stub
		self.spaces = dict()
		self.queue = dict()
		self.space_managers = dict()
		self.creating = {}
		# for query team access to space
		self.team_space_mapping = {}
		# cache team access to space
		self.space_team_mapping = {}

		# 分线信息统计, 和self.spaces结构保持对应关系
		self.sep_line_info = {'spaceno' : spaceno}

		# 是否需要分线统计, 比如副本之类的space可能就不需要分线逻辑
		# @note 设置为构造时候设定是因为, 理论上说, 该变量不可以后续改变
		# @note @TODO 以后需要留意, 如果启动的时候将stub和普通的game进程区别开, 需要启动的时候也将G.spacem进行设定
		self.need_sep = space_common.is_main_world(self.spaceno)
Example #7
0
    def __init__(self, sock, peername):
        # the connection has been established
        self.status = TcpConnection.ST_INIT
        self.w_buffer = StringIO()

        if sock:
            self.status = TcpConnection.ST_ESTABLISHED

        asyncore.dispatcher.__init__(self, sock)
        self.logger = LogManager.get_logger("mobilerpc.TcpConnection")
        self.recv_buffer_size = TcpConnection.DEFAULT_RECV_BUFFER
        self.channel_interface_obj = None
        self.peername = peername

        self.encrypter = None
        self.decrypter = None
        self.compressor = None

        if sock:
            self.setsockopt()
Example #8
0
 def __init__(self, logic_service, conn, processlagerbuf='True'):
     super(MobileRpcChannel, self).__init__()
     # 负责把Rpc请求传递给上层
     # Rpc请求异步解析
     self.logic_service = logic_service
     self.rpc_request = MobileRequest.request()
     self.rpc_request_parser = MobileRequest.request_parser()
     # 底层的网络连接,比如TcpConnection
     self.conn = conn
     self.conn.set_channel_interface_obj(self)
     # controller 用来传递channel给上层
     self.con_listeners = set()
     # LogManager
     self.logger = LogManager.get_logger("mobilerpc.MobileRpcChannel")
     self.logger.info('__init__: a new connection')
     # user data
     self.user_data = None
     # self.encrypted = False
     # self.compressed = False
     self.session_seed = None
     self.processlagerbuf = processlagerbuf
 def __init__(self):
     super(RpcChannelManager, self).__init__()
     self.logger = LogManager.get_logger("mobilerpc.RpcChannelManager")
     self.rpc_channels = {}
Example #10
0
from mobilelog.LogManager import LogManager
from RpcMethodArgs import Exposed
CLIENT_ONLY = 1
CLIENT_ANY = 2
SERVER_ONLY = 4
CLIENT_STUB = 8
CLIENT_SERVER = (CLIENT_ONLY | SERVER_ONLY)
ANY_SOURCES = (((CLIENT_ONLY | CLIENT_ANY) | SERVER_ONLY) | CLIENT_STUB)
CLIENT_EXPOSED = CLIENT_STUB
SERVER_EXPOSED = ((CLIENT_ONLY | CLIENT_ANY) | SERVER_ONLY)
EXPOSED_TO_CLIENT = (CLIENT_ONLY | CLIENT_ANY)
EXPOSED_TO_SERVER = (SERVER_ONLY | CLIENT_STUB)
ORDINARY_SERVER = 16
CROSS_SERVER = 32
ANY_SERVER = (ORDINARY_SERVER | CROSS_SERVER)
_logger = LogManager.get_logger('server.RpcMethod')


def rpc_call(func, parameters=None):
    args = []
    if parameters:
        if isinstance(parameters, list):
            parameters = {'__args': parameters}
        (('__args' in parameters)
         and parameters.update(dict(enumerate(parameters.pop('__args')))))
        for argtype in func.argtypes:
            argname = argtype.getname()
            args.append(argtype.convert(parameters[argname]))
    return func(*args)

Example #11
0
# -*- coding:utf-8 -*-

from hashlib import md5
from mobilelog.LogManager import LogManager
_logger = LogManager.get_logger('RpcIndexer')
VERIFY_TAG = '_v_e_r_i_f_y_'
DEFAULT_RECV_RPC_SALT = '0'
DEFAULT_SEND_RPC_SALT = '0'
try:
    from _PRESET_RPC_INDEXES import RPC2INDEX, INDEX2RPC, RECV_RPC_SALT, SEND_RPC_SALT, SEND_CACHE
    _logger.info('Using Preset RPC Indexes.')
    PRESET_RPC_INDEXES = True
except:
    _logger.info('No Preset RPC Indexes Found.')
    PRESET_RPC_INDEXES = False
    RPC2INDEX = {VERIFY_TAG: 0}
    INDEX2RPC = {}
    RECV_RPC_SALT = DEFAULT_RECV_RPC_SALT
    SEND_RPC_SALT = DEFAULT_SEND_RPC_SALT
    SEND_CACHE = {}


def register_rpc(rpcname):
    if (rpcname in RPC2INDEX):
        return
    index = recv_rpc_index(rpcname)
    if (index in INDEX2RPC):
        raise RuntimeError(
            ('RPC INDEX Of [%s] AND [%s] ARE CONFLICTED WITH SALT %s!' %
             (rpcname, INDEX2RPC[index], RECV_RPC_SALT)))
    INDEX2RPC[index] = rpcname
Example #12
0
 def __init__(self):
     super(EntityFactory, self).__init__()
     self.logger = LogManager.get_logger('server.EntityFactory')
     self.entity_classes = {}