/// <summary> /// 处理客户端消息 /// </summary> /// <param name="head">消息头</param> /// <param name="data">消息数据</param> protected virtual void DoClientMessage(MessageHead head, byte[] data) { try { byte[] temp = data; if (head.Encryption > 0) { //解密数据 if (EncryptObject == null) { OnDebug(LogMode.Error, string.Format("EncryptObject is null.")); return; } temp = EncryptObject.DecryptBytes(data, head.Encryption); } if (head.Type == (int)MessageType.Request) { string strMsg = Encoding.UTF8.GetString(temp); DoClientMessage(head, strMsg); } } catch (Exception ex) { OnDebug(LogMode.Error, string.Format("DoClientMessage fail.\t{0}", ex.Message)); } }
private void DoServerMessage(MessageHead head, byte[] data) { byte[] temp = data; if (head.Encryption > 0) { //解密数据 if (EncryptObject == null) { OnDebug(LogMode.Error, string.Format("EncryptObject is null.")); return; } temp = EncryptObject.DecryptBytes(data, head.Encryption); } OnMessageReceived(head, temp); if (head.Type == (int)MessageType.Response || head.Type == (int)MessageType.Notify) { string strMsg = Encoding.UTF8.GetString(temp); DoServerMessage(head, strMsg); } }