miscellaneous refactors (#4521)

This commit is contained in:
ebbit1q
2022-01-16 23:58:53 +01:00
committed by GitHub
parent 994704d353
commit ae9b8b8f34
8 changed files with 32 additions and 50 deletions

View File

@@ -44,7 +44,7 @@ If you'd like to help contribute to Cockatrice in any way, check out our [README
> ⚠️ **With this release, we no longer provide a ready-to-install binary for:** > ⚠️ **With this release, we no longer provide a ready-to-install binary for:**
> --DEPRECATED-OS-HERE-- > --DEPRECATED-OS-HERE--
--> -->
- Run the internal software updater: <kbd>Help → Check for Client Updates</kbd> - Run the internal software updater: <kbd>Help → Check for Client Updates</kbd>
Don't forget to update your card database right after! (<kbd>Help → Check for Card Updates...</kbd>) Don't forget to update your card database right after! (<kbd>Help → Check for Card Updates...</kbd>)

View File

@@ -2615,15 +2615,6 @@ void Player::clearArrows()
void Player::rearrangeCounters() void Player::rearrangeCounters()
{ {
qreal marginTop = 80; qreal marginTop = 80;
// Determine total height of bounding rectangles
qreal totalHeight = 0;
for (const auto &counter : counters) {
if (counter->getShownInCounterArea()) {
totalHeight += counter->boundingRect().height();
}
}
const qreal padding = 5; const qreal padding = 5;
qreal ySize = boundingRect().y() + marginTop; qreal ySize = boundingRect().y() + marginTop;

View File

@@ -4,11 +4,6 @@
#include <QCryptographicHash> #include <QCryptographicHash>
void PasswordHasher::initialize()
{
// dummy
}
QString PasswordHasher::computeHash(const QString &password, const QString &salt) QString PasswordHasher::computeHash(const QString &password, const QString &salt)
{ {
QCryptographicHash::Algorithm algo = QCryptographicHash::Sha512; QCryptographicHash::Algorithm algo = QCryptographicHash::Sha512;
@@ -41,4 +36,4 @@ QString PasswordHasher::generateRandomSalt(const int len)
QString PasswordHasher::generateActivationToken() QString PasswordHasher::generateActivationToken()
{ {
return QCryptographicHash::hash(generateRandomSalt().toUtf8(), QCryptographicHash::Md5).toBase64().left(16); return QCryptographicHash::hash(generateRandomSalt().toUtf8(), QCryptographicHash::Md5).toBase64().left(16);
} }

View File

@@ -6,7 +6,6 @@
class PasswordHasher class PasswordHasher
{ {
public: public:
static void initialize();
static QString computeHash(const QString &password, const QString &salt); static QString computeHash(const QString &password, const QString &salt);
static QString generateRandomSalt(const int len = 16); static QString generateRandomSalt(const int len = 16);
static QString generateActivationToken(); static QString generateActivationToken();

View File

@@ -50,9 +50,9 @@ void Server_ProtocolHandler::prepareDestroy()
return; return;
deleted = true; deleted = true;
QMapIterator<int, Server_Room *> roomIterator(rooms); for (auto *room : rooms.values()) {
while (roomIterator.hasNext()) room->removeClient(this);
roomIterator.next().value()->removeClient(this); }
QMap<int, QPair<int, int>> tempGames(getGames()); QMap<int, QPair<int, int>> tempGames(getGames());
@@ -61,27 +61,27 @@ void Server_ProtocolHandler::prepareDestroy()
while (gameIterator.hasNext()) { while (gameIterator.hasNext()) {
gameIterator.next(); gameIterator.next();
Server_Room *r = server->getRooms().value(gameIterator.value().first); Server_Room *room = server->getRooms().value(gameIterator.value().first);
if (!r) if (!room)
continue; continue;
r->gamesLock.lockForRead(); room->gamesLock.lockForRead();
Server_Game *g = r->getGames().value(gameIterator.key()); Server_Game *game = room->getGames().value(gameIterator.key());
if (!g) { if (!game) {
r->gamesLock.unlock(); room->gamesLock.unlock();
continue; continue;
} }
g->gameMutex.lock(); game->gameMutex.lock();
Server_Player *p = g->getPlayers().value(gameIterator.value().second); Server_Player *p = game->getPlayers().value(gameIterator.value().second);
if (!p) { if (!p) {
g->gameMutex.unlock(); game->gameMutex.unlock();
r->gamesLock.unlock(); room->gamesLock.unlock();
continue; continue;
} }
p->disconnectClient(); p->disconnectClient();
g->gameMutex.unlock(); game->gameMutex.unlock();
r->gamesLock.unlock(); room->gamesLock.unlock();
} }
server->roomsLock.unlock(); server->roomsLock.unlock();
@@ -671,24 +671,24 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoo
return Response::RespContextError; return Response::RespContextError;
QReadLocker serverLocker(&server->roomsLock); QReadLocker serverLocker(&server->roomsLock);
Server_Room *r = server->getRooms().value(cmd.room_id(), 0); Server_Room *room = server->getRooms().value(cmd.room_id(), 0);
if (!r) if (!room)
return Response::RespNameNotFound; return Response::RespNameNotFound;
if (!(userInfo->user_level() & ServerInfo_User::IsModerator)) if (!(userInfo->user_level() & ServerInfo_User::IsModerator))
if (!(r->userMayJoin(*userInfo))) if (!(room->userMayJoin(*userInfo)))
return Response::RespUserLevelTooLow; return Response::RespUserLevelTooLow;
r->addClient(this); room->addClient(this);
rooms.insert(r->getId(), r); rooms.insert(room->getId(), room);
Event_RoomSay joinMessageEvent; Event_RoomSay joinMessageEvent;
joinMessageEvent.set_message(r->getJoinMessage().toStdString()); joinMessageEvent.set_message(room->getJoinMessage().toStdString());
joinMessageEvent.set_message_type(Event_RoomSay::Welcome); joinMessageEvent.set_message_type(Event_RoomSay::Welcome);
rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, r->prepareRoomEvent(joinMessageEvent)); rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, room->prepareRoomEvent(joinMessageEvent));
QReadLocker chatHistoryLocker(&r->historyLock); QReadLocker chatHistoryLocker(&room->historyLock);
QList<ServerInfo_ChatMessage> chatHistory = r->getChatHistory(); QList<ServerInfo_ChatMessage> chatHistory = room->getChatHistory();
ServerInfo_ChatMessage chatMessage; ServerInfo_ChatMessage chatMessage;
for (int i = 0; i < chatHistory.size(); ++i) { for (int i = 0; i < chatHistory.size(); ++i) {
chatMessage = chatHistory.at(i); chatMessage = chatHistory.at(i);
@@ -697,11 +697,11 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoo
roomChatHistory.set_message_type(Event_RoomSay::ChatHistory); roomChatHistory.set_message_type(Event_RoomSay::ChatHistory);
roomChatHistory.set_time_of( roomChatHistory.set_time_of(
QDateTime::fromString(QString::fromStdString(chatMessage.time())).toMSecsSinceEpoch()); QDateTime::fromString(QString::fromStdString(chatMessage.time())).toMSecsSinceEpoch());
rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, r->prepareRoomEvent(roomChatHistory)); rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, room->prepareRoomEvent(roomChatHistory));
} }
Response_JoinRoom *re = new Response_JoinRoom; Response_JoinRoom *re = new Response_JoinRoom;
r->getInfo(*re->mutable_room_info(), true); room->getInfo(*re->mutable_room_info(), true);
rc.setResponseExtension(re); rc.setResponseExtension(re);
return Response::RespOk; return Response::RespOk;

View File

@@ -171,8 +171,6 @@ int main(int argc, char *argv[])
std::cerr << "Servatrice " << VERSION_STRING << " starting." << std::endl; std::cerr << "Servatrice " << VERSION_STRING << " starting." << std::endl;
std::cerr << "-------------------------" << std::endl; std::cerr << "-------------------------" << std::endl;
PasswordHasher::initialize();
if (testRandom) { if (testRandom) {
testRNG(); testRNG();
} }

View File

@@ -206,8 +206,9 @@ Servatrice::~Servatrice()
// clients live in other threads, we need to lock them // clients live in other threads, we need to lock them
clientsLock.lockForRead(); clientsLock.lockForRead();
for (auto client : clients) for (auto *client : clients) {
QMetaObject::invokeMethod(client, "prepareDestroy", Qt::QueuedConnection); QMetaObject::invokeMethod(client, "prepareDestroy", Qt::QueuedConnection);
}
clientsLock.unlock(); clientsLock.unlock();
// client destruction is asynchronous, wait for all clients to be gone // client destruction is asynchronous, wait for all clients to be gone

View File

@@ -893,8 +893,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdWarnUser(const Command_
delete se; delete se;
} }
QListIterator<QString> modIterator(moderatorList); for (QString &moderator : moderatorList) {
foreach (QString moderator, moderatorList) {
QString notificationMessage = sendingModerator + " has sent a warning with the following information"; QString notificationMessage = sendingModerator + " has sent a warning with the following information";
notificationMessage.append("\n Username: " + userName); notificationMessage.append("\n Username: " + userName);
notificationMessage.append("\n Reason: " + warningReason); notificationMessage.append("\n Reason: " + warningReason);
@@ -987,8 +986,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdBanFromServer(const Com
} }
} }
QListIterator<QString> modIterator(moderatorList); for (QString &moderator : moderatorList) {
foreach (QString moderator, moderatorList) {
QString notificationMessage = QString notificationMessage =
QString::fromStdString(userInfo->name()).simplified() + " has placed a ban with the following information"; QString::fromStdString(userInfo->name()).simplified() + " has placed a ban with the following information";
if (!userName.isEmpty()) if (!userName.isEmpty())