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

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