123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using CommonAI.Zone.Instance;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XmdsServerNode.Node.Interface;
- using Pomelo;
- using XmdsServerNode.Node;
- using CommonAI.Zone;
- using CommonLang.ByteOrder;
- using CommonLang.Property;
- using CommonLang.IO.Attribute;
- using CommonLang.Log;
- using CommonLang.Concurrent;
- using CommonLang;
- using static Pomelo.FuckFastStream;
- namespace XmdsServerEdgeJS.Zone
- {
- public class XmdsPlayer : IPlayer
- {
- private readonly Logger log = LoggerFactory.GetLogger("XmdsPlayer");
- private readonly string player_uuid;
- private readonly XmdsZoneNode node;
- private readonly ZoneService service;
- private readonly string instanceId;
- private IFastSession connectServerId;
- private readonly string uid;
- private HashMap<string, object> attributes = new HashMap<string, object>(1);
- private AtomicReference<ServerZoneNode.ZoneNodePlayer> mBindingObject = new AtomicReference<ServerZoneNode.ZoneNodePlayer>(null);
- public XmdsPlayer(ZoneService svc, string uuid, string uid, IFastSession connectServerId, XmdsZoneNode node)
- {
- this.node = node;
- this.service = svc;
- this.player_uuid = uuid;
- this.instanceId = node.InstanceID;
- this.connectServerId = connectServerId;
- this.uid = uid;
- }
- public ServerZoneNode Node { get { return node.Node; } }
- public string PlayerUUID { get { return player_uuid; } }
- public string InstanceId { get { return instanceId; } }
- public IFastSession ConnectServerId { get { return connectServerId; } }
- public string Uid { get { return uid; } }
- public void OnNetReconnect(string connetorId, IFastSession session)
- {
- if(this.connectServerId != null && this.connectServerId.ConnectorId != null && connetorId != null && this.connectServerId.ConnectorId.Equals(connetorId))
- {
- this.connectServerId = session;
- }
- }
- /// <summary>
- /// 用于显示的名字
- /// </summary>
- public string DisplayName { get { return ""; } }
- /// <summary>
- /// 绑定数据
- /// </summary>
- public ServerZoneNode.ZoneNodePlayer BindingObject
- {
- get { return mBindingObject.Value; }
- set { mBindingObject.Value = value; }
- }
- /// <summary>
- /// 绑定的玩家
- /// </summary>
- public InstancePlayer BindingActor
- {
- get
- {
- var binding = BindingObject;
- if (binding != null) { return binding.BindingActor; }
- return null;
- }
- }
- /// <summary>
- /// 向此玩家发送战斗服事件
- /// </summary>
- /// <param name="msg"></param>
- public void SendToClient(ArraySegment<byte> msg)
- {
- //通过fastStream发送
- //try
- //{
- FastStream.instance().Send(connectServerId, uid, instanceId, msg);
- //}
- //catch (Exception err)
- //{
- // log.Error(err.Message, err);
- //}
- }
- /// <summary>
- /// 发送事件到游戏服
- /// </summary>
- /// <param name="msg"></param>
- public void SendToGameServer(object msg)
- {
- node.SendToGameServer(EventType.areaEvent.ToString(), msg);
- }
- public void ReceiveMsgR2B(object data)
- {
- node.Node.ReceiveMsgR2B(this, data);
- }
- public InstancePlayer getInstancePlayer()
- {
- return node.Node.GetPlayer(this.player_uuid);
- }
- public bool IsAttribute(string key)
- {
- return attributes.ContainsKey(key);
- }
- public void SetAttribute(string key, object value)
- {
- attributes.Put(key, value);
- }
- public object GetAttribute(string key)
- {
- return attributes.Get(key);
- }
- public void Dispose()
- {
- attributes.Clear();
- }
- }
- }
|