Exemplo n.º 1
0
    async def GetDebugInfo(self) -> TMap[int32, FString]:
        entities = EntitiesDispatcher().entities

        result = dict()
        for e in entities.values():
            result[
                e.
                internal_id] = f"Entity [{'%3s' % getattr(e, 'internal_id', ' - ')} / {'%3s' % getattr(e, 'dbid', ' - ')}] {e.__class__.__name__}: {repr(e)}".replace(
                    "<", "&lt").replace(">", "&gt;")
        return result
Exemplo n.º 2
0
    async def GetEntityViewInfo(self, entity_id: int32) -> FString:
        entity = EntitiesDispatcher().entities.get(entity_id, None)
        if entity is None:
            return f"[No entity with id {entity_id}]"

        result = f"Entity {repr(entity).replace('>', '&gt;').replace('<', '&lt;')} <br> <table><tr><td>"

        result += "<table>"
        for property_name, property_info in entity.properties.items():
            result += f"""<tr><td><font color=blue>{property_name}</font>: {repr(getattr(entity, property_name, None)).replace('>', '&gt;').replace('<', '&lt;')}</td></tr>"""
        result += "</table>"

        result += "</td></tr><tr><td>"

        result += "<hr><table>"
        for display_attributes_name in entity.display_attributes:
            result += f"""<tr><td><font color=gray>{display_attributes_name}</font>: {repr(getattr(entity, display_attributes_name, None)).replace('>', '&gt;').replace('<', '&lt;')}<br></td></tr>"""
        result += "</table>"

        result += "</td></tr></table>"

        if hasattr(entity, 'display_actions'):
            for action_function in entity.display_actions:
                result += f'''<input type="button" size="40" value="{action_function.__name__}" onclick="CallDisplayAction('{action_function.__name__}', {entity_id});"> '''

        result += '<hr>'

        return result
Exemplo n.º 3
0
 async def __ainit__(self, entity_dbid, *, outer=None):
     self.dbid = entity_dbid
     self.outer = outer
     EntitiesDispatcher().register_dbid(self, entity_dbid)
     self.db = Globals.this_service.db
     self.failed = False
     self.properties_locks = dict()
     await super().__ainit__()
Exemplo n.º 4
0
    async def load_persistents(self):
        if not is_valid(self.db):
            self.failed = True
            return

        class_name = self.__class__.__name__
        serialized_data = await self.db.GetEntityData(self.dbid, class_name)
        srp = BinarySerialization(serialized_data).proxy()
        for prop_name, prop_info in self.properties.items():
            if Persistent in prop_info.specifiers:
                if not issubclass(prop_info.prop_type, BaseEntity):
                    prop_value = srp >> bytes
                    if "FDateTime" in prop_info.prop_type.__name__:
                        print(",,,")
                    deserialized = prop_info.prop_type.deserialize(prop_value)
                    T = prop_info.prop_type
                    value = T.instantiate(deserialized)

                    value.set_db_interface(
                        DatabaseVariableProxy(self.db, self.dbid, class_name,
                                              prop_name, prop_info))

                    value.initialize_property(self, prop_name)
                    self.properties_locks[prop_name] = asyncio.Lock()
                else:
                    prop_value = srp >> int32
                    value = EntitiesDispatcher().get_by_dbid(prop_value)
                    if value is None:
                        is_new_entity = False
                        if prop_value == 0:
                            prop_value = await self.db.CreateDefaultEntity(
                                prop_info.prop_type.__name__)
                            is_new_entity = True

                        value = await prop_info.prop_type(prop_value,
                                                          outer=self)
                        value.initialize_property(self, prop_name)
                        value.set_db_interface(
                            DatabaseVariableProxy(self.db, self.dbid,
                                                  class_name, prop_name,
                                                  prop_info))

                        if is_new_entity:
                            await value.on_entity_created()

                        if is_new_entity:
                            await value.async_save()

                # ERROR_MSG("Lolz %s %s" % (prop_name, value))
                # if issubclass(prop_info.prop_type, BaseEntity):
                #     if value
                self.set_property_value(prop_name, value)
Exemplo n.º 5
0
 def entities(self):
     return EntitiesDispatcher().entities
Exemplo n.º 6
0
 async def CallDisplayAction(self, entity_id: int32, action_name: FString):
     entity = EntitiesDispatcher().entities.get(entity_id, None)
     if entity is not None:
         action = getattr(entity, action_name, None)
         if action is not None:
             action()
Exemplo n.º 7
0
    async def handle_message(self, data):
        """ Обработка входящего сообщения """

        try:
            message_proxy = BinarySerialization(data).proxy()
        except Exception as e:
            ERROR_MSG("Unable to make proxy for data %s: %s" % (data, e))
            return
        try:
            message_type = message_proxy >> int
            message_data = message_proxy >> bytes
        except:
            print(message_proxy)


        if message_type == ConnectionMessageTypes.rmi_call:
            proxy = BinarySerialization(message_data).proxy()
            entity_id    = proxy >> int
            gen_sig      = proxy >> str
            method_index = proxy >> int
            future_id    = proxy >> int
            access_token = proxy >> str
            params       = proxy >> bytes
            if gen_sig == Globals.generator_signature:
                await EntitiesDispatcher().execute_rmi(self.client_connection, entity_id, method_index, future_id, access_token, params)
            else:
                EntitiesDispatcher().remote_response_error(self.client_connection, entity_id, future_id, "Generator signature mismatch")

        elif message_type == ConnectionMessageTypes.rmi_future:
            proxy = BinarySerialization(message_data).proxy()
            entity_id    = proxy >> int
            method_index = proxy >> int
            future_id    = proxy >> int
            returns      = proxy >> bytes
            if future_id != -1:
                EntitiesDispatcher().yield_rmi_result(future_id, entity_id, method_index, returns)

        elif message_type == ConnectionMessageTypes.rmi_error:
            proxy = BinarySerialization(message_data).proxy()
            error_source  = proxy >> str
            error_message = proxy >> str
            future_id     = proxy >> int

            WARN_MSG("Error from %s: %s" % (error_source, error_message))

            if future_id != -1:
                EntitiesDispatcher().yield_rmi_error(future_id)

        elif message_type == ConnectionMessageTypes.rmi_exception:
            proxy = BinarySerialization(message_data).proxy()
            exception_source  = proxy >> str
            exception_class   = proxy >> str
            exception_args    = proxy >> str
            future_id         = proxy >> int

            WARN_MSG("Exception from %s: %s" % (exception_source, exception_class))

            if future_id != -1:
                EntitiesDispatcher().yield_rmi_exception(future_id, exception_class, exception_args)

        await asyncio.sleep(0.1)