Skip to content

Commit 0c6e322

Browse files
committed
Corrected network messages
1 parent 2e09068 commit 0c6e322

20 files changed

Lines changed: 630 additions & 150 deletions

docs/Packets/C1-E5-GuildRelationshipRequest_by-server.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ A guild master sent a relationship change request (alliance or hostility) and th
66

77
## Causes the following actions on the client side
88

9-
The target guild master sees the incoming request dialog.
9+
The target guild master (receiver of this message) sees the incoming request dialog.
1010

1111
## Structure
1212

1313
| Index | Length | Data Type | Value | Description |
1414
|-------|--------|-----------|-------|-------------|
1515
| 0 | 1 | Byte | 0xC1 | [Packet type](PacketTypes.md) |
16-
| 1 | 1 | Byte | 13 | Packet header - length of the packet |
16+
| 1 | 1 | Byte | 7 | Packet header - length of the packet |
1717
| 2 | 1 | Byte | 0xE5 | Packet header - packet type identifier |
1818
| 3 | 1 | GuildRelationshipType | | RelationshipType |
1919
| 4 | 1 | GuildRelationshipRequestType | | RequestType |
20-
| 5 | 8 | String | | GuildName |
20+
| 5 | 2 | ShortBigEndian | | SenderId |
2121

2222
### GuildRelationshipType Enum
2323

docs/Packets/C1-E6-GuildRelationshipChangeResult_by-server.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,40 @@ The requester sees the result of the relationship change.
1313
| Index | Length | Data Type | Value | Description |
1414
|-------|--------|-----------|-------|-------------|
1515
| 0 | 1 | Byte | 0xC1 | [Packet type](PacketTypes.md) |
16-
| 1 | 1 | Byte | 6 | Packet header - length of the packet |
16+
| 1 | 1 | Byte | 8 | Packet header - length of the packet |
1717
| 2 | 1 | Byte | 0xE6 | Packet header - packet type identifier |
1818
| 3 | 1 | GuildRelationshipType | | RelationshipType |
1919
| 4 | 1 | GuildRelationshipRequestType | | RequestType |
20-
| 5 | 1 | Boolean | | Success |
20+
| 5 | 1 | GuildRelationshipChangeResultType | | Result |
21+
| 6 | 2 | ShortBigEndian | | GuildMasterId |
22+
23+
### GuildRelationshipChangeResultType Enum
24+
25+
Defines the result of a guild relationship change request.
26+
27+
| Value | Name | Description |
28+
|-------|------|-------------|
29+
| 0 | Failed | The request failed. |
30+
| 1 | Success | The request was successful. |
31+
| 16 | GuildNotFound | GUILD_ANS_NOTEXIST_GUILD: The guild does not exist. |
32+
| 16 | FailedDuringCastleSiege | GUILD_ANS_UNIONFAIL_BY_CASTLE: Alliance function will be restricted due to the Castle Siege. |
33+
| 17 | NoAuthorization | GUILD_ANS_NOTEXIST_PERMISSION: No authorization to perform this action. |
34+
| 18 | NotExistExtraStatus | GUILD_ANS_NOTEXIST_EXTRA_STATUS: The extra status does not exist. |
35+
| 19 | NotExistExtraType | GUILD_ANS_NOTEXIST_EXTRA_TYPE: The extra type does not exist. |
36+
| 21 | AlreadyInAlliance | GUILD_ANS_EXIST_RELATIONSHIP_UNION: The guild already has an alliance relationship. |
37+
| 22 | AlreadyInHostility | GUILD_ANS_EXIST_RELATIONSHIP_RIVAL: The guild already has a hostility relationship. |
38+
| 23 | GuildAllianceExists | GUILD_ANS_EXIST_UNION: A guild alliance already exists. |
39+
| 24 | HostileGuildExists | GUILD_ANS_EXIST_RIVAL: A hostile guild already exists. |
40+
| 25 | GuildAllianceDoesNotExist | GUILD_ANS_NOTEXIST_UNION: The guild alliance does not exist. |
41+
| 26 | HostileGuildDoesNotExist | GUILD_ANS_NOTEXIST_RIVAL: The hostile guild does not exist. |
42+
| 27 | NotMasterOfGuildAlliance | GUILD_ANS_NOT_UNION_MASTER: The player is not the master of the guild alliance. |
43+
| 28 | NotGuildRival | GUILD_ANS_NOT_GUILD_RIVAL: The guild is not a rival guild. |
44+
| 29 | IncompleteRequirementsToCreateAlliance | GUILD_ANS_CANNOT_BE_UNION_MASTER_GUILD: The requirements to create an alliance are incomplete. |
45+
| 30 | MaximumNumberOfGuildsInAllianceReached | GUILD_ANS_EXCEED_MAX_UNION_MEMBER: The maximum number of guilds in the alliance has been reached. |
46+
| 32 | RequestCancelled | GUILD_ANS_CANCEL_REQUEST: The request has been cancelled. |
47+
| 161 | AllianceMasterNotInGens | GUILD_ANS_UNION_MASTER_NOT_GENS: The alliance master is not in a Gens. |
48+
| 162 | GuildMasterNotInGens | GUILD_ANS_GUILD_MASTER_NOT_GENS: The guild master is not in a Gens. |
49+
| 163 | DifferentGens | GUILD_ANS_UNION_MASTER_DISAGREE_GENS: The alliance master and guild master belong to different Gens. |
2150

2251
### GuildRelationshipType Enum
2352

docs/Packets/C1-E9-AllianceList_by-server.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ The client shows the list of guilds in the alliance.
1515
| 0 | 1 | Byte | 0xC1 | [Packet type](PacketTypes.md) |
1616
| 1 | 1 | Byte | | Packet header - length of the packet |
1717
| 2 | 1 | Byte | 0xE9 | Packet header - packet type identifier |
18-
| 3 | 1 | Byte | | GuildCount |
19-
| 4 | AllianceGuildEntry.Length * GuildCount | Array of AllianceGuildEntry | | Guilds |
18+
| 4 | 1 | Byte | | GuildCount |
19+
| 5 | 1 | Boolean | | Success |
20+
| 6 | 1 | Byte | | __RivalCount |
21+
| 7 | 1 | Byte | | __UnionCount |
22+
| 8 | AllianceGuildEntry.Length * GuildCount | Array of AllianceGuildEntry | | Guilds |
2023

2124
### AllianceGuildEntry Structure
2225

2326
Contains the data of one alliance guild entry.
2427

25-
Length: 13 Bytes
28+
Length: 41 Bytes
2629

2730
| Index | Length | Data Type | Value | Description |
2831
|-------|--------|-----------|-------|-------------|
29-
| 0 | 4 | IntegerLittleEndian | | GuildId |
30-
| 4 | 9 | String | | GuildName |
32+
| 0 | 1 | Byte | | MemberCount |
33+
| 1 | 32 | Binary | | Logo |
34+
| 33 | 8 | String | | GuildName |

src/GameLogic/PlayerActions/Guild/GuildRelationshipChangeAction.cs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MUnique.OpenMU.GameLogic.PlayerActions.Guild;
66

7+
using MUnique.OpenMU.GameLogic.Views;
78
using MUnique.OpenMU.GameLogic.Views.Guild;
89
using MUnique.OpenMU.Interfaces;
910

@@ -25,15 +26,13 @@ public async ValueTask RequestAsync(Player player, ushort targetPlayerId, GuildR
2526
if (player.GuildStatus is not { } guildStatus
2627
|| player.GameContext is not IGameServerContext serverContext)
2728
{
28-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
29-
p => p.ShowResultAsync(relationshipType, requestType, false)).ConfigureAwait(false);
29+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.Failed, targetPlayerId)).ConfigureAwait(false);
3030
return;
3131
}
3232

3333
if (guildStatus.Position != GuildPosition.GuildMaster)
3434
{
35-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
36-
p => p.ShowResultAsync(relationshipType, requestType, false)).ConfigureAwait(false);
35+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.NoAuthorization, targetPlayerId)).ConfigureAwait(false);
3736
return;
3837
}
3938

@@ -42,8 +41,7 @@ await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
4241
{
4342
// When clearing hostility, targetGuildId is not used (the current hostility target is removed)
4443
await serverContext.GuildServer.SetHostilityAsync(guildStatus.GuildId, 0, false).ConfigureAwait(false);
45-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
46-
p => p.ShowResultAsync(relationshipType, requestType, true)).ConfigureAwait(false);
44+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.Success, targetPlayerId)).ConfigureAwait(false);
4745
return;
4846
}
4947

@@ -52,44 +50,37 @@ await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
5250
if (targetPlayer?.GuildStatus is not { } targetGuildStatus
5351
|| await serverContext.GuildServer.GetGuildAsync(targetGuildStatus.GuildId).ConfigureAwait(false) is not { Name: not null } targetGuild)
5452
{
55-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
56-
p => p.ShowResultAsync(relationshipType, requestType, false)).ConfigureAwait(false);
53+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.Failed, targetPlayerId)).ConfigureAwait(false);
5754
return;
5855
}
5956

6057
if (targetGuildStatus.Position != GuildPosition.GuildMaster)
6158
{
62-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
63-
p => p.ShowResultAsync(relationshipType, requestType, false)).ConfigureAwait(false);
59+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.Failed, targetPlayerId)).ConfigureAwait(false);
6460
return;
6561
}
6662

6763
if (relationshipType == GuildRelationshipType.Hostility && requestType == GuildRelationshipRequestType.Join)
6864
{
6965
// Hostility is set unilaterally (no consent from target needed)
70-
var success = await serverContext.GuildServer.SetHostilityAsync(
71-
guildStatus.GuildId, targetGuildStatus.GuildId, true).ConfigureAwait(false);
72-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
73-
p => p.ShowResultAsync(relationshipType, requestType, success)).ConfigureAwait(false);
66+
// TODO: Maybe return GuildRelationshipChangeResult from the guild server to be more specific about the failure reason
67+
var success = await serverContext.GuildServer.SetHostilityAsync(guildStatus.GuildId, targetGuildStatus.GuildId, true).ConfigureAwait(false);
68+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, success ? GuildRelationshipChangeResultType.Success : GuildRelationshipChangeResultType.Failed, targetPlayerId)).ConfigureAwait(false);
7469
return;
7570
}
7671

7772
if (relationshipType == GuildRelationshipType.Alliance && requestType == GuildRelationshipRequestType.Join)
7873
{
7974
// Store the pending request on the target player and ask for consent
8075
targetPlayer.PendingAllianceRequest = player;
81-
var requestingGuild = await serverContext.GuildServer.GetGuildAsync(guildStatus.GuildId).ConfigureAwait(false);
82-
var requestingGuildName = requestingGuild?.Name ?? string.Empty;
83-
await targetPlayer.InvokeViewPlugInAsync<IShowGuildRelationshipRequestPlugIn>(
84-
p => p.ShowRequestAsync(
85-
requestingGuildName,
86-
relationshipType,
87-
requestType)).ConfigureAwait(false);
76+
await targetPlayer.InvokeViewPlugInAsync<IShowGuildRelationshipRequestPlugIn>(p => p.ShowRequestAsync(
77+
player,
78+
relationshipType,
79+
requestType)).ConfigureAwait(false);
8880
return;
8981
}
9082

91-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
92-
p => p.ShowResultAsync(relationshipType, requestType, false)).ConfigureAwait(false);
83+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.Failed, targetPlayerId)).ConfigureAwait(false);
9384
}
9485

9586
/// <summary>
@@ -112,22 +103,22 @@ public async ValueTask ProcessResponseAsync(Player player, GuildRelationshipType
112103
return;
113104
}
114105

106+
var guildMasterId = player.GetId(requester);
115107
if (!accepted)
116108
{
117-
await requester.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
118-
p => p.ShowResultAsync(relationshipType, requestType, false)).ConfigureAwait(false);
109+
await requester.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, GuildRelationshipChangeResultType.RequestCancelled, guildMasterId)).ConfigureAwait(false);
119110
return;
120111
}
121112

122113
if (relationshipType == GuildRelationshipType.Alliance && requestType == GuildRelationshipRequestType.Join)
123114
{
124-
var success = await serverContext.GuildServer.CreateAllianceAsync(
125-
requesterGuildStatus.GuildId, responderGuildStatus.GuildId).ConfigureAwait(false);
115+
// TODO: Maybe return GuildRelationshipChangeResult from the guild server to be more specific about the failure reason
116+
var success = await serverContext.GuildServer.CreateAllianceAsync(requesterGuildStatus.GuildId, responderGuildStatus.GuildId).ConfigureAwait(false)
117+
? GuildRelationshipChangeResultType.Success
118+
: GuildRelationshipChangeResultType.Failed;
126119

127-
await requester.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
128-
p => p.ShowResultAsync(relationshipType, requestType, success)).ConfigureAwait(false);
129-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
130-
p => p.ShowResultAsync(relationshipType, requestType, success)).ConfigureAwait(false);
120+
await requester.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, success, guildMasterId)).ConfigureAwait(false);
121+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(relationshipType, requestType, success, guildMasterId)).ConfigureAwait(false);
131122
}
132123
}
133124
}

src/GameLogic/Views/Guild/IGuildRelationshipChangeResultPlugIn.cs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,68 @@ public enum GuildRelationshipRequestType
4444
/// A leave request.
4545
/// </summary>
4646
Leave,
47+
48+
/// <summary>
49+
/// A disband request? Only possible for <see cref="GuildRelationshipType.Alliance"/>.
50+
/// </summary>
51+
Disband,
52+
}
53+
54+
public enum GuildRelationshipChangeResultType
55+
{
56+
Failed,
57+
58+
Success,
59+
60+
GuildNotFound,
61+
62+
// GUILD_ANS_UNIONFAIL_BY_CASTLE: Alliance function will be restricted due to the Castle Siege.
63+
FailedDuringCastleSiege,
64+
65+
// GUILD_ANS_NOTEXIST_PERMISSION
66+
NoAuthorization,
67+
68+
// GUILD_ANS_EXIST_RELATIONSHIP_UNION
69+
AlreadyInAlliance,
70+
71+
// GUILD_ANS_EXIST_RELATIONSHIP_RIVAL
72+
AlreadyInHostility,
73+
74+
// GUILD_ANS_EXIST_UNION
75+
GuildAllianceExists,
76+
77+
// GUILD_ANS_EXIST_RIVAL
78+
HostileGuildExists,
79+
80+
// GUILD_ANS_NOTEXIST_UNION
81+
GuildAllianceDoesNotExist,
82+
83+
// GUILD_ANS_NOTEXIST_RIVAL
84+
HostileGuildDoesNotExist,
85+
86+
// GUILD_ANS_NOT_UNION_MASTER
87+
NotMasterOfGuildAlliance,
88+
89+
// GUILD_ANS_NOT_GUILD_RIVAL
90+
NotGuildRival,
91+
92+
// GUILD_ANS_CANNOT_BE_UNION_MASTER_GUILD
93+
IncompleteRequirementsToCreateAlliance,
94+
95+
// GUILD_ANS_EXCEED_MAX_UNION_MEMBER
96+
MaximumNumberOfGuildsInAllianceReached,
97+
98+
// GUILD_ANS_CANCEL_REQUEST
99+
RequestCancelled,
100+
101+
// GUILD_ANS_UNION_MASTER_NOT_GENS
102+
AllianceMasterNotInGens,
103+
104+
// GUILD_ANS_GUILD_MASTER_NOT_GENS
105+
GuildMasterNotInGens,
106+
107+
// GUILD_ANS_UNION_MASTER_DISAGREE_GENS
108+
DifferentGens = 0xA3,
47109
}
48110

49111
/// <summary>
@@ -56,6 +118,7 @@ public interface IGuildRelationshipChangeResultPlugIn : IViewPlugIn
56118
/// </summary>
57119
/// <param name="relationshipType">The type of relationship that was being changed.</param>
58120
/// <param name="requestType">The type of request (join/leave).</param>
59-
/// <param name="success">Whether the relationship change was successful.</param>
60-
ValueTask ShowResultAsync(GuildRelationshipType relationshipType, GuildRelationshipRequestType requestType, bool success);
121+
/// <param name="resultType">The result of the relationship change request.</param>
122+
/// <param name="guildMasterId">The id of the guild master which was asked for the relationship change.</param>
123+
ValueTask ShowResultAsync(GuildRelationshipType relationshipType, GuildRelationshipRequestType requestType, GuildRelationshipChangeResultType resultType, ushort guildMasterId);
61124
}

src/GameLogic/Views/Guild/IShowGuildRelationshipRequestPlugIn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public interface IShowGuildRelationshipRequestPlugIn : IViewPlugIn
1212
/// <summary>
1313
/// Shows the incoming guild relationship change request.
1414
/// </summary>
15-
/// <param name="requestingGuildName">Name of the requesting guild.</param>
15+
/// <param name="requestingGuildMaster">The guild master which is requesting the relationship change.</param>
1616
/// <param name="relationshipType">The type of relationship being requested.</param>
1717
/// <param name="requestType">The type of request (join/leave).</param>
18-
ValueTask ShowRequestAsync(string requestingGuildName, GuildRelationshipType relationshipType, GuildRelationshipRequestType requestType);
18+
ValueTask ShowRequestAsync(Player requestingGuildMaster, GuildRelationshipType relationshipType, GuildRelationshipRequestType requestType);
1919
}

src/GameServer/GameServerContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public async ValueTask ForEachAlliancePlayerAsync(uint guildId, Func<Player, Tas
121121

122122
foreach (var allianceGuild in allianceGuilds)
123123
{
124-
if (!this._playersByGuild.TryGetValue(allianceGuild.GuildId, out var playerList))
124+
if (!this._playersByGuild.TryGetValue(allianceGuild.Id, out var playerList))
125125
{
126126
continue;
127127
}

src/GameServer/MessageHandler/Guild/RemoveAllianceGuildHandlerPlugIn.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ namespace MUnique.OpenMU.GameServer.MessageHandler.Guild;
66

77
using System.Runtime.InteropServices;
88
using MUnique.OpenMU.GameLogic;
9+
using MUnique.OpenMU.GameLogic.Views;
910
using MUnique.OpenMU.GameLogic.Views.Guild;
1011
using MUnique.OpenMU.Interfaces;
11-
using RemoveAllianceGuildRequest = MUnique.OpenMU.Network.Packets.ClientToServer.RemoveAllianceGuildRequest;
1212
using MUnique.OpenMU.PlugIns;
13+
using RemoveAllianceGuildRequest = MUnique.OpenMU.Network.Packets.ClientToServer.RemoveAllianceGuildRequest;
14+
1315
/// <summary>
1416
/// Handler for remove alliance guild request packets (C1 EB 01).
1517
/// </summary>
@@ -61,10 +63,11 @@ public async ValueTask HandlePacketAsync(Player player, Memory<byte> packet)
6163
return;
6264
}
6365

64-
var success = await serverContext.GuildServer.RemoveAllianceGuildAsync(
65-
guildStatus.GuildId, targetGuildId).ConfigureAwait(false);
66+
// TODO: Maybe return GuildRelationshipChangeResult from the guild server to be more specific about the failure reason
67+
var success = await serverContext.GuildServer.RemoveAllianceGuildAsync(guildStatus.GuildId, targetGuildId).ConfigureAwait(false)
68+
? GuildRelationshipChangeResultType.Success
69+
: GuildRelationshipChangeResultType.Failed;
6670

67-
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(
68-
p => p.ShowResultAsync(GuildRelationshipType.Alliance, GuildRelationshipRequestType.Leave, success)).ConfigureAwait(false);
71+
await player.InvokeViewPlugInAsync<IGuildRelationshipChangeResultPlugIn>(p => p.ShowResultAsync(GuildRelationshipType.Alliance, GuildRelationshipRequestType.Leave, success, player.GetId(player))).ConfigureAwait(false);
6972
}
7073
}

0 commit comments

Comments
 (0)