Skip to content

Commit

Permalink
Merge pull request #106 from sebastian-heinz/party-refinement
Browse files Browse the repository at this point in the history
Party refinement
  • Loading branch information
sebastian-heinz authored Oct 10, 2022
2 parents a701be3 + f8be626 commit 53c3fd7
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 136 deletions.
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/GameStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void CDataCharacterListElement(
Character character)
{
CDataCommunityCharacterBaseInfo(cDataCharacterListElement.CommunityCharacterBaseInfo, character);
cDataCharacterListElement.ServerId = 0;
cDataCharacterListElement.ServerId = character.Server.Id;
cDataCharacterListElement.OnlineStatus = 0;
CDataJobBaseInfo(cDataCharacterListElement.CurrentJobBaseInfo, character.Job,
(byte)character.ActiveCharacterJobData.Lv);
Expand Down
51 changes: 27 additions & 24 deletions Arrowgene.Ddon.GameServer/Handler/PartyPartyCreateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

Expand All @@ -17,52 +18,54 @@ public PartyPartyCreateHandler(DdonGameServer server) : base(server)

public override void Handle(GameClient client, StructurePacket<C2SPartyPartyCreateReq> packet)
{
S2CPartyPartyCreateRes partyCreateRes = new S2CPartyPartyCreateRes();
S2CPartyPartyCreateRes res = new S2CPartyPartyCreateRes();

PartyGroup party = Server.PartyManager.NewParty();
if (party == null)
{
Logger.Error(client, "Failed to create party");
// TODO return error
Logger.Error(client, "can not create party (Server.PartyManager.NewParty() == null)");
res.Error = (uint)ErrorCode.ERROR_CODE_FAIL;
client.Send(res);
return;
}

PlayerPartyMember member = party.Invite(client, client);
if (member == null)
ErrorRes<PlayerPartyMember> invite = party.Invite(client, client);
if (invite.HasError)
{
Logger.Error(client, "Failed to join new party");
// TODO return error
Logger.Error(client, "failed to invite to new party");
res.Error = (uint)invite.ErrorCode;
client.Send(res);
return;
}

ErrorRes<PlayerPartyMember> memberRes = party.Accept(client);
if (memberRes.HasError)
ErrorRes<PlayerPartyMember> accept = party.Accept(client);
if (accept.HasError)
{
Logger.Error(client, "Failed to accept new party");
partyCreateRes.Error = (uint)memberRes.ErrorCode;
client.Send(partyCreateRes);
Logger.Error(client, "failed to accept new party");
res.Error = (uint)accept.ErrorCode;
client.Send(res);
return;
}

member = party.Join(client);
if (member == null)
ErrorRes<PlayerPartyMember> join = party.Join(client);
if (join.HasError)
{
Logger.Error(client, "Failed to join new party");
// TODO return error
res.Error = (uint)join.ErrorCode;
client.Send(res);
return;
}

Logger.Info(client, $"Created Party with PartyId:{party.Id}");

S2CPartyPartyJoinNtc partyJoinNtc = new S2CPartyPartyJoinNtc();
partyJoinNtc.HostCharacterId = client.Character.Id;
partyJoinNtc.LeaderCharacterId = client.Character.Id;
partyJoinNtc.PartyMembers.Add(member.GetCDataPartyMember());
client.Send(partyJoinNtc);
S2CPartyPartyJoinNtc ntc = new S2CPartyPartyJoinNtc();
ntc.HostCharacterId = client.Character.Id;
ntc.LeaderCharacterId = client.Character.Id;
ntc.PartyMembers.Add(join.Value.GetCDataPartyMember());
client.Send(ntc);

res.PartyId = party.Id;
client.Send(res);

partyCreateRes.PartyId = party.Id;
client.Send(partyCreateRes);
Logger.Info(client, $"created party with PartyId:{party.Id}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ public PartyPartyInviteCancelHandler(DdonGameServer server) : base(server)
{
}


/// <summary>
/// There seems to be no way to
/// </summary>
/// <param name="client"></param>
/// <param name="packet"></param>
public override void Handle(GameClient client, StructurePacket<C2SPartyPartyInviteCancelReq> packet)
{
Logger.Info(client, $"C2SPartyPartyInviteCancelReq -> ServerId:{packet.Structure.ServerId} PartyId:{packet.Structure.PartyId}");
S2CPartyPartyInviteCancelRes res = new S2CPartyPartyInviteCancelRes();

PartyGroup party = client.Party;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

Expand Down Expand Up @@ -33,38 +35,37 @@ public PartyPartyInviteCharacterHandler(DdonGameServer server) : base(server)
// S2CContextGetLobbyPlayerContextNtc to the new party member, it should maybe also be sent to all members
// More stuff to determine
// TODO: Figure out just how much packets/data within those packets we can do without while keeping everything functioning.
// TODO PartyGorup need invite management
public override void Handle(GameClient client, StructurePacket<C2SPartyPartyInviteCharacterReq> packet)
{
S2CPartyPartyInviteCharacterRes res = new S2CPartyPartyInviteCharacterRes();

GameClient invitedClient = Server.ClientLookup.GetClientByCharacterId(packet.Structure.CharacterId);
if (invitedClient == null)
{
Logger.Error(client,
$"Could not locate CharacterId:{packet.Structure.CharacterId} for party invitation");
// TODO error response
Logger.Error(client, $"not found CharacterId:{packet.Structure.CharacterId} for party invitation");
res.Error = (uint)ErrorCode.ERROR_CODE_FAIL;
client.Send(res);
return;
}

PartyGroup party = client.Party;
if (party == null)
{
Logger.Error(client,
$"can not invite, as he is not inside party");
// TODO error response
Logger.Error(client, "can not invite (client.Party == null)");
res.Error = (uint)ErrorCode.ERROR_CODE_FAIL;
client.Send(res);
return;
}

PlayerPartyMember invitedMember = party.Invite(invitedClient, client);
if (invitedMember == null)
ErrorRes<PlayerPartyMember> invitedMember = party.Invite(invitedClient, client);
if (invitedMember.HasError)
{
Logger.Error(client,
$"could not invite {invitedClient.Identity}, party did not accept invitiation");
// TODO error response
Logger.Error(client, $"could not invite {invitedClient.Identity}");
res.Error = (uint)invitedMember.ErrorCode;
client.Send(res);
return;
}

Logger.Info(client, $"Invited Client:{invitedClient.Identity} to PartyId:{party.Id}");

S2CPartyPartyInviteNtc ntc = new S2CPartyPartyInviteNtc();
ntc.TimeoutSec = PartyManager.InvitationTimeoutSec;
ntc.PartyListInfo.PartyId = party.Id;
Expand All @@ -73,15 +74,17 @@ public override void Handle(GameClient client, StructurePacket<C2SPartyPartyInvi
{
ntc.PartyListInfo.MemberList.Add(member.GetCDataPartyMember());
}

invitedClient.Send(ntc);


S2CPartyPartyInviteCharacterRes response = new S2CPartyPartyInviteCharacterRes();
response.TimeoutSec = PartyManager.InvitationTimeoutSec;
response.Info.PartyId = party.Id;
response.Info.ServerId = Server.AssetRepository.ServerList[0].Id;
response.Info.MemberList.Add(invitedMember.GetCDataPartyMember());
client.Send(response);
res.TimeoutSec = PartyManager.InvitationTimeoutSec;
res.Info.PartyId = party.Id;
res.Info.ServerId = Server.AssetRepository.ServerList[0].Id;
res.Info.MemberList.Add(invitedMember.Value.GetCDataPartyMember());
client.Send(res);

Logger.Info(client, $"Invited Client:{invitedClient.Identity} to PartyId:{party.Id}");
}
}
}
24 changes: 15 additions & 9 deletions Arrowgene.Ddon.GameServer/Handler/PartyPartyInviteRefuseHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

Expand All @@ -18,39 +20,43 @@ public PartyPartyInviteRefuseHandler(DdonGameServer server) : base(server)
public override void Handle(GameClient client, StructurePacket<C2SPartyPartyInviteRefuseReq> packet)
{
S2CPartyPartyInviteRefuseRes res = new S2CPartyPartyInviteRefuseRes();

PartyInvitation invitation = Server.PartyManager.GetPartyInvitation(client);
if (invitation == null)
{
Logger.Error(client, "failed to find invitation");
res.Error = (uint)ErrorCode.ERROR_CODE_PARTY_NOT_INVITED;
client.Send(res);
return;
}

GameClient host = invitation.Host;
if (host == null)
{
Logger.Error(client, "host does not exist");
Logger.Error(client, "invitation has no host");
res.Error = (uint)ErrorCode.ERROR_CODE_PARTY_NOT_INVITED;
client.Send(res);
return;
}



PartyGroup party = invitation.Party;
if (party == null)
{
Logger.Error(client, "failed to find invited party");
Logger.Error(client, "failed to find party");
res.Error = (uint)ErrorCode.ERROR_CODE_PARTY_NOT_INVITED;
client.Send(res);
return;
}

party.RefuseInvite(client);

// TODO update others about refuse
ErrorRes<PartyInvitation> refuse = party.RefuseInvite(client);
if (refuse.HasError)
{
res.Error = (uint)refuse.ErrorCode;
client.Send(res);
return;
}

client.Send(res);
Logger.Info(client, $"refuse invite for PartyId:{invitation.Party.Id}");
}
}
}
40 changes: 21 additions & 19 deletions Arrowgene.Ddon.GameServer/Handler/PartyPartyJoinHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

Expand All @@ -16,40 +18,38 @@ public PartyPartyJoinHandler(DdonGameServer server) : base(server)

public override void Handle(GameClient client, StructurePacket<C2SPartyPartyJoinReq> packet)
{
S2CPartyPartyJoinRes res = new S2CPartyPartyJoinRes();

PartyGroup party = Server.PartyManager.GetParty(packet.Structure.PartyId);
if (party == null)
{
Logger.Error(client, "Could not join party, does not exist");
// todo return error
Logger.Error(client, "failed to find party (Server.PartyManager.GetParty() == null)");
res.Error = (uint)ErrorCode.ERROR_CODE_FAIL;
client.Send(res);
return;
}

PartyMember partyMember = party.Join(client);
if (partyMember == null)
ErrorRes<PlayerPartyMember> join = party.Join(client);
if (join.HasError)
{
Logger.Error(client, "Could not join party, its full");
// todo return error
Logger.Error(client, "failed to join party");
res.Error = (uint)join.ErrorCode;
client.Send(res);
return;
}

Logger.Info(client, $"Joined PartyId:{party.Id}");


S2CPartyPartyJoinRes response = new S2CPartyPartyJoinRes();
response.PartyId = party.Id;
client.Send(response);
res.PartyId = party.Id;
client.Send(res);

// Send updated member list to all party members
S2CPartyPartyJoinNtc partyJoinNtc = new S2CPartyPartyJoinNtc();
partyJoinNtc.HostCharacterId = party.Host.Character.Id;
partyJoinNtc.LeaderCharacterId = party.Leader.Character.Id;
// Send party player context NTCs to the new member
S2CPartyPartyJoinNtc ntc = new S2CPartyPartyJoinNtc();
ntc.HostCharacterId = party.Host.Character.Id;
ntc.LeaderCharacterId = party.Leader.Character.Id;
foreach (PartyMember member in party.Members)
{
partyJoinNtc.PartyMembers.Add(member.GetCDataPartyMember());
ntc.PartyMembers.Add(member.GetCDataPartyMember());
}

party.SendToAll(partyJoinNtc);
party.SendToAll(ntc);


// Send party player context NTCs to the new member
Expand All @@ -58,6 +58,8 @@ public override void Handle(GameClient client, StructurePacket<C2SPartyPartyJoin
party.SendToAll(member.GetS2CContextGetParty_ContextNtc());
// TODO only new member or all ?
}

Logger.Info(client, $"joined PartyId:{party.Id}");
}
}
}
24 changes: 14 additions & 10 deletions Arrowgene.Ddon.GameServer/Handler/PartyPartyMemberKickHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

Expand All @@ -16,31 +18,33 @@ public PartyPartyMemberKickHandler(DdonGameServer server) : base(server)

public override void Handle(GameClient client, StructurePacket<C2SPartyPartyMemberKickReq> packet)
{
S2CPartyPartyMemberKickRes res = new S2CPartyPartyMemberKickRes();

PartyGroup party = client.Party;
if (party == null)
{
Logger.Error(client, "party null");
// TODO
Logger.Error(client, "(party == null)");
res.Error = (uint)ErrorCode.ERROR_CODE_FAIL;
client.Send(res);
return;
}

PartyMember member = party.Kick(packet.Structure.MemberIndex);
if (member == null)
ErrorRes<PartyMember> member = party.Kick(client, packet.Structure.MemberIndex);
if (member.HasError)
{
Logger.Error(client, "failed to kick");
// TODO
res.Error = (uint)member.ErrorCode;
client.Send(res);
return;
}

S2CPartyPartyMemberKickNtc ntc = new S2CPartyPartyMemberKickNtc();
ntc.MemberIndex = (byte)member.MemberIndex;
ntc.MemberIndex = (byte)member.Value.MemberIndex;
party.SendToAll(ntc);
if (member is PlayerPartyMember playerMember)
if (member.Value is PlayerPartyMember playerMember)
{
playerMember.Client.Send(ntc);
}

S2CPartyPartyMemberKickRes res = new S2CPartyPartyMemberKickRes();

client.Send(res);
}
}
Expand Down
Loading

0 comments on commit 53c3fd7

Please sign in to comment.