Skip to content

Commit

Permalink
fix #944 click user game announcement link if game has ended
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GrotheFAF committed Jan 2, 2018
1 parent b1b600a commit f372ce7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
36 changes: 31 additions & 5 deletions src/chat/channel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fa.replay import replay

from model.game import GameState
import util
from PyQt5 import QtWidgets, QtCore, QtGui
import time
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/fa/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/model/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f372ce7

Please sign in to comment.