PublicLogicManager.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Concurrent;
  2. using NetCore;
  3. using NetCore.ContentParse;
  4. using NetCore.Protocol.MemoryPack;
  5. using NetServer.InternalServer;
  6. using NetServerCore.NetLink;
  7. namespace NetServer.ServerLogic;
  8. public class PublicLogicManager : LogicManagerBaisc<InternalMemoryRequst>
  9. {
  10. private ConcurrentDictionary<long, IConnection> _concurrentDictionary =
  11. new ConcurrentDictionary<long, IConnection>();
  12. public override void Logic(object data, IConnection iConnection)
  13. {
  14. byte[] databyte = data as byte[];
  15. int index = 0;
  16. byte[] serverType = new byte[4];
  17. serverType[0] = databyte[index++];
  18. serverType[1] = databyte[index++];
  19. serverType[2] = databyte[index++];
  20. serverType[3] = databyte[index++];
  21. ServerType serverTypeEnum = (ServerType)BitConverter.ToInt32(serverType, 0);
  22. byte[] TransparentData = new byte[databyte.Length - 4];
  23. Array.Copy(databyte, 4, TransparentData, 0, TransparentData.Length);
  24. InternalMemoryResponese internalMemoryResponese = new InternalMemoryResponese();
  25. internalMemoryResponese.SendType = InternalSendType.Transparent;
  26. internalMemoryResponese.ClinetConnectionId = iConnection.ConnectionId;
  27. internalMemoryResponese.TransitData = TransparentData;
  28. SendInternalServerManager.Instance.SendInternalServer(serverTypeEnum, internalMemoryResponese,
  29. ResponeseCallBack);
  30. }
  31. private void ResponeseCallBack(InternalMemoryRequst internalMemoryRequst)
  32. {
  33. if (_concurrentDictionary.TryGetValue(internalMemoryRequst.ResponeseClinetConnectionId,
  34. out IConnection iConnection))
  35. {
  36. iConnection.SendData(internalMemoryRequst.TransitData);
  37. }
  38. }
  39. public override void AddConnection(IConnection iConnection)
  40. {
  41. _concurrentDictionary.TryAdd(iConnection.ConnectionId, iConnection);
  42. }
  43. public override void RemoveConnection(IConnection iConnection)
  44. {
  45. _concurrentDictionary.TryRemove(iConnection.ConnectionId, out _);
  46. }
  47. }