From e76502cf0edb030f05c0e6bec78ee843520d4107 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 1 May 2012 21:16:16 +0200 Subject: [PATCH] handle dead commands when the connection is lost before the reply gets processed --- cockatrice/src/remoteclient.cpp | 8 +++++++- cockatrice/src/tab_deck_storage.cpp | 9 +++++++++ cockatrice/src/tab_replays.cpp | 6 ++++++ common/pb/response.proto | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index 91b9d17a..640e84a7 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -166,8 +166,14 @@ void RemoteClient::doDisconnectFromServer() messageLength = 0; QList pc = pendingCommands.values(); - for (int i = 0; i < pc.size(); i++) + for (int i = 0; i < pc.size(); i++) { + Response response; + response.set_response_code(Response::RespNotConnected); + response.set_cmd_id(pc[i]->getCommandContainer().cmd_id()); + pc[i]->processResponse(response); + delete pc[i]; + } pendingCommands.clear(); setStatus(StatusDisconnected); diff --git a/cockatrice/src/tab_deck_storage.cpp b/cockatrice/src/tab_deck_storage.cpp index 724d1940..b98d17d9 100644 --- a/cockatrice/src/tab_deck_storage.cpp +++ b/cockatrice/src/tab_deck_storage.cpp @@ -177,6 +177,9 @@ void TabDeckStorage::actUpload() void TabDeckStorage::uploadFinished(const Response &r, const CommandContainer &commandContainer) { + if (r.response_code() != Response::RespOk) + return; + const Response_DeckUpload &resp = r.GetExtension(Response_DeckUpload::ext); const Command_DeckUpload &cmd = commandContainer.session_command(0).GetExtension(Command_DeckUpload::ext); @@ -208,6 +211,9 @@ void TabDeckStorage::actOpenRemoteDeck() void TabDeckStorage::openRemoteDeckFinished(const Response &r) { + if (r.response_code() != Response::RespOk) + return; + const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext); // WndDeckEditor *deckEditor = new WndDeckEditor; @@ -243,6 +249,9 @@ void TabDeckStorage::actDownload() void TabDeckStorage::downloadFinished(const Response &r, const CommandContainer &/*commandContainer*/, const QVariant &extraData) { + if (r.response_code() != Response::RespOk) + return; + const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext); QString filePath = extraData.toString(); diff --git a/cockatrice/src/tab_replays.cpp b/cockatrice/src/tab_replays.cpp index 5119d50b..c7c44f5a 100644 --- a/cockatrice/src/tab_replays.cpp +++ b/cockatrice/src/tab_replays.cpp @@ -162,6 +162,9 @@ void TabReplays::actOpenRemoteReplay() void TabReplays::openRemoteReplayFinished(const Response &r) { + if (r.response_code() != Response::RespOk) + return; + const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext); GameReplay *replay = new GameReplay; replay->ParseFromString(resp.replay_data()); @@ -197,6 +200,9 @@ void TabReplays::actDownload() void TabReplays::downloadFinished(const Response &r, const CommandContainer &commandContainer, const QVariant &extraData) { + if (r.response_code() != Response::RespOk) + return; + const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext); QString filePath = extraData.toString(); diff --git a/common/pb/response.proto b/common/pb/response.proto index 18541963..7e1431fa 100644 --- a/common/pb/response.proto +++ b/common/pb/response.proto @@ -1,5 +1,6 @@ message Response { enum ResponseCode { + RespNotConnected = -1; RespNothing = 0; RespOk = 1; RespNotInRoom = 2;