/// <summary>
/// 功能:SP登录请求
/// 作者:吕永义
/// 时间:2011年3月28日
/// 2011年4月12日测试登录包正常
/// </summary>
public class Login
{
/// <summary>
/// 消息体的长度
/// </summary>
private readonly int BodyLength = 8 + 16 + 1 + 4 + 1; //消息体的长度
/// <summary>
/// 消息流水号
/// </summary>
private uint sequenceID;
/// <summary>
/// 消息流水号
/// </summary>
public uint SequenceID
{
get { return sequenceID; }
set { sequenceID = value; }
}
/// <summary>
/// 消息头变量
/// </summary>
private MessageHeader msgHeader;
/// <summary>
/// 消息头
/// </summary>
public MessageHeader MsgHeader
{
get { return msgHeader; }
set { msgHeader = value; }
}
private string clientID;
private string clientPwd;
/// <summary>
/// 登录服务端的密码
/// </summary>
public string ClientPwd
{
get { return clientPwd; }
set { clientPwd = value; }
}
/// <summary>
/// 客户端登录服务器端的账号
/// </summary>
public string ClientID
{
get { return clientID; }
set { clientID = value; }
}
/// <summary>
/// 客户端验证码
/// </summary>
private byte[] authenticatorClient;
/// <summary>
/// 客户端验证码
/// </summary>
public byte[] AuthenticatorClient
{
get { return authenticatorClient; }
set { authenticatorClient = value; }
}
/// <summary>
/// 登录服务端的登录类型
/// </summary>
private uint loginMode;
/// <summary>
/// 登录服务端的登录类型
/// </summary>
public uint LoginMode
{
get { return loginMode; }
set { loginMode = value; }
}
/// <summary>
/// 时间戳
/// </summary>
private uint timeStamp;
/// <summary>
/// 时间戳
/// </summary>
public uint TimeStamp
{
get { return timeStamp; }
set { timeStamp = value; }
}
private string _timeStamp;
/// <summary>
/// 客户端支持的协议版本号
/// </summary>
private byte clientVersion;
/// <summary>
/// 客户端支持的协议版本号
/// </summary>
public byte ClientVersion
{
get { return clientVersion; }
set { clientVersion = value; }
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="clientID">客户端登录名</param>
/// <param name="clientPwd">客户端登录的密码</param>
/// <param name="loginMode">登录模式</param>
/// <param name="clientVersion">版本号</param>
/// <param name="sequenceID">消息流水号</param>
public Login(string clientID,string clientPwd, uint loginMode, byte clientVersion,uint sequenceID)
{
this.clientPwd = clientPwd;
this.clientID = clientID;
this.loginMode = loginMode;
this.clientVersion = clientVersion;
this.sequenceID = sequenceID;
//消息头赋值
this.MsgHeader = new MessageHeader((uint)(MessageHeader.HeaderLength + BodyLength), (RequestID)RequestID.Login, this.sequenceID);
_timeStamp = Util.Get_MMDDHHMMSS_String(DateTime.Now);
this.timeStamp = uint.Parse(_timeStamp);
this.authenticatorClient = getMd5Code();
}
/// <summary>
/// 返回字节数组
/// </summary>
/// <returns></returns>
public byte[] ToBytes()
{
int i = 0;
byte[] bytes = new Byte[MessageHeader.HeaderLength + this.BodyLength];
byte[] buffer = this.msgHeader.ToBytes();//消息头
Util.ByteCopyToByte(buffer, 0, bytes, i, buffer.Length);
i = i + 12;
buffer = BIConvert.String2Bytes(this.clientID);//客户端登录名
Util.ByteCopyToByte(buffer, 0, bytes, i, buffer.Length);
i = i + 8;
buffer = this.authenticatorClient;
Util.ByteCopyToByte(buffer, 0, bytes, i, buffer.Length);//客户端认证码
i = i + 16;
bytes[i++] = (byte)this.loginMode;//登录模式
buffer = BIConvert.Int2Bytes(this.timeStamp);
Util.ByteCopyToByte(buffer, 0, bytes, i, buffer.Length);
i = i + 4;
bytes[i++] = this.clientVersion;//版本号
return bytes;
}