/// <summary> /// 启动 /// </summary> public void Start() { if (_client == null) { //复位RC4输入输出增量值 CustomRC4Key.CreateCustomRC4Key().BuildKey(); _instance.Connect(); Thread thread = new Thread(ParseMinaQueueThread); thread.IsBackground = true; thread.Start(); //登录 OpFactory <UserOp> .Create(_instance).Get(_user, _pwd, Id, "self-connecting logon"); } else { _instance.Notified?.Invoke(CVResult.InfocenterAlreadyStarted, _instance); } }
public byte[] Dequeue() { lock (this) { if (_buff == null || _buff.Length < 4) { return(null); } //整包长度 int len = CustomRC4Key.GetDecRC4Len(_buff); //是否整包 if (_buff.Length < len) { return(null); } //整包 byte[] body = new byte[len]; Buffer.BlockCopy(_buff, 4, body, 0, len); if (_buff.Length - len >= 4) { //剩余包 byte[] temp = new byte[_buff.Length - len - 4]; Buffer.BlockCopy(_buff, len + 4, temp, 0, _buff.Length - len - 4); _buff = temp; //可用包 return(body); } else { //没有可用包 return(null); } } }
/// <summary> /// 将类型和protobuff打包成流 /// 4B+2B+protobuffer.Length /// protobuffer.Length+2 cmd protobuffer /// </summary> /// <param name="type"></param> /// <param name="t"></param> /// <returns></returns> public static byte[] Packaging <T>(int type, T t) { byte[] src = ProtobufWrapper.ByteSerialize <T>(t); byte[] buff = new byte[4 + 2 + src.Length]; byte[] headerbuf = BitConverter.GetBytes(src.Length + 2); byte[] header = new byte[4] { headerbuf[3], headerbuf[2], headerbuf[1], headerbuf[0] }; byte[] cmdbuff = BitConverter.GetBytes(type); byte[] cmd = new byte[2] { cmdbuff[1], cmdbuff[0] }; //header Buffer.BlockCopy(header, 0, buff, 0, header.Length); //cmd Buffer.BlockCopy(cmd, 0, buff, header.Length, cmd.Length); //protocolbuffer Buffer.BlockCopy(src, 0, buff, header.Length + cmd.Length, src.Length); /** * wg:update */ //以下两个行为Java客户端的请求加密方式 // byte[] ciphertext = RC4.RC4Custom(plaintext, key.getComplexKey(), key.getOutputCounter()); //key.outputCounterIncrease(ciphertext.length); //一下为获取增量 CustomRC4Key key = CustomRC4Key.CreateCustomRC4Key(); byte[] rc4byte = RC4.Convert(buff, 0);// key.GetOutputCounter()); key.OutputCounterIncrease(rc4byte.Length); //end return(rc4byte); }