package cn.net.cpzslibs.prot;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.SocketTimeoutException;

public class Prot101Login extends ProtBase {
	private final short iTaskCode101 = 101;
	// 任务号101： 用户登录时，没有相应的用户名，iErrCode=0xFFC6
	public final int errNoUserName = 0xFFC6;
	public void dealProt(SocketCreate create, String userid, String password) throws IOException {
		sendProt(create.getDos(), iTaskCode101, userid, password);
		recProt(create.getDis(), iTaskCode101);
	}

	public boolean isNoUserName() {
		return getiRecErrcode() == errNoUserName;
	}

	private void recProt(DataInputStream dis, short iTaskCode) throws IOException {
		recHeader(dis);
		recFFFF(dis, iTaskCode);
	}
	private void sendProt(DataOutputStream dos, short iTaskCode, String userid, String password)
			throws SocketTimeoutException, IOException {
		byte[] sendUserIds = getSendBytes(userid, 12);// 发送用户名
		byte[] sendPwds = getSendBytes(password, 8);
		short iBodySize = (short) (countBodySize(sendUserIds, sendPwds));
		sendHeader(dos, iTaskCode, iBodySize);
		dos.write(sendUserIds);
		dos.write(sendPwds);
		sendCheckCode(dos);

	}
}
