Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        public MessageTransferable RecyclePop()
        {
            MessageTransferable val = null;

            lock (this){
                val = cache.Count > 0 ? cache.Pop() : GetNew();
            }
            return(val);
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 9
0
 public void Return(ushort opCode, MessageTransferable instance)
 {
     lookup[opCode].RecyclePush(instance);
 }
Ejemplo n.º 10
0
 public void Serialize(ushort opCode, BinaryWriter writer, MessageTransferable instance)
 {
     lookup[opCode].Serialize(writer, instance, opCode);
 }