feat : 채널 매니저(각 채널, 유저 관리) 구현 / 유저 정보 구현 / 패킷 이동 채널 접속 구현
This commit is contained in:
82
MMOTestServer/MMOserver/Game/Channel/Channel.cs
Normal file
82
MMOTestServer/MMOserver/Game/Channel/Channel.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using MMOserver.Game.Channel.Maps;
|
||||
|
||||
namespace MMOserver.Game.Channel;
|
||||
|
||||
public class Channel
|
||||
{
|
||||
// 로비
|
||||
private Robby robby = new Robby();
|
||||
|
||||
// 채널 내 유저 상태 (hashKey → Player)
|
||||
private Dictionary<long, Player> connectUsers = new Dictionary<long, Player>();
|
||||
|
||||
public int ChannelId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int UserCount
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int UserCountMax
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = 100;
|
||||
|
||||
public Channel(int channelId)
|
||||
{
|
||||
ChannelId = channelId;
|
||||
}
|
||||
|
||||
public void AddUser(long userId, Player player)
|
||||
{
|
||||
connectUsers[userId] = player;
|
||||
UserCount++;
|
||||
}
|
||||
|
||||
public void RemoveUser(long userId)
|
||||
{
|
||||
connectUsers.Remove(userId);
|
||||
UserCount--;
|
||||
}
|
||||
|
||||
// 채널 내 모든 유저의 hashKey 반환
|
||||
public IEnumerable<long> GetConnectUsers()
|
||||
{
|
||||
return connectUsers.Keys;
|
||||
}
|
||||
|
||||
// 채널 내 모든 Player 반환
|
||||
public IEnumerable<Player> GetPlayers()
|
||||
{
|
||||
return connectUsers.Values;
|
||||
}
|
||||
|
||||
// 특정 유저의 Player 반환
|
||||
public Player? GetPlayer(long userId)
|
||||
{
|
||||
connectUsers.TryGetValue(userId, out Player? player);
|
||||
return player;
|
||||
}
|
||||
|
||||
public int HasUser(long userId)
|
||||
{
|
||||
if (connectUsers.ContainsKey(userId))
|
||||
{
|
||||
return ChannelId;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 로비 가져옴
|
||||
public Robby GetRobby()
|
||||
{
|
||||
return robby;
|
||||
}
|
||||
}
|
||||
84
MMOTestServer/MMOserver/Game/Channel/ChannelManager.cs
Normal file
84
MMOTestServer/MMOserver/Game/Channel/ChannelManager.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
namespace MMOserver.Game.Channel;
|
||||
|
||||
public class ChannelManager
|
||||
{
|
||||
// 일단은 채널은 서버 켤때 고정으로간다 1개
|
||||
public static ChannelManager Instance
|
||||
{
|
||||
get;
|
||||
} = new ChannelManager();
|
||||
|
||||
// 채널 관리
|
||||
private List<Channel> channels = new List<Channel>();
|
||||
|
||||
// 채널별 유저 관리 (유저 key, 채널 val)
|
||||
private Dictionary<long, int> connectUsers = new Dictionary<long, int>();
|
||||
|
||||
public ChannelManager()
|
||||
{
|
||||
Initializer();
|
||||
}
|
||||
|
||||
public void Initializer(int channelSize = 1)
|
||||
{
|
||||
for (int i = 0; i < channelSize; i++)
|
||||
{
|
||||
channels.Add(new Channel(i));
|
||||
}
|
||||
}
|
||||
|
||||
public Channel GetChannel(int channelId)
|
||||
{
|
||||
return channels[channelId];
|
||||
}
|
||||
|
||||
public List<Channel> GetChannels()
|
||||
{
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void AddUser(int channelId, long userId, Player player)
|
||||
{
|
||||
// 유저 추가
|
||||
connectUsers[userId] = channelId;
|
||||
// 채널에 유저 추가
|
||||
channels[channelId].AddUser(userId, player);
|
||||
}
|
||||
|
||||
public bool RemoveUser(long userId)
|
||||
{
|
||||
// 채널 있으면
|
||||
int channelId = connectUsers[userId];
|
||||
|
||||
// 날린다.
|
||||
if (channelId >= 0)
|
||||
{
|
||||
channels[channelId].RemoveUser(userId);
|
||||
connectUsers.Remove(userId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int HasUser(long userId)
|
||||
{
|
||||
int channelId = -1;
|
||||
if (connectUsers.ContainsKey(userId))
|
||||
{
|
||||
channelId = connectUsers[userId];
|
||||
}
|
||||
|
||||
if (channelId != -1)
|
||||
{
|
||||
return channels[channelId].HasUser(userId);
|
||||
}
|
||||
|
||||
return channelId;
|
||||
}
|
||||
|
||||
public Dictionary<long, int> GetConnectUsers()
|
||||
{
|
||||
return connectUsers;
|
||||
}
|
||||
}
|
||||
17
MMOTestServer/MMOserver/Game/Channel/Maps/Robby.cs
Normal file
17
MMOTestServer/MMOserver/Game/Channel/Maps/Robby.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using MMOserver.Game.Engine;
|
||||
|
||||
namespace MMOserver.Game.Channel.Maps;
|
||||
|
||||
public class Robby
|
||||
{
|
||||
// 마을 시작 지점 넣어 둔다.
|
||||
public static Vector3 StartPosition
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new Vector3(0, 0, 0);
|
||||
|
||||
public Robby()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user