예제 #1
0
        public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context)
        {
            logger = new LoggerConfiguration()
                     .MinimumLevel.Information()
                     .WriteTo.GmodSink()
                     .CreateLogger();

            gmodInteropService = new GmodInteropService(lua);

            try
            {
                logger.Information("Creating and starting web host.");
                webHost = CreateHostBuilder().Build();
                webHost.Start();
                logger.Information("Web host was started.");
            }
            catch (Exception e)
            {
                logger.Fatal(e, $"Error was thrown while loading module {nameof(TemplateModuleWeb)}.");
            }
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

            app.Run(async context =>
            {
                GmodInteropService gmodInteropService = context.RequestServices.GetRequiredService <GmodInteropService>();
                List <string> players = await gmodInteropService.GetPlayersList();
                string response_text  = "Hello! \nPlayers on server:";
                foreach (string player in players)
                {
                    response_text += "\n" + player;
                }
                context.Response.StatusCode = 200;
                context.Response.Headers.Add("Content-Type", "text/plain");
                await context.Response.WriteAsync(response_text);
            });
        }