diff --git a/cockatrice/src/user_context_menu.cpp b/cockatrice/src/user_context_menu.cpp index 2925cd19..9bf0f484 100644 --- a/cockatrice/src/user_context_menu.cpp +++ b/cockatrice/src/user_context_menu.cpp @@ -231,23 +231,13 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(banUser_processUserInfoResponse(Response))); client->sendCommand(pend); - } else if (actionClicked == aPromoteToMod) { + } else if (actionClicked == aPromoteToMod || actionClicked == aDemoteFromMod) { Command_AdjustMod cmd; cmd.set_user_name(userName.toStdString()); - cmd.set_should_be_mod(true); + cmd.set_should_be_mod(actionClicked == aPromoteToMod); - // client->sendCommand(client->prepareAdminCommand(cmd)); PendingCommand *pend = client->prepareAdminCommand(cmd); - connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(adjustMod_processUserResponse(Response,CommandContainer))); - client->sendCommand(pend); - } else if (actionClicked == aDemoteFromMod) { - Command_AdjustMod cmd; - cmd.set_user_name(userName.toStdString()); - cmd.set_should_be_mod(false); - - // client->sendCommand(client->prepareAdminCommand(cmd)); - PendingCommand *pend = client->prepareAdminCommand(cmd); - connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(adjustMod_processUserResponse(Response,CommandContainer))); + connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(adjustMod_processUserResponse(Response, CommandContainer))); client->sendCommand(pend); } diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index a50ca128..84c1002d 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include +#include #include #include #include @@ -1008,47 +1009,45 @@ Response::ResponseCode ServerSocketInterface::cmdAdjustMod(const Command_AdjustM QString userName = QString::fromStdString(cmd.user_name()); if (cmd.should_be_mod()) { - logDebugMessage("Received admin command: promote user"); QSqlQuery *query = sqlInterface->prepareQuery( "update {prefix}_users set admin = :adminlevel where name = :username"); query->bindValue(":adminlevel", 2); query->bindValue(":username", userName); - if (!sqlInterface->execSqlQuery(query)) + if (!sqlInterface->execSqlQuery(query)){ + logger->logMessage(QString::fromStdString("Failed to promote user %1: %2").arg(userName).arg(query->lastError().text())); return Response::RespInternalError; + } ServerSocketInterface *user = static_cast(server->getUsers().value(userName)); - Event_NotifyUser event; - event.set_type(Event_NotifyUser::PROMOTED); - SessionEvent *se = user->prepareSessionEvent(event); - user->sendProtocolItem(*se); - delete se; - + if (user) { + Event_NotifyUser event; + event.set_type(Event_NotifyUser::PROMOTED); + SessionEvent *se = user->prepareSessionEvent(event); + user->sendProtocolItem(*se); + delete se; + } } else { - logDebugMessage("Received admin command: demote user"); QSqlQuery *query = sqlInterface->prepareQuery("update {prefix}_users set admin = :adminlevel where name = :username"); query->bindValue(":adminlevel", 0); query->bindValue(":username", userName); - if (!sqlInterface->execSqlQuery(query)) + if (!sqlInterface->execSqlQuery(query)){ + logger->logMessage(QString::fromStdString("Failed to demote user %1: %2").arg(userName).arg(query->lastError().text())); return Response::RespInternalError; + } - QList userList; ServerSocketInterface *user = static_cast(server->getUsers().value(userName)); - userList.append(user); - - if (!userList.isEmpty()) { + if (user) { Event_ConnectionClosed event; event.set_reason(Event_ConnectionClosed::DEMOTED); event.set_reason_str("Your moderator status has been revoked."); event.set_end_time(QDateTime::currentDateTime().toTime_t()); - for (int i = 0; i < userList.size(); ++i) { - SessionEvent *se = userList[i]->prepareSessionEvent(event); - userList[i]->sendProtocolItem(*se); - delete se; - QMetaObject::invokeMethod(userList[i], "prepareDestroy", Qt::QueuedConnection); - } - userList.clear(); + + SessionEvent *se = user->prepareSessionEvent(event); + user->sendProtocolItem(*se); + delete se; } + QMetaObject::invokeMethod(user, "prepareDestroy", Qt::QueuedConnection); } return Response::RespOk;