Exemplo n.º 1
0
 def __init__(self, entityId=None):
     super(ClientEntity, self).__init__()
     self.logger = LogManager.getLogger('ClientEntity.%s' % self.__class__.__name__)
     self.logger.info('ClientEntity.__init__')
     self.eid = (entityId is None) and IdCreator.genId() or entityId
     EntityManager.addEntity(self.eid, self, False)
     self.server = None
Exemplo n.º 2
0
 def destroyEntity(self, controller, entityData, done):
     self.increaseSeq()
     entityId = IdCreator.bytes2id(entityData.id)
     entity = EntityManager.getEntity(entityId)
     if entity != None:
         try:
             entity.destroy()
         except Exception:
             self.handleLastTraceback('GateClient.destroyEntity: %s(%s) failed' % (entity.__class__.__name__, entityId))
             return
         self.logger.info('GateClient.destroyEntity: %s(%s) success', entity.__class__.__name__, entityId)
Exemplo n.º 3
0
 def callServerMethod(self, methodName, parameters=None, entityId=None):
     if entityId is None:
         entityId = self.getOwnerId()
         if entityId is None:
             self.logger.error('callServerMethod: did not find owner %s, need pass entityId to call %s', str(self.owner), methodName)
             return
     entityRpc = EntityRpc()
     entityRpc.id = IdCreator.id2bytes(entityId)
     self.encoder.encode(entityRpc.method, methodName)
     if parameters is not None:
         if self.proto == 'BSON' or self.proto == 'bson':
             entityRpc.arguments = BSON.encode(parameters)
         elif self.proto == 'msgpack':
             entityRpc.arguments = msgpack.packb(parameters, use_bin_type=True, default=msgPackExt)
     self.stub.entityRpc(None, entityRpc)
Exemplo n.º 4
0
import msgpack

from MarsLog.LogManager import LogManager
from MarsRpc.ChannelClient import ChannelClient
from MarsRpc.Compressor import Compressor

from Utils.PyProto import ClientGate_pb2
from Utils.PyProto import Common_pb2
from Utils.EntityFactory import EntityFactory
from Utils.EntityManager import EntityManager
from Utils.IdCreator import IdCreator
from Utils.MessageCodec import Md5IndexDecoder, Md5IndexEncoder

from ServerProxy import ServerProxy

MARS_DEVICEID = str(IdCreator.genId())

class GateClient(ClientGate_pb2.SGate2Client):
    ST_INIT                 = 0
    ST_CONNECTING           = 1
    ST_RECONNECTING         = 3
    ST_CONNECT_FAILED       = 4
    ST_CONNECT_SUCCESSED    = 5
    ST_DISCONNECTED         = 6

    CB_ON_CONNECT_FAILED        = 1
    CB_ON_CONNECT_SUCCESSED     = 2
    CB_ON_DISCONNECTED          = 3
    CB_ON_CONNECT_REPLY         = 4
    CB_ON_RELIABLE_MSG_UNSENT   = 5