fix : playerID == hashkey 통일 / long => int로 변경
This commit is contained in:
@@ -13,12 +13,12 @@ namespace MMOserver.Game;
|
||||
|
||||
public class GameServer : ServerBase
|
||||
{
|
||||
private readonly Dictionary<ushort, Action<NetPeer, long, byte[]>> packetHandlers;
|
||||
private readonly Dictionary<ushort, Action<NetPeer, int, byte[]>> packetHandlers;
|
||||
private UuidGenerator userUuidGenerator;
|
||||
|
||||
public GameServer(int port, string connectionString) : base(port, connectionString)
|
||||
{
|
||||
packetHandlers = new Dictionary<ushort, Action<NetPeer, long, byte[]>>
|
||||
packetHandlers = new Dictionary<ushort, Action<NetPeer, int, byte[]>>
|
||||
{
|
||||
[(ushort)PacketCode.INTO_CHANNEL] = OnIntoChannel,
|
||||
[(ushort)PacketCode.EXIT_CHANNEL] = OnExitChannel,
|
||||
@@ -51,7 +51,7 @@ public class GameServer : ServerBase
|
||||
protected override void HandleAuthDummy(NetPeer peer, byte[] payload)
|
||||
{
|
||||
DummyAccTokenPacket accTokenPacket = Serializer.Deserialize<DummyAccTokenPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
long hashKey = accTokenPacket.Token;
|
||||
int hashKey = accTokenPacket.Token;
|
||||
|
||||
if (sessions.TryGetValue(hashKey, out NetPeer? existing))
|
||||
{
|
||||
@@ -73,8 +73,8 @@ public class GameServer : ServerBase
|
||||
Player newPlayer = new Player
|
||||
{
|
||||
HashKey = hashKey,
|
||||
PlayerId = (int)(hashKey & 0x7FFFFFFF),
|
||||
Nickname = (hashKey & 0x7FFFFFFF).ToString()
|
||||
PlayerId = hashKey,
|
||||
Nickname = hashKey.ToString()
|
||||
};
|
||||
|
||||
cm.AddUser(1, hashKey, newPlayer, peer);
|
||||
@@ -94,7 +94,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
AccTokenPacket accTokenPacket = Serializer.Deserialize<AccTokenPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
string token = accTokenPacket.Token;
|
||||
tokenHash.TryGetValue(token, out long hashKey);
|
||||
tokenHash.TryGetValue(token, out int hashKey);
|
||||
if (hashKey <= 1000)
|
||||
{
|
||||
hashKey = userUuidGenerator.Create();
|
||||
@@ -133,7 +133,7 @@ public class GameServer : ServerBase
|
||||
OnSessionConnected(peer, hashKey);
|
||||
}
|
||||
|
||||
protected override void OnSessionConnected(NetPeer peer, long hashKey)
|
||||
protected override void OnSessionConnected(NetPeer peer, int hashKey)
|
||||
{
|
||||
Log.Information("[GameServer] 세션 연결 HashKey={Key} PeerId={Id}", hashKey, peer.Id);
|
||||
|
||||
@@ -154,7 +154,7 @@ public class GameServer : ServerBase
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSessionDisconnected(NetPeer peer, long hashKey, DisconnectInfo info)
|
||||
protected override void OnSessionDisconnected(NetPeer peer, int hashKey, DisconnectInfo info)
|
||||
{
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
|
||||
@@ -176,9 +176,9 @@ public class GameServer : ServerBase
|
||||
userUuidGenerator.Release(hashKey);
|
||||
}
|
||||
|
||||
protected override void HandlePacket(NetPeer peer, long hashKey, ushort type, byte[] payload)
|
||||
protected override void HandlePacket(NetPeer peer, int hashKey, ushort type, byte[] payload)
|
||||
{
|
||||
if (packetHandlers.TryGetValue(type, out Action<NetPeer, long, byte[]>? handler))
|
||||
if (packetHandlers.TryGetValue(type, out Action<NetPeer, int, byte[]>? handler))
|
||||
{
|
||||
handler(peer, hashKey, payload);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public class GameServer : ServerBase
|
||||
// 보내는 패킷
|
||||
// ============================================================
|
||||
|
||||
private void SendLoadChannelPacket(NetPeer peer, long hashKey)
|
||||
private void SendLoadChannelPacket(NetPeer peer, int hashKey)
|
||||
{
|
||||
LoadChannelPacket loadChannelPacket = new LoadChannelPacket();
|
||||
foreach (Channel.Channel channel in ChannelManager.Instance.GetChannels())
|
||||
@@ -209,7 +209,7 @@ public class GameServer : ServerBase
|
||||
}
|
||||
|
||||
// 나간 유저를 같은 채널 유저들에게 알림 (UPDATE_CHANNEL_USER IsAdd=false)
|
||||
private void SendExitChannelPacket(NetPeer peer, long hashKey, int channelId, Player player)
|
||||
private void SendExitChannelPacket(NetPeer peer, int hashKey, int channelId, Player player)
|
||||
{
|
||||
UpdateChannelUserPacket packet = new UpdateChannelUserPacket
|
||||
{
|
||||
@@ -224,7 +224,7 @@ public class GameServer : ServerBase
|
||||
// 채널 입장 시 패킷 전송
|
||||
// - 새 유저에게 : 기존 채널 유저 목록 (INTO_CHANNEL)
|
||||
// - 기존 유저들에게 : 새 유저 입장 알림 (UPDATE_CHANNEL_USER IsAdd=true)
|
||||
private void SendIntoChannelPacket(NetPeer peer, long hashKey)
|
||||
private void SendIntoChannelPacket(NetPeer peer, int hashKey)
|
||||
{
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
int channelId = cm.HasUser(hashKey);
|
||||
@@ -238,7 +238,7 @@ public class GameServer : ServerBase
|
||||
|
||||
// 1. 새 유저에게: 자신을 제외한 기존 채널 유저 목록 전송
|
||||
IntoChannelPacket response = new IntoChannelPacket { ChannelId = channelId };
|
||||
foreach (long userId in channel.GetConnectUsers())
|
||||
foreach (int userId in channel.GetConnectUsers())
|
||||
{
|
||||
if (userId == hashKey)
|
||||
{
|
||||
@@ -270,7 +270,7 @@ public class GameServer : ServerBase
|
||||
|
||||
// 채널 입장 시 패킷 전송
|
||||
// - 자신 유저에게 : 내 정보 (LOAD_GAME)
|
||||
private void SendLoadGame(NetPeer peer, long hashKey)
|
||||
private void SendLoadGame(NetPeer peer, int hashKey)
|
||||
{
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
int channelId = cm.HasUser(hashKey);
|
||||
@@ -340,7 +340,7 @@ public class GameServer : ServerBase
|
||||
// 패킷 핸들러
|
||||
// ============================================================
|
||||
|
||||
private void OnIntoChannel(NetPeer peer, long hashKey, byte[] payload)
|
||||
private void OnIntoChannel(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
IntoChannelPacket packet = Serializer.Deserialize<IntoChannelPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
@@ -361,8 +361,8 @@ public class GameServer : ServerBase
|
||||
Player newPlayer = new Player
|
||||
{
|
||||
HashKey = hashKey,
|
||||
PlayerId = (int)(hashKey & 0x7FFFFFFF),
|
||||
Nickname = (hashKey & 0x7FFFFFFF).ToString()
|
||||
PlayerId = hashKey,
|
||||
Nickname = hashKey.ToString()
|
||||
};
|
||||
|
||||
cm.AddUser(packet.ChannelId, hashKey, newPlayer, peer);
|
||||
@@ -375,7 +375,7 @@ public class GameServer : ServerBase
|
||||
SendLoadGame(peer, hashKey);
|
||||
}
|
||||
|
||||
private void OnExitChannel(NetPeer peer, long hashKey, byte[] payload)
|
||||
private void OnExitChannel(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
ExitChannelPacket packet = Serializer.Deserialize<ExitChannelPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
@@ -395,7 +395,7 @@ public class GameServer : ServerBase
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTransformPlayer(NetPeer peer, long hashKey, byte[] payload)
|
||||
private void OnTransformPlayer(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
TransformPlayerPacket packet = Serializer.Deserialize<TransformPlayerPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
@@ -421,7 +421,7 @@ public class GameServer : ServerBase
|
||||
BroadcastToChannel(channelId, data, peer, DeliveryMethod.Unreliable);
|
||||
}
|
||||
|
||||
private void OnActionPlayer(NetPeer peer, long hashKey, byte[] payload)
|
||||
private void OnActionPlayer(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
ActionPlayerPacket packet = Serializer.Deserialize<ActionPlayerPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
@@ -437,7 +437,7 @@ public class GameServer : ServerBase
|
||||
BroadcastToChannel(channelId, data, peer);
|
||||
}
|
||||
|
||||
private void OnStatePlayer(NetPeer peer, long hashKey, byte[] payload)
|
||||
private void OnStatePlayer(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
StatePlayerPacket packet = Serializer.Deserialize<StatePlayerPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user