private int OnInBoundRecieve(ushort opCode, string clientGuid, MessageTransferable data) { Debug.Log("address: " + clientGuid); if (opCode == OpCode.PLAYER_JOIN) { Debug.Log(((PlayerJoinMessage)data).playerSessionId); } return(1); }
public MessageTransferable RecyclePop() { MessageTransferable val = null; lock (this){ val = cache.Count > 0 ? cache.Pop() : GetNew(); } return(val); }
public void Serialize(BinaryWriter writer, MessageTransferable instance, ushort opCode) { if (instance.GetType() == transferrableType) { instance.Serialize(writer); } else { throw new Exception("serialization of wrong type for " + opCode); } }
public void RecyclePush(MessageTransferable instance) { if (instance.GetType() == transferrableType) { lock (this){ if (cache.Count < MAX_CACHE_SIZE) { cache.Push(instance); } } } else { throw new Exception("wrong type pushed to recycle"); } }
public void Recieve(ushort oPcode, MessageTransferable data) { lock (this) { while (msgDataPending.Count > MAX_RECIEVE_QUEUE) { var dropped = msgDataPending.Dequeue(); if (msgDataCache.Count < MAX_RECIEVE_QUEUE) { msgDataCache.Push(dropped); } } var messageData = (msgDataCache.Count > 0) ? msgDataCache.Pop() : (new MessageData()); messageData.data = data; messageData.opCode = oPcode; msgDataPending.Enqueue(messageData); } }
private int OnOutboundRecieve(ushort opCode, MessageTransferable data) { Debug.Log("outboundback: " + opCode); return(1); }
public static bool IsFor(MessageTransferable toCheck, string guid) { return(toCheck is PlayerGuidMessage ? ((PlayerGuidMessage)toCheck).PlayerGuid.Equals(guid) : false); }
public static string Get(MessageTransferable toCheck) { return(toCheck is PlayerGuidMessage ? ((PlayerGuidMessage)toCheck).PlayerGuid : string.Empty); }
public void Return(ushort opCode, MessageTransferable instance) { lookup[opCode].RecyclePush(instance); }
public void Serialize(ushort opCode, BinaryWriter writer, MessageTransferable instance) { lookup[opCode].Serialize(writer, instance, opCode); }