def get_player_in_seat(self, seat_id): from app.mtga_app import mtga_logger if self.hero.seat == seat_id: return self.hero elif self.opponent.seat == seat_id: return self.opponent else: mtga_logger.info("NOTHING TO RETURN OH NO")
def match_game_id_to_card(self, instance_id, card_id): from app.mtga_app import mtga_logger for card in self.cards: assert isinstance(card, GameCard) if card.game_id == instance_id or instance_id in card.previous_iids: # if card.mtga_id != -1 and card.mtga_id != card_id: # raise Exception("WHOA. tried to match iid {} to {}, but already has card {}".format(str(instance_id), str(card_id), str(card.mtga_id))) card.transform_to(card_id) elif card.mtga_id == card_id: # only allowed to set it if it's still -1 (should probably never hit this!) if card.game_id == -1: mtga_logger.info("What the hell?! How'd we get a card ID without an instance ID?") card.game_id = instance_id
def block_watch_task(in_queue, out_queue): while all_die_queue.empty(): block_recieved = in_queue.get() if block_recieved is None: out_queue.put(None) break log_line = None if isinstance(block_recieved, tuple): log_line, block_recieved = block_recieved if "[" not in block_recieved and "{" not in block_recieved: continue block_lines = block_recieved.split("\n") if len(block_lines) < 2: continue request_or_response = None json_str = "" # hit the ex timestamp = None block_title_seq = None if block_lines[1] and block_lines[1].startswith( "==>") or block_lines[1].startswith("<=="): """ these logs looks like: [UnityCrossThreadLogger]6/7/2018 7:21:03 PM ==> Log.Info(530): { "json": "stuff" } """ title_line = block_lines[1] block_title = " ".join(title_line.split(" ")[1:]).split("(")[0] block_title_seq = None if "(" in title_line and ")" in title_line: block_title_seq = title_line.split("(")[1].split(")")[ 0] # wtf is this thing? request_or_response = "response" if title_line.startswith("==>"): request_or_response = "request" json_str = "\n".join(block_lines[2:]).strip() if json_str.startswith("["): # this is not valid json, we need to surround it with a header such that it's an object instead of a list json_str = '{{"{}": {}}}'.format(block_title, json_str) elif block_lines[1].strip() == "{": """ these logs look like: [UnityCrossThreadLogger]6/7/2018 7:21:03 PM: Match to 26848417E29213FE: GreToClientEvent { "json": "stuff" } """ try: timestamp = dateutil.parser.parse( block_lines[0].split("]")[1].split(": ")[0]) except: pass block_title = block_lines[0].split(" ")[-1] json_str = "\n".join(block_lines[1:]) elif block_lines[0].strip().endswith("{"): """ these blocks looks like: [UnityCrossThreadLogger]7/2/2018 10:27:59 PM (-1) Incoming Rank.Updated { "json": "stuff } """ block_title = block_lines[0].strip().split(" ")[ -2] # skip trailing { json_str = "{" + "\n".join( block_lines[1:] ) # just cut the first line and manually add { back in if json_str: try: blob = json.loads(json_str) if log_line: blob["log_line"] = log_line if timestamp: blob["timestamp"] = timestamp mtga_logger.info( "{}success parsing blob: {}({}) / log_line {}".format( util.ld(), block_title, block_title_seq, log_line)) if request_or_response: blob["request_or_response"] = request_or_response if block_title: blob["block_title"] = block_title.strip() if block_title_seq: blob["block_title_sequence"] = block_title_seq out_queue.put(blob) except Exception as e: mtga_logger.error("{}Could not parse json_blob `{}`".format( util.ld(), json_str)) mtga_watch_app.send_error( "Could not parse json_blob {}".format(json_str))
def block_watch_task(in_queue, out_queue): BLOCK_SEQ = 0 while all_die_queue.empty(): block_recieved = in_queue.get() if block_recieved is None: out_queue.put(None) break log_line = None if isinstance(block_recieved, tuple): log_line, block_recieved = block_recieved if "[" not in block_recieved and "{" not in block_recieved: continue block_lines = block_recieved.split("\n") request_or_response = None json_str = "" # hit the ex timestamp = None block_title_seq = None if block_lines[0] and block_lines[0].startswith( "[UnityCrossThreadLogger]"): line = block_lines[0].split("[UnityCrossThreadLogger]")[1] if line.startswith("==>") or line.startswith("<=="): request_or_response = "response" if line.startswith("==>"): request_or_response = "request" line = line[4:] block_title = line.split(" ")[0] indexes = [] if "{" in line: indexes.append(line.index("{")) if "[" in line: indexes.append(line.index("[")) first_open_bracket = min(indexes) json_str = line[first_open_bracket:] elif len(block_lines) > 1: try: timestamp = dateutil.parser.parse( block_lines[0].split("]")[1].split(": ")[0]) except: pass block_title = block_lines[0].split(" ")[-1] json_str = "\n".join(block_lines[1:]) # I think everything below this is deprecated... elif block_lines[1] and block_lines[1].startswith( "==>") or block_lines[1].startswith("<=="): """ these logs looks like: [UnityCrossThreadLogger]6/7/2018 7:21:03 PM ==> Log.Info(530): { "json": "stuff" } """ title_line = block_lines[1] block_title = " ".join(title_line.split(" ")[1:]).split("(")[0] block_title_seq = None if "(" in title_line and ")" in title_line: block_title_seq = title_line.split("(")[1].split(")")[ 0] # wtf is this thing? request_or_response = "response" if title_line.startswith("==>"): request_or_response = "request" json_str = "\n".join(block_lines[2:]).strip() if json_str.startswith("["): # this is not valid json, we need to surround it with a header such that it's an object instead of a list json_str = '{{"{}": {}}}'.format(block_title, json_str) elif block_lines[1].strip() == "{": """ DEPRECATED these logs look like: [UnityCrossThreadLogger]6/7/2018 7:21:03 PM: Match to 26848417E29213FE: GreToClientEvent { "json": "stuff" } """ try: timestamp = dateutil.parser.parse( block_lines[0].split("]")[1].split(": ")[0]) except: pass block_title = block_lines[0].split(" ")[-1] json_str = "\n".join(block_lines[1:]) elif block_lines[1].strip().endswith("{"): """ these blocks looks like: [UnityCrossThreadLogger]7/2/2018 10:27:59 PM (-1) Incoming Rank.Updated { "json": "stuff } """ block_title = block_lines[1].strip().split(" ")[ -2] # skip trailing { json_str = "{" + "\n".join( block_lines[2:] ) # cut the first two lines and manually add { back in if json_str: try: blob = json.loads(json_str) BLOCK_SEQ += 1 # useful: next time you're trying to figure out why a blob isn't getting through the queue: # if "DirectGame" in json_str and "method" in blob: # import pprint # pprint.pprint(blob) if log_line: blob["log_line"] = log_line if timestamp: blob["timestamp"] = timestamp mtga_logger.info( "{}success parsing blob: {}({}) / log_line {}".format( util.ld(), block_title, block_title_seq, log_line)) if request_or_response: blob["request_or_response"] = request_or_response if block_title: blob["block_title"] = block_title.strip() blob["block_title_sequence"] = BLOCK_SEQ out_queue.put(blob) except Exception as e: mtga_logger.error("{}Could not parse json_blob `{}`".format( util.ld(), json_str)) mtga_watch_app.send_error( "Could not parse json_blob {}".format(json_str))
def block_watch_task(in_queue, out_queue): while all_die_queue.empty(): block_recieved = in_queue.get() if block_recieved is None: out_queue.put(None) break if "[" not in block_recieved and "{" not in block_recieved: continue block_lines = block_recieved.split("\n") if len(block_lines) < 2: continue request_or_response = None json_str = "" # hit the ex if block_lines[1] and block_lines[1].startswith( "==>") or block_lines[1].startswith("<=="): """ these logs looks like: [UnityCrossThreadLogger]6/7/2018 7:21:03 PM ==> Log.Info(530): { "json": "stuff" } """ title_line = block_lines[1] block_title = " ".join(title_line.split(" ")[1:]).split("(")[0] block_title_seq = None if "(" in title_line and ")" in title_line: block_title_seq = title_line.split("(")[1].split(")")[ 0] # wtf is this thing? request_or_response = "response" if title_line.startswith("==>"): request_or_response = "request" json_str = "\n".join(block_lines[2:]).strip() if json_str.startswith("["): # this is not valid json, we need to surround it with a header such that it's an object instead of a list json_str = '{{"{}": {}}}'.format(block_title, json_str) elif block_lines[1].strip() == "{": """ these logs look like: [UnityCrossThreadLogger]6/7/2018 7:21:03 PM: Match to 26848417E29213FE: GreToClientEvent { "json": "stuff" } """ block_title = block_lines[0].split(" ")[-1] json_str = "\n".join(block_lines[1:]) if json_str: try: blob = json.loads(json_str) mtga_logger.info("{}success parsing blob: {}({})".format( util.ld(), block_title, block_title_seq)) if request_or_response: blob["request_or_response"] = request_or_response if block_title: blob["block_title"] = block_title.strip() if block_title_seq: blob["block_title_sequence"] = block_title_seq out_queue.put(blob) except: mtga_logger.error("{}Could not parse json_blob `{}`".format( util.ld(), json_str)) mtga_watch_app.send_error( "Could not parse json_blob {}".format(json_str))