XmdsPlayer.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using CommonAI.Zone.Instance;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using XmdsServerNode.Node.Interface;
  8. using Pomelo;
  9. using XmdsServerNode.Node;
  10. using CommonAI.Zone;
  11. using CommonLang.ByteOrder;
  12. using CommonLang.Property;
  13. using CommonLang.IO.Attribute;
  14. using CommonLang.Log;
  15. using CommonLang.Concurrent;
  16. using CommonLang;
  17. using static Pomelo.FuckFastStream;
  18. namespace XmdsServerEdgeJS.Zone
  19. {
  20. public class XmdsPlayer : IPlayer
  21. {
  22. private readonly Logger log = LoggerFactory.GetLogger("XmdsPlayer");
  23. private readonly string player_uuid;
  24. private readonly XmdsZoneNode node;
  25. private readonly ZoneService service;
  26. private readonly string instanceId;
  27. private IFastSession connectServerId;
  28. private readonly string uid;
  29. private HashMap<string, object> attributes = new HashMap<string, object>(1);
  30. private AtomicReference<ServerZoneNode.ZoneNodePlayer> mBindingObject = new AtomicReference<ServerZoneNode.ZoneNodePlayer>(null);
  31. public XmdsPlayer(ZoneService svc, string uuid, string uid, IFastSession connectServerId, XmdsZoneNode node)
  32. {
  33. this.node = node;
  34. this.service = svc;
  35. this.player_uuid = uuid;
  36. this.instanceId = node.InstanceID;
  37. this.connectServerId = connectServerId;
  38. this.uid = uid;
  39. }
  40. public ServerZoneNode Node { get { return node.Node; } }
  41. public string PlayerUUID { get { return player_uuid; } }
  42. public string InstanceId { get { return instanceId; } }
  43. public IFastSession ConnectServerId { get { return connectServerId; } }
  44. public string Uid { get { return uid; } }
  45. public void OnNetReconnect(string connetorId, IFastSession session)
  46. {
  47. if(this.connectServerId != null && this.connectServerId.ConnectorId != null && connetorId != null && this.connectServerId.ConnectorId.Equals(connetorId))
  48. {
  49. this.connectServerId = session;
  50. }
  51. }
  52. /// <summary>
  53. /// 用于显示的名字
  54. /// </summary>
  55. public string DisplayName { get { return ""; } }
  56. /// <summary>
  57. /// 绑定数据
  58. /// </summary>
  59. public ServerZoneNode.ZoneNodePlayer BindingObject
  60. {
  61. get { return mBindingObject.Value; }
  62. set { mBindingObject.Value = value; }
  63. }
  64. /// <summary>
  65. /// 绑定的玩家
  66. /// </summary>
  67. public InstancePlayer BindingActor
  68. {
  69. get
  70. {
  71. var binding = BindingObject;
  72. if (binding != null) { return binding.BindingActor; }
  73. return null;
  74. }
  75. }
  76. /// <summary>
  77. /// 向此玩家发送战斗服事件
  78. /// </summary>
  79. /// <param name="msg"></param>
  80. public void SendToClient(ArraySegment<byte> msg)
  81. {
  82. //通过fastStream发送
  83. //try
  84. //{
  85. FastStream.instance().Send(connectServerId, uid, instanceId, msg);
  86. //}
  87. //catch (Exception err)
  88. //{
  89. // log.Error(err.Message, err);
  90. //}
  91. }
  92. /// <summary>
  93. /// 发送事件到游戏服
  94. /// </summary>
  95. /// <param name="msg"></param>
  96. public void SendToGameServer(object msg)
  97. {
  98. node.SendToGameServer(EventType.areaEvent.ToString(), msg);
  99. }
  100. public void ReceiveMsgR2B(object data)
  101. {
  102. node.Node.ReceiveMsgR2B(this, data);
  103. }
  104. public InstancePlayer getInstancePlayer()
  105. {
  106. return node.Node.GetPlayer(this.player_uuid);
  107. }
  108. public bool IsAttribute(string key)
  109. {
  110. return attributes.ContainsKey(key);
  111. }
  112. public void SetAttribute(string key, object value)
  113. {
  114. attributes.Put(key, value);
  115. }
  116. public object GetAttribute(string key)
  117. {
  118. return attributes.Get(key);
  119. }
  120. public void Dispose()
  121. {
  122. attributes.Clear();
  123. }
  124. }
  125. }