[성현모] Http, Socket 통신 추가

This commit is contained in:
SHM
2025-04-21 08:30:59 +09:00
parent 1bfc56f437
commit a12a3949bf
25 changed files with 1370 additions and 264 deletions

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HubX.Library.Socket.Object
{
public class ObjectManager
{
public static ObjectManager Instance { get; } = new ObjectManager();
object _lock = new object();
Dictionary<int, Client> _players = new Dictionary<int, Client>();
// [UNUSED(1)][TYPE(7)][ID(24)]
int _counter = 0;
public T Add<T>() where T : Client, new()
{
T gameObject = new T();
lock (_lock)
{
gameObject.Id = GenerateId(gameObject.ObjectType);
if (gameObject.ObjectType == EnumObjectType.Client)
{
_players.Add(gameObject.Id, gameObject as Client);
}
}
return gameObject;
}
int GenerateId(EnumObjectType type)
{
lock (_lock)
{
return ((int)type << 24) | (_counter++);
}
}
public static EnumObjectType GetObjectTypeById(int id)
{
int type = (id >> 24) & 0x7F;
return (EnumObjectType)type;
}
public bool Remove(int objectId)
{
EnumObjectType objectType = GetObjectTypeById(objectId);
lock (_lock)
{
if (objectType == EnumObjectType.Client)
return _players.Remove(objectId);
}
return false;
}
public Client Find(int objectId)
{
EnumObjectType objectType = GetObjectTypeById(objectId);
lock (_lock)
{
if (objectType == EnumObjectType.Client)
{
Client player = null;
if (_players.TryGetValue(objectId, out player))
return player;
}
}
return null;
}
}
}