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();
        }
Beispiel #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);
            }
        }
Beispiel #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();
        }
Beispiel #4
0
        public IActionResult Export(Region region, string version, string path, [FromQuery] bool rawImage = false)
        {
            MSPackageCollection wz   = _wzFactory.GetWZ(region, version);
            WZProperty          prop = wz.Resolve(path);

            if (prop == null)
            {
                return(NotFound());
            }
            if (prop.Type == PropertyType.Directory)
            {
                return(Forbid());
            }

            Queue <WZProperty> propQueue = new Queue <WZProperty>();

            propQueue.Enqueue(prop);

            if (rawImage && rawImage)
            {
                using (WZReader reader = prop.FileContainer.GetContentReader(null, prop.Resolve()))
                {
                    reader.BaseStream.Seek(prop.Offset, SeekOrigin.Begin);
                    return(File(reader.ReadBytes((int)prop.Size), "wizet/img", $"{prop.NameWithoutExtension}.img"));
                }
            }

            using (MemoryStream mem = new MemoryStream())
            {
                using (ZipArchive archive = new ZipArchive(mem, ZipArchiveMode.Create, true))
                {
                    while (propQueue.TryDequeue(out WZProperty entry))
                    {
                        byte[] data      = null;
                        string extension = null;
                        if (entry.Type == PropertyType.Audio)
                        {
                            data      = (byte[])((IWZPropertyVal <byte[]>)entry).Value;
                            extension = "mp3";
                        }
                        else if (entry.Type == PropertyType.Canvas)
                        {
                            data      = entry.ResolveForOrNull <Image <Rgba32> >()?.ImageToByte(Request, false, null, false);
                            extension = "png";
                        }

                        if (data != null)
                        {
                            ZipArchiveEntry zipEntry = archive.CreateEntry(entry.Path + '.' + extension, CompressionLevel.Optimal);
                            using (Stream zipEntryData = zipEntry.Open())
                            {
                                zipEntryData.Write(data, 0, data.Length);
                                zipEntryData.Flush();
                            }
                        }

                        foreach (WZProperty child in entry.Children)
                        {
                            propQueue.Enqueue(child);
                        }
                    }
                }

                return(File(mem.ToArray(), "application/zip", "export.zip"));
            }
        }
Beispiel #5
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();
        }