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();
|
clearNewClientFeatures();
|
||||||
|
maxTimeout = SettingsCache::instance().getTimeOut();
|
||||||
int keepalive = SettingsCache::instance().getKeepAlive();
|
int keepalive = SettingsCache::instance().getKeepAlive();
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
timer->setInterval(keepalive * 1000);
|
timer->setInterval(keepalive * 1000);
|
||||||
|
|
|
@ -89,7 +89,7 @@ private slots:
|
||||||
void submitForgotPasswordChallengeResponse(const Response &response);
|
void submitForgotPasswordChallengeResponse(const Response &response);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int maxTimeout = 5;
|
int maxTimeout;
|
||||||
int timeRunning, lastDataReceived;
|
int timeRunning, lastDataReceived;
|
||||||
QByteArray inputBuffer;
|
QByteArray inputBuffer;
|
||||||
bool messageInProgress;
|
bool messageInProgress;
|
||||||
|
|
|
@ -195,6 +195,7 @@ SettingsCache::SettingsCache()
|
||||||
|
|
||||||
lang = settings->value("personal/lang").toString();
|
lang = settings->value("personal/lang").toString();
|
||||||
keepalive = settings->value("personal/keepalive", 3).toInt();
|
keepalive = settings->value("personal/keepalive", 3).toInt();
|
||||||
|
timeout = settings->value("personal/timeout", 5).toInt();
|
||||||
|
|
||||||
// tip of the day settings
|
// tip of the day settings
|
||||||
showTipsOnStartup = settings->value("tipOfDay/showTips", true).toBool();
|
showTipsOnStartup = settings->value("tipOfDay/showTips", true).toBool();
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
bool spectatorsCanSeeEverything;
|
bool spectatorsCanSeeEverything;
|
||||||
bool createGameAsSpectator;
|
bool createGameAsSpectator;
|
||||||
int keepalive;
|
int keepalive;
|
||||||
|
int timeout;
|
||||||
void translateLegacySettings();
|
void translateLegacySettings();
|
||||||
QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
||||||
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
||||||
|
@ -434,6 +435,10 @@ public:
|
||||||
{
|
{
|
||||||
return keepalive;
|
return keepalive;
|
||||||
}
|
}
|
||||||
|
int getTimeOut() const
|
||||||
|
{
|
||||||
|
return timeout;
|
||||||
|
}
|
||||||
int getMaxFontSize() const
|
int getMaxFontSize() const
|
||||||
{
|
{
|
||||||
return maxFontSize;
|
return maxFontSize;
|
||||||
|
|
|
@ -21,6 +21,10 @@ public:
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
void setId(int _id)
|
||||||
|
{
|
||||||
|
id = _id;
|
||||||
|
}
|
||||||
Server_Card *getStartCard() const
|
Server_Card *getStartCard() const
|
||||||
{
|
{
|
||||||
return startCard;
|
return startCard;
|
||||||
|
|
|
@ -296,6 +296,12 @@ void Server_Player::addArrow(Server_Arrow *arrow)
|
||||||
arrows.insert(arrow->getId(), 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)
|
bool Server_Player::deleteArrow(int arrowId)
|
||||||
{
|
{
|
||||||
Server_Arrow *arrow = arrows.value(arrowId, 0);
|
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();
|
const QList<Server_Player *> &players = game->getPlayers().values();
|
||||||
for (auto player : players) {
|
for (auto player : players) {
|
||||||
QList<int> arrowsToDelete;
|
QList<int> arrowsToDelete;
|
||||||
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
|
for (Server_Arrow *arrow : player->getArrows()) {
|
||||||
while (arrowIterator.hasNext()) {
|
|
||||||
Server_Arrow *arrow = arrowIterator.next().value();
|
|
||||||
if ((arrow->getStartCard() == card) || (arrow->getTargetItem() == card))
|
if ((arrow->getStartCard() == card) || (arrow->getTargetItem() == card))
|
||||||
arrowsToDelete.append(arrow->getId());
|
arrowsToDelete.append(arrow->getId());
|
||||||
}
|
}
|
||||||
|
@ -1478,9 +1482,8 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
||||||
// Copy Arrows
|
// Copy Arrows
|
||||||
const QList<Server_Player *> &players = game->getPlayers().values();
|
const QList<Server_Player *> &players = game->getPlayers().values();
|
||||||
for (auto player : players) {
|
for (auto player : players) {
|
||||||
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
|
QList<int> changedArrowIds;
|
||||||
while (arrowIterator.hasNext()) {
|
for (Server_Arrow *arrow : player->getArrows()) {
|
||||||
Server_Arrow *arrow = arrowIterator.next().value();
|
|
||||||
bool sendGameEvent = false;
|
bool sendGameEvent = false;
|
||||||
const auto *startCard = arrow->getStartCard();
|
const auto *startCard = arrow->getStartCard();
|
||||||
if (startCard == targetCard) {
|
if (startCard == targetCard) {
|
||||||
|
@ -1497,7 +1500,10 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
||||||
if (sendGameEvent) {
|
if (sendGameEvent) {
|
||||||
Event_CreateArrow _event;
|
Event_CreateArrow _event;
|
||||||
ServerInfo_Arrow *arrowInfo = _event.mutable_arrow_info();
|
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_player_id(player->getPlayerId());
|
||||||
arrowInfo->set_start_zone(startCard->getZone()->getName().toStdString());
|
arrowInfo->set_start_zone(startCard->getZone()->getName().toStdString());
|
||||||
arrowInfo->set_start_card_id(startCard->getId());
|
arrowInfo->set_start_card_id(startCard->getId());
|
||||||
|
@ -1514,6 +1520,9 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
||||||
ges.enqueueGameEvent(_event, player->getPlayerId());
|
ges.enqueueGameEvent(_event, player->getPlayerId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (int id : changedArrowIds) {
|
||||||
|
player->updateArrowId(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
targetCard->resetState();
|
targetCard->resetState();
|
||||||
|
@ -1579,9 +1588,7 @@ Server_Player::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer
|
||||||
return Response::RespNameNotFound;
|
return Response::RespNameNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMapIterator<int, Server_Arrow *> arrowIterator(arrows);
|
for (Server_Arrow *temp : arrows) {
|
||||||
while (arrowIterator.hasNext()) {
|
|
||||||
Server_Arrow *temp = arrowIterator.next().value();
|
|
||||||
if ((temp->getStartCard() == startCard) && (temp->getTargetItem() == targetItem)) {
|
if ((temp->getStartCard() == startCard) && (temp->getTargetItem() == targetItem)) {
|
||||||
return Response::RespContextError;
|
return Response::RespContextError;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@ public:
|
||||||
|
|
||||||
void addZone(Server_CardZone *zone);
|
void addZone(Server_CardZone *zone);
|
||||||
void addArrow(Server_Arrow *arrow);
|
void addArrow(Server_Arrow *arrow);
|
||||||
|
void updateArrowId(int id);
|
||||||
bool deleteArrow(int arrowId);
|
bool deleteArrow(int arrowId);
|
||||||
void addCounter(Server_Counter *counter);
|
void addCounter(Server_Counter *counter);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue