Skip to content

Commit

Permalink
Try to get server IP
Browse files Browse the repository at this point in the history
if server-ip.txt is not found
  • Loading branch information
oldnapalm committed Jan 19, 2024
1 parent 08c0ad3 commit ccac832
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<details><summary>Android (non-rooted device)</summary>

* Install apk-mitm (https://github.com/shroudedcode/apk-mitm)
Expand Down
20 changes: 5 additions & 15 deletions standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
23 changes: 12 additions & 11 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,23 @@
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
if os.path.exists(SERVER_IP_FILE):
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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ccac832

Please sign in to comment.