private void Login() { byte[] loginPacket = new byte[ProtoHeader.kHeadLen + kUserNameLen + kPwdLen]; ProtoHeader proHdr = new ProtoHeader(loginPacket); Array.Clear(loginPacket, 0, (loginPacket.Length)); byte[] nameArray = System.Text.Encoding.Default.GetBytes(UserName); byte[] pwdArray = System.Text.Encoding.Default.GetBytes(Password); if (nameArray.Length >= kUserNameLen) { throw new PDBException(PDBErrorCode.PdbE_INVALID_USER_NAME, "非法的用户名:用户名不合法"); } for (int i = 0; i < nameArray.Length; i++) { loginPacket[ProtoHeader.kHeadLen + i] = nameArray[i]; } UInt64 pwd64 = CRC.Crc64(pwdArray); UInt32 pwd32 = (UInt32)(pwd64 & 0xFFFFFFFF); IntTool.PutUint32(loginPacket, (ProtoHeader.kHeadLen + kUserNameLen), pwd32); UInt32 bodyCrc = CRC.Crc32(loginPacket, ProtoHeader.kHeadLen, (kUserNameLen + kPwdLen)); proHdr.SetVersion(ProtoHeader.kProtoVersion); proHdr.SetMethod(ProtoHeader.MethodCmdLoginReq); proHdr.SetBodyLen((uint)(kUserNameLen + kPwdLen)); proHdr.SetReturnVal(0); proHdr.SetRecordCnt((uint)0); proHdr.SetBodyCrc(bodyCrc); proHdr.SetHeadCrc(); Request(loginPacket); byte[] resBuf = Recv(); ProtoHeader resHdr = new ProtoHeader(resBuf); if (resHdr.GetMethod() != ProtoHeader.MethodCmdLoginRep) { throw new PDBException(PDBErrorCode.PdbE_PACKET_ERROR); } if (resHdr.GetReturnVal() != 0) { throw new PDBException(PDBErrorCode.PdbE_NET_ERROR, "网络错误:登录失败," + resHdr.GetReturnVal().ToString()); } }
public void SetHeadCrc() { IntTool.PutUint32(headProto, kHeadHeadCrcOffset, CRC.Crc32(headProto, 0, 60)); }
public void SetBodyCrc(UInt32 bodyCrc) { IntTool.PutUint32(headProto, kHeadBodyCrcOffset, bodyCrc); }
public void SetErrPos(UInt32 errPos) { IntTool.PutUint32(headProto, kHeadErrPosOffset, errPos); }
public void SetRecordCnt(UInt32 recordCnt) { IntTool.PutUint32(headProto, kHeadRecordCntOffset, recordCnt); }
public void SetFieldCnt(UInt32 fieldCnt) { IntTool.PutUint32(headProto, kHeadFieldCntOffset, fieldCnt); }
public void SetReturnVal(UInt32 retVal) { IntTool.PutUint32(headProto, kHeadRetValOffset, retVal); }
public void SetBodyLen(UInt32 bodyLen) { IntTool.PutUint32(headProto, kHeadBodyLenOffset, bodyLen); }
public void SetMethod(UInt32 methodId) { IntTool.PutUint32(headProto, kHeadMethodOffset, methodId); }
public void SetVersion(UInt32 version) { IntTool.PutUint32(headProto, kHeadVerOffset, version); }