Skip to content

Commit

Permalink
loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-heinz committed Jan 10, 2022
1 parent d22bad5 commit ecd32b1
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 67 deletions.
22 changes: 16 additions & 6 deletions Arrowgene.Ddon.Cli/Command/ServerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -18,29 +20,35 @@ 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"))
{
_webServer.Start();
_gameServer.Start();
_loginServer.Start();
_selectServer.Start();
return CommandResultType.Completed;
}

Expand All @@ -49,6 +57,7 @@ public CommandResultType Run(CommandParameter parameter)
_webServer.Stop();
_gameServer.Stop();
_loginServer.Stop();
_selectServer.Stop();
return CommandResultType.Completed;
}

Expand All @@ -65,6 +74,7 @@ public void Shutdown()
if (_gameServer != null)
{
_gameServer.Stop();
_selectServer.Stop();
}

if (_webServer != null)
Expand Down
12 changes: 8 additions & 4 deletions Arrowgene.Ddon.Cli/Setting.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.Serialization;
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.GameServer;
using Arrowgene.Ddon.LoginServer;
using Arrowgene.Ddon.WebServer;

Expand All @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<GameClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(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);
}
}
}
18 changes: 16 additions & 2 deletions Arrowgene.Ddon.GameServer/Handler/ServerGetServerListHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
}
24 changes: 24 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/WarpGetStartPointListHandler.cs
Original file line number Diff line number Diff line change
@@ -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<GameClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(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);
}
}
}
27 changes: 7 additions & 20 deletions Arrowgene.Ddon.Server/Network/PacketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,34 +129,18 @@ public List<Packet> 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();
Expand All @@ -172,6 +157,8 @@ public List<Packet> 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)
{
Expand Down
22 changes: 7 additions & 15 deletions Arrowgene.Ddon.WebServer/DdonWebServer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ushort>() {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());
Expand Down
34 changes: 14 additions & 20 deletions Arrowgene.Ddon.WebServer/WebServerSetting.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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<ushort>() {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; }
}
}

0 comments on commit ecd32b1

Please sign in to comment.