internal void SetConnection(IEditorConnection connection)
        {
            var newConnection = connection ?? throw new ArgumentNullException(nameof(connection));

            TearDownConnection();
            m_Connection = newConnection;
            SetupConnection();
        }
Пример #2
0
        public bool Start()
        {
            _logger = LogManager.GetLogger("[MainHost]");

            _logger.Info("------------------------------JEDIUM SERVER---------------------------");
            _logger.Info("Starting at: " + DateTime.Now);

            //settings
            var     parser = new FileIniDataParser();
            IniData data   = parser.ReadFile("config\\ServerConfig.ini");

            MainSettings.BehavioursPluginPath = data["Server"]["BehavioursPluginPath"];
            MainSettings.WebApiHost           = data["Server"]["WebApiHost"];
            MainSettings.DBUrl                   = data["Server"]["DBUrl"];
            MainSettings.DatabaseName            = data["Server"]["DatabaseName"];
            MainSettings.CollectMessageStats     = bool.Parse(data["Statistics"]["CollectMessageStats"]);
            MainSettings.StatsCollectionInterval = int.Parse(data["Statistics"]["StatsCollectionInterval"]);
            MainSettings.mainURL                 = data["Server"]["MainURL"];
            MainSettings.TickDelay               = int.Parse(data["Server"]["TickDelay"]);

            _logger.Warn("___TICK DELAY:" + MainSettings.TickDelay);
            MD5 mcalc = MD5.Create();

            byte[] dbytes = File.ReadAllBytes("Domain.dll");
            MainSettings.ServerHash = mcalc.ComputeHash(dbytes).ToHex(false);
            _logger.Info($"Server domain hash: {MainSettings.ServerHash}");


            //preload domain
            var type = typeof(ISceneActor);

            if (type == null)
            {
                throw new InvalidProgramException("!");
            }

            //load plugins
            // BehaviourManager.LoadBehaviours(MainSettings.BehavioursPluginPath);


            //get config (app.config)
            AkkaConfigurationSection section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");

            //_logger.Info();
            Config aconfig = section.AkkaConfig;

            Config localConfig = ConfigurationFactory.ParseString("akka.remote.helios.tcp.hostname = " + MainSettings.mainURL)
                                 .WithFallback(aconfig);

            //попытаться запустить актер сервера
            try
            {
                _system = ActorSystem.Create("VirtualFramework", localConfig);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                throw;
            }

            // на случай разрыва соединения
            DeadRequestProcessingActor.Install(_system);


            _databaseAgent = _system.ActorOf(Props.Create(() => new MongoDbActor()), "DataBase")
                             .Cast <DatabaseAgentRef>(); //TODO: Add test for connection

            _terminal = _system.ActorOf(Props.Create(() => new TerminalConnection(_databaseAgent)), "Terminal")
                        .Cast <TerminalConnectionRef>();


            _serverConnection = _system
                                .ActorOf(Props.Create(() => new ServerConnection(_databaseAgent)), "ServerEndpoint")
                                .Cast <ConnectionRef>();

            //_databaseAgent.SetDummyObjectTest().Wait();


            _manager = _system
                       .ActorOf(Props.Create(() => new ObjectsManager(_databaseAgent, _serverConnection)), "ObjectManager")
                       .Cast <ObjectsManagerRef>();


            //Editor

            _editorConnection = _system.ActorOf(Props.Create(() => new EditorConnection(_manager, _databaseAgent)), "EditorConnection")
                                .Cast <EditorConnectionRef>();

            //assets host
            _webApiHost = _system
                          .ActorOf(Props.Create(() => new WebApiHost(MainSettings.WebApiHost, _databaseAgent, _manager)),
                                   "AssetsHost")
                          .Cast <WebApiHostRef>();


            _pluginsHost = _system.ActorOf(Props.Create(() => new PluginsHost(_databaseAgent, _manager)), "PluginsHost")
                           .Cast <PluginsHostRef>();

            // _pluginsHost.LoadPlugins().Wait();


            _manager.LoadAllScenes().Wait();


            return(true);
        }
Пример #3
0
 public static void SendArray <T>(this IEditorConnection connection, Guid msgGuid, NativeArray <T> data, int playerId = 0) where T : unmanaged
 {
     connection.Send(msgGuid, MessageEventArgsExtensions.SerializeUnmanagedArray(data), playerId);
 }