Skip to content

Commit

Permalink
Merge pull request #298 from micheljung/feature/rehost
Browse files Browse the repository at this point in the history
Process 'Rehost'
  • Loading branch information
Sheeo committed Jun 1, 2016
2 parents e222b51 + c8088a7 commit f240082
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/client/_clientwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ def request_launch():
self.game_session.ready.connect(request_launch)
self.game_session.listen()

def host_game(self, title, mod, visibility, mapname, password):
def host_game(self, title, mod, visibility, mapname, password, is_rehost=False):
def request_launch():
msg = {
'command': 'game_host',
Expand All @@ -1227,12 +1227,14 @@ def request_launch():
'visibility': visibility,
'mapname': mapname,
'password': password,
'is_rehost': is_rehost
}
if self.connectivity.state == 'STUN':
msg['relay_address'] = self.connectivity.relay_address
self.send(msg)
self.game_session.ready.disconnect(request_launch)
if self.game_session:
self.game_session.game_password = password
self.game_session.ready.connect(request_launch)
self.game_session.listen()

Expand All @@ -1250,6 +1252,7 @@ def request_launch():
self.send(msg)
self.game_session.ready.disconnect(request_launch)
if self.game_session:
self.game_session.game_password = password
self.game_session.ready.connect(request_launch)
self.game_session.listen()

Expand Down Expand Up @@ -1308,6 +1311,8 @@ def handle_game_launch(self, message):

info = dict(uid=message['uid'], recorder=self.login, featured_mod=message['mod'], launched_at=time.time())

self.game_session.game_uid = message['uid']

fa.run(info, self.game_session.relay_port, arguments)

def handle_coop_info(self, message):
Expand All @@ -1320,6 +1325,12 @@ def handle_mod_info(self, message):
self.modInfo.emit(message)

def handle_game_info(self, message):
if message['uid'] == self.game_session.game_uid:
self.game_session.game_map = message['mapname']
self.game_session.game_mod = message['featured_mod']
self.game_session.game_name = message['title']
self.game_session.game_visibility = message['visibility']

if 'games' in message:
for game in message['games']:
self.gameInfo.emit(game)
Expand Down
26 changes: 26 additions & 0 deletions src/fa/game_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class GameSession(QObject):
def __init__(self, client, connectivity):
QObject.__init__(self)
self._state = GameSessionState.OFF
self._rehost = False
self.game_uid = None
self.game_name = None
self.game_mod = None
self.game_visibility = None
self.game_map = None
self.game_password = None

# Subscribe to messages targeted at 'game' from the server
client.subscribe_to('game', self)
Expand Down Expand Up @@ -147,6 +154,9 @@ def _on_game_message(self, command, args):
elif args[0] == 'Lobby':
# TODO: Eagerly initialize the game by hosting/joining early
pass
elif command == 'Rehost':
self._rehost = True

self.send(command, args)

def _turn_state_changed(self, val):
Expand All @@ -161,3 +171,19 @@ def _exited(self, status):
self.state = GameSessionState.OFF
self._logger.info("Game has exited with status code: {}".format(status))
self.send('GameState', ['Ended'])

if self._rehost:
self.client.host_game(title=self.game_name,
mod=self.game_mod,
visibility=self.game_visibility,
mapname=self.game_map,
password=self.game_password,
is_rehost=True)

self._rehost = False
self.game_uid = None
self.game_name = None
self.game_mod = None
self.game_visibility = None
self.game_map = None
self.game_password = None

0 comments on commit f240082

Please sign in to comment.