void UserInfoBox::updateInfo(const QString &userName) { Command_GetUserInfo cmd; cmd.set_user_name(userName.toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(processResponse(const Response &))); client->sendCommand(pend); }
Response::ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc) { if (authState == NotLoggedIn) return Response::RespLoginNeeded; QString userName = QString::fromStdString(cmd.user_name()); Response_GetUserInfo *re = new Response_GetUserInfo; if (userName.isEmpty()) re->mutable_user_info()->CopyFrom(*userInfo); else { QReadLocker locker(&server->clientsLock); ServerInfo_User_Container *infoSource = server->findUser(userName); 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; }
void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, bool online, int playerId) { aUserName->setText(userName); QMenu *menu = new QMenu(static_cast<QWidget *>(parent())); menu->addAction(aUserName); menu->addSeparator(); menu->addAction(aDetails); menu->addAction(aShowGames); menu->addAction(aChat); if (userLevel.testFlag(ServerInfo_User::IsRegistered) && (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)) { menu->addSeparator(); if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName)) menu->addAction(aRemoveFromBuddyList); else menu->addAction(aAddToBuddyList); if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName)) menu->addAction(aRemoveFromIgnoreList); else menu->addAction(aAddToIgnoreList); } if (game && (game->isHost() || !tabSupervisor->getAdminLocked())) { menu->addSeparator(); menu->addAction(aKick); } if (!tabSupervisor->getAdminLocked()) { menu->addSeparator(); menu->addAction(aBan); } bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name()); aDetails->setEnabled(online); aChat->setEnabled(anotherUser && online); aShowGames->setEnabled(anotherUser); aAddToBuddyList->setEnabled(anotherUser); aRemoveFromBuddyList->setEnabled(anotherUser); aAddToIgnoreList->setEnabled(anotherUser); aRemoveFromIgnoreList->setEnabled(anotherUser); aKick->setEnabled(anotherUser); aBan->setEnabled(anotherUser); QAction *actionClicked = menu->exec(pos); if (actionClicked == aDetails) { UserInfoBox *infoWidget = new UserInfoBox(client, false, static_cast<QWidget *>(parent()), Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); infoWidget->setAttribute(Qt::WA_DeleteOnClose); infoWidget->updateInfo(userName); } else if (actionClicked == aChat) emit openMessageDialog(userName, true); else if (actionClicked == aShowGames) { Command_GetGamesOfUser cmd; cmd.set_user_name(userName.toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(gamesOfUserReceived(Response, CommandContainer))); client->sendCommand(pend); } else if (actionClicked == aAddToBuddyList) { Command_AddToList cmd; cmd.set_list("buddy"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aRemoveFromBuddyList) { Command_RemoveFromList cmd; cmd.set_list("buddy"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aAddToIgnoreList) { Command_AddToList cmd; cmd.set_list("ignore"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aRemoveFromIgnoreList) { Command_RemoveFromList cmd; cmd.set_list("ignore"); cmd.set_user_name(userName.toStdString()); client->sendCommand(client->prepareSessionCommand(cmd)); } else if (actionClicked == aKick) { Command_KickFromGame cmd; cmd.set_player_id(playerId); game->sendGameCommand(cmd); } else if (actionClicked == aBan) { Command_GetUserInfo cmd; cmd.set_user_name(userName.toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(banUser_processUserInfoResponse(Response))); client->sendCommand(pend); } delete menu; }