Skip to content

Commit

Permalink
Update user storage
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Nov 22, 2024
1 parent 6f47911 commit 184d075
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
14 changes: 13 additions & 1 deletion protobuf/user_storage.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
syntax = "proto2";

message UserStorage {
optional Attributes attributes = 2;
repeated Attributes attributes = 2;
}

message Attributes {
optional GameSettings game_settings = 22;
optional GarageItemLastSelected garage_last_selected = 23;
optional SpecialEventSeen special_event_seen = 25;
}

message GameSettings {
Expand All @@ -16,3 +18,13 @@ message GameSettings {
optional int32 power_meter_slot2 = 6;
optional int32 power_meter_slot3 = 7;
}

message GarageItemLastSelected {
optional string signature = 1;
optional uint64 time = 2;
}

message SpecialEventSeen {
optional string signature = 1;
optional uint64 time = 2;
}
14 changes: 9 additions & 5 deletions protobuf/user_storage_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3697,16 +3697,22 @@ def api_player_profile_user_game_storage_attributes():
if request.method == 'POST':
new = user_storage_pb2.UserStorage()
new.ParseFromString(request.stream.read())
user_storage.MergeFrom(new)
for n in new.attributes:
for f in n.DESCRIPTOR.fields_by_name:
if n.HasField(f):
for a in list(user_storage.attributes):
if a.HasField(f) and (not 'signature' in getattr(a, f).DESCRIPTOR.fields_by_name \
or getattr(a, f).signature == getattr(n, f).signature):
user_storage.attributes.remove(a)
user_storage.attributes.add().CopyFrom(n)
with open(user_storage_file, 'wb') as f:
f.write(user_storage.SerializeToString())
return '', 202
ret = user_storage_pb2.UserStorage()
n = int(request.args.get('n'))
if n in user_storage.attributes.DESCRIPTOR.fields_by_number:
field = user_storage.attributes.DESCRIPTOR.fields_by_number[n].name
if user_storage.attributes.HasField(field):
getattr(ret.attributes, field).CopyFrom(getattr(user_storage.attributes, field))
for n in request.args.getlist('n'):
for a in user_storage.attributes:
if int(n) in a.DESCRIPTOR.fields_by_number and a.HasField(a.DESCRIPTOR.fields_by_number[int(n)].name):
ret.attributes.add().CopyFrom(a)
return ret.SerializeToString(), 200


Expand Down

0 comments on commit 184d075

Please sign in to comment.