Read hostname and pin from config file if available.

This commit is contained in:
codestation
2015-03-22 22:27:00 -04:30
parent 380f3049da
commit 023d46cf0f
3 changed files with 22 additions and 3 deletions

View File

@@ -41,11 +41,13 @@ bool DeviceCapability::exchangeInfo(vita_device_t *device)
vita_info.protocolVersion, VITAMTP_PROTOCOL_MAX_VERSION);
}
QString hostname = QHostInfo::localHostName();
QSettings settings;
QString hostname = settings.value("hostName", QHostInfo::localHostName()).toString();
int protocol_version = ::getVitaProtocolVersion();
qDebug() << "Sending Qcma protocol version:" << protocol_version;
qDebug() << "Identifying as" << hostname;
const initiator_info_t *pc_info = VitaMTP_Data_Initiator_New(hostname.toUtf8().data(), protocol_version);

View File

@@ -56,7 +56,7 @@ CmaBroadcast::CmaBroadcast(QObject *obj_parent) :
settings.setValue("guid", uuid);
}
hostname = QHostInfo::localHostName();
hostname = settings.value("hostName", QHostInfo::localHostName()).toString();
setAvailable();
socket = new QUdpSocket(this);

View File

@@ -187,13 +187,30 @@ int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err)
// save the device name in a temporal variable, just in case the pin is rejected
tempOnlineId = QString(info->name);
qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr);
int pin = rand() % 10000 * 10000 | rand() % 10000;
QString staticPin = QSettings().value("staticPin").toString();
int pin;
if(!staticPin.isNull() && staticPin.length() == 8) {
bool ok;
pin = staticPin.toInt(&ok);
if(!ok) {
pin = rand() % 10000 * 10000 | rand() % 10000;
}
} else {
pin = rand() % 10000 * 10000 | rand() % 10000;
}
QTextStream out(stdout);
out << "Your registration PIN for " << info->name << " is: ";
out.setFieldWidth(8);
out.setPadChar('0');
out << pin << endl;
qDebug("PIN: %08i", pin);
*p_err = 0;
emit this_object->receivedPin(info->name, pin);
return pin;