Skip to content

Commit 184d075

Browse files
committed
Update user storage
1 parent 6f47911 commit 184d075

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

protobuf/user_storage.proto

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
syntax = "proto2";
22

33
message UserStorage {
4-
optional Attributes attributes = 2;
4+
repeated Attributes attributes = 2;
55
}
66

77
message Attributes {
88
optional GameSettings game_settings = 22;
9+
optional GarageItemLastSelected garage_last_selected = 23;
10+
optional SpecialEventSeen special_event_seen = 25;
911
}
1012

1113
message GameSettings {
@@ -16,3 +18,13 @@ message GameSettings {
1618
optional int32 power_meter_slot2 = 6;
1719
optional int32 power_meter_slot3 = 7;
1820
}
21+
22+
message GarageItemLastSelected {
23+
optional string signature = 1;
24+
optional uint64 time = 2;
25+
}
26+
27+
message SpecialEventSeen {
28+
optional string signature = 1;
29+
optional uint64 time = 2;
30+
}

protobuf/user_storage_pb2.py

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zwift_offline.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,16 +3697,22 @@ def api_player_profile_user_game_storage_attributes():
36973697
if request.method == 'POST':
36983698
new = user_storage_pb2.UserStorage()
36993699
new.ParseFromString(request.stream.read())
3700-
user_storage.MergeFrom(new)
3700+
for n in new.attributes:
3701+
for f in n.DESCRIPTOR.fields_by_name:
3702+
if n.HasField(f):
3703+
for a in list(user_storage.attributes):
3704+
if a.HasField(f) and (not 'signature' in getattr(a, f).DESCRIPTOR.fields_by_name \
3705+
or getattr(a, f).signature == getattr(n, f).signature):
3706+
user_storage.attributes.remove(a)
3707+
user_storage.attributes.add().CopyFrom(n)
37013708
with open(user_storage_file, 'wb') as f:
37023709
f.write(user_storage.SerializeToString())
37033710
return '', 202
37043711
ret = user_storage_pb2.UserStorage()
3705-
n = int(request.args.get('n'))
3706-
if n in user_storage.attributes.DESCRIPTOR.fields_by_number:
3707-
field = user_storage.attributes.DESCRIPTOR.fields_by_number[n].name
3708-
if user_storage.attributes.HasField(field):
3709-
getattr(ret.attributes, field).CopyFrom(getattr(user_storage.attributes, field))
3712+
for n in request.args.getlist('n'):
3713+
for a in user_storage.attributes:
3714+
if int(n) in a.DESCRIPTOR.fields_by_number and a.HasField(a.DESCRIPTOR.fields_by_number[int(n)].name):
3715+
ret.attributes.add().CopyFrom(a)
37103716
return ret.SerializeToString(), 200
37113717

37123718

0 commit comments

Comments
 (0)