diff --git a/Arrowgene.Ddon.Cli/Command/ServerCommand.cs b/Arrowgene.Ddon.Cli/Command/ServerCommand.cs index d03f32cb0..8529f21f5 100644 --- a/Arrowgene.Ddon.Cli/Command/ServerCommand.cs +++ b/Arrowgene.Ddon.Cli/Command/ServerCommand.cs @@ -7,8 +7,10 @@ namespace Arrowgene.Ddon.Cli.Command { public class ServerCommand : ICommand { + private Setting _setting; private DdonLoginServer _loginServer; private DdonGameServer _gameServer; + private DdonGameServer _selectServer; private DdonWebServer _webServer; public string Key => "server"; @@ -18,22 +20,27 @@ public class ServerCommand : ICommand public CommandResultType Run(CommandParameter parameter) { + if (_setting == null) + { + _setting = new Setting(); + } if (_loginServer == null) { - LoginServerSetting setting = new LoginServerSetting(); - _loginServer = new DdonLoginServer(setting); + _loginServer = new DdonLoginServer(_setting.LoginServerSetting); } if (_webServer == null) { - WebServerSetting setting = new WebServerSetting(); - _webServer = new DdonWebServer(); + _webServer = new DdonWebServer(_setting.WebServerSetting); } if (_gameServer == null) { - GameServerSetting setting = new GameServerSetting(); - _gameServer = new DdonGameServer(setting); + _gameServer = new DdonGameServer(_setting.GameServerSetting); + + GameServerSetting s = new GameServerSetting(); + s.ServerSetting.ServerPort = 52200; + _selectServer = new DdonGameServer(s); } if (parameter.Arguments.Contains("start")) @@ -41,6 +48,7 @@ public CommandResultType Run(CommandParameter parameter) _webServer.Start(); _gameServer.Start(); _loginServer.Start(); + _selectServer.Start(); return CommandResultType.Completed; } @@ -49,6 +57,7 @@ public CommandResultType Run(CommandParameter parameter) _webServer.Stop(); _gameServer.Stop(); _loginServer.Stop(); + _selectServer.Stop(); return CommandResultType.Completed; } @@ -65,6 +74,7 @@ public void Shutdown() if (_gameServer != null) { _gameServer.Stop(); + _selectServer.Stop(); } if (_webServer != null) diff --git a/Arrowgene.Ddon.Cli/Setting.cs b/Arrowgene.Ddon.Cli/Setting.cs index 0e034726e..26da029ed 100644 --- a/Arrowgene.Ddon.Cli/Setting.cs +++ b/Arrowgene.Ddon.Cli/Setting.cs @@ -1,5 +1,6 @@ using System.Runtime.Serialization; using Arrowgene.Ddon.Database; +using Arrowgene.Ddon.GameServer; using Arrowgene.Ddon.LoginServer; using Arrowgene.Ddon.WebServer; @@ -9,20 +10,23 @@ namespace Arrowgene.Ddon.Cli public class Setting { [DataMember(Order = 10)] public WebServerSetting WebServerSetting { get; set; } - [DataMember(Order = 11)] public LoginServerSetting GameServerSetting { get; set; } - [DataMember(Order = 12)] public DatabaseSetting DatabaseSetting { get; set; } + [DataMember(Order = 20)] public GameServerSetting GameServerSetting { get; set; } + [DataMember(Order = 30)] public LoginServerSetting LoginServerSetting { get; set; } + [DataMember(Order = 40)] public DatabaseSetting DatabaseSetting { get; set; } public Setting() { WebServerSetting = new WebServerSetting(); - GameServerSetting = new LoginServerSetting(); + GameServerSetting = new GameServerSetting(); + LoginServerSetting = new LoginServerSetting(); DatabaseSetting = new DatabaseSetting(); } public Setting(Setting setting) { setting.WebServerSetting = new WebServerSetting(setting.WebServerSetting); - setting.GameServerSetting = new LoginServerSetting(setting.GameServerSetting); + setting.GameServerSetting = new GameServerSetting(setting.GameServerSetting); + setting.LoginServerSetting = new LoginServerSetting(setting.LoginServerSetting); setting.DatabaseSetting = new DatabaseSetting(setting.DatabaseSetting); } } diff --git a/Arrowgene.Ddon.GameServer/DdonGameServer.cs b/Arrowgene.Ddon.GameServer/DdonGameServer.cs index b8e6ca021..11dd4a165 100644 --- a/Arrowgene.Ddon.GameServer/DdonGameServer.cs +++ b/Arrowgene.Ddon.GameServer/DdonGameServer.cs @@ -62,11 +62,13 @@ private void LoadPacketHandler() AddHandler(new ConnectionLoginHandler(this)); AddHandler(new ConnectionMoveOutServerHandler(this)); AddHandler(new ConnectionPingHandler(this)); + AddHandler(new ConnectionReserveServerHandler(this)); AddHandler(new LoadingInfoLoadingGetInfoHandler(this)); AddHandler(new ServerGetGameSettingHandler(this)); AddHandler(new ServerGetRealTimeHandler(this)); AddHandler(new ServerGetServerListHandler(this)); AddHandler(new StageGetStageListHandler(this)); + AddHandler(new WarpGetStartPointListHandler(this)); } } } diff --git a/Arrowgene.Ddon.GameServer/Handler/ConnectionReserveServerHandler.cs b/Arrowgene.Ddon.GameServer/Handler/ConnectionReserveServerHandler.cs new file mode 100644 index 000000000..8439f63bf --- /dev/null +++ b/Arrowgene.Ddon.GameServer/Handler/ConnectionReserveServerHandler.cs @@ -0,0 +1,24 @@ +using Arrowgene.Ddon.GameServer.Dump; +using Arrowgene.Ddon.Server.Logging; +using Arrowgene.Ddon.Server.Network; +using Arrowgene.Logging; + +namespace Arrowgene.Ddon.GameServer.Handler +{ + public class ConnectionReserveServerHandler : PacketHandler + { + private static readonly DdonLogger Logger = LogProvider.Logger(typeof(ConnectionReserveServerHandler)); + + + public ConnectionReserveServerHandler(DdonGameServer server) : base(server) + { + } + + public override PacketId Id => PacketId.C2S_CONNECTION_RESERVE_SERVER_REQ; + + public override void Handle(GameClient client, Packet packet) + { + client.Send(GameDump.Dump_27); + } + } +} diff --git a/Arrowgene.Ddon.GameServer/Handler/ServerGetServerListHandler.cs b/Arrowgene.Ddon.GameServer/Handler/ServerGetServerListHandler.cs index c253f80d9..b270437d3 100644 --- a/Arrowgene.Ddon.GameServer/Handler/ServerGetServerListHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/ServerGetServerListHandler.cs @@ -1,4 +1,6 @@ -using Arrowgene.Ddon.GameServer.Dump; +using System; +using Arrowgene.Buffers; +using Arrowgene.Ddon.GameServer.Dump; using Arrowgene.Ddon.Server.Logging; using Arrowgene.Ddon.Server.Network; using Arrowgene.Logging; @@ -18,7 +20,19 @@ public ServerGetServerListHandler(DdonGameServer server) : base(server) public override void Handle(GameClient client, Packet packet) { - client.Send(GameDump.Dump_23); + IBuffer buffer = new StreamBuffer(GameDump.data_Dump_23); + buffer.Position = 56; + string firstIp = "127.0.0.1"; + buffer.WriteUInt16((ushort) firstIp.Length, Endianness.Big); + buffer.WriteString(firstIp); + + buffer.WriteUInt16((ushort) 52200, Endianness.Big); + + buffer.WriteBytes(GameDump.data_Dump_23.AsSpan(72 + 2).ToArray()); + + client.Send(new Packet(PacketId.S2C_SERVER_GET_SERVER_LIST_RES, buffer.GetAllBytes(), PacketSource.Server)); + + // client.Send(GameDump.Dump_23); } } } diff --git a/Arrowgene.Ddon.GameServer/Handler/WarpGetStartPointListHandler.cs b/Arrowgene.Ddon.GameServer/Handler/WarpGetStartPointListHandler.cs new file mode 100644 index 000000000..11f26557f --- /dev/null +++ b/Arrowgene.Ddon.GameServer/Handler/WarpGetStartPointListHandler.cs @@ -0,0 +1,24 @@ +using Arrowgene.Ddon.GameServer.Dump; +using Arrowgene.Ddon.Server.Logging; +using Arrowgene.Ddon.Server.Network; +using Arrowgene.Logging; + +namespace Arrowgene.Ddon.GameServer.Handler +{ + public class WarpGetStartPointListHandler : PacketHandler + { + private static readonly DdonLogger Logger = LogProvider.Logger(typeof(WarpGetStartPointListHandler)); + + + public WarpGetStartPointListHandler(DdonGameServer server) : base(server) + { + } + + public override PacketId Id => PacketId.C2S_WARP_GET_START_POINT_LIST_REQ; + + public override void Handle(GameClient client, Packet packet) + { + client.Send(GameDump.Dump_25); + } + } +} diff --git a/Arrowgene.Ddon.Server/Network/PacketFactory.cs b/Arrowgene.Ddon.Server/Network/PacketFactory.cs index b8f762a67..ce379b0dd 100644 --- a/Arrowgene.Ddon.Server/Network/PacketFactory.cs +++ b/Arrowgene.Ddon.Server/Network/PacketFactory.cs @@ -27,9 +27,10 @@ public class PacketFactory private const int PacketLengthFieldSize = 2; private const int PacketHeaderSize = 9; + private const int PacketMinimumDataSize = 16; private bool _readHeader; - private uint _dataSize; + private ushort _dataSize; private uint _packetCount; private int _position; private IBuffer _buffer; @@ -128,34 +129,18 @@ public List Read(byte[] data) if (!_readHeader && _buffer.Size - _buffer.Position >= PacketLengthFieldSize) { _dataSize = _buffer.ReadUInt16(Endianness.Big); - if (_dataSize < PacketLengthFieldSize) + if (_dataSize < PacketMinimumDataSize) { - Logger.Error($"DataSize:{_dataSize} < PacketLengthFieldSize:{PacketLengthFieldSize}"); + Logger.Error($"DataSize:{_dataSize} < PacketMinimumDataSize:{PacketMinimumDataSize}"); Reset(); return packets; } - - if (_dataSize > int.MaxValue) - { - Logger.Error($"DataSize:{_dataSize} < int.MaxValue:{int.MaxValue} - not supported"); - Reset(); - return packets; - } - _readHeader = true; } if (_readHeader && _buffer.Size - _buffer.Position >= _dataSize) { - int dataSize = (int) _dataSize; - if (dataSize < PacketHeaderSize) - { - Logger.Error($"DataSize:{dataSize} < PacketHeaderSize:{PacketHeaderSize}"); - Reset(); - return packets; - } - - byte[] encryptedPacketData = _buffer.ReadBytes(dataSize); + byte[] encryptedPacketData = _buffer.ReadBytes(_dataSize); byte[] packetData = Decrypt(encryptedPacketData); IBuffer packetBuffer = new StreamBuffer(packetData); packetBuffer.SetPositionStart(); @@ -172,6 +157,8 @@ public List Read(byte[] data) if (unknownA != 0 /*reading client packet*/ && unknownA != 0x34 /*reading server packet*/) { + // TODO potentially change this to check if it is the first packet of a session + // and treat it as the challenge payload = packetData; if (_packetIdResolver.ServerType == ServerType.Game) { diff --git a/Arrowgene.Ddon.WebServer/DdonWebServer.cs b/Arrowgene.Ddon.WebServer/DdonWebServer.cs index 0f4ba5f86..cc80de7f1 100644 --- a/Arrowgene.Ddon.WebServer/DdonWebServer.cs +++ b/Arrowgene.Ddon.WebServer/DdonWebServer.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using Arrowgene.Ddon.Shared; +using System.Threading.Tasks; using Arrowgene.WebServer; using Arrowgene.WebServer.Server; using Arrowgene.WebServer.Server.Kestrel; @@ -13,21 +10,16 @@ namespace Arrowgene.Ddon.WebServer public class DdonWebServer { private readonly WebService _webService; + private readonly WebServerSetting _setting; - public DdonWebServer() + public DdonWebServer(WebServerSetting setting) { - WebSetting setting = new WebSetting(); - setting.ServerHeader = ""; - setting.WebFolder = Path.Combine(Util.ExecutingDirectory(), "Files/www"); - setting.HttpPorts = new List() {80}; - setting.HttpsEnabled = false; - setting.HttpsPort = 443; - setting.HttpsCertPath = ""; - setting.HttpsCertPw = ""; - IWebServerCore core = new KestrelWebServer(setting); + _setting = setting; + + IWebServerCore core = new KestrelWebServer(_setting.WebSetting); _webService = new WebService(core); - IFileProvider webFileProvider = new PhysicalFileProvider(setting.WebFolder); + IFileProvider webFileProvider = new PhysicalFileProvider(_setting.WebSetting.WebFolder); _webService.AddMiddleware(new StaticFileMiddleware("", webFileProvider)); _webService.AddRoute(new IndexRoute()); diff --git a/Arrowgene.Ddon.WebServer/WebServerSetting.cs b/Arrowgene.Ddon.WebServer/WebServerSetting.cs index 0c6605c1f..819aff54c 100644 --- a/Arrowgene.Ddon.WebServer/WebServerSetting.cs +++ b/Arrowgene.Ddon.WebServer/WebServerSetting.cs @@ -1,6 +1,8 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using System.Runtime.Serialization; using Arrowgene.Ddon.Shared; +using Arrowgene.WebServer; namespace Arrowgene.Ddon.WebServer { @@ -9,29 +11,21 @@ public class WebServerSetting { public WebServerSetting() { - ServerHeader = null; - WebFolder = Path.Combine(Util.ExecutingDirectory(), "Files/www"); - HttpPort = 80; - HttpsEnabled = false; - HttpsPort = 443; - HttpsCertPath = Path.Combine(Util.ExecutingDirectory(), "Files/ddon.pfx"); + WebSetting = new WebSetting(); + WebSetting.ServerHeader = ""; + WebSetting.WebFolder = Path.Combine(Util.ExecutingDirectory(), "Files/www"); + WebSetting.HttpPorts = new List() {80}; + WebSetting.HttpsEnabled = false; + WebSetting.HttpsPort = 443; + WebSetting.HttpsCertPath = ""; + WebSetting.HttpsCertPw = ""; } - public WebServerSetting(WebServerSetting webSetting) + public WebServerSetting(WebServerSetting webServerSetting) { - ServerHeader = webSetting.ServerHeader; - WebFolder = webSetting.WebFolder; - HttpPort = webSetting.HttpPort; - HttpsEnabled = webSetting.HttpsEnabled; - HttpsPort = webSetting.HttpsPort; - HttpsCertPath = webSetting.HttpsCertPath; + WebSetting = new WebSetting(webServerSetting.WebSetting); } - [DataMember(Order = 1)] public string ServerHeader { get; set; } - [DataMember(Order = 2)] public short HttpPort { get; set; } - [DataMember(Order = 3)] public bool HttpsEnabled { get; set; } - [DataMember(Order = 4)] public short HttpsPort { get; set; } - [DataMember(Order = 5)] public string HttpsCertPath { get; set; } - [DataMember(Order = 6)] public string WebFolder { get; set; } + [DataMember(Order = 1)] public WebSetting WebSetting { get; set; } } }