Storing game saves

How did we do?

You can use HiveMP Attributes to store game saves in the cloud, allowing players to bring their progress with them regardless of the device or system they are playing on.

Designing your data storage

As outlined in Attribute Storage, all attribute values are stored as strings. Since game save data is often complex, you'll need to encode it so that it can be stored in HiveMP Attributes.

Maximum size on attribute values

The maximum size of values that can be stored in HiveMP Attributes is 100kb. If the encoded size of your game saves can be larger than 100kb, you'll need to store the actual save data in HiveMP UGC Cache and reference it from HiveMP Attributes.

Saving game files

To store your game files in HiveMP Attributes, you'll need to encode them into ASCII-safe strings. If your save game data is binary data, encode it with Base64 before storing it in HiveMP Attributes.

If save game files are under 100kb

If the encoded save game file is under than 100kb, you can store it in HiveMP Attributes:

curl -s \
  -H "X-API-Key: $apiKey" \
  -H "Accept: application/json" \
  -H "Content-Length: 0" \
  -X PUT \
  "https://attribute-api.hivemp.com/v1/attribute"\
"?id=u-5682741632827394"\
"&key=savefile"\
"&value=ENCODED_SAVE_FILE_CONTENT"

If save game files are larger than 100kb

If the save game file is larger than 100kb, you'll need to store it in HiveMP UGC Cache:

read -r -d '' _request_body << EOM
"RAW_SAVE_FILE_CONTENT_TO_UPLOAD"
EOM
curl -s \
  -H "X-API-Key: $apiKey" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data "$_request_body" \
  -X PUT \
  "https://ugc-cache-api.hivemp.com/v1/item"\
"?lookupKey=u-5682741632827394"

You should also store an attribute that indicates the user account has a save file present and that it's been stored in HiveMP UGC Cache:

curl -s \
  -H "X-API-Key: $apiKey" \
  -H "Accept: application/json" \
  -H "Content-Length: 0" \
  -X PUT \
  "https://attribute-api.hivemp.com/v1/attribute"\
"?id=u-5682741632827394"\
"&key=savefile"\
"&value=stored-in-ugc-cache"

Loading game files

You can load a player's save game by retrieving the previously stored attribute for that player:

curl -s \
  -H "X-API-Key: $apiKey" \
  -H "Accept: application/json" \
  -H "Content-Length: 0" \
  -X GET \
  "https://attribute-api.hivemp.com/v1/attribute"\
"?id=u-5682741632827394"\
"&key=savefile"\
"&ownerId=u-5682741632827394"

If you've followed the guide above and are storing save games larger than 100kb in HiveMP UGC Cache, then you should check the return value of retrieving the attribute and if it is stored-in-ugc-cache, then you should retrieve the actual save data from HiveMP UGC Cache:

curl -s \
  -H "X-API-Key: $apiKey" \
  -H "Accept: application/json" \
  -H "Content-Length: 0" \
  -X GET \
  "https://ugc-cache-api.hivemp.com/v1/content"\
"?lookupKey=u-5682741632827394"