Exemple #1
0
 protected bool HandleReader(JHSNetworkReader reader)
 {
     try
     {
         ushort sz        = reader.ReadUInt16();
         short  msgType   = reader.ReadInt16();
         byte[] msgBuffer = reader.ReadBytes(sz);
         if (isClient)
         {
             JHSNetworkReader msgReader = new JHSNetworkReader(msgBuffer);
             if (m_MessageHandlersDict.ContainsKey(msgType))
             {
                 JHSNetworkClient.PushMessage(new JHSNetworkMessage()
                 {
                     msgType = msgType,
                     reader  = msgReader,
                     conn    = this
                 });
             }
             else
             {
                 if (NetConfig.logFilter >= JHSLogFilter.Error)
                 {
                     JHSDebug.LogError("JHSConnection :: Unknown message ID " + msgType + " connId:" + connectionId);
                 }
                 if (NetConfig.UseStatistics)
                 {
                     ReadError += 1;
                 }
             }
         }
         else
         {
             JHSNetworkReader          msgReader   = new JHSNetworkReader(msgBuffer);
             JHSNetworkMessageDelegate msgDelegate = null;
             if (m_MessageHandlersDict.ContainsKey(msgType))
             {
                 msgDelegate = m_MessageHandlersDict[msgType];
             }
             if (msgDelegate != null)
             {
                 msgDelegate(new JHSNetworkMessage()
                 {
                     msgType = msgType,
                     reader  = msgReader,
                     conn    = this
                 });
             }
             else
             {
                 if (NetConfig.logFilter >= JHSLogFilter.Error)
                 {
                     JHSDebug.LogError("JHSConnection :: Unknown message ID " + msgType + " connId:" + connectionId);
                 }
                 if (NetConfig.UseStatistics)
                 {
                     ReadError += 1;
                 }
             }
         }
     }
     catch { }
     return(true);
 }