def blink():
    global source_name
    global visible

    source = obs.obs_get_source_by_name(source_name)
    if source is not None:
        visible = not visible
        obs.obs_source_set_enabled(source, visible)
Пример #2
0
def blur(pred):
    # Switches blur on if probability is high
    source = obs.obs_get_source_by_name(stgs.source)
    blured = obs.obs_source_enabled(source)
    if blured and pred <= stgs.pred_threshold:
        obs.obs_source_set_enabled(source, False)
    if not blured and pred > stgs.pred_threshold:
        obs.obs_source_set_enabled(source, True)
    obs.obs_source_release(source)
def reset_relics(props, prop):
    """Sets faction of all relics in overlay to NS by disabling overlays for other factions"""

    global previous_relic_status, previous_wg_status, previous_connected_status

    for name in relic_source_names:  # Iterate through and disable relic overlay sources
        source = obs.obs_get_source_by_name(name)
        if source is not None:
            obs.obs_source_set_enabled(source, False)
        obs.obs_source_release(
            source)  # Release sources to prevent memory leak

    for name in warpgate_names:  # Iterate through and disable warpgate overlay sources
        for fxn in ['_VS', '_NC', '_TR']:
            nm = warpgate_names[name] + fxn
            source = obs.obs_get_source_by_name(nm)
            if source is not None:
                obs.obs_source_set_enabled(source, False)
            obs.obs_source_release(
                source)  # Release sources to prevent memory leak

    for name in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                 'I']:  # Iterate through and disable cutoff overlay sources
        nm = name + '_cutoff'
        source = obs.obs_get_source_by_name(nm)
        if source is not None:
            obs.obs_source_set_enabled(source, False)
        obs.obs_source_release(
            source)  # Release sources to prevent memory leak

    previous_relic_status = {
        'A': 0,
        'B': 0,
        'C': 0,
        'D': 0,
        'E': 0,
        'F': 0,
        'G': 0,
        'H': 0,
        'I': 0
    }
    previous_wg_status = {'N_WG': 0, 'SE_WG': 0, 'SW_WG': 0}
    previous_connected_status = {
        'A': True,
        'B': True,
        'C': True,
        'D': True,
        'E': True,
        'F': True,
        'G': True,
        'H': True,
        'I': True
    }
def update_territory_data(match: OWMatch):
    """Sends web request to Census API and updates status of territories based on response."""

    global service_id, world, target_zone, previous_relic_status, previous_wg_status, previous_connected_status, \
        first_time

    if not first_time:
        for relic in match.relics:  # Get previous state of relics prior to update
            try:
                previous_relic_status[relic.letter] = relic.current_faction
            except KeyError:
                print(
                    f'[{datetime.datetime.now()}][TRACKER] ERROR: Failed to set relic letter due to KeyError, Line 196.'
                )

        url = f'https://census.daybreakgames.com/s:{service_id}/get/ps2:v2/map/?world_id={world}&zone_ids={target_zone}'

        print(f'[{datetime.datetime.now()}][WEB REQUEST] Querying API...'
              )  # Get new relic data from API
        try:
            response = requests.get(url)
            if response.status_code == 200:  # Success
                print(f'[{datetime.datetime.now()}][WEB REQUEST] 200 OK')
            elif response.status_code == 429:  # Rate limit
                print(
                    f'[{datetime.datetime.now()}][WEB REQUEST] ERROR 429: TOO MANY REQUESTS! Stopping tracker. Slow down update rate and try again.'
                )
            elif response.status_code in status_codes:  # Specific error
                print(
                    f'[{datetime.datetime.now()}][WEB REQUEST] ERROR {response.status_code}: {status_codes[response.status_code]}'
                )
            else:  # Generic error
                print(
                    f'[{datetime.datetime.now()}][WEB REQUEST] UNEXPECTED RESPONSE: {response.status_code}'
                )

            try:
                payload = json.loads(response.text)  # Load json payload
                try:
                    territory_list = payload['map_list'][0]['Regions']['Row']
                    for territory in territory_list:
                        region_id = int(territory['RowData']['RegionId'])
                        faction_id = int(territory['RowData']['FactionId'])
                        for relic in match.relics:  # Update faction IDs of relics
                            if relic.region_id == region_id:
                                relic.current_faction = faction_id
                                break

                        if (match.warpgate_vs
                                == None) or (match.warpgate_nc
                                             == None) or (match.warpgate_tr
                                                          == None):
                            for warpgate_id in warpgate_names:  # Update warpgate IDs
                                if warpgate_id == region_id:
                                    if faction_id == 1:
                                        match.warpgate_vs = warpgate_names.get(
                                            warpgate_id, None)
                                    elif faction_id == 2:
                                        match.warpgate_nc = warpgate_names.get(
                                            warpgate_id, None)
                                    elif faction_id == 3:
                                        match.warpgate_tr = warpgate_names.get(
                                            warpgate_id, None)
                except KeyError:
                    print(
                        f'[{datetime.datetime.now()}][WEB REQUEST] ERROR: Failed to parse json data from response. Printing response.'
                    )
                    print(response.text)
            except Exception as e:
                print(
                    f'[{datetime.datetime.now()}][WEB REQUEST] ERROR: Failed to load json data from response. Printing response.'
                )
                print(f'[{datetime.datetime.now()}][WEB REQUEST]',
                      response.text)

            match.validate_relic_lattice_connections()
            print(
                f'[{datetime.datetime.now()}][TRACKER] Successfully validated facility lattice connections.'
            )

            for relic in match.relics:  # Change relic factions on UI
                for prev_status in previous_relic_status.keys():
                    if prev_status == relic.letter:  # Find letter of relic in recorded list
                        if previous_relic_status[
                                prev_status] != relic.current_faction:
                            print(
                                f'[{datetime.datetime.now()}][TRACKER] Detected territory change in Relic '
                                + relic.letter)
                            prev_source_names = []
                            source_name_current = None
                            current_letter = relic.letter

                            if current_letter is not None:
                                if relic.current_faction == 1:
                                    source_name_current = current_letter + '_VS'
                                    prev_source_names = [
                                        current_letter + '_NC',
                                        current_letter + '_TR'
                                    ]
                                elif relic.current_faction == 2:
                                    source_name_current = current_letter + '_NC'
                                    prev_source_names = [
                                        current_letter + '_VS',
                                        current_letter + '_TR'
                                    ]
                                elif relic.current_faction == 3:
                                    source_name_current = current_letter + '_TR'
                                    prev_source_names = [
                                        current_letter + '_NC',
                                        current_letter + '_VS'
                                    ]
                                elif relic.current_faction == 0 or relic.current_faction == 4:
                                    source_name_current = None
                                    prev_source_names = [
                                        current_letter + '_VS',
                                        current_letter + '_NC',
                                        current_letter + '_TR'
                                    ]

                            if len(prev_source_names) > 0:
                                for source_name_prev in prev_source_names:
                                    prev_source = obs.obs_get_source_by_name(
                                        source_name_prev)
                                    if prev_source is not None:
                                        obs.obs_source_set_enabled(
                                            prev_source, False)
                                    obs.obs_source_release(prev_source)

                            if source_name_current is not None:
                                current_source = obs.obs_get_source_by_name(
                                    source_name_current)
                                if current_source is not None:
                                    obs.obs_source_set_enabled(
                                        current_source, True)
                                obs.obs_source_release(current_source)

                            previous_relic_status[
                                prev_status] = relic.current_faction
                            # update this relic
                        break

            for relic in match.relics:  # Change relic cutoff status on UI
                if relic.connected != previous_connected_status[
                        relic.letter]:  # Change in cutoff status
                    source_name_current = None
                    current_letter = relic.letter
                    if current_letter is not None:
                        source_name_current = current_letter + '_cutoff'
                    if relic.connected:
                        if current_letter is not None:
                            current_source = obs.obs_get_source_by_name(
                                source_name_current)
                            if current_source is not None:
                                obs.obs_source_set_enabled(
                                    current_source, False)
                            obs.obs_source_release(current_source)
                    else:
                        if current_letter is not None:
                            current_source = obs.obs_get_source_by_name(
                                source_name_current)
                            if current_source is not None:
                                obs.obs_source_set_enabled(
                                    current_source, True)
                            obs.obs_source_release(current_source)
                    previous_connected_status[relic.letter] = relic.connected

            for wg in warpgate_names:  # Change warpgate factions on UI
                source_name_current = None
                source_name_others = None
                if match.warpgate_vs is not None:
                    if warpgate_names[wg] == match.warpgate_vs:
                        if previous_wg_status[match.warpgate_vs] != 1:
                            source_name_current = match.warpgate_vs + '_VS'
                            source_name_others = [
                                match.warpgate_vs + '_NC',
                                match.warpgate_vs + '_TR'
                            ]
                            if source_name_others is not None:
                                for source_name_otr in source_name_others:
                                    prev_source = obs.obs_get_source_by_name(
                                        source_name_otr)
                                    if prev_source is not None:
                                        obs.obs_source_set_enabled(
                                            prev_source, False)
                                    obs.obs_source_release(prev_source)
                            if source_name_current is not None:
                                current_source = obs.obs_get_source_by_name(
                                    source_name_current)
                                if current_source is not None:
                                    obs.obs_source_set_enabled(
                                        current_source, True)
                                obs.obs_source_release(current_source)
                            previous_wg_status[match.warpgate_vs] = 1
                if match.warpgate_nc is not None:
                    if warpgate_names[wg] == match.warpgate_nc:
                        if previous_wg_status[match.warpgate_nc] != 2:
                            source_name_current = match.warpgate_nc + '_NC'
                            source_name_others = [
                                match.warpgate_nc + '_VS',
                                match.warpgate_nc + '_TR'
                            ]
                            if source_name_others is not None:
                                for source_name_otr in source_name_others:
                                    prev_source = obs.obs_get_source_by_name(
                                        source_name_otr)
                                    if prev_source is not None:
                                        obs.obs_source_set_enabled(
                                            prev_source, False)
                                    obs.obs_source_release(prev_source)
                            if source_name_current is not None:
                                current_source = obs.obs_get_source_by_name(
                                    source_name_current)
                                if current_source is not None:
                                    obs.obs_source_set_enabled(
                                        current_source, True)
                                obs.obs_source_release(current_source)
                            previous_wg_status[match.warpgate_nc] = 2
                if match.warpgate_tr is not None:
                    if warpgate_names[wg] == match.warpgate_tr:
                        if previous_wg_status[match.warpgate_tr] != 3:
                            source_name_current = match.warpgate_tr + '_TR'
                            source_name_others = [
                                match.warpgate_tr + '_VS',
                                match.warpgate_tr + '_NC'
                            ]
                            if source_name_others is not None:
                                for source_name_otr in source_name_others:
                                    prev_source = obs.obs_get_source_by_name(
                                        source_name_otr)
                                    if prev_source is not None:
                                        obs.obs_source_set_enabled(
                                            prev_source, False)
                                    obs.obs_source_release(prev_source)
                            if source_name_current is not None:
                                current_source = obs.obs_get_source_by_name(
                                    source_name_current)
                                if current_source is not None:
                                    obs.obs_source_set_enabled(
                                        current_source, True)
                                obs.obs_source_release(current_source)
                            previous_wg_status[match.warpgate_tr] = 3

            print(
                f'[{datetime.datetime.now()}][TRACKER] Successfully updated relic sources.'
            )
        except Exception as conn_err:
            print(f'[{datetime.datetime.now()}][WEB REQUEST] Error:',
                  conn_err.__class__.__name__)
    first_time = False
Пример #5
0
def disable_button(properties, button):
    source = obs.obs_get_source_by_name(stgs.source)
    enabled = obs.obs_source_enabled(source)
    if enabled:
        obs.obs_source_set_enabled(source, False)
    obs.obs_source_release(source)
Пример #6
0
 def disable_layer(self):
     with source_ar(self.layer_source_name) as source:
         obs.obs_source_set_enabled(source, False)
Пример #7
0
 def enable_layer(self):
     with source_ar(self.layer_source_name) as source:
         obs.obs_source_set_enabled(source, True)
Пример #8
0
def start():

    print(c_ipA)
    print(c_port)

    # Open Port?
    """
	#open Port
	if (c_port != ""):
		cmd = 'netsh advfirewall firewall add rule name= \"Open Port ' + str(c_port) + '\" dir=in action=allow protocol=TCP localport='+str(c_port)
		#os.system('cmd /k ' + cmd)
		subprocess.call(['runas', '/user:Administrator', cmd])	
	else:
		#cmd = "echo Hello"#"netsh advfirewall firewall add rule name= \"Open Port \" dir=in action=allow protocol=TCP localport=80"
		#os.system('cmd /k ' + cmd)
		pass
	"""
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.settimeout(5)
        if c_ipA != "" and c_port != "":
            print("Connecting with custom ip adress and port...")
            s.bind((c_ipA, int(c_port)))
        elif c_ipA == "" and c_port != "":
            print("Connecting with custom port...")
            s.bind((getIP(), int(c_port)))
        elif c_ipA != "" and c_port == "":
            print("Connecting with custom ip adress...")
            s.bind((c_ipA, PORT))
        else:
            print("Connecting with default values...")
            s.bind(ADDR)
        s.listen()
        print("Server Started...")

        global runServer
        global stopServer
        while runServer:
            print("Server Running...")
            try:
                conn, addr = s.accept()
                conn.settimeout(5)
                with conn:
                    print("connected by", addr)
                    connected = True
                    while connected:
                        try:
                            msg = conn.recv(1024)
                            if not msg:
                                break

                            msg = msg.decode(FORMAT)

                            if "scene" in msg:
                                try:
                                    scene = int(msg[5:])
                                    scenes = obs.obs_frontend_get_scenes()
                                    if len(scenes) >= (scene + 1):
                                        obs.obs_frontend_set_current_scene(
                                            scenes[scene])
                                except:
                                    pass
                            elif "s_mute" in msg:
                                try:
                                    msource = str(msg[6:])
                                    source = obs.obs_get_source_by_name(
                                        msource)
                                    if source is not None:
                                        obs.obs_source_set_muted(source, True)
                                except:
                                    pass
                            elif "s_unmute" in msg:
                                try:
                                    umsource = str(msg[8:])
                                    source = obs.obs_get_source_by_name(
                                        umsource)
                                    if source is not None:
                                        obs.obs_source_set_muted(source, False)
                                except:
                                    pass
                            elif "s_hide" in msg:
                                try:
                                    hsource = str(msg[6:])
                                    source = obs.obs_get_source_by_name(
                                        hsource)
                                    if source is not None:
                                        obs.obs_source_set_enabled(
                                            source, False)
                                except:
                                    pass
                            elif "s_unhide" in msg:
                                try:
                                    uhsource = str(msg[8:])
                                    source = obs.obs_get_source_by_name(
                                        uhsource)
                                    if source is not None:
                                        obs.obs_source_set_enabled(
                                            source, True)
                                except:
                                    pass

                            elif "st_start" in msg:
                                try:
                                    obs.obs_frontend_streaming_start()
                                except:
                                    pass
                            elif "st_stop" in msg:
                                try:
                                    obs.obs_frontend_streaming_stop()
                                except:
                                    pass
                            elif "re_start" in msg:
                                try:
                                    obs.obs_frontend_recording_start()
                                except:
                                    pass
                            elif "re_stop" in msg:
                                try:
                                    obs.obs_frontend_recording_stop()
                                except:
                                    pass
                            elif "re_pause" in msg:
                                try:
                                    if obs.obs_frontend_recording_paused():
                                        obs.obs_frontend_recording_pause(False)
                                    else:
                                        obs.obs_frontend_recording_pause(True)
                                except:
                                    pass

                            if "server_stop" in msg:
                                connected = False
                                runServer = False
                                stopServer = False
                        except:
                            if runServer == False:
                                connected = False

                    print("Closing Connection")
                    conn.close()
                    print("Server Stopped...")
                    sys.exit()
            except:
                pass

        print("Server Stopped...")
        sys.exit()
Пример #9
0
def lue():
    global ser
    global viestit

    if not ser.is_open:
        print("remove_current_callback")
        obs.remove_current_callback()
        return

    while True:
        if ser.read(1).hex() == "f8":
            break
    viesti = ser.read(53)
    #viesti = b'3004242064128E123200100000000000000000000000021040000'
    #viesti = b'30010000000001550000100000000000000000000000000240000'
    #viesti = b'300001 22211144615001000000000000000000000000210D0000'

    koodi = viesti[0:1].hex()

    if not koodi in viestit:
        print("tuntematon viesti")
        return

    if not viesti[52:53].hex() == "0d":
        print("virheellinen viesti")
        return

    for liite in viestit[koodi]:
        tavut = viestit[koodi][liite][0]
        sourcet = viestit[koodi][liite][1]

        if liite == "_K":
            if str(viesti)[tavut[1] - 1:tavut[1]] == " ":
                tieto = str(int(str(viesti)[tavut[0]:tavut[0] + 2])
                            ) + "." + str(viesti)[tavut[0] + 2:tavut[1] - 1]
            else:
                tieto = (str(viesti)[tavut[0]:tavut[0] + 2] + ":" +
                         str(viesti)[tavut[0] + 2:tavut[1]]).lstrip("0")

        elif liite == "_A":
            tieto = str(viesti)[tavut[0]:tavut[0] +
                                1] + ":" + str(viesti)[tavut[1] - 2:tavut[1]]
            for source in grafiikat[2]:
                if not tieto == " :  ":
                    obs.obs_source_set_enabled(source, True)
                else:
                    obs.obs_source_set_enabled(source, False)

        elif liite == "_PA" or liite == "_PB":
            tieto = str(viesti)[tavut[0]:tavut[1]].lstrip("0")
            if tieto == "":
                tieto = "0"

        elif liite == "_H":
            if str(viesti)[tavut[0] + 1:tavut[1]] in "@ABCDEFGHI":
                tieto = str(viesti)[tavut[0]:tavut[1] -
                                    1] + "." + merkit[str(viesti)[tavut[0] +
                                                                  1:tavut[1]]]
            else:
                tieto = str(viesti)[tavut[0]:tavut[1]].lstrip("0")
            if tieto == "" or tieto == "0.0":
                tieto = "0"

        elif liite == "_JVA":
            tieto = str(viesti)[tavut[0]:tavut[1]]
            for i in range(len(grafiikat[0])):
                if i < int(tieto):
                    obs.obs_source_set_enabled(grafiikat[0][i], True)
                else:
                    obs.obs_source_set_enabled(grafiikat[0][i], False)

        elif liite == "_JVB":
            tieto = str(viesti)[tavut[0]:tavut[1]]
            for i in range(len(grafiikat[1])):
                if i < int(tieto):
                    obs.obs_source_set_enabled(grafiikat[1][i], True)
                else:
                    obs.obs_source_set_enabled(grafiikat[1][i], False)

        else:
            tieto = str(viesti)[tavut[0]:tavut[1]]

        for source in sourcet:
            data = obs.obs_data_create()
            obs.obs_data_set_string(data, "text", tieto)
            obs.obs_source_update(source, data)
            obs.obs_data_release(data)