From c9dc75f5897915d0387a0614215cec4f332bdd0a Mon Sep 17 00:00:00 2001 From: Battlerax Date: Fri, 24 Feb 2017 14:52:22 -0600 Subject: [PATCH] [Browser] Fixed two crashes relating to invalid data --- apps/browser/NetController.cpp | 15 ++++++++------- apps/browser/ServerInfoDialog.cpp | 25 ++++++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/apps/browser/NetController.cpp b/apps/browser/NetController.cpp index e97463c59..e539f0983 100644 --- a/apps/browser/NetController.cpp +++ b/apps/browser/NetController.cpp @@ -85,13 +85,12 @@ void NetController::setData(QString address, QJsonObject server, ServerModel *mo model->setData(mi, server["passw"].toBool()); mi = model->index(0, ServerData::PING); - // This *should* fix a crash when a port isn't returned by data. - if(!address.contains(":")) - { - address.append(":25565"); - } - QStringList addr = address.split(":"); - model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort())); + + // This *should* fix a crash when a port isn't returned by data. + if(!address.contains(":")) + address.append(":25565"); + QStringList addr = address.split(":"); + model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort())); } bool NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index) @@ -229,6 +228,8 @@ void NetController::updateInfo() sd->players = map["players"].toInt(); sd->maxPlayers = map["max_players"].toInt(); + if(!sd->addr.contains(":")) + sd->addr.append(":25565"); QStringList addr = sd->addr.split(":"); sd->ping = PingRakNetServer(addr[0].toLatin1(), addr[1].toUShort()); if(sd->ping != PING_UNREACHABLE) diff --git a/apps/browser/ServerInfoDialog.cpp b/apps/browser/ServerInfoDialog.cpp index 2fe75b890..5ed4b2a31 100644 --- a/apps/browser/ServerInfoDialog.cpp +++ b/apps/browser/ServerInfoDialog.cpp @@ -22,15 +22,18 @@ void ServerInfoDialog::refresh() { NetController::get()->updateInfo(); ServerData *sd = NetController::get()->selectedServer(); - leAddr->setText(sd->addr); - lblName->setText(sd->hostName); - lblPing->setNum(sd->ping); - - listPlayers->clear(); - QStringList players = NetController::get()->players(); - listPlayers->addItems(players); - listPlugins->clear(); - listPlugins->addItems(NetController::get()->plugins()); - - lblPlayers->setText(QString::number(players.size()) + " / " + QString::number(sd->maxPlayers)); + if (sd) + { + leAddr->setText(sd->addr); + lblName->setText(sd->hostName); + lblPing->setNum(sd->ping); + + listPlayers->clear(); + QStringList players = NetController::get()->players(); + listPlayers->addItems(players); + listPlugins->clear(); + listPlugins->addItems(NetController::get()->plugins()); + + lblPlayers->setText(QString::number(players.size()) + " / " + QString::number(sd->maxPlayers)); + } }