Merge pull request #1502 from woogerboy21/fix_ban_crash

Fix server crash on banning
This commit is contained in:
Zach 2015-09-13 01:12:29 -04:00
commit 59da62d240
4 changed files with 21 additions and 12 deletions

View file

@ -210,7 +210,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
} }
} }
bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name()); bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name());
aDetails->setEnabled(online); aDetails->setEnabled(true);
aChat->setEnabled(anotherUser && online); aChat->setEnabled(anotherUser && online);
aShowGames->setEnabled(anotherUser); aShowGames->setEnabled(anotherUser);
aAddToBuddyList->setEnabled(anotherUser); aAddToBuddyList->setEnabled(anotherUser);

View file

@ -124,19 +124,19 @@ void BanDialog::okClicked()
} }
if (nameBanCheckBox->isChecked()) if (nameBanCheckBox->isChecked())
if (nameBanEdit->text() == ""){ if (nameBanEdit->text().simplified() == ""){
QMessageBox::critical(this, tr("Error"), tr("You must have a value in the name ban when selecting the name ban checkbox.")); QMessageBox::critical(this, tr("Error"), tr("You must have a value in the name ban when selecting the name ban checkbox."));
return; return;
} }
if (ipBanCheckBox->isChecked()) if (ipBanCheckBox->isChecked())
if (ipBanEdit->text() == ""){ if (ipBanEdit->text().simplified() == ""){
QMessageBox::critical(this, tr("Error"), tr("You must have a value in the ip ban when selecting the ip ban checkbox.")); QMessageBox::critical(this, tr("Error"), tr("You must have a value in the ip ban when selecting the ip ban checkbox."));
return; return;
} }
if (idBanCheckBox->isChecked()) if (idBanCheckBox->isChecked())
if (idBanCheckBox->text() == ""){ if (idBanEdit->text().simplified() == ""){
QMessageBox::critical(this, tr("Error"), tr("You must have a value in the clientid ban when selecting the clientid ban checkbox.")); QMessageBox::critical(this, tr("Error"), tr("You must have a value in the clientid ban when selecting the clientid ban checkbox."));
return; return;
} }

View file

@ -18,6 +18,7 @@
#include "pb/event_user_message.pb.h" #include "pb/event_user_message.pb.h"
#include "pb/event_game_joined.pb.h" #include "pb/event_game_joined.pb.h"
#include "pb/event_room_say.pb.h" #include "pb/event_room_say.pb.h"
#include "pb/serverinfo_user.pb.h"
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include "featureset.h" #include "featureset.h"
@ -536,12 +537,14 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetU
QReadLocker locker(&server->clientsLock); QReadLocker locker(&server->clientsLock);
ServerInfo_User_Container *infoSource = server->findUser(userName); ServerInfo_User_Container *infoSource = server->findUser(userName);
if (!infoSource) if (!infoSource) {
return Response::RespNameNotFound; re->mutable_user_info()->CopyFrom(databaseInterface->getUserData(userName,true));
} else {
re->mutable_user_info()->CopyFrom(infoSource->copyUserInfo(true, false, userInfo->user_level() & ServerInfo_User::IsModerator)); re->mutable_user_info()->CopyFrom(infoSource->copyUserInfo(true, false, userInfo->user_level() & ServerInfo_User::IsModerator));
}
} }
rc.setResponseExtension(re); rc.setResponseExtension(re);
return Response::RespOk; return Response::RespOk;
} }

View file

@ -768,8 +768,13 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
if (!sqlInterface->checkSql()) if (!sqlInterface->checkSql())
return Response::RespInternalError; return Response::RespInternalError;
QString userName = QString::fromStdString(cmd.user_name()); QString userName = QString::fromStdString(cmd.user_name()).simplified();
QString address = QString::fromStdString(cmd.address()); QString address = QString::fromStdString(cmd.address()).simplified();
QString clientID = QString::fromStdString(cmd.clientid()).simplified();
if (userName.isEmpty() && address.isEmpty() && clientID.isEmpty())
return Response::RespOk;
QString trustedSources = settingsCache->value("server/trusted_sources","127.0.0.1,::1").toString(); QString trustedSources = settingsCache->value("server/trusted_sources","127.0.0.1,::1").toString();
int minutes = cmd.minutes(); int minutes = cmd.minutes();
if (trustedSources.contains(address,Qt::CaseInsensitive)) if (trustedSources.contains(address,Qt::CaseInsensitive))
@ -790,10 +795,11 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
if (!userName.isEmpty()) { if (!userName.isEmpty()) {
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName)); ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
userList.append(user); if (user)
userList.append(user);
} }
if (userName.isEmpty() && address.isEmpty() && (!QString::fromStdString(cmd.clientid()).isEmpty())) { if (userName.isEmpty() && address.isEmpty() && (!clientID.isEmpty())) {
QSqlQuery *query = sqlInterface->prepareQuery("select name from {prefix}_users where clientid = :client_id"); QSqlQuery *query = sqlInterface->prepareQuery("select name from {prefix}_users where clientid = :client_id");
query->bindValue(":client_id", QString::fromStdString(cmd.clientid())); query->bindValue(":client_id", QString::fromStdString(cmd.clientid()));
sqlInterface->execSqlQuery(query); sqlInterface->execSqlQuery(query);