mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
[Server][Game][Arrows] Properly notify clients when deleting arrows on card move and transform into (#6936)
* [Server][Game][Arrows] Properly notify clients when deleting arrows on card move and transform into Took 15 minutes * Observe "not found" response Took 18 minutes Took 4 seconds --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
98c00c55ed
commit
90ab663212
4 changed files with 33 additions and 8 deletions
|
|
@ -217,7 +217,20 @@ void GameEventHandler::handleArrowDeletion(int arrowId)
|
||||||
{
|
{
|
||||||
Command_DeleteArrow cmd;
|
Command_DeleteArrow cmd;
|
||||||
cmd.set_arrow_id(arrowId);
|
cmd.set_arrow_id(arrowId);
|
||||||
sendGameCommand(cmd);
|
|
||||||
|
auto preparedCommand = prepareGameCommand(cmd);
|
||||||
|
|
||||||
|
connect(preparedCommand, &PendingCommand::finished, this,
|
||||||
|
[arrowId, this](const Response &response) { handleArrowDeletionFinished(response, arrowId); });
|
||||||
|
|
||||||
|
sendGameCommand(preparedCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameEventHandler::handleArrowDeletionFinished(const Response &response, int arrowId)
|
||||||
|
{
|
||||||
|
if (response.response_code() == Response::RespNameNotFound) {
|
||||||
|
emit arrowDeleted(arrowId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventSpectatorSay(const Event_GameSay &event,
|
void GameEventHandler::eventSpectatorSay(const Event_GameSay &event,
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ public:
|
||||||
void handleGameLeft();
|
void handleGameLeft();
|
||||||
void handleChatMessageSent(const QString &chatMessage);
|
void handleChatMessageSent(const QString &chatMessage);
|
||||||
void handleArrowDeletion(int arrowId);
|
void handleArrowDeletion(int arrowId);
|
||||||
|
void handleArrowDeletionFinished(const Response &response, int arrowId);
|
||||||
|
|
||||||
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
|
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
|
||||||
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
|
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
|
||||||
|
|
@ -112,6 +113,7 @@ signals:
|
||||||
void containerProcessingStarted(GameEventContext context);
|
void containerProcessingStarted(GameEventContext context);
|
||||||
void setContextJudgeName(QString judgeName);
|
void setContextJudgeName(QString judgeName);
|
||||||
void containerProcessingDone();
|
void containerProcessingDone();
|
||||||
|
void arrowDeleted(int arrowId);
|
||||||
void logSpectatorSay(ServerInfo_User userInfo, QString message);
|
void logSpectatorSay(ServerInfo_User userInfo, QString message);
|
||||||
void logSpectatorLeave(QString name, QString reason);
|
void logSpectatorLeave(QString name, QString reason);
|
||||||
void logGameStart();
|
void logGameStart();
|
||||||
|
|
|
||||||
|
|
@ -1147,6 +1147,7 @@ void TabGame::createPlayAreaWidget(bool bReplay)
|
||||||
connect(game->getPlayerManager(), &PlayerManager::playerCountChanged, scene, &GameScene::rearrange);
|
connect(game->getPlayerManager(), &PlayerManager::playerCountChanged, scene, &GameScene::rearrange);
|
||||||
connect(scene, &GameScene::requestArrowDeletion, game->getGameEventHandler(),
|
connect(scene, &GameScene::requestArrowDeletion, game->getGameEventHandler(),
|
||||||
&GameEventHandler::handleArrowDeletion);
|
&GameEventHandler::handleArrowDeletion);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::arrowDeleted, scene, &GameScene::onArrowDeleted);
|
||||||
gameView = new GameView(scene);
|
gameView = new GameView(scene);
|
||||||
|
|
||||||
auto gamePlayAreaVBox = new QVBoxLayout;
|
auto gamePlayAreaVBox = new QVBoxLayout;
|
||||||
|
|
|
||||||
|
|
@ -397,6 +397,9 @@ void Server_AbstractPlayer::processMoveCard(GameEventStorage &ges,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int j : arrowsToDelete) {
|
for (int j : arrowsToDelete) {
|
||||||
|
Event_DeleteArrow event;
|
||||||
|
event.set_arrow_id(j);
|
||||||
|
ges.enqueueGameEvent(event, player->getPlayerId());
|
||||||
player->deleteArrow(j);
|
player->deleteArrow(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1132,12 +1135,18 @@ Server_AbstractPlayer::cmdCreateToken(const Command_CreateToken &cmd, ResponseCo
|
||||||
targetItem = card;
|
targetItem = card;
|
||||||
}
|
}
|
||||||
if (sendGameEvent) {
|
if (sendGameEvent) {
|
||||||
Event_CreateArrow _event;
|
const int oldId = arrow->getId();
|
||||||
ServerInfo_Arrow *arrowInfo = _event.mutable_arrow_info();
|
changedArrowIds.append(oldId);
|
||||||
changedArrowIds.append(arrow->getId());
|
|
||||||
int id = player->newArrowId();
|
Event_DeleteArrow deleteEvent;
|
||||||
arrow->setId(id);
|
deleteEvent.set_arrow_id(oldId);
|
||||||
arrowInfo->set_id(id);
|
ges.enqueueGameEvent(deleteEvent, player->getPlayerId());
|
||||||
|
|
||||||
|
Event_CreateArrow createEvent;
|
||||||
|
ServerInfo_Arrow *arrowInfo = createEvent.mutable_arrow_info();
|
||||||
|
const int newId = player->newArrowId();
|
||||||
|
arrow->setId(newId);
|
||||||
|
arrowInfo->set_id(newId);
|
||||||
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());
|
||||||
|
|
@ -1151,7 +1160,7 @@ Server_AbstractPlayer::cmdCreateToken(const Command_CreateToken &cmd, ResponseCo
|
||||||
arrowInfo->set_target_card_id(arrowTargetCard->getId());
|
arrowInfo->set_target_card_id(arrowTargetCard->getId());
|
||||||
}
|
}
|
||||||
arrowInfo->mutable_arrow_color()->CopyFrom(arrow->getColor());
|
arrowInfo->mutable_arrow_color()->CopyFrom(arrow->getColor());
|
||||||
ges.enqueueGameEvent(_event, player->getPlayerId());
|
ges.enqueueGameEvent(createEvent, player->getPlayerId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int id : changedArrowIds) {
|
for (int id : changedArrowIds) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue