From 46f78fcead8146657f620b6e353ece8c93a35e30 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Fri, 11 Sep 2015 18:41:02 -0400 Subject: [PATCH] Fix server crash on banning --- cockatrice/src/user_context_menu.cpp | 2 +- cockatrice/src/userlist.cpp | 6 +++--- common/server_protocolhandler.cpp | 11 +++++++---- servatrice/src/serversocketinterface.cpp | 14 ++++++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/user_context_menu.cpp b/cockatrice/src/user_context_menu.cpp index 0949f355..d6983449 100644 --- a/cockatrice/src/user_context_menu.cpp +++ b/cockatrice/src/user_context_menu.cpp @@ -210,7 +210,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName } } bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name()); - aDetails->setEnabled(online); + aDetails->setEnabled(true); aChat->setEnabled(anotherUser && online); aShowGames->setEnabled(anotherUser); aAddToBuddyList->setEnabled(anotherUser); diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index d438f5f5..87a282e9 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -124,19 +124,19 @@ void BanDialog::okClicked() } 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.")); return; } 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.")); return; } 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.")); return; } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index cb8515f3..70191566 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -18,6 +18,7 @@ #include "pb/event_user_message.pb.h" #include "pb/event_game_joined.pb.h" #include "pb/event_room_say.pb.h" +#include "pb/serverinfo_user.pb.h" #include #include "featureset.h" @@ -536,12 +537,14 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetU QReadLocker locker(&server->clientsLock); ServerInfo_User_Container *infoSource = server->findUser(userName); - if (!infoSource) - return Response::RespNameNotFound; - - re->mutable_user_info()->CopyFrom(infoSource->copyUserInfo(true, false, userInfo->user_level() & ServerInfo_User::IsModerator)); + if (!infoSource) { + 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)); + } } + rc.setResponseExtension(re); return Response::RespOk; } diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 5250ee4c..6911d9f6 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -768,8 +768,13 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban if (!sqlInterface->checkSql()) return Response::RespInternalError; - QString userName = QString::fromStdString(cmd.user_name()); - QString address = QString::fromStdString(cmd.address()); + QString userName = QString::fromStdString(cmd.user_name()).simplified(); + 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(); int minutes = cmd.minutes(); if (trustedSources.contains(address,Qt::CaseInsensitive)) @@ -790,10 +795,11 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban if (!userName.isEmpty()) { ServerSocketInterface *user = static_cast(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"); query->bindValue(":client_id", QString::fromStdString(cmd.clientid())); sqlInterface->execSqlQuery(query);