From f372ce7ea2387a0f21a59ab1998cd9a7aba4ec72 Mon Sep 17 00:00:00 2001 From: GrotheFAF Date: Sun, 31 Dec 2017 05:52:36 +0100 Subject: [PATCH] fix #944 click user game announcement link if game has ended click on player live game announcement when game had ended, let to fa starting with error message. Now it will give a message about game ended, with an option to search users replays in Vault click on host/join game announcent when the game has already started, now will gives a message with an option to watch the live game --- src/chat/channel.py | 36 +++++++++++++++++++++++++++++++----- src/fa/replay.py | 2 +- src/model/game.py | 3 ++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/chat/channel.py b/src/chat/channel.py index 1566fe4ae..8e37964b1 100644 --- a/src/chat/channel.py +++ b/src/chat/channel.py @@ -1,5 +1,5 @@ from fa.replay import replay - +from model.game import GameState import util from PyQt5 import QtWidgets, QtCore, QtGui import time @@ -206,10 +206,36 @@ def pingWindow(self): @QtCore.pyqtSlot(QtCore.QUrl) def openUrl(self, url): logger.debug("Clicked on URL: " + url.toString()) - if url.scheme() == "faflive": - replay(url) - elif url.scheme() == "fafgame": - self.chat_widget.client.joinGameFromURL(url) + if url.scheme() == "faflive" or url.scheme() == "fafgame": + replay_id = int(QtCore.QUrlQuery(url).queryItemValue("uid")) + if replay_id in self.chat_widget.client.gameset: + game = self.chat_widget.client.gameset[replay_id] + if game.state == GameState.OPEN: # and url.scheme() == "fafgame" + self.chat_widget.client.joinGameFromURL(url) + elif game.state == GameState.PLAYING: + if game.has_live_replay: + if url.scheme() == "faflive" or QtWidgets.QMessageBox.question( + QtWidgets.QApplication.activeWindow(), "Live Game started", + "Would you like to join and watch the live game?", + QtWidgets.QMessageBox.Yes, + QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes: + replay(game.url(game.host_player.id)) + else: + QtWidgets.QMessageBox.information( + QtWidgets.QApplication.activeWindow(), "Live Game started", + "But ... it is to early to join (5 minute delay)\n" + "(Wait for the user/player status cross to turn silver)") + elif url.scheme() == "faflive" and QtWidgets.QMessageBox.question( + QtWidgets.QApplication.activeWindow(), "Live Game ended", + "Would you like to look for it in Replays?", + QtWidgets.QMessageBox.Yes, + QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes: + player = QtCore.QUrlQuery(url).queryItemValue("player") + self.chat_widget.client.searchUserReplays(player) + elif url.scheme() == "fafgame": + QtWidgets.QMessageBox.information( + QtWidgets.QApplication.activeWindow(), "Game ended", + "Host has abandoned game or the game already ended") else: QtGui.QDesktopServices.openUrl(url) diff --git a/src/fa/replay.py b/src/fa/replay.py index e87c1c811..937634792 100644 --- a/src/fa/replay.py +++ b/src/fa/replay.py @@ -87,7 +87,7 @@ def replay(source, detach=False): if url.scheme() == "faflive": mod = QtCore.QUrlQuery(url).queryItemValue("mod") mapname = QtCore.QUrlQuery(url).queryItemValue("map") - replay_id = url.path().split("/")[0] + replay_id = QtCore.QUrlQuery(url).queryItemValue("uid") # whip the URL into shape so ForgedAllianceForever.exe understands it arg_url = QtCore.QUrl(url) arg_url.setScheme("gpgnet") diff --git a/src/model/game.py b/src/model/game.py index 7b068daa2..5afae339c 100644 --- a/src/model/game.py +++ b/src/model/game.py @@ -231,11 +231,12 @@ def url(self, player_id): query = QUrlQuery() query.addQueryItem("map", self.mapname) query.addQueryItem("mod", self.featured_mod) + query.addQueryItem("uid", str(self.uid)) + query.addQueryItem("player", str(self._playerset[player_id].login)) if self.state == GameState.OPEN: url.setScheme("fafgame") url.setPath("/" + str(player_id)) - query.addQueryItem("uid", str(self.uid)) else: url.setScheme("faflive") url.setPath("/" + str(self.uid) + "/" + str(player_id) + ".SCFAreplay")