PublicLogicManager.cs 2.1 KB

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