[Browser] Fixed two crashes relating to invalid data

pull/172/head
Battlerax 8 years ago committed by Stanislav Zhukov
parent 76e866c5c9
commit c9dc75f589

@ -85,11 +85,10 @@ void NetController::setData(QString address, QJsonObject server, ServerModel *mo
model->setData(mi, server["passw"].toBool()); model->setData(mi, server["passw"].toBool());
mi = model->index(0, ServerData::PING); mi = model->index(0, ServerData::PING);
// This *should* fix a crash when a port isn't returned by data. // This *should* fix a crash when a port isn't returned by data.
if(!address.contains(":")) if(!address.contains(":"))
{
address.append(":25565"); address.append(":25565");
}
QStringList addr = address.split(":"); QStringList addr = address.split(":");
model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort())); model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort()));
} }
@ -229,6 +228,8 @@ void NetController::updateInfo()
sd->players = map["players"].toInt(); sd->players = map["players"].toInt();
sd->maxPlayers = map["max_players"].toInt(); sd->maxPlayers = map["max_players"].toInt();
if(!sd->addr.contains(":"))
sd->addr.append(":25565");
QStringList addr = sd->addr.split(":"); QStringList addr = sd->addr.split(":");
sd->ping = PingRakNetServer(addr[0].toLatin1(), addr[1].toUShort()); sd->ping = PingRakNetServer(addr[0].toLatin1(), addr[1].toUShort());
if(sd->ping != PING_UNREACHABLE) if(sd->ping != PING_UNREACHABLE)

@ -22,6 +22,8 @@ void ServerInfoDialog::refresh()
{ {
NetController::get()->updateInfo(); NetController::get()->updateInfo();
ServerData *sd = NetController::get()->selectedServer(); ServerData *sd = NetController::get()->selectedServer();
if (sd)
{
leAddr->setText(sd->addr); leAddr->setText(sd->addr);
lblName->setText(sd->hostName); lblName->setText(sd->hostName);
lblPing->setNum(sd->ping); lblPing->setNum(sd->ping);
@ -33,4 +35,5 @@ void ServerInfoDialog::refresh()
listPlugins->addItems(NetController::get()->plugins()); listPlugins->addItems(NetController::get()->plugins());
lblPlayers->setText(QString::number(players.size()) + " / " + QString::number(sd->maxPlayers)); lblPlayers->setText(QString::number(players.size()) + " / " + QString::number(sd->maxPlayers));
}
} }

Loading…
Cancel
Save