int main() { int i; char* argv[8]; int argc; printf_register(serial_putchar); printf("waiting..."); // Wait a short while for(i = 0; i < 10000; ++i) asm volatile ("nop"); printf("configuring..."); i2c_init(); argv[0] = "1"; argc = 1; doConfig(argv, argc); printf("done.\n"); while (1) { printf("\n> "); argc = readcmd(argv, 8); printf("\r\n> "); if(argc > 0) { switch(argv[0][0]) { case 'S': doSet(argv, argc); break; case 'G': doGet(argv, argc); break; case 'R': doResult(argv, argc); break; case 'W': doWrite(argv, argc); break; case 'X': doRead(argv, argc); break; case 'Z': doStatus(argv, argc); break; case 'I': switch(argv[0][1]) { case 'I': i2c_init(); break; case 'W': doI2CWrite(argv, argc); break; case 'R': doI2CRead(argv, argc); break; case 'C': doConfig(argv, argc); break; } break; } } } }
/** * Обработка входящей станзы и вызов соответствующих методов */ bool GameSessions::processIncomingIqStanza(int account, const QDomElement &xml, const QString &acc_status, bool conf_priv) { const QString iq_type = xml.attribute("type"); if(iq_type == "set") { QDomElement childElem = xml.firstChildElement("create"); if(!childElem.isNull() && childElem.attribute("xmlns") == "games:board" && childElem.attribute("type") == constProtoType) { const QString from = xml.attribute("from"); const QString id = xml.attribute("id"); const QString protoId = childElem.attribute("id"); if (protoId != constProtoId) { sendErrorIq(account, from, id, "Incorrect protocol version"); return true; } Options *options = Options::instance(); if ((options->getOption(constDndDisable).toBool() && acc_status == "dnd") || (options->getOption(constConfDisable).toBool() && conf_priv)) { sendErrorIq(account, from, id, ""); return true; } if (incomingInvitation(account, from, childElem.attribute("color"), id)) { emit doInviteEvent(account, from, tr("%1: Invitation from %2").arg(constPluginName).arg(from), this, SLOT(showInvitation(QString))); } return true; } if (activeCount() == 0) // Нет ни одной активной игровой сессии (наиболее вероятный исход большую часть времени) return false; // Остальные проверки бессмысленны childElem = xml.firstChildElement("turn"); if (!childElem.isNull() && childElem.attribute("xmlns") == "games:board" && childElem.attribute("type") == constProtoType) { const QString from = xml.attribute("from"); const QString id = xml.attribute("id"); const QString protoId = childElem.attribute("id"); if (protoId != constProtoId) { sendErrorIq(account, from, id, "Incorrect protocol version"); return true; } QDomElement turnChildElem = childElem.firstChildElement("move"); if (!turnChildElem.isNull()) { return doTurnAction(account, from, id, turnChildElem.attribute("pos")); } turnChildElem = childElem.firstChildElement("resign"); if (!turnChildElem.isNull()) { return youWin(account, from, id); } turnChildElem = childElem.firstChildElement("draw"); if (!turnChildElem.isNull()) { return setDraw(account, from, id); } return false; } childElem = xml.firstChildElement("close"); if (!childElem.isNull() && childElem.attribute("xmlns") == "games:board" && childElem.attribute("type") == constProtoType) { const QString from = xml.attribute("from"); const QString id = xml.attribute("id"); const QString protoId = childElem.attribute("id"); if (protoId != constProtoId) { sendErrorIq(account, from, id, "Incorrect protocol version"); return true; } return closeRemoteGameBoard(account, from, id); } childElem = xml.firstChildElement("load"); if (!childElem.isNull() && childElem.attribute("xmlns") == "games:board" && childElem.attribute("type") == constProtoType) { const QString from = xml.attribute("from"); const QString id = xml.attribute("id"); const QString protoId = childElem.attribute("id"); if (protoId != constProtoId) { sendErrorIq(account, from, id, "Incorrect protocol version"); return true; } return remoteLoad(account, from, id, childElem.text()); } } else if (iq_type == "result") { if (doResult(account, xml.attribute("from"), xml.attribute("id"))) { return true; } } else if (iq_type == "error") { if (doReject(account, xml.attribute("from"), xml.attribute("id"))) { return true; } } return false; }