Skip to content

Commit

Permalink
Merge pull request #1 from Andoryuuta/login-server-patches
Browse files Browse the repository at this point in the history
Login server patches
  • Loading branch information
sebastian-heinz authored Jan 10, 2022
2 parents 88d10a8 + f641d20 commit 272fcae
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 87 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## User-specific VS project launch settings
Arrowgene.Ddo.Cli/Properties/launchSettings.json

## Folders specific
/publish/
/release/
Expand Down
7 changes: 4 additions & 3 deletions Arrowgene.Ddon.LoginServer/DdonLoginServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is part of Arrowgene.Ddon.LoginServer
*
* Arrowgene.Ddon.LoginServer is a server implementation for the game "Dragons Dogma Online".
Expand Down Expand Up @@ -59,12 +59,13 @@ public override LoginClient NewClient(ITcpSocket socket)
private void LoadPacketHandler()
{
AddHandler(new ClientChallengeHandler(this));
AddHandler(new ClientSessionKeyHandler(this));
AddHandler(new ClientX1Handler(this));
AddHandler(new ClientLoginHandler(this));
AddHandler(new ClientPingHandler(this));
AddHandler(new GetErrorMessageListHandler(this));
AddHandler(new GetLoginSettingHandler(this));
AddHandler(new GpCourseGetInfoHandler(this));
AddHandler(new GetCharacterListHandler(this));
AddHandler(new DeleteCharacterHandler(this));
AddHandler(new ClientX6Handler(this));
AddHandler(new ClientX9Handler(this));
AddHandler(new ClientX10Handler(this));
Expand Down
50 changes: 50 additions & 0 deletions Arrowgene.Ddon.LoginServer/Handler/ClientLoginHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Server.Logging;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Logging;
using System.Text;

namespace Arrowgene.Ddon.LoginServer.Handler
{
public class ClientLoginHandler : PacketHandler<LoginClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(typeof(ClientLoginHandler));


public ClientLoginHandler(DdonLoginServer server) : base(server)
{
}

public override PacketId Id => PacketId.C2L_LOGIN_REQ;

public override void Handle(LoginClient client, Packet packet)
{
IBuffer recv = packet.AsBuffer();
ushort len = recv.ReadUInt16(Endianness.Big);
string onetimeToken = recv.ReadString(len);

/*
PLATFORM_TYPE_NONE = 0x0,
PLATFORM_TYPE_PC = 0x1,
PLATFORM_TYPE_PS3 = 0x2,
PLATFORM_TYPE_PS4 = 0x3,
*/
byte inPlatform = recv.ReadByte();

Logger.Debug(client, $"Received OnetimeToken: {onetimeToken}");

client.OnetimeToken = onetimeToken;

IBuffer buffer = new StreamBuffer();
buffer.WriteInt32(0); //us_error
buffer.WriteInt32(0); //n_result

// Onetime Token (MtString)
byte[] utf8 = Encoding.UTF8.GetBytes(client.OnetimeToken);
buffer.WriteUInt16((ushort)client.OnetimeToken.Length, Endianness.Big);
buffer.WriteBytes(utf8);

client.Send(new Packet(PacketId.L2C_LOGIN_RES, buffer.GetAllBytes(), PacketSource.Server));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
using Arrowgene.Buffers;
using Arrowgene.Buffers;
using Arrowgene.Ddon.Server.Logging;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.LoginServer.Handler
{
public class ClientX1Handler : PacketHandler<LoginClient>
public class ClientPingHandler : PacketHandler<LoginClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(typeof(ClientX1Handler));
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(typeof(ClientPingHandler));


public ClientX1Handler(DdonLoginServer server) : base(server)
public ClientPingHandler(DdonLoginServer server) : base(server)
{
}

public override PacketId Id => PacketId.X1_REQ;
public override PacketId Id => PacketId.C2L_PING_REQ;

public override void Handle(LoginClient client, Packet packet)
{
IBuffer buffer = new StreamBuffer();
buffer.WriteUInt32(0, Endianness.Big);
buffer.WriteUInt32(0, Endianness.Big);
buffer.WriteBytes(new byte[15]);
client.Send(new Packet(PacketId.X1_RES, buffer.GetAllBytes(), PacketSource.Server));

client.Send(new Packet(PacketId.L2C_PING_RES, buffer.GetAllBytes(), PacketSource.Server));
}
}
}
53 changes: 0 additions & 53 deletions Arrowgene.Ddon.LoginServer/Handler/ClientSessionKeyHandler.cs

This file was deleted.

33 changes: 23 additions & 10 deletions Arrowgene.Ddon.LoginServer/Handler/ClientX6Handler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Arrowgene.Buffers;
using Arrowgene.Buffers;
using Arrowgene.Ddon.LoginServer.Dump;
using Arrowgene.Ddon.Server.Logging;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.LoginServer.Handler
Expand All @@ -22,16 +23,28 @@ public override void Handle(LoginClient client, Packet packet)
client.Send(LoginDump.Dump_28);
client.Send(LoginDump.Dump_31);

string ip = "127.0.0.1";
IBuffer buffer = new StreamBuffer(LoginDump.data_Dump_32);
buffer.SetPositionStart();
buffer.Position = 48;
buffer.WriteUInt16((ushort) ip.Length, Endianness.Big);
buffer.WriteString(ip);
buffer.WriteUInt16(52000, Endianness.Big);
buffer.WriteBytes(new byte[] {0x0, 0x1, 0x46, 0xE9, 0x1D});
// Begin writing L2C_NEXT_CONNECT_SERVER_NTC
IBuffer buffer = new StreamBuffer();
buffer.WriteUInt32(0, Endianness.Big); // Error

CDataGameServerListInfoSerializer serializer = new CDataGameServerListInfoSerializer();
serializer.Write(buffer, new CDataGameServerListInfo
{
ID = 17,
Name = "サーバー017",
Brief = "",
TrafficName = "少なめ",
MaxLoginNum = 1000, // Player cap
LoginNum = 0x1C, // Current players
Addr = "127.0.0.1",
Port = 52000,
IsHide = false
});

buffer.WriteByte(1); // "counter".
byte[] data = buffer.GetBytes(0, buffer.Position);
client.Send(new Packet(PacketId.X8, data, PacketSource.Server));

client.Send(new Packet(PacketId.L2C_NEXT_CONNECT_SERVER_NTC, data, PacketSource.Server));
}
}
}
32 changes: 32 additions & 0 deletions Arrowgene.Ddon.LoginServer/Handler/DeleteCharacterHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Server.Logging;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Logging;
using System.Text;

namespace Arrowgene.Ddon.LoginServer.Handler
{
public class DeleteCharacterHandler : PacketHandler<LoginClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(typeof(DeleteCharacterHandler));

public DeleteCharacterHandler(DdonLoginServer server) : base(server)
{
}

public override PacketId Id => PacketId.C2L_DELETE_CHARACTER_INFO_REQ;

public override void Handle(LoginClient client, Packet packet)
{
IBuffer recv = packet.AsBuffer();
uint characterID = recv.ReadUInt32(Endianness.Big);
Logger.Debug(client, $"Tried to delete character with ID: {characterID}");


IBuffer buffer = new StreamBuffer();
buffer.WriteInt32(0); //us_error
buffer.WriteUInt32(0, Endianness.Big);
client.Send(new Packet(PacketId.L2C_DELETE_CHARACTER_INFO_RES, buffer.GetAllBytes(), PacketSource.Server));
}
}
}
4 changes: 2 additions & 2 deletions Arrowgene.Ddon.LoginServer/LoginClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Networking.Tcp;

namespace Arrowgene.Ddon.LoginServer
Expand All @@ -10,6 +10,6 @@ public LoginClient(ITcpSocket socket, PacketFactory packetFactory) : base(socket
Identity = $"[LoginClient@{socket.Identity}]";
}

public string SessionKey { get; set; }
public string OnetimeToken { get; set; }
}
}
7 changes: 6 additions & 1 deletion Arrowgene.Ddon.Server/Network/PacketFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Arrowgene.Buffers;
using Arrowgene.Ddon.Server.Logging;
Expand Down Expand Up @@ -90,8 +90,13 @@ public byte[] Write(Packet packet)
packetDataBuffer.WriteByte(packet.Id.HandlerSubId);
packetDataBuffer.WriteByte(0x34);
packetDataBuffer.WriteUInt32(_packetCount, Endianness.Big);

packetDataBuffer.WriteBytes(data);

// Align packet data to 16 bytes.
var neededBytes = 16 - (packetDataBuffer.Position % 16);
packetDataBuffer.WriteBytes(new byte[neededBytes]);

byte[] packetData = packetDataBuffer.GetAllBytes();
byte[] encryptedPacketData = Encrypt(packetData);

Expand Down
27 changes: 16 additions & 11 deletions Arrowgene.Ddon.Server/Network/PacketId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace Arrowgene.Ddon.Server.Network
Expand Down Expand Up @@ -83,10 +83,10 @@ public override int GetHashCode()
// public static readonly PacketId L2C_LOGIN_SERVER_CERT_NOTICE = new PacketId(0,0,0, "L2C_LOGIN_SERVER_CERT_NOTICE");
public static readonly PacketId C2L_CLIENT_CHALLENGE_REQ = new PacketId(1, 0, 1, "C2L_CLIENT_CHALLENGE_REQ");
public static readonly PacketId L2C_CLIENT_CHALLENGE_RES = new PacketId(1, 0, 2, "L2C_CLIENT_CHALLENGE_RES");
public static readonly PacketId C2L_GET_GAME_SESSION_KEY_REQ = new PacketId(0, 1, 1, "C2L_GET_GAME_SESSION_KEY_REQ");
public static readonly PacketId L2C_GET_GAME_SESSION_KEY_RES = new PacketId(0, 1, 2, "L2C_GET_GAME_SESSION_KEY_RES");
public static readonly PacketId X1_REQ = new PacketId(0, 0, 1, "X1_REQ");
public static readonly PacketId X1_RES = new PacketId(0, 0, 2, "X1_RES");
public static readonly PacketId C2L_LOGIN_REQ = new PacketId(0, 1, 1, "C2L_LOGIN_REQ");
public static readonly PacketId L2C_LOGIN_RES = new PacketId(0, 1, 2, "L2C_LOGIN_RES");
public static readonly PacketId C2L_PING_REQ = new PacketId(0, 0, 1, "C2L_PING_REQ");
public static readonly PacketId L2C_PING_RES = new PacketId(0, 0, 2, "L2C_PING_RES");
public static readonly PacketId C2L_GET_ERROR_MESSAGE_LIST_REQ = new PacketId(3, 0, 1, "C2L_GET_ERROR_MESSAGE_LIST_REQ");
public static readonly PacketId L2C_GET_ERROR_MESSAGE_LIST_RES = new PacketId(3, 0, 2, "L2C_GET_ERROR_MESSAGE_LIST_RES");
public static readonly PacketId L2C_GET_ERROR_MESSAGE_LIST_NTC = new PacketId(3, 0, 0x10, "L2C_GET_ERROR_MESSAGE_LIST_NTC");
Expand All @@ -99,11 +99,14 @@ public override int GetHashCode()
public static readonly PacketId X11_REQ = new PacketId(5, 3, 1, "X11_REQ");
public static readonly PacketId X11_RES = new PacketId(5, 3, 2, "X11_RES");

public static readonly PacketId C2L_DELETE_CHARACTER_INFO_REQ = new PacketId(5, 4, 1, "C2L_DELETE_CHARACTER_INFO_REQ");
public static readonly PacketId L2C_DELETE_CHARACTER_INFO_RES = new PacketId(5, 4, 2, "L2C_DELETE_CHARACTER_INFO_RES");

public static readonly PacketId X60 = new PacketId(5, 1, 1, "X60");
public static readonly PacketId X61 = new PacketId(5, 1, 2, "X61");
public static readonly PacketId X62 = new PacketId(5, 5, 16, "X62");

public static readonly PacketId X8 = new PacketId(2, 3, 16, "X8");
public static readonly PacketId L2C_NEXT_CONNECT_SERVER_NTC = new PacketId(2, 3, 16, "L2C_NEXT_CONNECT_SERVER_NTC");

public static readonly PacketId X9_REQ = new PacketId(2, 1, 1, "X9_REQ");
public static readonly PacketId X9_RES = new PacketId(2, 1, 2, "X9_RES");
Expand All @@ -121,10 +124,10 @@ private static Dictionary<int, PacketId> InitializeLoginPacketIds()
// AddPacketIdEntry(packetIds, L2C_LOGIN_SERVER_CERT_NOTICE);
AddPacketIdEntry(packetIds, C2L_CLIENT_CHALLENGE_REQ);
AddPacketIdEntry(packetIds, L2C_CLIENT_CHALLENGE_RES);
AddPacketIdEntry(packetIds, C2L_GET_GAME_SESSION_KEY_REQ);
AddPacketIdEntry(packetIds, L2C_GET_GAME_SESSION_KEY_RES);
AddPacketIdEntry(packetIds, X1_REQ);
AddPacketIdEntry(packetIds, X1_RES);
AddPacketIdEntry(packetIds, C2L_LOGIN_REQ);
AddPacketIdEntry(packetIds, L2C_LOGIN_RES);
AddPacketIdEntry(packetIds, C2L_PING_REQ);
AddPacketIdEntry(packetIds, L2C_PING_RES);
AddPacketIdEntry(packetIds, C2L_GET_ERROR_MESSAGE_LIST_REQ);
AddPacketIdEntry(packetIds, L2C_GET_ERROR_MESSAGE_LIST_RES);
AddPacketIdEntry(packetIds, L2C_GET_ERROR_MESSAGE_LIST_NTC);
Expand All @@ -134,10 +137,12 @@ private static Dictionary<int, PacketId> InitializeLoginPacketIds()
AddPacketIdEntry(packetIds, L2C_GP_COURSE_GET_INFO_RES);
AddPacketIdEntry(packetIds, C2L_GET_CHARACTER_LIST_REQ);
AddPacketIdEntry(packetIds, L2C_GET_CHARACTER_LIST_RES);
AddPacketIdEntry(packetIds, C2L_DELETE_CHARACTER_INFO_REQ);
AddPacketIdEntry(packetIds, L2C_DELETE_CHARACTER_INFO_RES);
AddPacketIdEntry(packetIds, X60);
AddPacketIdEntry(packetIds, X61);
AddPacketIdEntry(packetIds, X62);
AddPacketIdEntry(packetIds, X8);
AddPacketIdEntry(packetIds, L2C_NEXT_CONNECT_SERVER_NTC);
AddPacketIdEntry(packetIds, X9_REQ);
AddPacketIdEntry(packetIds, X9_RES);
AddPacketIdEntry(packetIds, X10_REQ);
Expand Down
Loading

0 comments on commit 272fcae

Please sign in to comment.