[Browser] Add ability for connect to passworded servers

pull/163/head
Koncord 8 years ago
parent 0e92f43822
commit 6f2d12d2c6

@ -125,6 +125,15 @@ void MainWindow::play()
QStringList arguments; QStringList arguments;
arguments.append(QLatin1String("--connect=") + sm->myData[sourceId].addr.toLatin1()); arguments.append(QLatin1String("--connect=") + sm->myData[sourceId].addr.toLatin1());
if(sm->myData[sourceId].needPassw)
{
bool ok;
QString passw = QInputDialog::getText(this, "Connecting to: " + sm->myData[sourceId].addr, "Password: ", QLineEdit::Password, "", &ok);
if(!ok)
return;
arguments.append(QLatin1String("--password=") + passw.toLatin1());
}
if (mGameInvoker->startProcess(QLatin1String("tes3mp"), arguments, true)) if (mGameInvoker->startProcess(QLatin1String("tes3mp"), arguments, true))
return qApp->quit(); return qApp->quit();
} }

@ -80,6 +80,10 @@ void NetController::setData(QString address, QJsonObject server, ServerModel *mo
mi = model->index(0, ServerData::VERSION); mi = model->index(0, ServerData::VERSION);
model->setData(mi, server["version"].toString()); model->setData(mi, server["version"].toString());
mi = model->index(0, ServerData::PASSW);
model->setData(mi, server["passw"].toBool());
mi = model->index(0, ServerData::PING); mi = model->index(0, ServerData::PING);
QStringList addr = address.split(":"); QStringList addr = address.split(":");
@ -152,6 +156,7 @@ bool NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index)
qDebug() << server["players"].toInt(); qDebug() << server["players"].toInt();
qDebug() << server["max_players"].toInt(); qDebug() << server["max_players"].toInt();
qDebug() << server["version"].toString(); qDebug() << server["version"].toString();
qDebug() << server["passw"].toBool();
QVector<ServerData>::Iterator value = std::find_if(model->myData.begin(), model->myData.end(), pattern(iter.key())); QVector<ServerData>::Iterator value = std::find_if(model->myData.begin(), model->myData.end(), pattern(iter.key()));
if(value == model->myData.end()) if(value == model->myData.end())
@ -213,6 +218,7 @@ void NetController::updateInfo()
qDebug() << map["players"].toInt(); qDebug() << map["players"].toInt();
qDebug() << map["max_players"].toInt(); qDebug() << map["max_players"].toInt();
qDebug() << map["version"].toString(); qDebug() << map["version"].toString();
qDebug() << map["passw"].toBool();
sd->hostName = map["hostname"].toString(); sd->hostName = map["hostname"].toString();
sd->modName = map["modname"].toString(); sd->modName = map["modname"].toString();

@ -33,6 +33,9 @@ QVariant ServerModel::data(const QModelIndex &index, int role) const
case ServerData::ADDR: case ServerData::ADDR:
var = sd.addr; var = sd.addr;
break; break;
case ServerData::PASSW:
var = sd.needPassw;
break;
case ServerData::VERSION: case ServerData::VERSION:
var = sd.version; var = sd.version;
break; break;
@ -78,6 +81,9 @@ QVariant ServerModel::headerData(int section, Qt::Orientation orientation, int r
case ServerData::ADDR: case ServerData::ADDR:
var = "Address"; var = "Address";
break; break;
case ServerData::PASSW:
var = "P";
break;
case ServerData::VERSION: case ServerData::VERSION:
var = "Version"; var = "Version";
break; break;
@ -126,6 +132,9 @@ bool ServerModel::setData(const QModelIndex &index, const QVariant &value, int r
sd.addr = value.toString(); sd.addr = value.toString();
ok = !sd.addr.isEmpty(); ok = !sd.addr.isEmpty();
break; break;
case ServerData::PASSW:
sd.needPassw = value.toBool();
break;
case ServerData::VERSION: case ServerData::VERSION:
sd.version = value.toString(); sd.version = value.toString();
ok = !sd.addr.isEmpty(); ok = !sd.addr.isEmpty();
@ -162,7 +171,7 @@ bool ServerModel::insertRows(int position, int count, const QModelIndex &index)
beginInsertRows(QModelIndex(), position, position + count - 1); beginInsertRows(QModelIndex(), position, position + count - 1);
for (int row = 0; row < count; ++row) { for (int row = 0; row < count; ++row) {
ServerData sd {"", -1, -1, -1, "", ""}; ServerData sd {"", -1, -1, -1, "", "", false, 0};
myData.insert(position, sd); myData.insert(position, sd);
} }

@ -13,10 +13,12 @@ struct ServerData
int ping; int ping;
QString hostName; QString hostName;
QString modName; QString modName;
bool needPassw;
QString version; QString version;
enum IDS enum IDS
{ {
ADDR, ADDR,
PASSW,
HOSTNAME, HOSTNAME,
PLAYERS, PLAYERS,
MAX_PLAYERS, MAX_PLAYERS,

Loading…
Cancel
Save