diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index de1c0d35fa..1810c2e429 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -231,6 +231,38 @@ public: void LoadCheck(CompanyProperties *c) const override { this->Load(c); } }; +class SlAllowListData : public DefaultSaveLoadHandler { +public: + struct KeyWrapper { + std::string key; + }; + + inline static const SaveLoad description[] = { + SLE_SSTR(KeyWrapper, key, SLE_STR), + }; + inline const static SaveLoadCompatTable compat_description = {}; + + void Save(CompanyProperties *cprops) const override + { + SlSetStructListLength(cprops->allow_list.size()); + for (std::string &str : cprops->allow_list) { + SlObject(&str, this->GetDescription()); + } + } + + void Load(CompanyProperties *cprops) const override + { + size_t num_keys = SlGetStructListLength(UINT32_MAX); + cprops->allow_list.clear(); + cprops->allow_list.resize(num_keys); + for (std::string &str : cprops->allow_list) { + SlObject(&str, this->GetLoadDescription()); + } + } + + void LoadCheck(CompanyProperties *cprops) const override { this->Load(cprops); } +}; + /* Save/load of companies */ static const SaveLoad _company_desc[] = { SLE_VAR(CompanyProperties, name_2, SLE_UINT32), @@ -241,7 +273,8 @@ static const SaveLoad _company_desc[] = { SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32), SLE_CONDSSTR(CompanyProperties, president_name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION), - SLE_CONDVECTOR(CompanyProperties, allow_list, SLE_STR, SLV_COMPANY_ALLOW_LIST, SL_MAX_VERSION), + SLE_CONDVECTOR(CompanyProperties, allow_list, SLE_STR, SLV_COMPANY_ALLOW_LIST, SLV_COMPANY_ALLOW_LIST_V2), + SLEG_CONDSTRUCTLIST("allow_list", SlAllowListData, SLV_COMPANY_ALLOW_LIST_V2, SL_MAX_VERSION), SLE_VAR(CompanyProperties, face, SLE_UINT32), diff --git a/src/sl/saveload_common.h b/src/sl/saveload_common.h index 736d6e09fe..9190f9313f 100644 --- a/src/sl/saveload_common.h +++ b/src/sl/saveload_common.h @@ -400,6 +400,7 @@ enum SaveLoadVersion : uint16_t { SLV_COMPANY_INAUGURATED_PERIOD, ///< 339 PR#12798 Companies show the period inaugurated in wallclock mode. SLV_ROAD_STOP_TILE_DATA, ///< 340 PR#12883 Move storage of road stop tile data, also save for road waypoints. + SLV_COMPANY_ALLOW_LIST_V2, ///< 341 PR#12908 Fixed savegame format for saving of list of client keys that are allowed to join this company. SL_MAX_VERSION, ///< Highest possible saveload version