public static void OnRecvHead(NetBuffer buffer, out int cmd, out int datalen) { if (_isXorEncrypt) { NetBuffer buf = new NetBuffer(); byte[] tmp = buffer.ReadBytes(HEAD_LEN); buf.WriteBytes(NetEncoder.XOR(tmp, HEAD_LEN, _xorKey, _xorKey.Length)); buf.Seek(0, SeekOrigin.Begin); cmd = (int)buf.ReadUInt(); datalen = (int)buf.ReadUInt(); if (datalen < 0) { buffer.PrintBytes(); buf.PrintBytes(); UnityEngine.Debug.LogError("error datalen " + datalen); } } else { cmd = (int)buffer.ReadUInt(); datalen = (int)buffer.ReadUInt(); if (datalen < 0) { UnityEngine.Debug.LogError("error datalen " + datalen); } } }
public static void OnSendHead(NetBuffer buf, int cmd, int datalen) { if (_isXorEncrypt) { NetBuffer tmp = new NetBuffer(); tmp.WriteUInt((uint)cmd); tmp.WriteUInt((uint)(datalen)); buf.WriteBytes(NetEncoder.XOR(tmp.ToBytes(), HEAD_LEN, _xorKey, _xorKey.Length)); } else { buf.WriteUInt((uint)cmd); buf.WriteUInt((uint)(datalen)); } }