Exemple #1
0
        /// <summary>
        ///     Loads this instance.
        /// </summary>
        /// <returns>Config.</returns>
        public static Config Load()
        {
            var    section = new AkkaConfigurationSection();
            Config config  = section.AkkaConfig;

            return(config);
        }
        public static Config GetAkkaSettings()
        {
            var defaultC = DistributedPubSub.DefaultConfig();

            AkkaConfigurationSection configurationSection = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka") ?? new AkkaConfigurationSection();
            Config config = ConfigurationFactory.ParseString(GetHoconForEnvironmentVariables() + configurationSection.Hocon.Content);

            return(config);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            AkkaConfigurationSection section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
            Config aconfig = section.AkkaConfig;


            try
            {
                _system = ActorSystem.Create("VirtualFrameworkConsole", aconfig);
            }
            catch (Exception ex)
            {
                ColorConsole.WriteLine($"Error initializig Akka:{ex.Message}".Red());
                //  throw;
            }

            try
            {
                IActorRef asel =
                    _system.ActorSelection(_localUrl)
                    .ResolveOne(TimeSpan.Zero).Result;

                _terminal = asel.Cast <TerminalConnectionRef>();
            }
            catch (Exception e)
            {
                ColorConsole.WriteLine($"Error connecting to server:{e.Message}".Red());
            }


            if (_terminal == null)
            {
                ColorConsole.WriteLine("Error connecting to server".Red());
            }


            var shell = new Shell();

            RegisterCommands(shell, true);

            shell.WritePrompt          += ShellOnWritePrompt;
            shell.ShellCommandNotFound += ShellOnShellCommandNotFound;
            shell.PrintAlternatives    += ShellOnPrintAlternatives;

            try
            {
                shell.RunShell();
            }
            catch (ApplicationExitException)
            {
                _system.Terminate().Wait();
            }
        }
        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);
        }