Merge branch 'oldnapalm-mp' into mp

This commit is contained in:
perast
2020-11-14 21:20:25 +01:00
15 changed files with 24 additions and 13 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+11 -9
View File
@@ -30,17 +30,20 @@ if getattr(sys, 'frozen', False):
START_LINES_FILE = '%s/start_lines.csv' % STORAGE_DIR
if not os.path.isfile(START_LINES_FILE):
copyfile('%s/start_lines.csv' % sys._MEIPASS, START_LINES_FILE)
PACE_PARTNERS_DIR = '%s/pace_partners' % sys._MEIPASS
else:
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
CDN_DIR = "%s/cdn" % SCRIPT_DIR
STORAGE_DIR = "%s/storage" % SCRIPT_DIR
START_LINES_FILE = '%s/start_lines.csv' % SCRIPT_DIR
PACE_PARTNERS_DIR = '%s/pace_partners' % SCRIPT_DIR
PROXYPASS_FILE = "%s/cdn-proxy.txt" % STORAGE_DIR
SERVER_IP_FILE = "%s/server-ip.txt" % STORAGE_DIR
MAP_OVERRIDE = deque(maxlen=16)
update_freq = 3
ghost_update_freq = 3
pacer_update_freq = 1
last_pp_updates = {}
global_ghosts = {}
ghosts_enabled = {}
@@ -350,12 +353,11 @@ class PacePartnerVariables:
position = 0
def load_pace_partners():
folder = '%s/pace_partners' % STORAGE_DIR
if not os.path.isdir(folder): return
for (root, dirs, files) in os.walk(folder):
if not os.path.isdir(PACE_PARTNERS_DIR): return
for (root, dirs, files) in os.walk(PACE_PARTNERS_DIR):
for pp_id in dirs:
p_id = int(pp_id)
route = '%s/%s/route.bin' % (folder, pp_id)
route = '%s/%s/route.bin' % (PACE_PARTNERS_DIR, pp_id)
if os.path.isfile(route):
with open(route, 'rb') as fd:
global_pace_partners[p_id] = PacePartnerVariables()
@@ -375,7 +377,7 @@ def play_pace_partners():
state.id = pp_id
state.watchingRiderId = pp_id
state.worldTime = zwift_offline.world_time()
ppthreadevent.wait(timeout=update_freq)
ppthreadevent.wait(timeout=pacer_update_freq)
def get_empty_message(player_id):
message = udp_node_msgs_pb2.ServerToClient()
@@ -442,7 +444,7 @@ class UDPHandler(socketserver.BaseRequestHandler):
ghosts.loaded = True
load_ghosts(player_id, state, ghosts)
if state.roadTime and ghosts.last_rt and state.roadTime != ghosts.last_rt:
if t >= ghosts.last_rec + update_freq:
if t >= ghosts.last_rec + ghost_update_freq:
s = ghosts.rec.states.add()
s.CopyFrom(state)
ghosts.last_rec = t
@@ -474,7 +476,7 @@ class UDPHandler(socketserver.BaseRequestHandler):
for p_id in remove_players:
global_ghosts.pop(p_id)
if ghosts.started and t >= ghosts.last_play + update_freq:
if ghosts.started and t >= ghosts.last_play + ghost_update_freq:
message = get_empty_message(player_id)
active_ghosts = 0
for g in ghosts.play.ghosts:
@@ -513,7 +515,7 @@ class UDPHandler(socketserver.BaseRequestHandler):
#Check if players are close in world
if zwift_offline.is_nearby(nearby_state, player):
nearby.append(p_id)
if t >= last_pp_update + update_freq:
if t >= last_pp_update + pacer_update_freq:
last_pp_updates[player_id] = t
for p_id in global_pace_partners.keys():
pace_partner_variables = global_pace_partners[p_id]
+1
View File
@@ -18,6 +18,7 @@ a = Analysis(['standalone.py'],
cipher=block_cipher,
noarchive=False)
a.datas += Tree('cdn', prefix='cdn')
a.datas += Tree('pace_partners', prefix='pace_partners')
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+12 -4
View File
@@ -55,9 +55,11 @@ if getattr(sys, 'frozen', False):
# If we're running as a pyinstaller bundle
SCRIPT_DIR = sys._MEIPASS
STORAGE_DIR = "%s/storage" % os.path.dirname(sys.executable)
PACE_PARTNERS_DIR = '%s/pace_partners' % sys._MEIPASS
else:
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
STORAGE_DIR = "%s/storage" % SCRIPT_DIR
PACE_PARTNERS_DIR = '%s/pace_partners' % SCRIPT_DIR
try:
# Ensure storage dir exists
@@ -196,7 +198,10 @@ def get_online():
def get_partial_profile(player_id):
if not player_id in player_partial_profiles:
#Read from disk
profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, player_id)
if player_id in [2462261, 2466327, 2466331, 2466341]:
profile_file = '%s/%s/profile.bin' % (PACE_PARTNERS_DIR, player_id)
else:
profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, player_id)
if os.path.isfile(profile_file):
try:
with open(profile_file, 'rb') as fd:
@@ -722,12 +727,15 @@ def api_profiles():
p.country_code = 0
else:
profile = profile_pb2.Profile()
profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, i)
if i in ['2462261', '2466327', '2466331', '2466341']:
profile_file = '%s/%s/profile.bin' % (PACE_PARTNERS_DIR, i)
else:
profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, i)
if os.path.isfile(profile_file):
with open(profile_file, 'rb') as fd:
profile.ParseFromString(fd.read())
p = profiles.profiles.add()
p.CopyFrom(profile)
p = profiles.profiles.add()
p.CopyFrom(profile)
return profiles.SerializeToString(), 200