Skip to content

Commit

Permalink
Merge pull request #7 from alborrajo/feature/chat
Browse files Browse the repository at this point in the history
Feature/chat
  • Loading branch information
sebastian-heinz authored Jan 21, 2022
2 parents 7c694e6 + 2e4c839 commit 90e8237
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 7 deletions.
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.2.0",
"configurations": [

{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Arrowgene.Ddon.Cli/bin/Debug/netcoreapp3.0/Arrowgene.Ddon.Cli.dll",
"args": [],
"cwd": "${workspaceFolder}/Arrowgene.Ddon.Cli",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": "DDOn Server Start",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Arrowgene.Ddon.Cli/bin/Debug/netcoreapp3.0/Arrowgene.Ddon.Cli.dll",
"args": ["server", "start"],
"cwd": "${workspaceFolder}/Arrowgene.Ddon.Cli",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "integratedTerminal",
"stopAtEntry": false,
"logging": {
"moduleLoad": false
}
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Arrowgene.Ddon.Cli/Arrowgene.Ddon.Cli.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Arrowgene.Ddon.Cli/Arrowgene.Ddon.Cli.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/Arrowgene.Ddon.Cli/Arrowgene.Ddon.Cli.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
13 changes: 12 additions & 1 deletion Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with Arrowgene.Ddon.GameServer. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using Arrowgene.Ddon.GameServer.Handler;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Logging;
Expand All @@ -33,6 +34,8 @@ public class DdonGameServer : DdonServer<GameClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(typeof(DdonGameServer));

private HashSet<GameClient> clients = new HashSet<GameClient>();

public DdonGameServer(GameServerSetting setting) : base(setting.ServerSetting)
{
Setting = new GameServerSetting(setting);
Expand All @@ -48,11 +51,19 @@ protected override void ClientConnected(GameClient client)

protected override void ClientDisconnected(GameClient client)
{
clients.Remove(client);
}

public override GameClient NewClient(ITcpSocket socket)
{
return new GameClient(socket, new PacketFactory(Setting.ServerSetting, PacketIdResolver.GamePacketIdResolver));
GameClient newClient = new GameClient(socket, new PacketFactory(Setting.ServerSetting, PacketIdResolver.GamePacketIdResolver));
clients.Add(newClient);
return newClient;
}

public override ICollection<GameClient> Clients
{
get { return clients; }
}

private void LoadPacketHandler()
Expand Down
37 changes: 34 additions & 3 deletions Arrowgene.Ddon.GameServer/Handler/LobbyLobbyChatMsgHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Buffers;
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.Server.Logging;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
Expand All @@ -16,9 +19,37 @@ public LobbyLobbyChatMsgHandler(DdonGameServer server) : base(server)

public override PacketId Id => PacketId.C2S_LOBBY_LOBBY_CHAT_MSG_REQ;

public override void Handle(GameClient client, Packet packet)
public override void Handle(GameClient requestingClient, Packet request)
{
client.Send(GameFull.Dump_114);
// Read request
CDataLobbyChatMsgReq req = EntitySerializer.Get<CDataLobbyChatMsgReq>().Read(request.AsBuffer());
Logger.Debug(requestingClient, $"{req.type}, {req.unk2}, {req.unk3}, {req.unk4}, {req.unk5}: {req.strMessage}"); // Log chat message

// Write response
IBuffer resBuffer = new StreamBuffer();
resBuffer.WriteInt32(0, Endianness.Big); // error
resBuffer.WriteInt32(0, Endianness.Big); // result

CDataLobbyChatMsgRes res = new CDataLobbyChatMsgRes();
EntitySerializer.Get<CDataLobbyChatMsgRes>().Write(resBuffer, res);
Packet response = new Packet(PacketId.S2C_LOBBY_LOBBY_CHAT_MSG_RES, resBuffer.GetAllBytes());
requestingClient.Send(response);

// Notify all players
foreach(GameClient client in Server.Clients)
{
IBuffer ntcBuffer = new StreamBuffer();
CDataLobbyChatMsgNotice ntc = new CDataLobbyChatMsgNotice();
ntc.unk0 = (byte) req.type;
ntc.strMessage = req.strMessage;
ntc.characterBaseInfo.strFirstName = "FirstName";
ntc.characterBaseInfo.strLastName = "LastName";
ntc.characterBaseInfo.strClanName = "ClanName";
EntitySerializer.Get<CDataLobbyChatMsgNotice>().Write(ntcBuffer, ntc);
Packet notice = new Packet(PacketId.S2C_LOBBY_LOBBY_CHAT_MSG_NTC, ntcBuffer.GetAllBytes());
client.Send(notice);
}
}
}

}
10 changes: 10 additions & 0 deletions Arrowgene.Ddon.LoginServer/DdonLoginServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with Arrowgene.Ddon.LoginServer. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using Arrowgene.Ddon.LoginServer.Handler;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Logging;
Expand All @@ -33,6 +34,8 @@ public class DdonLoginServer : DdonServer<LoginClient>
{
private static readonly DdonLogger Logger = LogProvider.Logger<DdonLogger>(typeof(DdonLoginServer));

private HashSet<LoginClient> clients;

public DdonLoginServer(LoginServerSetting setting) : base(setting.ServerSetting)
{
Setting = new LoginServerSetting(setting);
Expand All @@ -45,17 +48,24 @@ public DdonLoginServer(LoginServerSetting setting) : base(setting.ServerSetting)
protected override void ClientConnected(LoginClient client)
{
client.InitializeChallenge();
clients.Add(client);
}

protected override void ClientDisconnected(LoginClient client)
{
clients.Remove(client);
}

public override LoginClient NewClient(ITcpSocket socket)
{
return new LoginClient(socket, new PacketFactory(Setting.ServerSetting, PacketIdResolver.LoginPacketIdResolver));
}

public override ICollection<LoginClient> Clients
{
get { return clients; }
}

private void LoadPacketHandler()
{
AddHandler(new ClientChallengeHandler(this));
Expand Down
6 changes: 6 additions & 0 deletions Arrowgene.Ddon.Server/DdonServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with Arrowgene.Ddon.LoginServer. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using Arrowgene.Ddon.Server.Logging;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Logging;
Expand Down Expand Up @@ -72,5 +73,10 @@ protected void AddHandler(IPacketHandler<TClient> packetHandler)
protected abstract void ClientConnected(TClient client);
protected abstract void ClientDisconnected(TClient client);
public abstract TClient NewClient(ITcpSocket socket);

public abstract ICollection<TClient> Clients
{
get;
}
}
}
4 changes: 2 additions & 2 deletions Arrowgene.Ddon.Server/Network/PacketId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private static Dictionary<int, PacketId> InitializeLoginPacketIds()
public static readonly PacketId S2C_LOBBY_LOBBY_LEAVE_RES = new PacketId(3, 1, 2, "S2C_LOBBY_LOBBY_LEAVE_RES"); // ロビーの退室に
public static readonly PacketId C2S_LOBBY_LOBBY_CHAT_MSG_REQ = new PacketId(3, 2, 1, "C2S_LOBBY_LOBBY_CHAT_MSG_REQ");
public static readonly PacketId S2C_LOBBY_LOBBY_CHAT_MSG_RES = new PacketId(3, 2, 2, "S2C_LOBBY_LOBBY_CHAT_MSG_RES");
public static readonly PacketId S2C_LOBBY_3_2_16_NTC = new PacketId(3, 2, 16, "S2C_LOBBY_3_2_16_NTC");
public static readonly PacketId S2C_LOBBY_LOBBY_CHAT_MSG_NTC = new PacketId(3, 2, 16, "S2C_LOBBY_LOBBY_CHAT_MSG_NTC");
public static readonly PacketId S2C_LOBBY_3_4_16_NTC = new PacketId(3, 4, 16, "S2C_LOBBY_3_4_16_NTC");

// Group: 4 - (CHAT)
Expand Down Expand Up @@ -2182,7 +2182,7 @@ private static Dictionary<int, PacketId> InitializeGamePacketIds()
AddPacketIdEntry(packetIds, S2C_LOBBY_LOBBY_LEAVE_RES);
AddPacketIdEntry(packetIds, C2S_LOBBY_LOBBY_CHAT_MSG_REQ);
AddPacketIdEntry(packetIds, S2C_LOBBY_LOBBY_CHAT_MSG_RES);
AddPacketIdEntry(packetIds, S2C_LOBBY_3_2_16_NTC);
AddPacketIdEntry(packetIds, S2C_LOBBY_LOBBY_CHAT_MSG_NTC);
AddPacketIdEntry(packetIds, S2C_LOBBY_3_4_16_NTC);

// Group: 4 - (CHAT)
Expand Down
4 changes: 4 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public abstract class EntitySerializer
Create(new CDataEquipJobItemSerializer()),
Create(new CDataGPCourseValidSerializer()),
Create(new CDataJobPlayPointSerializer()),
Create(new CDataLobbyChatMsgNoticeSerializer()),
Create(new CDataLobbyChatMsgNoticeCharacterSerializer()),
Create(new CDataLobbyChatMsgReqSerializer()),
Create(new CDataLobbyChatMsgResSerializer()),
Create(new CDataLoginSettingSerializer()),
Create(new CDataMatchingProfileSerializer()),
Create(new CDataOrbCategoryStatusSerializer()),
Expand Down
55 changes: 55 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/Structure/CDataLobbyChatMsgNotice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Arrowgene.Buffers;

namespace Arrowgene.Ddon.Shared.Entity.Structure
{
public class CDataLobbyChatMsgNotice {

// Unidentified variables from the PS4 version:
// ucType (u8) (use CDataLobbyChatMsgType when identified)
// unHandleId (u32)

public CDataLobbyChatMsgNotice() {
unk0 = 0;
unk1 = 0;
characterBaseInfo = new CDataLobbyChatMsgNoticeCharacterBaseInfo();
unk2 = 0;
unk3 = 0;
unk4 = 0;
strMessage = string.Empty;
}

public byte unk0;
public uint unk1;
public CDataLobbyChatMsgNoticeCharacterBaseInfo characterBaseInfo;
public byte unk2;
public uint unk3;
public uint unk4;
public string strMessage;
}

public class CDataLobbyChatMsgNoticeSerializer : EntitySerializer<CDataLobbyChatMsgNotice> {
public override void Write(IBuffer buffer, CDataLobbyChatMsgNotice obj)
{
WriteByte(buffer, obj.unk0);
WriteUInt32(buffer, obj.unk1);
WriteEntity<CDataLobbyChatMsgNoticeCharacterBaseInfo>(buffer, obj.characterBaseInfo);
WriteByte(buffer, obj.unk2);
WriteUInt32(buffer, obj.unk3);
WriteUInt32(buffer, obj.unk4);
WriteMtString(buffer, obj.strMessage);
}

public override CDataLobbyChatMsgNotice Read(IBuffer buffer)
{
CDataLobbyChatMsgNotice obj = new CDataLobbyChatMsgNotice();
obj.unk0 = ReadByte(buffer);
obj.unk1 = ReadUInt32(buffer);
obj.characterBaseInfo = ReadEntity<CDataLobbyChatMsgNoticeCharacterBaseInfo>(buffer);
obj.unk2 = ReadByte(buffer);
obj.unk3 = ReadUInt32(buffer);
obj.unk4 = ReadUInt32(buffer);
obj.strMessage = ReadMtString(buffer);
return obj;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Arrowgene.Buffers;

namespace Arrowgene.Ddon.Shared.Entity.Structure
{
public class CDataLobbyChatMsgNoticeCharacterBaseInfo
{
public CDataLobbyChatMsgNoticeCharacterBaseInfo()
{
characterId = 0;
strFirstName = string.Empty;
strLastName = string.Empty;
strClanName = string.Empty;
}

public uint characterId;
public string strFirstName;
public string strLastName;
public string strClanName;
}

public class CDataLobbyChatMsgNoticeCharacterSerializer : EntitySerializer<CDataLobbyChatMsgNoticeCharacterBaseInfo> {
public override void Write(IBuffer buffer, CDataLobbyChatMsgNoticeCharacterBaseInfo obj)
{
WriteUInt32(buffer, obj.characterId);
WriteMtString(buffer, obj.strFirstName);
WriteMtString(buffer, obj.strLastName);
WriteMtString(buffer, obj.strClanName);
}

public override CDataLobbyChatMsgNoticeCharacterBaseInfo Read(IBuffer buffer)
{
CDataLobbyChatMsgNoticeCharacterBaseInfo obj = new CDataLobbyChatMsgNoticeCharacterBaseInfo();
obj.characterId = ReadByte(buffer);
obj.strFirstName = ReadMtString(buffer);
obj.strLastName = ReadMtString(buffer);
obj.strClanName = ReadMtString(buffer);
return obj;
}
}
}
Loading

0 comments on commit 90e8237

Please sign in to comment.