Compare commits
2 Commits
a53d838e24
...
3188dbeb3d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3188dbeb3d | ||
|
|
06741f2a55 |
@@ -516,6 +516,31 @@ public class DamagePacket
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 에러
|
||||
// ============================================================
|
||||
|
||||
public enum ErrorCode : int
|
||||
{
|
||||
// 파티 (10021~)
|
||||
PARTY_ALREADY_IN_PARTY = 10021,
|
||||
PARTY_JOIN_FAILED = 10022,
|
||||
PARTY_NOT_IN_PARTY = 10023,
|
||||
PARTY_DELETE_FAILED = 10024,
|
||||
}
|
||||
|
||||
// ERROR (서버 -> 클라)
|
||||
[ProtoContract]
|
||||
public class ErrorPacket
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public ErrorCode Code
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 파티
|
||||
// ============================================================
|
||||
|
||||
@@ -52,7 +52,10 @@ public enum PacketCode : ushort
|
||||
UPDATE_PARTY,
|
||||
|
||||
// 파티 참가/탈퇴/생성/해산 요청 (클라 -> 서버)
|
||||
REQUEST_PARTY
|
||||
REQUEST_PARTY,
|
||||
|
||||
// 요청 실패 응답 (서버 -> 클라)
|
||||
ERROR = 9999
|
||||
}
|
||||
|
||||
public class PacketHeader
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using LiteNetLib;
|
||||
using MMOserver.Game.Channel.Maps;
|
||||
using MMOserver.Game.Party;
|
||||
|
||||
namespace MMOserver.Game.Channel;
|
||||
|
||||
@@ -8,6 +9,9 @@ public class Channel
|
||||
// 로비
|
||||
private Robby robby = new Robby();
|
||||
|
||||
// 파티
|
||||
private PartyManager partyManager = new PartyManager();
|
||||
|
||||
// 채널 내 유저 상태 (hashKey → Player)
|
||||
private Dictionary<int, Player> connectUsers = new Dictionary<int, Player>();
|
||||
|
||||
@@ -97,4 +101,10 @@ public class Channel
|
||||
{
|
||||
return robby;
|
||||
}
|
||||
|
||||
// 파티매니저 가져옴
|
||||
public PartyManager GetPartyManager()
|
||||
{
|
||||
return partyManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +468,15 @@ public class GameServer : ServerBase
|
||||
private void OnRequestParty(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
RequestPartyPacket req = Serializer.Deserialize<RequestPartyPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
PartyManager pm = PartyManager.Instance;
|
||||
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
int channelId = cm.HasUser(hashKey);
|
||||
if (channelId < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PartyManager pm = cm.GetChannel(channelId).GetPartyManager();
|
||||
|
||||
switch (req.Type)
|
||||
{
|
||||
@@ -476,6 +484,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
if (!pm.CreateParty(hashKey, req.PartyName, out PartyInfo? party))
|
||||
{
|
||||
SendError(peer, ErrorCode.PARTY_ALREADY_IN_PARTY);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -495,6 +504,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
if (!pm.JoinParty(hashKey, req.PartyId, out PartyInfo? party))
|
||||
{
|
||||
SendError(peer, ErrorCode.PARTY_JOIN_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -513,6 +523,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
if (!pm.LeaveParty(hashKey, out PartyInfo? party))
|
||||
{
|
||||
SendError(peer, ErrorCode.PARTY_NOT_IN_PARTY);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -525,7 +536,10 @@ public class GameServer : ServerBase
|
||||
};
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
if (party != null)
|
||||
{
|
||||
BroadcastToUsers(party.PartyMemberIds, data); // 남은 멤버들에게
|
||||
}
|
||||
|
||||
SendTo(peer, data); // 탈퇴자 본인에게
|
||||
break;
|
||||
}
|
||||
@@ -533,6 +547,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
if (!pm.DeleteParty(hashKey, req.PartyId, out PartyInfo? party))
|
||||
{
|
||||
SendError(peer, ErrorCode.PARTY_DELETE_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -549,6 +564,13 @@ public class GameServer : ServerBase
|
||||
}
|
||||
}
|
||||
|
||||
private void SendError(NetPeer peer, ErrorCode code)
|
||||
{
|
||||
ErrorPacket err = new ErrorPacket { Code = code };
|
||||
byte[] data = PacketSerializer.Serialize<ErrorPacket>((ushort)PacketCode.ERROR, err);
|
||||
SendTo(peer, data);
|
||||
}
|
||||
|
||||
private void BroadcastToUsers(IEnumerable<int> userIds, byte[] data, DeliveryMethod method = DeliveryMethod.ReliableOrdered)
|
||||
{
|
||||
foreach (int userId in userIds)
|
||||
|
||||
@@ -2,7 +2,7 @@ using MMOserver.Utils;
|
||||
|
||||
namespace MMOserver.Game.Party;
|
||||
|
||||
public class PartyManager : Singleton<PartyManager>
|
||||
public class PartyManager
|
||||
{
|
||||
private readonly UuidGenerator partyUuidGenerator = new UuidGenerator();
|
||||
|
||||
|
||||
@@ -516,6 +516,31 @@ public class DamagePacket
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 에러
|
||||
// ============================================================
|
||||
|
||||
public enum ErrorCode : int
|
||||
{
|
||||
// 파티 (10021~)
|
||||
PARTY_ALREADY_IN_PARTY = 10021,
|
||||
PARTY_JOIN_FAILED = 10022,
|
||||
PARTY_NOT_IN_PARTY = 10023,
|
||||
PARTY_DELETE_FAILED = 10024,
|
||||
}
|
||||
|
||||
// ERROR (서버 -> 클라)
|
||||
[ProtoContract]
|
||||
public class ErrorPacket
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public ErrorCode Code
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 파티
|
||||
// ============================================================
|
||||
|
||||
@@ -52,7 +52,10 @@ public enum PacketCode : ushort
|
||||
UPDATE_PARTY,
|
||||
|
||||
// 파티 참가/탈퇴/생성/해산 요청 (클라 -> 서버)
|
||||
REQUEST_PARTY
|
||||
REQUEST_PARTY,
|
||||
|
||||
// 요청 실패 응답 (서버 -> 클라)
|
||||
ERROR = 9999
|
||||
}
|
||||
|
||||
public class PacketHeader
|
||||
|
||||
Reference in New Issue
Block a user