assign new arrow id when arrow is moved to transformed card (#5012)
* add timeout to settingscache * assign new arrow id when arrow is moved to transformed card fixes bug introduced in #4907 fixes #5008
This commit is contained in:
parent
e8c7fba8b0
commit
f174614496
7 changed files with 30 additions and 11 deletions
|
@ -32,6 +32,7 @@ RemoteClient::RemoteClient(QObject *parent)
|
|||
{
|
||||
|
||||
clearNewClientFeatures();
|
||||
maxTimeout = SettingsCache::instance().getTimeOut();
|
||||
int keepalive = SettingsCache::instance().getKeepAlive();
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(keepalive * 1000);
|
||||
|
|
|
@ -89,7 +89,7 @@ private slots:
|
|||
void submitForgotPasswordChallengeResponse(const Response &response);
|
||||
|
||||
private:
|
||||
static const int maxTimeout = 5;
|
||||
int maxTimeout;
|
||||
int timeRunning, lastDataReceived;
|
||||
QByteArray inputBuffer;
|
||||
bool messageInProgress;
|
||||
|
|
|
@ -195,6 +195,7 @@ SettingsCache::SettingsCache()
|
|||
|
||||
lang = settings->value("personal/lang").toString();
|
||||
keepalive = settings->value("personal/keepalive", 3).toInt();
|
||||
timeout = settings->value("personal/timeout", 5).toInt();
|
||||
|
||||
// tip of the day settings
|
||||
showTipsOnStartup = settings->value("tipOfDay/showTips", true).toBool();
|
||||
|
|
|
@ -134,6 +134,7 @@ private:
|
|||
bool spectatorsCanSeeEverything;
|
||||
bool createGameAsSpectator;
|
||||
int keepalive;
|
||||
int timeout;
|
||||
void translateLegacySettings();
|
||||
QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
||||
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
||||
|
@ -434,6 +435,10 @@ public:
|
|||
{
|
||||
return keepalive;
|
||||
}
|
||||
int getTimeOut() const
|
||||
{
|
||||
return timeout;
|
||||
}
|
||||
int getMaxFontSize() const
|
||||
{
|
||||
return maxFontSize;
|
||||
|
|
|
@ -21,6 +21,10 @@ public:
|
|||
{
|
||||
return id;
|
||||
}
|
||||
void setId(int _id)
|
||||
{
|
||||
id = _id;
|
||||
}
|
||||
Server_Card *getStartCard() const
|
||||
{
|
||||
return startCard;
|
||||
|
|
|
@ -296,6 +296,12 @@ void Server_Player::addArrow(Server_Arrow *arrow)
|
|||
arrows.insert(arrow->getId(), arrow);
|
||||
}
|
||||
|
||||
void Server_Player::updateArrowId(int id)
|
||||
{
|
||||
auto *arrow = arrows.take(id);
|
||||
arrows.insert(arrow->getId(), arrow);
|
||||
}
|
||||
|
||||
bool Server_Player::deleteArrow(int arrowId)
|
||||
{
|
||||
Server_Arrow *arrow = arrows.value(arrowId, 0);
|
||||
|
@ -497,9 +503,7 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges,
|
|||
const QList<Server_Player *> &players = game->getPlayers().values();
|
||||
for (auto player : players) {
|
||||
QList<int> arrowsToDelete;
|
||||
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
|
||||
while (arrowIterator.hasNext()) {
|
||||
Server_Arrow *arrow = arrowIterator.next().value();
|
||||
for (Server_Arrow *arrow : player->getArrows()) {
|
||||
if ((arrow->getStartCard() == card) || (arrow->getTargetItem() == card))
|
||||
arrowsToDelete.append(arrow->getId());
|
||||
}
|
||||
|
@ -1478,9 +1482,8 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
|||
// Copy Arrows
|
||||
const QList<Server_Player *> &players = game->getPlayers().values();
|
||||
for (auto player : players) {
|
||||
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
|
||||
while (arrowIterator.hasNext()) {
|
||||
Server_Arrow *arrow = arrowIterator.next().value();
|
||||
QList<int> changedArrowIds;
|
||||
for (Server_Arrow *arrow : player->getArrows()) {
|
||||
bool sendGameEvent = false;
|
||||
const auto *startCard = arrow->getStartCard();
|
||||
if (startCard == targetCard) {
|
||||
|
@ -1497,7 +1500,10 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
|||
if (sendGameEvent) {
|
||||
Event_CreateArrow _event;
|
||||
ServerInfo_Arrow *arrowInfo = _event.mutable_arrow_info();
|
||||
arrowInfo->set_id(arrow->getId());
|
||||
changedArrowIds.append(arrow->getId());
|
||||
int id = player->newArrowId();
|
||||
arrow->setId(id);
|
||||
arrowInfo->set_id(id);
|
||||
arrowInfo->set_start_player_id(player->getPlayerId());
|
||||
arrowInfo->set_start_zone(startCard->getZone()->getName().toStdString());
|
||||
arrowInfo->set_start_card_id(startCard->getId());
|
||||
|
@ -1514,6 +1520,9 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
|||
ges.enqueueGameEvent(_event, player->getPlayerId());
|
||||
}
|
||||
}
|
||||
for (int id : changedArrowIds) {
|
||||
player->updateArrowId(id);
|
||||
}
|
||||
}
|
||||
|
||||
targetCard->resetState();
|
||||
|
@ -1579,9 +1588,7 @@ Server_Player::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer
|
|||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
||||
QMapIterator<int, Server_Arrow *> arrowIterator(arrows);
|
||||
while (arrowIterator.hasNext()) {
|
||||
Server_Arrow *temp = arrowIterator.next().value();
|
||||
for (Server_Arrow *temp : arrows) {
|
||||
if ((temp->getStartCard() == startCard) && (temp->getTargetItem() == targetItem)) {
|
||||
return Response::RespContextError;
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ public:
|
|||
|
||||
void addZone(Server_CardZone *zone);
|
||||
void addArrow(Server_Arrow *arrow);
|
||||
void updateArrowId(int id);
|
||||
bool deleteArrow(int arrowId);
|
||||
void addCounter(Server_Counter *counter);
|
||||
|
||||
|
|
Loading…
Reference in a new issue