Add limits on the range of client_id values (#95)

This commit is contained in:
Marius Muja 2023-11-05 17:50:59 -08:00 committed by GitHub
parent 718237ae84
commit 7be33e1c20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -27,7 +27,7 @@ namespace ratgdo {
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
if (!this->pref_.load(&value)) {
if (this->number_type_ == RATGDO_CLIENT_ID) {
value = ((random_uint32() + 1) % 0xFFFF) << 12 | 0x539;
value = ((random_uint32() + 1) % 0x7FF) << 12 | 0x539; // max size limited to be precisely convertible to float
} else {
value = 0;
}
@ -36,7 +36,7 @@ namespace ratgdo {
if (this->number_type_ == RATGDO_CLIENT_ID) {
uint32_t int_value = static_cast<uint32_t>(value);
if ((int_value & 0xFFF) != 0x539) {
value = ((random_uint32() + 1) % 0xFFFF) << 12 | 0x539;
value = ((random_uint32() + 1) % 0x7FF) << 12 | 0x539; // max size limited to be precisely convertible to float
this->pref_.save(&value);
}
}
@ -69,7 +69,9 @@ namespace ratgdo {
} else if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
this->traits.set_max_value(0xfffffff);
} else if (this->number_type_ == RATGDO_CLIENT_ID) {
this->traits.set_max_value(0xFFFFFFFF);
this->traits.set_step(0x1000);
this->traits.set_min_value(0x539);
this->traits.set_max_value(0x7ff539);
}
}