[성현모] Http, Socket 통신 추가
This commit is contained in:
33
Projects/HubX/HubX.Library/Socket/Packet/EnumMessageId.cs
Normal file
33
Projects/HubX/HubX.Library/Socket/Packet/EnumMessageId.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HubX.Library.Socket.Packet
|
||||
{
|
||||
public enum EnumMessageId
|
||||
{
|
||||
//C2S : Client to Server
|
||||
//S2C : Server to Client
|
||||
|
||||
//unique key CRUD
|
||||
C2S_INSERT_UniqueKey = 10,
|
||||
S2C_INSERT_UniqueKey = 11,
|
||||
C2S_SELECT_UniqueKey = 12,
|
||||
S2C_SELECT_UniqueKey = 13,
|
||||
C2S_UPDATE_UniqueKey = 14,
|
||||
S2C_UPDATE_UniqueKey = 15,
|
||||
C2S_DELETE_UniqueKey = 16,
|
||||
S2C_DELETE_UniqueKey = 17,
|
||||
}
|
||||
|
||||
public enum EnumMessageResult
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Success = 10,
|
||||
Failed = 10,
|
||||
Error = 11,
|
||||
}
|
||||
}
|
||||
43
Projects/HubX/HubX.Library/Socket/Packet/PacketHandler.cs
Normal file
43
Projects/HubX/HubX.Library/Socket/Packet/PacketHandler.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using HubX.Library.Socket.Object;
|
||||
using HubX.Library.Socket.Session;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Core.Communication;
|
||||
|
||||
namespace HubX.Library.Socket.Packet
|
||||
{
|
||||
|
||||
public class PacketHandler
|
||||
{
|
||||
public static void C2S_INSERT_UniqueKeyHandler(PacketSession session, IMessage packet)
|
||||
{
|
||||
C2S_INSERT_UniqueKey movePacket = packet as C2S_INSERT_UniqueKey;
|
||||
ClientSession clientSession = session as ClientSession;
|
||||
|
||||
Client client = clientSession.Client;
|
||||
if (client == null)
|
||||
return;
|
||||
}
|
||||
|
||||
public static void C_SkillHandler(PacketSession session, IMessage packet)
|
||||
{
|
||||
//C_Skill skillPacket = packet as C_Skill;
|
||||
//ClientSession clientSession = session as ClientSession;
|
||||
|
||||
//Player player = clientSession.MyPlayer;
|
||||
//if (player == null)
|
||||
// return;
|
||||
|
||||
//GameRoom room = player.Room;
|
||||
//if (room == null)
|
||||
// return;
|
||||
|
||||
//room.Push(room.HandleSkill, player, skillPacket);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
46
Projects/HubX/HubX.Library/Socket/Packet/Protocol.cs
Normal file
46
Projects/HubX/HubX.Library/Socket/Packet/Protocol.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HubX.Library.Socket.Packet
|
||||
{
|
||||
public interface IMessage
|
||||
{
|
||||
}
|
||||
|
||||
public class C2S : IMessage
|
||||
{
|
||||
public EnumMessageId MessageId { get; set; }
|
||||
}
|
||||
|
||||
public class S2C : IMessage
|
||||
{
|
||||
public EnumMessageId MessageId { get; set; }
|
||||
|
||||
public EnumMessageResult Result { get; set; }
|
||||
}
|
||||
|
||||
public sealed class C2S_INSERT_UniqueKey : C2S
|
||||
{
|
||||
public string Identity { get; set; }
|
||||
|
||||
public string Data1 { get; set; }
|
||||
public string Data2 { get; set; }
|
||||
public string Data3 { get; set; }
|
||||
public string Data4 { get; set; }
|
||||
public string Data5 { get; set; }
|
||||
}
|
||||
|
||||
public sealed class S2C_INSERT_UniqueKey : S2C
|
||||
{
|
||||
public string Identity { get; set; }
|
||||
|
||||
public string Data1 { get; set; }
|
||||
public string Data2 { get; set; }
|
||||
public string Data3 { get; set; }
|
||||
public string Data4 { get; set; }
|
||||
public string Data5 { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Core.Communication;
|
||||
|
||||
namespace HubX.Library.Socket.Packet
|
||||
{
|
||||
public class PacketManager
|
||||
{
|
||||
#region Singleton
|
||||
static PacketManager _instance = new PacketManager();
|
||||
public static PacketManager Instance { get { return _instance; } }
|
||||
#endregion
|
||||
|
||||
PacketManager()
|
||||
{
|
||||
Register();
|
||||
}
|
||||
|
||||
Dictionary<ushort, Action<PacketSession, ArraySegment<byte>, ushort>> _onRecv = new Dictionary<ushort, Action<PacketSession, ArraySegment<byte>, ushort>>();
|
||||
Dictionary<ushort, Action<PacketSession, IMessage>> _handler = new Dictionary<ushort, Action<PacketSession, IMessage>>();
|
||||
|
||||
public Action<PacketSession, IMessage, ushort> CustomHandler { get; set; }
|
||||
|
||||
public void Register()
|
||||
{
|
||||
_onRecv.Add((ushort)EnumMessageId.C2S_INSERT_UniqueKey, MakePacket<C2S_INSERT_UniqueKey>);
|
||||
_handler.Add((ushort)EnumMessageId.C2S_INSERT_UniqueKey, PacketHandler.C2S_INSERT_UniqueKeyHandler);
|
||||
}
|
||||
|
||||
public void OnRecvPacket(PacketSession session, ArraySegment<byte> buffer)
|
||||
{
|
||||
ushort count = 0;
|
||||
|
||||
ushort size = BitConverter.ToUInt16(buffer.Array, buffer.Offset);
|
||||
count += 2;
|
||||
ushort id = BitConverter.ToUInt16(buffer.Array, buffer.Offset + count);
|
||||
count += 2;
|
||||
|
||||
Action<PacketSession, ArraySegment<byte>, ushort> action = null;
|
||||
if (_onRecv.TryGetValue(id, out action))
|
||||
action.Invoke(session, buffer, id);
|
||||
}
|
||||
|
||||
void MakePacket<T>(PacketSession session, ArraySegment<byte> buffer, ushort id) where T : IMessage, new()
|
||||
{
|
||||
T pkt = new T();
|
||||
//pkt.MergeFrom(buffer.Array, buffer.Offset + 4, buffer.Count - 4);
|
||||
|
||||
if (CustomHandler != null)
|
||||
{
|
||||
CustomHandler.Invoke(session, pkt, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Action<PacketSession, IMessage> action = null;
|
||||
if (_handler.TryGetValue(id, out action))
|
||||
action.Invoke(session, pkt);
|
||||
}
|
||||
}
|
||||
|
||||
public Action<PacketSession, IMessage> GetPacketHandler(ushort id)
|
||||
{
|
||||
Action<PacketSession, IMessage> action = null;
|
||||
if (_handler.TryGetValue(id, out action))
|
||||
return action;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user