private static void RegisterProto(Type type) { System.Object target = Activator.CreateInstance(type); if (target is Packet) { Packet packet = target as Packet; _factory[packet.GetPacketId()] = new PacketFactory(type); ReturnPacket(packet); } else { LogHelper.PrintError($"[ProtoHelper]RegisterProto:{type.ToString()} error."); } }
private static void RegisterProto(Type type) { System.Object target = Activator.CreateInstance(type); if (target is Packet) { Packet packet = target as Packet; _factory[packet.GetPacketId()] = new PacketFactory(type); ReturnPacket(packet); } else { LogUtil.LogUtility.PrintError(string.Format("[ProtoRegister]Register {0} error!", type.ToString())); } }
public static void ReturnPacket(Packet packet) { lock (_thisLock) { int type = packet.GetPacketId(); if (_factory.ContainsKey(type)) { _factory[type].ReturnPacket(packet); } else { LogHelper.PrintError($"[ProtoHelper]ReturnPacket:{type.ToString()}!"); } } }
public static void ReturnPacket(Packet packet) { lock (thisLock) { int type = packet.GetPacketId(); if (_factory.ContainsKey(type)) { _factory[type].ReturnPacket(packet); } else { LogHelper.PrintError(string.Format("[ProtoRegister]UnRegister {0}!", type.ToString())); } } }
public static void ReturnPacket(Packet packet) { lock (_lock) { int packetId = packet.GetPacketId(); if (_factoryDict.ContainsKey(packetId)) { _factoryDict[packetId].ReturnPacket(packet); } else { LogHelper.PrintError($"[ProtoHelper]ReturnPacket:{packetId.ToString()} error."); } } }
//패킷의 헤더 생성 byte[] CreateHeader <T>(Packet <T> data) { byte[] msg = data.GetPacketData(); HeaderData headerData = new HeaderData(); HeaderSerializer headerSerializer = new HeaderSerializer(); headerData.length = (short)msg.Length; headerData.source = (byte)NetworkManager.Source.ClientSource; headerData.id = (byte)data.GetPacketId(); headerSerializer.Serialize(headerData); byte[] header = headerSerializer.GetSerializedData(); return(header); }