diff --git a/README.md b/README.md index 763298db..dbda19c9 100644 --- a/README.md +++ b/README.md @@ -278,8 +278,6 @@ To enable support for multiple users perform the steps below: ### Step 7 [OPTIONAL]: Install Zwift Companion App -Create a ``server-ip.txt`` file in the ``storage`` directory containing the IP address of the PC running zoffline. -
Android (non-rooted device) * Install apk-mitm (https://github.com/shroudedcode/apk-mitm) diff --git a/standalone.py b/standalone.py index 14495344..66e0e637 100644 --- a/standalone.py +++ b/standalone.py @@ -59,7 +59,6 @@ def patched_create_connection(address, *args, **kwargs): except: pass -SERVER_IP_FILE = "%s/server-ip.txt" % STORAGE_DIR FAKE_DNS_FILE = "%s/fake-dns.txt" % STORAGE_DIR ENABLE_BOTS_FILE = "%s/enable_bots.txt" % STORAGE_DIR DISCORD_CONFIG_FILE = "%s/discord.cfg" % STORAGE_DIR @@ -270,22 +269,15 @@ def handle(self): msg = udp_node_msgs_pb2.ServerToClient() msg.player_id = hello.player_id msg.world_time = 0 - if self.request.getpeername()[0] == '127.0.0.1': # to avoid needing hairpinning - udp_node_ip = "127.0.0.1" - elif os.path.exists(SERVER_IP_FILE): - with open(SERVER_IP_FILE, 'r') as f: - udp_node_ip = f.read().rstrip('\r\n') - else: - udp_node_ip = "127.0.0.1" details1 = msg.udp_config.relay_addresses.add() details1.lb_realm = udp_node_msgs_pb2.ZofflineConstants.RealmID details1.lb_course = 6 # watopia crowd - details1.ip = udp_node_ip + details1.ip = zo.server_ip details1.port = 3022 details2 = msg.udp_config.relay_addresses.add() details2.lb_realm = 0 #generic load balancing realm details2.lb_course = 0 #generic load balancing course - details2.ip = udp_node_ip + details2.ip = zo.server_ip details2.port = 3022 msg.udp_config.uc_f2 = 10 msg.udp_config.uc_f3 = 30 @@ -836,11 +828,9 @@ def handle(self): ri = threading.Thread(target=remove_inactive) ri.start() -if os.path.exists(FAKE_DNS_FILE) and os.path.exists(SERVER_IP_FILE): +if os.path.exists(FAKE_DNS_FILE): from fake_dns import fake_dns - with open(SERVER_IP_FILE, 'r') as f: - server_ip = f.read().rstrip('\r\n') - dns = threading.Thread(target=fake_dns, args=(server_ip,)) - dns.start() + dns = threading.Thread(target=fake_dns, args=(zo.server_ip,)) + dns.start() zo.run_standalone(online, global_relay, global_pace_partners, global_bots, global_ghosts, ghosts_enabled, save_ghost, regroup_ghosts, player_update_queue, map_override, climb_override, discord) diff --git a/zwift_offline.py b/zwift_offline.py index eda439c3..d0aaa861 100644 --- a/zwift_offline.py +++ b/zwift_offline.py @@ -86,8 +86,6 @@ DATABASE_PATH = "%s/zwift-offline.db" % STORAGE_DIR DATABASE_CUR_VER = 3 -PACE_PARTNERS_DIR = "%s/pace_partners" % SCRIPT_DIR - # For auth server AUTOLAUNCH_FILE = "%s/auto_launch.txt" % STORAGE_DIR SERVER_IP_FILE = "%s/server-ip.txt" % STORAGE_DIR @@ -95,7 +93,16 @@ with open(SERVER_IP_FILE, 'r') as f: server_ip = f.read().rstrip('\r\n') else: - server_ip = '127.0.0.1' + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + s.connect(('10.254.254.254', 1)) + server_ip = s.getsockname()[0] + except: + server_ip = '127.0.0.1' + finally: + s.close() + logger.info("server-ip.txt not found, using %s", server_ip) SECRET_KEY_FILE = "%s/secret-key.txt" % STORAGE_DIR ENABLEGHOSTS_FILE = "%s/enable_ghosts.txt" % STORAGE_DIR MULTIPLAYER = os.path.exists("%s/multiplayer.txt" % STORAGE_DIR) @@ -1262,10 +1269,7 @@ def api_users_login(): response.info.apis.trainingpeaks_url = "https://api.trainingpeaks.com" response.info.time = int(time.time()) udp_node = response.info.nodes.nodes.add() - if request.remote_addr == '127.0.0.1': # to avoid needing hairpinning - udp_node.ip = "127.0.0.1" - else: - udp_node.ip = server_ip # TCP telemetry server + udp_node.ip = server_ip # TCP telemetry server udp_node.port = 3023 response.relay_session_id = player_id response.expiration = 70 @@ -2867,10 +2871,7 @@ def api_profiles_goals_id(player_id, goal_id): def api_tcp_config(): infos = per_session_info_pb2.TcpConfig() info = infos.nodes.add() - if request.remote_addr == '127.0.0.1': # to avoid needing hairpinning - info.ip = "127.0.0.1" - else: - info.ip = server_ip + info.ip = server_ip info.port = 3023 return infos.SerializeToString(), 200