176 lines
6.4 KiB
C#
176 lines
6.4 KiB
C#
using System.Net;
|
|
using System.Reflection;
|
|
using Amazon.DynamoDBv2.DocumentModel;
|
|
using CommandLine;
|
|
using ControlCenter.NamedPipeHost.Extensions;
|
|
using Google.Protobuf;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using NLog.Web;
|
|
using ServerCommon;
|
|
using ServerCore; using ServerBase;
|
|
using UGQApiServer.Converter;
|
|
using UGQApiServer.Extensions;
|
|
using UGQApiServer.Settings;
|
|
using UGQApiServer.Storage;
|
|
using UGQApiServer.UGQData;
|
|
using UGQApiServer.Auth;
|
|
using UGQApiServer.BackGroundService;
|
|
using UGQDataAccess.Logs;
|
|
|
|
namespace UGQApiServer
|
|
{
|
|
public class CommandLineOptions
|
|
{
|
|
[Option('t', "serverType", Required = true, HelpText = "UGQ API Server Type: [UgqApi, UgqAdmin, UgqIngame, UgqAllInOne]")]
|
|
public UgqApiType m_type { get; set; }
|
|
|
|
[Option('p', "port", Required = true, HelpText = "UGQ API Server Port")]
|
|
public int m_port { get; set; }
|
|
|
|
[Option('d', "develop", Default = false, Required = false, HelpText = "UGQ API Server Development Mode")]
|
|
public bool m_develop { get; set; }
|
|
}
|
|
|
|
/*
|
|
message UgqGameTaskDataForClient
|
|
{
|
|
int32 taskNum = 1;
|
|
UgqGameTextDataForClient goalText = 2;
|
|
optional string dialogueId = 3;
|
|
}
|
|
*/
|
|
|
|
public class Program
|
|
{
|
|
public static async Task Main(string[] args)
|
|
{
|
|
var parsing = Parser.Default.ParseArguments<CommandLineOptions>(args);
|
|
if (parsing?.Value == null) return;
|
|
|
|
var options = parsing.Value;
|
|
var apiAllowSettings = new ApiAllowSettings(options.m_type);
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
Console.WriteLine($"Env: {builder.Environment.EnvironmentName}");
|
|
|
|
// kestrel
|
|
options.m_port = usingKestrel(builder, options.m_port);
|
|
|
|
Log.NLogFileName = "./Config/nlog-UGQApiServer.config";
|
|
Log.initLog(options.m_type.ToString(), "Developer");
|
|
Log.setIPnPort(AwsHelper.getAwsPublicIPv4OrEthernetIPv4(), (ushort)options.m_port);
|
|
UgqApiBusinessLogger.initBusinessLog();
|
|
|
|
Log.getLogger().info("startup");
|
|
|
|
|
|
builder.Logging.ClearProviders();
|
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
|
builder.Host.UseNLog();
|
|
|
|
builder.Services.AddSingleton(apiAllowSettings);
|
|
builder.Services.AddSingleton(options);
|
|
builder.Services.AddSingleton<AuthSql>();
|
|
|
|
builder.Services.AddSingleton<ReserveAccountGradeBackGroundService>();
|
|
builder.Services.AddHostedService(provider => provider.GetRequiredService<ReserveAccountGradeBackGroundService>());
|
|
builder.Services.AddOnTimeBackgroundService();
|
|
|
|
builder.Services.AddOnTimeTask("logging", new DateTime(1, 1, 1, 0, 1, 0), new Task(DailyEmptyLogging));
|
|
|
|
await builder.Services.AddUGQApiExtention(builder.Configuration);
|
|
|
|
var assemblies = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
|
|
var serverType = changeServerTypeFromUgcTypeToControlCenterType(options.m_type);
|
|
builder.Services.AddNamedPipelineClientManager(assemblies, serverType, ServiceCategory.Caliverse.ToString(), NetworkHelper.getEthernetLocalIPv4(), options.m_port);
|
|
|
|
var app = builder.Build();
|
|
|
|
// app.UseHttpLogging();
|
|
|
|
app.MapHealthChecks("/healthcheck");
|
|
|
|
UGQConverter.init(app.Services.GetRequiredService<IStorageService>(), app.Services.GetRequiredService<UGQMetaData>());
|
|
InGameConverter.init(app.Services.GetRequiredService<IStorageService>(), app.Services.GetRequiredService<UGQMetaData>());
|
|
|
|
bool isDevelopment = app.Environment.IsDevelopment() || options.m_develop ||
|
|
(builder.Environment.EnvironmentName == "AWSDev");
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (isDevelopment == true)
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
// Account api 때문에 모든 설정에서 보여야 함
|
|
// if (apiAllowSettings.AllowWebApi) c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
|
if (apiAllowSettings.AllowInGameApi) c.SwaggerEndpoint("/swagger/ingame/swagger.json", "InGame");
|
|
if (apiAllowSettings.AllowAdminApi) c.SwaggerEndpoint("/swagger/admin/swagger.json", "Admin");
|
|
if (isDevelopment) c.SwaggerEndpoint("/swagger/development/swagger.json", "Development");
|
|
});
|
|
}
|
|
|
|
app.UseRequestLocalization();
|
|
|
|
|
|
app.UseCors("Everything");
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
app.UseNamedPipelineClientManager();
|
|
await app.RunAsync();
|
|
}
|
|
|
|
private static void DailyEmptyLogging()
|
|
{
|
|
List<ILogInvoker> business_logs = [
|
|
new UgqApiEmptyLoginBusinessLog(),
|
|
];
|
|
var log_action = new LogActionEx(LogActionType.TestBusinessLog);
|
|
var empty_business_refresh_with_log_actor = new EmptyBusinessWithLogActor();
|
|
BusinessLogger.collectLogs(log_action, empty_business_refresh_with_log_actor, business_logs);
|
|
}
|
|
|
|
private static int usingKestrel(WebApplicationBuilder builder, int port)
|
|
{
|
|
port = port <= 0 ? Default.DefaultPort : port;
|
|
|
|
builder.WebHost.ConfigureKestrel(options =>
|
|
{
|
|
// port 설정
|
|
options.Listen(IPAddress.Any, port, o =>
|
|
{
|
|
// https 사용 설정
|
|
//o.UseHttps("*.pfx", "pwd");
|
|
|
|
// protocols 설정
|
|
o.Protocols = HttpProtocols.Http1;
|
|
});
|
|
});
|
|
|
|
return port;
|
|
}
|
|
|
|
private static ServerControlCenter.ServerType changeServerTypeFromUgcTypeToControlCenterType(UgqApiType type)
|
|
{
|
|
return type switch
|
|
{
|
|
UgqApiType.UgqApi or UgqApiType.UgqAllInOne => ServerControlCenter.ServerType.UgqApi,
|
|
UgqApiType.UgqIngame => ServerControlCenter.ServerType.UgqIngame,
|
|
UgqApiType.UgqAdmin => ServerControlCenter.ServerType.UgqAdmin,
|
|
_ => ServerControlCenter.ServerType.None
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|