throws DownloadFailedException
{
// m_sp.addLine(sLin);
m_bSilent = bSilent;
m_nCurCard = 0;
Deal d = new Deal();
String sLastComm = "";
Scanner sc = new Scanner(sLin).useDelimiter("\\|");
while (sc.hasNext()) {
String sComm = sc.next();
if (sComm.length() == 0) {
throw new DownloadFailedException(
PbnTools.getStr("lin.error.emptyCmd", sc.match().start()),
m_sp, !m_bSilent);
}
if (!sc.hasNext()) {
throw new DownloadFailedException(
PbnTools.getStr("lin.error.noArg", sComm), m_sp, !m_bSilent);
}
String sArg = sc.next();
if (sComm.equals("ah"))
readNumber(d, sArg);
else if (sComm.equals("an") && sLastComm.equals("mb")) {
d.annotateLastBid(sArg);
} else if (sComm.equals("pc"))
try {
readPlay(d, sArg);
} catch (DownloadFailedException dfe) {
// ignore played cards errors, as it's not the main functionality
m_sp.addLine(dfe.getMessage());
}
else if (sComm.equals("pg"))
{} // pause game, ignore it
else if (sComm.equals("pn"))
readPlayers(d, sArg);
else if (sComm.equals("mb"))
readBid(d, sArg);
else if (sComm.equals("mc")) {
try {
int cTricks = Integer.parseInt(sArg);
if (cTricks < 0 || cTricks > 13)
throw new NumberFormatException();
d.setResult(cTricks);
} catch (NumberFormatException nfe) {
m_sp.addLine(PbnTools.getStr("error.linInvArg", sComm, sArg));
}
} else if (sComm.equals("md"))
readHands(d, sArg);
else if (sComm.equals("rh") || sComm.equals("st")) {
if (!sArg.isEmpty() && !m_bSilent)
m_sp.addLine(PbnTools.getStr("msg.interesting", sComm + sArg));
}
else if (sComm.equals("sv"))
readVulner(d, sArg);
else {
if (!m_bSilent) {
m_sp.addLine(PbnTools.getStr("msg.interesting",
"Command: " + sComm + ", arg: " + sArg));
}
}
sLastComm = sComm;
}
// contract must be deduced from auction
ArrayList<String> asErrors = new ArrayList<String>();
d.setContractFromAuction(asErrors);
if (asErrors.size() > 0) {
m_sp.addLine(PbnTools.getStr("lin.error.noContract"));
for (String sMsg: asErrors)
m_sp.addLine(" " + sMsg);
}
// passed out - result can be deduced :)
if (d.getContractHeight() == 0)
d.setResult(0);
if (d.getResult() < 0 && d.getContractHeight() > 0) {
// the result must be deduced from plays
asErrors.clear();
d.setResultFromPlays(asErrors);
if (asErrors.size() > 0) {
m_sp.addLine(PbnTools.getStr("lin.error.noContract"));
for (String sMsg: asErrors)
m_sp.addLine(" " + sMsg);
}
}
// when no result, don't show the contract either
if (d.getResult() < 0)
d.setContractHeight(-1);
return new Deal[] { d };
} //}}}