mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 12:54:10 -07:00
[Fix-Warnings] Local variable can be made const
This commit is contained in:
parent
8abd04dab1
commit
f2d3e81331
214 changed files with 1375 additions and 1355 deletions
|
|
@ -111,7 +111,7 @@ bool Server_AbstractParticipant::updatePingTime() // returns true if ping time c
|
|||
{
|
||||
QMutexLocker locker(&playerMutex);
|
||||
|
||||
int oldPingTime = pingTime;
|
||||
const int oldPingTime = pingTime;
|
||||
if (userInterface) {
|
||||
pingTime = userInterface->getLastCommandTime();
|
||||
} else {
|
||||
|
|
@ -232,7 +232,7 @@ Server_AbstractParticipant::cmdGameSay(const Command_GameSay &cmd, ResponseConta
|
|||
* (b) the spectator is a moderator/administrator
|
||||
* (c) the spectator is a judge
|
||||
*/
|
||||
bool isModOrJudge = (userInfo->user_level() & (ServerInfo_User::IsModerator | ServerInfo_User::IsJudge));
|
||||
const bool isModOrJudge = (userInfo->user_level() & (ServerInfo_User::IsModerator | ServerInfo_User::IsJudge));
|
||||
if (!isModOrJudge && !game->getSpectatorsCanTalk()) {
|
||||
return Response::RespFunctionNotAllowed;
|
||||
}
|
||||
|
|
@ -447,7 +447,7 @@ Response::ResponseCode Server_AbstractParticipant::cmdReverseTurn(const Command_
|
|||
}
|
||||
}
|
||||
|
||||
bool reversedTurn = game->reverseTurnOrder();
|
||||
const bool reversedTurn = game->reverseTurnOrder();
|
||||
|
||||
Event_ReverseTurn event;
|
||||
event.set_reversed(reversedTurn);
|
||||
|
|
@ -595,7 +595,7 @@ void Server_AbstractParticipant::setUserInterface(Server_AbstractUserInterface *
|
|||
|
||||
void Server_AbstractParticipant::disconnectClient()
|
||||
{
|
||||
bool isRegistered = userInfo->user_level() & ServerInfo_User::IsRegistered;
|
||||
const bool isRegistered = userInfo->user_level() & ServerInfo_User::IsRegistered;
|
||||
if (!isRegistered || spectator) {
|
||||
game->removeParticipant(this, Event_Leave::USER_DISCONNECTED);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ int Server_AbstractPlayer::newCardId()
|
|||
int Server_AbstractPlayer::newArrowId() const
|
||||
{
|
||||
int id = 0;
|
||||
for (Server_Arrow *a : arrows) {
|
||||
for (const Server_Arrow *a : arrows) {
|
||||
if (a->getId() > id) {
|
||||
id = a->getId();
|
||||
}
|
||||
|
|
@ -96,12 +96,12 @@ void Server_AbstractPlayer::setupZones()
|
|||
|
||||
void Server_AbstractPlayer::clearZones()
|
||||
{
|
||||
for (Server_CardZone *zone : zones) {
|
||||
for (const Server_CardZone *zone : zones) {
|
||||
delete zone;
|
||||
}
|
||||
zones.clear();
|
||||
|
||||
for (Server_Arrow *arrow : arrows) {
|
||||
for (const Server_Arrow *arrow : arrows) {
|
||||
delete arrow;
|
||||
}
|
||||
arrows.clear();
|
||||
|
|
@ -125,7 +125,7 @@ void Server_AbstractPlayer::updateArrowId(int id)
|
|||
|
||||
bool Server_AbstractPlayer::deleteArrow(int arrowId)
|
||||
{
|
||||
Server_Arrow *arrow = arrows.value(arrowId, 0);
|
||||
const Server_Arrow *arrow = arrows.value(arrowId, 0);
|
||||
if (!arrow) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -449,7 +449,7 @@ void Server_AbstractPlayer::onCardBeingMoved(GameEventStorage &ges,
|
|||
}
|
||||
|
||||
// set card pt
|
||||
QString ptString = QString::fromStdString(thisCardProperties->pt());
|
||||
const QString ptString = QString::fromStdString(thisCardProperties->pt());
|
||||
if (!ptString.isEmpty()) {
|
||||
setCardAttrHelper(ges, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), card->getId(), AttrPT,
|
||||
ptString);
|
||||
|
|
@ -726,7 +726,8 @@ Server_AbstractPlayer::cmdMoveCard(const Command_MoveCard &cmd, ResponseContaine
|
|||
return Response::RespContextError;
|
||||
}
|
||||
|
||||
Server_AbstractPlayer *startPlayer = game->getPlayer(cmd.has_start_player_id() ? cmd.start_player_id() : playerId);
|
||||
const Server_AbstractPlayer *startPlayer =
|
||||
game->getPlayer(cmd.has_start_player_id() ? cmd.start_player_id() : playerId);
|
||||
if (!startPlayer) {
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
|
@ -739,7 +740,7 @@ Server_AbstractPlayer::cmdMoveCard(const Command_MoveCard &cmd, ResponseContaine
|
|||
return Response::RespContextError;
|
||||
}
|
||||
|
||||
Server_AbstractPlayer *targetPlayer = game->getPlayer(cmd.target_player_id());
|
||||
const Server_AbstractPlayer *targetPlayer = game->getPlayer(cmd.target_player_id());
|
||||
if (!targetPlayer) {
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
|
@ -800,7 +801,7 @@ Server_AbstractPlayer::cmdFlipCard(const Command_FlipCard &cmd, ResponseContaine
|
|||
event.set_face_down(faceDown);
|
||||
ges.enqueueGameEvent(event, playerId);
|
||||
|
||||
QString ptString = nameFromStdString(cmd.pt());
|
||||
const QString ptString = nameFromStdString(cmd.pt());
|
||||
if (!ptString.isEmpty() && !faceDown) {
|
||||
setCardAttrHelper(ges, playerId, zone->getName(), card->getId(), AttrPT, ptString);
|
||||
}
|
||||
|
|
@ -870,13 +871,13 @@ Server_AbstractPlayer::cmdAttachCard(const Command_AttachCard &cmd, ResponseCont
|
|||
for (auto *player : game->getPlayers()) {
|
||||
QList<Server_Arrow *> _arrows = player->getArrows().values();
|
||||
QList<Server_Arrow *> toDelete;
|
||||
for (auto a : _arrows) {
|
||||
auto *tCard = qobject_cast<Server_Card *>(a->getTargetItem());
|
||||
for (const auto a : _arrows) {
|
||||
const auto *tCard = qobject_cast<Server_Card *>(a->getTargetItem());
|
||||
if ((tCard == card) || (a->getStartCard() == card)) {
|
||||
toDelete.append(a);
|
||||
}
|
||||
}
|
||||
for (auto &i : toDelete) {
|
||||
for (const auto &i : toDelete) {
|
||||
Event_DeleteArrow event;
|
||||
event.set_arrow_id(i->getId());
|
||||
ges.enqueueGameEvent(event, player->getPlayerId());
|
||||
|
|
@ -1136,10 +1137,10 @@ void Server_AbstractPlayer::sendCreateTokenEvents(Server_CardZone *zone,
|
|||
}
|
||||
|
||||
// Token is face-down. We have to send different info to each player
|
||||
auto eventOthers = makeCreateTokenEvent(zone, card, xCoord, yCoord, false);
|
||||
const auto eventOthers = makeCreateTokenEvent(zone, card, xCoord, yCoord, false);
|
||||
ges.enqueueGameEvent(eventOthers, playerId, GameEventStorageItem::SendToOthers);
|
||||
|
||||
auto eventPrivate = makeCreateTokenEvent(zone, card, xCoord, yCoord, true);
|
||||
const auto eventPrivate = makeCreateTokenEvent(zone, card, xCoord, yCoord, true);
|
||||
ges.enqueueGameEvent(eventPrivate, playerId, GameEventStorageItem::SendToPrivate, playerId);
|
||||
|
||||
// Event_CreateToken didn't use to have face_down field; send attribute event afterward for backwards compatibility
|
||||
|
|
@ -1161,14 +1162,14 @@ Server_AbstractPlayer::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseCo
|
|||
return Response::RespContextError;
|
||||
}
|
||||
|
||||
Server_AbstractPlayer *startPlayer = game->getPlayer(cmd.start_player_id());
|
||||
const Server_AbstractPlayer *startPlayer = game->getPlayer(cmd.start_player_id());
|
||||
Server_AbstractPlayer *targetPlayer = game->getPlayer(cmd.target_player_id());
|
||||
if (!startPlayer || !targetPlayer) {
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
QString startZoneName = nameFromStdString(cmd.start_zone());
|
||||
const QString startZoneName = nameFromStdString(cmd.start_zone());
|
||||
Server_CardZone *startZone = startPlayer->getZones().value(startZoneName);
|
||||
bool playerTarget = !cmd.has_target_zone();
|
||||
const bool playerTarget = !cmd.has_target_zone();
|
||||
Server_CardZone *targetZone = nullptr;
|
||||
if (!playerTarget) {
|
||||
targetZone = targetPlayer->getZones().value(nameFromStdString(cmd.target_zone()));
|
||||
|
|
@ -1207,9 +1208,10 @@ Server_AbstractPlayer::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseCo
|
|||
}
|
||||
}
|
||||
|
||||
int currentPhase = game->getActivePhase();
|
||||
int deletionPhase = cmd.has_delete_in_phase() ? cmd.delete_in_phase() : currentPhase;
|
||||
auto arrow = new Server_Arrow(newArrowId(), startCard, targetItem, cmd.arrow_color(), currentPhase, deletionPhase);
|
||||
const int currentPhase = game->getActivePhase();
|
||||
const int deletionPhase = cmd.has_delete_in_phase() ? cmd.delete_in_phase() : currentPhase;
|
||||
const auto arrow =
|
||||
new Server_Arrow(newArrowId(), startCard, targetItem, cmd.arrow_color(), currentPhase, deletionPhase);
|
||||
addArrow(arrow);
|
||||
|
||||
Event_CreateArrow event;
|
||||
|
|
@ -1321,7 +1323,7 @@ Response::ResponseCode Server_AbstractPlayer::cmdIncCardCounter(const Command_In
|
|||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
||||
int newValue = card->getCounter(cmd.counter_id()) + cmd.counter_delta();
|
||||
const int newValue = card->getCounter(cmd.counter_id()) + cmd.counter_delta();
|
||||
card->setCounter(cmd.counter_id(), newValue);
|
||||
|
||||
Event_SetCardCounter event;
|
||||
|
|
@ -1341,7 +1343,7 @@ Server_AbstractPlayer::cmdDumpZone(const Command_DumpZone &cmd, ResponseContaine
|
|||
return Response::RespGameNotStarted;
|
||||
}
|
||||
|
||||
Server_AbstractPlayer *otherPlayer = game->getPlayer(cmd.player_id());
|
||||
const Server_AbstractPlayer *otherPlayer = game->getPlayer(cmd.player_id());
|
||||
if (!otherPlayer) {
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
|
@ -1353,7 +1355,7 @@ Server_AbstractPlayer::cmdDumpZone(const Command_DumpZone &cmd, ResponseContaine
|
|||
return Response::RespContextError;
|
||||
}
|
||||
|
||||
int numberCards = cmd.number_cards();
|
||||
const int numberCards = cmd.number_cards();
|
||||
const QList<Server_Card *> &cards = zone->getCards();
|
||||
|
||||
auto *re = new Response_DumpZone;
|
||||
|
|
@ -1365,7 +1367,7 @@ Server_AbstractPlayer::cmdDumpZone(const Command_DumpZone &cmd, ResponseContaine
|
|||
|
||||
for (int i = 0; (i < cards.size()) && (i < numberCards || numberCards == -1); ++i) {
|
||||
const auto &findId = cmd.is_reversed() ? cards.size() - numberCards + i : i;
|
||||
Server_Card *card = cards[findId];
|
||||
const Server_Card *card = cards[findId];
|
||||
QString displayedName = card->getFaceDown() ? QString() : card->getName();
|
||||
ServerInfo_Card *cardInfo = zoneInfo->add_card_list();
|
||||
cardInfo->set_provider_id(card->getProviderId().toStdString());
|
||||
|
|
@ -1554,9 +1556,9 @@ Response::ResponseCode Server_AbstractPlayer::cmdChangeZoneProperties(const Comm
|
|||
}
|
||||
|
||||
// Neither value changed -> error.
|
||||
bool alwaysRevealChanged =
|
||||
const bool alwaysRevealChanged =
|
||||
cmd.has_always_reveal_top_card() && zone->getAlwaysRevealTopCard() != cmd.always_reveal_top_card();
|
||||
bool alwaysLookAtTopChanged =
|
||||
const bool alwaysLookAtTopChanged =
|
||||
cmd.has_always_look_at_top_card() && zone->getAlwaysLookAtTopCard() != cmd.always_look_at_top_card();
|
||||
if (!alwaysRevealChanged && !alwaysLookAtTopChanged) {
|
||||
return Response::RespContextError;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ int Server_CardZone::removeCard(Server_Card *card)
|
|||
|
||||
int Server_CardZone::removeCard(Server_Card *card, bool &wasLookedAt)
|
||||
{
|
||||
int index = cards.indexOf(card);
|
||||
const int index = cards.indexOf(card);
|
||||
wasLookedAt = isCardAtPosLookedAt(index);
|
||||
if (wasLookedAt && cardsBeingLookedAt > 0) {
|
||||
cardsBeingLookedAt -= 1;
|
||||
|
|
@ -251,7 +251,7 @@ void Server_CardZone::fixFreeSpaces(GameEventStorage &ges)
|
|||
return;
|
||||
|
||||
QSet<QPair<int, int>> placesToLook;
|
||||
for (auto &card : cards)
|
||||
for (const auto &card : cards)
|
||||
placesToLook.insert(QPair<int, int>((card->getX() / 3) * 3, card->getY()));
|
||||
|
||||
QSetIterator<QPair<int, int>> placeIterator(placesToLook);
|
||||
|
|
@ -303,7 +303,7 @@ void Server_CardZone::insertCard(Server_Card *card, int x, int y)
|
|||
|
||||
void Server_CardZone::clear()
|
||||
{
|
||||
for (auto card : cards)
|
||||
for (const auto card : cards)
|
||||
delete card;
|
||||
cards.clear();
|
||||
coordinateMap.clear();
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ int Server_Player::newCounterId() const
|
|||
int id = 0;
|
||||
QMapIterator<int, Server_Counter *> i(counters);
|
||||
while (i.hasNext()) {
|
||||
Server_Counter *c = i.next().value();
|
||||
const Server_Counter *c = i.next().value();
|
||||
if (c->getId() > id) {
|
||||
id = c->getId();
|
||||
}
|
||||
|
|
@ -141,9 +141,9 @@ void Server_Player::setupZones()
|
|||
// ------------------------------------------------------------------
|
||||
|
||||
// Assign card ids and create deck from deck list
|
||||
InnerDecklistNode *listRoot = deck->getRoot();
|
||||
const InnerDecklistNode *listRoot = deck->getRoot();
|
||||
for (int i = 0; i < listRoot->size(); ++i) {
|
||||
auto *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
const auto *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
Server_CardZone *z;
|
||||
if (currentZone->getName() == DECK_ZONE_MAIN) {
|
||||
z = deckZone;
|
||||
|
|
@ -154,7 +154,7 @@ void Server_Player::setupZones()
|
|||
}
|
||||
|
||||
for (int j = 0; j < currentZone->size(); ++j) {
|
||||
auto *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
const auto *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
if (!currentCard) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ void Server_Player::setupZones()
|
|||
void Server_Player::clearZones()
|
||||
{
|
||||
Server_AbstractPlayer::clearZones();
|
||||
for (Server_Counter *counter : counters) {
|
||||
for (const Server_Counter *counter : counters) {
|
||||
delete counter;
|
||||
}
|
||||
counters.clear();
|
||||
|
|
@ -241,7 +241,7 @@ Response::ResponseCode Server_Player::drawCards(GameEventStorage &ges, int numbe
|
|||
|
||||
if (number > 0) {
|
||||
revealTopCardIfNeeded(deckZone, ges);
|
||||
int currentKnownCards = deckZone->getCardsBeingLookedAt();
|
||||
const int currentKnownCards = deckZone->getCardsBeingLookedAt();
|
||||
deckZone->setCardsBeingLookedAt(currentKnownCards - number);
|
||||
}
|
||||
|
||||
|
|
@ -256,13 +256,13 @@ void Server_Player::onCardBeingMoved(GameEventStorage &ges,
|
|||
{
|
||||
Server_AbstractPlayer::onCardBeingMoved(ges, cardStruct, startzone, targetzone, undoingDraw);
|
||||
|
||||
Server_Card *card = cardStruct.card;
|
||||
const Server_Card *card = cardStruct.card;
|
||||
|
||||
// "Undo draw" should only remain valid if the just-drawn card stays within the user's hand (e.g., they only
|
||||
// reorder their hand). If a just-drawn card leaves the hand then remove cards before it from the list
|
||||
// (Ignore the case where the card is currently being un-drawn.)
|
||||
if (startzone->getName() == "hand" && targetzone->getName() != "hand" && !undoingDraw) {
|
||||
int index = lastDrawList.lastIndexOf(card->getId());
|
||||
const int index = lastDrawList.lastIndexOf(card->getId());
|
||||
if (index != -1) {
|
||||
lastDrawList.erase(lastDrawList.begin(), lastDrawList.begin() + index);
|
||||
}
|
||||
|
|
@ -410,7 +410,7 @@ Server_Player::cmdMulligan(const Command_Mulligan &cmd, ResponseContainer & /*rc
|
|||
|
||||
Server_CardZone *hand = zones.value("hand");
|
||||
Server_CardZone *_deck = zones.value("deck");
|
||||
int number = cmd.number();
|
||||
const int number = cmd.number();
|
||||
|
||||
if (!hand->getCards().isEmpty()) {
|
||||
auto cardsToMove = QList<const CardToMove *>();
|
||||
|
|
@ -558,7 +558,7 @@ Server_Player::cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &
|
|||
return Response::RespContextError;
|
||||
}
|
||||
|
||||
Server_Counter *counter = counters.value(cmd.counter_id(), 0);
|
||||
const Server_Counter *counter = counters.value(cmd.counter_id(), 0);
|
||||
if (!counter) {
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
|
@ -614,7 +614,7 @@ Response::ResponseCode Server_Player::cmdChangeZoneProperties(const Command_Chan
|
|||
ResponseContainer &rc,
|
||||
GameEventStorage &ges)
|
||||
{
|
||||
auto ret = Server_AbstractPlayer::cmdChangeZoneProperties(cmd, rc, ges);
|
||||
const auto ret = Server_AbstractPlayer::cmdChangeZoneProperties(cmd, rc, ges);
|
||||
|
||||
Server_CardZone *zone = zones.value(nameFromStdString(cmd.zone_name()));
|
||||
if (!zone) {
|
||||
|
|
|
|||
|
|
@ -98,8 +98,8 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session,
|
|||
|
||||
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
|
||||
|
||||
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, clientid, reasonStr,
|
||||
secondsLeft, passwordNeedsHash);
|
||||
const AuthenticationResult authState = databaseInterface->checkUserPassword(
|
||||
session, name, password, clientid, reasonStr, secondsLeft, passwordNeedsHash);
|
||||
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid ||
|
||||
authState == UserIsInactive)
|
||||
return authState;
|
||||
|
|
@ -117,7 +117,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session,
|
|||
event.set_reason_str("You have been logged out due to logging in at another location.");
|
||||
event.set_end_time(QDateTime::currentDateTime().toSecsSinceEpoch());
|
||||
|
||||
SessionEvent *se = users.value(name)->prepareSessionEvent(event);
|
||||
const SessionEvent *se = users.value(name)->prepareSessionEvent(event);
|
||||
users.value(name)->sendProtocolItem(*se);
|
||||
delete se;
|
||||
|
||||
|
|
@ -163,8 +163,8 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session,
|
|||
|
||||
Event_UserJoined event;
|
||||
event.mutable_user_info()->CopyFrom(session->copyUserInfo(false));
|
||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
for (auto &client : clients)
|
||||
const SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
for (const auto &client : clients)
|
||||
if (client->getAcceptsUserListChanges())
|
||||
client->sendProtocolItem(*se);
|
||||
delete se;
|
||||
|
|
@ -227,7 +227,7 @@ void Server::addClient(Server_ProtocolHandler *client)
|
|||
|
||||
void Server::removeClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
int clientIndex = clients.indexOf(client);
|
||||
const int clientIndex = clients.indexOf(client);
|
||||
if (clientIndex == -1) {
|
||||
qWarning() << "tried to remove non existing client";
|
||||
return;
|
||||
|
|
@ -241,12 +241,12 @@ void Server::removeClient(Server_ProtocolHandler *client)
|
|||
|
||||
QWriteLocker locker(&clientsLock);
|
||||
clients.removeAt(clientIndex);
|
||||
ServerInfo_User *data = client->getUserInfo();
|
||||
const ServerInfo_User *data = client->getUserInfo();
|
||||
if (data) {
|
||||
Event_UserLeft event;
|
||||
event.set_name(data->name());
|
||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
for (auto &_client : clients)
|
||||
const SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
for (const auto &_client : clients)
|
||||
if (_client->getAcceptsUserListChanges())
|
||||
_client->sendProtocolItem(*se);
|
||||
sendIsl_SessionEvent(*se);
|
||||
|
|
@ -271,7 +271,7 @@ QList<QString> Server::getOnlineModeratorList() const
|
|||
// clients list should be locked by calling function prior to iteration otherwise sigfaults may occur
|
||||
QList<QString> results;
|
||||
for (auto &client : clients) {
|
||||
ServerInfo_User *data = client->getUserInfo();
|
||||
const ServerInfo_User *data = client->getUserInfo();
|
||||
|
||||
// TODO: this line should be updated in the event there is any type of new user level created
|
||||
if (data &&
|
||||
|
|
@ -293,8 +293,8 @@ void Server::externalUserJoined(const ServerInfo_User &userInfo)
|
|||
Event_UserJoined event;
|
||||
event.mutable_user_info()->CopyFrom(userInfo);
|
||||
|
||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
for (auto &client : clients)
|
||||
const SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
for (const auto &client : clients)
|
||||
if (client->getAcceptsUserListChanges())
|
||||
client->sendProtocolItem(*se);
|
||||
delete se;
|
||||
|
|
@ -310,21 +310,21 @@ void Server::externalUserLeft(const QString &userName)
|
|||
// This function is always called from the main thread via signal/slot.
|
||||
|
||||
clientsLock.lockForWrite();
|
||||
Server_AbstractUserInterface *user = externalUsers.take(userName);
|
||||
const Server_AbstractUserInterface *user = externalUsers.take(userName);
|
||||
externalUsersBySessionId.remove(user->getUserInfo()->session_id());
|
||||
clientsLock.unlock();
|
||||
|
||||
QMap<int, QPair<int, int>> userGames(user->getGames());
|
||||
const QMap<int, QPair<int, int>> userGames(user->getGames());
|
||||
QMapIterator<int, QPair<int, int>> userGamesIterator(userGames);
|
||||
roomsLock.lockForRead();
|
||||
while (userGamesIterator.hasNext()) {
|
||||
userGamesIterator.next();
|
||||
Server_Room *room = rooms.value(userGamesIterator.value().first);
|
||||
const Server_Room *room = rooms.value(userGamesIterator.value().first);
|
||||
if (!room)
|
||||
continue;
|
||||
|
||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||
Server_Game *game = room->getGames().value(userGamesIterator.key());
|
||||
const Server_Game *game = room->getGames().value(userGamesIterator.key());
|
||||
if (!game)
|
||||
continue;
|
||||
|
||||
|
|
@ -342,9 +342,9 @@ void Server::externalUserLeft(const QString &userName)
|
|||
Event_UserLeft event;
|
||||
event.set_name(userName.toStdString());
|
||||
|
||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
const SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
clientsLock.lockForRead();
|
||||
for (auto &client : clients)
|
||||
for (const auto &client : clients)
|
||||
if (client->getAcceptsUserListChanges())
|
||||
client->sendProtocolItem(*se);
|
||||
clientsLock.unlock();
|
||||
|
|
@ -443,7 +443,7 @@ void Server::externalJoinGameCommandReceived(const Command_JoinGame &cmd,
|
|||
}
|
||||
|
||||
ResponseContainer responseContainer(cmdId);
|
||||
Response::ResponseCode responseCode = room->processJoinGameCommand(cmd, responseContainer, userInterface);
|
||||
const Response::ResponseCode responseCode = room->processJoinGameCommand(cmd, responseContainer, userInterface);
|
||||
userInterface->sendResponseContainer(responseContainer, responseCode);
|
||||
} catch (Response::ResponseCode &code) {
|
||||
Response response;
|
||||
|
|
@ -466,7 +466,7 @@ void Server::externalGameCommandContainerReceived(const CommandContainer &cont,
|
|||
Response::ResponseCode finalResponseCode = Response::RespOk;
|
||||
|
||||
QReadLocker roomsLocker(&roomsLock);
|
||||
Server_Room *room = rooms.value(cont.room_id());
|
||||
const Server_Room *room = rooms.value(cont.room_id());
|
||||
if (!room) {
|
||||
qDebug() << "externalGameCommandContainerReceived: room id=" << cont.room_id() << "not found";
|
||||
throw Response::RespNotInRoom;
|
||||
|
|
@ -491,7 +491,7 @@ void Server::externalGameCommandContainerReceived(const CommandContainer &cont,
|
|||
const GameCommand &sc = cont.game_command(i);
|
||||
qDebug() << "[ISL]" << getSafeDebugString(sc);
|
||||
|
||||
Response::ResponseCode resp = participant->processGameCommand(sc, responseContainer, ges);
|
||||
const Response::ResponseCode resp = participant->processGameCommand(sc, responseContainer, ges);
|
||||
|
||||
if (resp != Response::RespOk)
|
||||
finalResponseCode = resp;
|
||||
|
|
@ -545,10 +545,10 @@ void Server::broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl
|
|||
Event_ListRooms event;
|
||||
event.add_room_list()->CopyFrom(roomInfo);
|
||||
|
||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
const SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
|
||||
clientsLock.lockForRead();
|
||||
for (auto &client : clients)
|
||||
for (const auto &client : clients)
|
||||
if (client->getAcceptsRoomListChanges())
|
||||
client->sendProtocolItem(*se);
|
||||
clientsLock.unlock();
|
||||
|
|
@ -581,7 +581,7 @@ int Server::getGamesCount() const
|
|||
QReadLocker locker(&roomsLock);
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext()) {
|
||||
Server_Room *room = roomIterator.next().value();
|
||||
const Server_Room *room = roomIterator.next().value();
|
||||
QReadLocker roomLocker(&room->gamesLock);
|
||||
result += room->getGames().size();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void Server_AbstractUserInterface::sendResponseContainer(const ResponseContainer
|
|||
Response response;
|
||||
response.set_cmd_id(responseContainer.getCmdId());
|
||||
response.set_response_code(responseCode);
|
||||
::google::protobuf::Message *responseExtension = responseContainer.getResponseExtension();
|
||||
const ::google::protobuf::Message *responseExtension = responseContainer.getResponseExtension();
|
||||
if (responseExtension)
|
||||
response.GetReflection()
|
||||
->MutableMessage(&response, responseExtension->GetDescriptor()->FindExtensionByName("ext"))
|
||||
|
|
@ -86,14 +86,14 @@ void Server_AbstractUserInterface::playerAddedToGame(int gameId, int roomId, int
|
|||
|
||||
void Server_AbstractUserInterface::joinPersistentGames(ResponseContainer &rc)
|
||||
{
|
||||
QList<PlayerReference> gamesToJoin =
|
||||
const QList<PlayerReference> gamesToJoin =
|
||||
server->getPersistentPlayerReferences(QString::fromStdString(userInfo->name()));
|
||||
|
||||
server->roomsLock.lockForRead();
|
||||
for (int i = 0; i < gamesToJoin.size(); ++i) {
|
||||
const PlayerReference &pr = gamesToJoin.at(i);
|
||||
|
||||
Server_Room *room = server->getRooms().value(pr.getRoomId());
|
||||
const Server_Room *room = server->getRooms().value(pr.getRoomId());
|
||||
if (!room)
|
||||
continue;
|
||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue