コード例 #1
0
        public WvsGameRegistry()
        {
            For <WvsGameOptions>().Use(c =>
            {
                var configBuilder = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile("WvsGame.example.json")
                                    .AddJsonFile("WvsGame.json", true);
                var config  = configBuilder.Build();
                var options = new WvsGameOptions();

                config.Bind(options);
                return(options);
            }).Singleton();

            For <DataContext>().Use(c =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <DataContext>();

                optionsBuilder.UseMySql(c.GetInstance <WvsGameOptions>().ConnectionString);
                return(new DataContext(optionsBuilder.Options));
            });

            For <CommandRegistry>().Use <CommandRegistry>().Singleton();

            For <PackageCollection>().Use(c =>
            {
                WZReader.InitializeKeys();
                return(new PackageCollection(c.GetInstance <WvsGameOptions>().BaseWZPath));
            }).Singleton();

            For <ItemNameManager>().Use <ItemNameManager>().Singleton();
            For <FieldNameManager>().Use <FieldNameManager>().Singleton();
            For <EagerTemplateManager <ItemOptionTemplate> >().Use <ItemOptionTemplateManager>().Singleton();
            For <EagerTemplateManager <SetItemInfoTemplate> >().Use <SetItemInfoTemplateManager>().Singleton();
            For <LazyTemplateManager <SkillTemplate> >().Use <SkillTemplateManager>().Singleton();
            For <LazyTemplateManager <ItemTemplate> >().Use <ItemLazyTemplateManager>().Singleton();
            For <LazyTemplateManager <FieldTemplate> >().Use <FieldLazyTemplateManager>().Singleton();
            For <LazyTemplateManager <NPCTemplate> >().Use <NpcLazyTemplateManager>().Singleton();
            For <LazyTemplateManager <MobTemplate> >().Use <MobLazyTemplateManager>().Singleton();

            For <ConversationManager <FieldUser, FieldNPC> >().Use <NPCConversationManager>().Singleton();

            For <CenterServerSocketFactory>().Use <CenterServerSocketFactory>();
            For <GameClientSocketFactory>().Use <GameClientSocketFactory>();

            For <WvsGame>().Use <WvsGame>().Singleton();
        }
コード例 #2
0
        public WvsCenter(int channels)
        {
            config = new ConfigurationBuilder()
                     .AddJsonFile("Global.json", optional: true, reloadOnChange: true)
                     .Build();

            WZReader.InitializeKeys();

            WzProvider = new PackageCollection(Constants.WzLocation);

            Db       = new MongoDb();
            LoggedIn = new List <PendingLogin>();

            m_login = new WvsLogin(this);
            m_games = new WvsGame[channels];

            for (int i = 0; i < m_games.Length; i++)
            {
                var channel = (byte)i;
                m_games[i] = new WvsGame(this, channel);
            }
        }
コード例 #3
0
        public WvsLoginRegistry()
        {
            For <WvsLoginOptions>().Use(c =>
            {
                var configBuilder = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile("WvsLogin.example.json")
                                    .AddJsonFile("WvsLogin.json", true);
                var config  = configBuilder.Build();
                var options = new WvsLoginOptions();

                config.Bind(options);
                return(options);
            }).Singleton();

            For <DataContext>().Use(c =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <DataContext>();

                optionsBuilder.UseMySql(c.GetInstance <WvsLoginOptions>().ConnectionString);
                return(new DataContext(optionsBuilder.Options));
            });

            For <PackageCollection>().Use(c =>
            {
                WZReader.InitializeKeys();
                return(new PackageCollection(c.GetInstance <WvsLoginOptions>().BaseWZPath));
            }).Singleton();

            For <LazyTemplateManager <ItemTemplate> >().Use <ItemLazyTemplateManager>().Singleton();

            For <CenterServerSocketFactory>().Use <CenterServerSocketFactory>();
            For <LoginClientSocketFactory>().Use <LoginClientSocketFactory>();

            For <WvsLogin>().Use <WvsLogin>().Singleton();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            Console.WriteLine($"Console Arguments: {string.Join(",", args)}");

            Stopwatch watch = Stopwatch.StartNew();

            ILoggerFactory              logging                 = LoggerFactory.Create(builder => builder.AddConsole(options => options.LogToStandardErrorThreshold = LogLevel.Trace));
            ILogger <Package>           packageLogger           = logging.CreateLogger <Package>();
            ILogger <PackageCollection> packageCollectionLogger = logging.CreateLogger <PackageCollection>();
            ILogger <VersionGuesser>    versionGuesserLogger    = logging.CreateLogger <VersionGuesser>();
            ILogger <WZReader>          readerLogging           = logging.CreateLogger <WZReader>();

            MSPackageCollection.Logger  = logging.CreateLogger <MSPackageCollection>();
            WZFactory.Logger            = logging.CreateLogger <WZFactory>();
            WZAppSettingsFactory.Logger = logging.CreateLogger <WZAppSettingsFactory>();
            PackageCollection.Logging   = (s) => packageCollectionLogger.LogInformation(s);
            VersionGuesser.Logging      = (s) => versionGuesserLogger.LogInformation(s);
            Package.Logging             = (s) => packageLogger.LogInformation(s);

            WZProperty.SpecialUOL.Add("version", (uol, version) =>
            {
                string path            = uol.Path;
                MSPackageCollection wz = WZFactory.GetWZFromCache(uol.FileContainer.Collection.WZRegion, version);
                if (wz != null)
                {
                    return(wz.Resolve(path));
                }

                using (ApplicationDbContext dbCtx = new ApplicationDbContext())
                {
                    WZFactory wzFactory = new WZFactory(dbCtx);
                    return(wzFactory.GetWZ(uol.FileContainer.Collection.WZRegion, version).Resolve(path));
                }
            });

            //WZProperty.ChildrenMutate = (i) =>
            //{
            //    return i.Select(c =>
            //    {
            //        if (c.Type != PropertyType.Lua) return c;

            //        string luaVal = c.ResolveForOrNull<string>();
            //        if (!luaVal.StartsWith("!")) return c;

            //        string specialType = luaVal.Substring(1, luaVal.IndexOf(':') - 1);
            //        if (WZProperty.SpecialUOL.ContainsKey(specialType))
            //            return WZProperty.SpecialUOL[specialType](c, luaVal.Substring(specialType.Length + 2));
            //        else throw new InvalidOperationException("Unable to follow Special UOL, as there is no defined route");
            //    });
            //};

            readerLogging.LogDebug("Initializing Keys");
            WZReader.InitializeKeys();
            readerLogging.LogDebug("Done");

            //WZFactory.LoadAllWZ();

            ILogger prog = logging.CreateLogger <Program>();

            watch.Stop();
            prog.LogInformation($"Starting aspnet kestrel, took {watch.ElapsedMilliseconds}ms to initialize");

            var host = new WebHostBuilder()
                       .UseKestrel(options =>
            {
                options.Limits.MaxConcurrentConnections         = ushort.MaxValue;
                options.Limits.MaxConcurrentUpgradedConnections = ushort.MaxValue;
                options.Limits.MaxRequestLineSize    = ushort.MaxValue;
                options.Limits.MaxRequestBufferSize  = int.MaxValue;
                options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(15);
                options.Limits.KeepAliveTimeout      = TimeSpan.FromSeconds(120);
            })
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseUrls("http://*:5000")
                       .UseStartup <Startup>()
                       .Build();

            host.Run();
        }