def parse_match_complete(blob): import app.mtga_app as mtga_app game_room_info = blob['matchGameRoomStateChangedEvent']['gameRoomInfo'] final_match_result = game_room_info['finalMatchResult'] result_list = final_match_result["resultList"] match_id = game_room_info['gameRoomConfig']['matchId'] for result in result_list: scope = result["scope"] if scope == 'MatchScope_Match': # TODO: with BO3, check games too. (might be in a different event type) winning_team = result["winningTeamId"] with mtga_app.mtga_watch_app.game_lock: mtga_app.mtga_watch_app.game.final = True mtga_app.mtga_watch_app.game.winner = mtga_app.mtga_watch_app.game.get_player_in_seat( winning_team) # let electron handle the upload game_state_change_queue.put({ "match_complete": True, "game": mtga_app.mtga_watch_app.game.to_json() }) if match_id != mtga_app.mtga_watch_app.game.match_id: fstr = "match_id {} ended, but doesn't match current game object ({})!" raise Exception( fstr.format(match_id, mtga_app.mtga_watch_app.game.match_id))
def parse_game_results(_unused_locked, match_id, result_list): import app.mtga_app as mtga_app for idx, result in enumerate(result_list): if not app.mtga_app.mtga_watch_app.match.has_results(idx): # scope = result["scope"] # if scope == 'MatchScope_Match': # TODO: with BO3, check games too. (might be in a different event type) winning_team = result["winningTeamId"] mtga_app.mtga_watch_app.game.final = True mtga_app.mtga_watch_app.game.winner = mtga_app.mtga_watch_app.game.get_player_in_seat( winning_team) # let electron handle the upload result = { "match_complete": True, "game": mtga_app.mtga_watch_app.game.to_json() } if "end" not in mtga_app.mtga_watch_app.game.recorded_targetspecs: mtga_app.mtga_watch_app.game.recorded_targetspecs.append("end") reason = None if "reason" in result.keys(): reason = result["reason"].split("_")[1] won_text = "{} won!".format( mtga_app.mtga_watch_app.game.winner.player_name) if reason: won_text += "({})".format(reason) event_text = build_event_text(won_text, "game") event_texts = [event_text] queue_obj = {"game_history_event": event_texts} mtga_app.mtga_watch_app.game.events.append( queue_obj["game_history_event"]) general_output_queue.put(queue_obj) app.mtga_app.mtga_watch_app.match.add_result(result) game_state_change_queue.put(result) if match_id != mtga_app.mtga_watch_app.game.match_id: fstr = "match_id {} ended, but doesn't match current game object ({})!" raise Exception( fstr.format(match_id, mtga_app.mtga_watch_app.game.match_id))
def parse_game_results(_unused_locked, match_id, result_list): import app.mtga_app as mtga_app for idx, result in enumerate(result_list): if not app.mtga_app.mtga_watch_app.match.has_results(idx): # scope = result["scope"] # if scope == 'MatchScope_Match': # TODO: with BO3, check games too. (might be in a different event type) winning_team = result["winningTeamId"] mtga_app.mtga_watch_app.game.final = True mtga_app.mtga_watch_app.game.winner = mtga_app.mtga_watch_app.game.get_player_in_seat(winning_team) # let electron handle the upload result = { "match_complete": True, "game": mtga_app.mtga_watch_app.game.to_json() } app.mtga_app.mtga_watch_app.match.add_result(result) game_state_change_queue.put(result) if match_id != mtga_app.mtga_watch_app.game.match_id: fstr = "match_id {} ended, but doesn't match current game object ({})!" raise Exception(fstr.format(match_id, mtga_app.mtga_watch_app.game.match_id))
def json_blob_reader_task(in_queue, out_queue): def check_for_client_id(blob): if "authenticateResponse" in blob: if "clientId" in blob["authenticateResponse"]: # screw it, no one else is going to use this message, mess up the timestamp, who cares with mtga_watch_app.game_lock: if mtga_watch_app.player_id != blob[ "authenticateResponse"]['clientId']: mtga_watch_app.player_id = blob[ "authenticateResponse"]['clientId'] mtga_logger.debug( "{}check_for_client_id: got new clientId".format( util.ld())) mtga_watch_app.save_settings() general_output_queue.put( {"authenticateResponse": blob["authenticateResponse"]}) last_blob = None last_decklist = None error_count = 0 while all_die_queue.empty(): json_recieved = in_queue.get() if json_recieved is None: out_queue.put(None) break if last_blob == json_recieved: continue # don't double fire # check for decklist changes if mtga_watch_app.player_decks != last_decklist: last_decklist = mtga_watch_app.player_decks decklist_change_queue.put({ k: v.to_serializable(transform_to_counted=True) for k, v in last_decklist.items() }) # check for gamestate changes try: hero_library_hash = -1 opponent_hand_hash = -1 if mtga_watch_app.game: hero_library_hash = hash(mtga_watch_app.game.hero.library) opponent_hand_hash = hash(mtga_watch_app.game.opponent.hand) check_for_client_id(json_recieved) dispatchers.dispatch_blob(json_recieved) mtga_watch_app.last_blob = json_recieved error_count = 0 hero_library_hash_post = -1 opponent_hand_hash_post = -1 if mtga_watch_app.game: hero_library_hash_post = hash(mtga_watch_app.game.hero.library) opponent_hand_hash_post = hash( mtga_watch_app.game.opponent.hand) if hero_library_hash != hero_library_hash_post or opponent_hand_hash != opponent_hand_hash_post: game_state_change_queue.put(mtga_watch_app.game.game_state( )) # TODO: BREAKPOINT HERE if mtga_watch_app.game.final: game_state_change_queue.put({ "match_complete": True, "gameID": mtga_watch_app.game.match_id }) except: import traceback exc = traceback.format_exc() stack = traceback.format_stack() mtga_logger.error("{}Exception @ count {}".format( util.ld(True), mtga_watch_app.error_count)) mtga_logger.error(exc) mtga_logger.error(stack) mtga_watch_app.send_error( "Exception during check game state. Check log for more details" ) if error_count > 5: mtga_logger.error("{}error count too high; exiting".format( util.ld())) return last_blob = json_recieved