139 lines
4.2 KiB
C#
139 lines
4.2 KiB
C#
using System.Collections.Concurrent;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using CommandLine;
|
|
using ControlCenter.NamedPipe.Model;
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
|
|
|
|
using SESSION_ID = System.Int32;
|
|
using META_ID = System.UInt32;
|
|
using ENTITY_GUID = System.String;
|
|
using ACCOUNT_ID = System.String;
|
|
using OWNER_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
using CHARACTER_GUID = System.String;
|
|
using ITEM_GUID = System.String;
|
|
|
|
|
|
|
|
namespace GameServer;
|
|
|
|
public class Options
|
|
{
|
|
[Option("port", Default = (UInt16)9001)]
|
|
public UInt16 Port { get; set; } = 9001;
|
|
|
|
[Option("config", Default = "ServerConfig.json")]
|
|
public string Config { get; set; } = "ServerConfig.json";
|
|
|
|
[Option("serverType", Default = nameof(ServerType.Channel))]
|
|
public string ServerTypeString { get; set; } = ServerType.Channel.toServerTypeString();
|
|
|
|
[Option("worldId", Default = 1)]
|
|
public int WorldId { get; set; } = 1;
|
|
|
|
[Option("channelNo", Default = (UInt16) 1)]
|
|
public UInt16 ChannelNo { get; set; } = 1;
|
|
|
|
[Option("defaultMaxUser", Default = (UInt16)2000 )]
|
|
public UInt16 DefaultMaxUser { get; set; } = 2000;
|
|
|
|
// 디버그용 옵션 추가
|
|
[Option("debug", Default = false)]
|
|
public bool Debug { get; set; } = false;
|
|
}
|
|
|
|
public static class GameServerApp
|
|
{
|
|
private static GameServerLogic? m_server_logic;
|
|
|
|
public static GameServerLogic getServerLogic()
|
|
{
|
|
NullReferenceCheckHelper.throwIfNull(m_server_logic);
|
|
return m_server_logic;
|
|
}
|
|
|
|
|
|
private static async Task<int> Main(string[] args)
|
|
{
|
|
var result = new Result();
|
|
|
|
ServerCore.Log.getLogger().info($"GameServer start");
|
|
|
|
try
|
|
{
|
|
result = await Parser.Default.ParseArguments<Options>(args).MapResult(
|
|
async (Options opts) =>
|
|
{
|
|
return await runServer(opts);
|
|
|
|
}, errors => Task.FromResult(result)
|
|
);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
var err_msg = $"Exception !!!, GameServerApp.runServer() : message:{e}";
|
|
result.setFail(ServerErrorCode.TryCatchException, err_msg);
|
|
}
|
|
finally
|
|
{
|
|
if (result.isFail())
|
|
{
|
|
ServerCore.Log.getLogger().error($"GameServer finally error !!! - {result.toBasicString()}");
|
|
}
|
|
}
|
|
|
|
ServerCore.Log.shutdown();
|
|
|
|
ServerCore.Log.getLogger().info($"GameServer terminated");
|
|
|
|
return 0;
|
|
}
|
|
|
|
private static async Task<Result> runServer(Options argOptions)
|
|
{
|
|
var result = new Result();
|
|
|
|
var key_options = new Dictionary<string, string>
|
|
{
|
|
{ "port", argOptions.Port.ToString() },
|
|
{ "config", argOptions.Config },
|
|
{ "serverType", argOptions.ServerTypeString },
|
|
{ "worldId", argOptions.WorldId.ToString() },
|
|
{ "channelNo", argOptions.ChannelNo.ToString() },
|
|
{ "defaultMaxUser", argOptions.DefaultMaxUser.ToString() },
|
|
{ "debug", argOptions.Debug.ToString() }
|
|
};
|
|
|
|
var configuration = new ConfigurationBuilder().AddInMemoryCollection(key_options!).Build();
|
|
NullReferenceCheckHelper.throwIfNull(configuration, () => $"configuration is null !!!");
|
|
var server_config = new ServerConfig();
|
|
|
|
m_server_logic = new GameServerLogic(server_config);
|
|
m_server_logic.setServerType(argOptions.ServerTypeString);
|
|
m_server_logic.setConfiguration(configuration);
|
|
|
|
var config = m_server_logic.getConfiguration();
|
|
|
|
var namedOptionBuilder = new NamedPipeClientOptionBuilder();
|
|
namedOptionBuilder.setIP(NetworkHelper.getEthernetLocalIPv4())
|
|
.setPort(config.getPort())
|
|
.setType(config.getServerType().toServerTypeString())
|
|
.setServiceCategory(nameof(ServiceCategory.Caliverse))
|
|
.setWorldID((int)config.getWorldId())
|
|
.setChannelNo((int)config.getChannelNo());
|
|
|
|
result = await m_server_logic.onRunServer(namedOptionBuilder);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|