🚢
Airship
  • Getting Started
    • Welcome to Airship
    • Installing Airship
  • TypeScript
    • Overview
    • AirshipBehaviour
      • Adding Inspector Properties
      • AirshipSingleton
      • Using Component Decorators
      • Accessing Other Components
  • Publishing
    • Publish Game
    • Developer Console
  • Networking
    • Multiplayer
    • Local Server Mode
    • Network Signals
    • Network Functions
    • Network Identity
    • Network Transform
  • Input
    • User Input
      • Actions
      • Keyboard
      • Mouse
    • Proximity Prompts
  • Core Package
    • What is the Core Package?
    • Chat Commands
    • Inventory
    • Spawning Characters
    • Enable / Disable Core Features
  • Physics
    • Physics Settings
    • Physics Layers
  • Platform Services
    • Data Store
      • Locking
    • Cache Store
    • Leaderboards
    • Platform Inventory
    • Server Management
    • Server List
    • Server Transfers
    • Users
    • Parties
    • Matchmaking
    • External Services
  • CHARACTERS
    • Quick Configuration
    • Character Movement System
      • Character Movement Data
      • Character Movement Events
    • Character Camera
      • First Person Camera
      • Simple Usage
      • Camera Structure
      • Default Camera Modes
      • Disabling the Camera System
    • Character Animations
      • Character Blender Animations
      • Character Ragdoll
  • Accessories
    • Accessories Intro
    • Creating Accessories
    • Using Accessories
  • ANIMATIONS
    • Animation Events
  • Optimization
    • Live Game Profiler
    • Reducing Bundle Size
  • Game Settings
    • Game Visibility
  • Other
    • Project Status
    • FAQ
    • DataType Math
    • JS to Luau
    • Tags
    • Terrain
    • AirshipNetworkBehaviour
      • Lifecycle Events
      • ServerRpc
      • ObserversRpc
      • TargetRpc
    • VoxelWorld
      • Voxel World Getting Started
      • Voxel World Tips
      • Prefab Voxels
      • QuarterBlocks
    • Easy Helper Utils
      • Easy Motion
      • Easy Grid Align
      • Easy Look At
      • Easy Shake
      • Easy Destroy
Powered by GitBook
On this page
  1. Platform Services
  2. Data Store

Locking

Data Store keys can be locked to a specific game server by calling LockKeyOrStealSafely() or LockKey(). Keys can be locked in two modes:

Mode
Description

ReadWrite

Blocks reads and writes on all other servers. This is the default.

Write

Blocks writes on all other servers. All servers can read the key at any time.

A key lock will last for 24 hours, or until it is unlocked with the UnlockKey() function. Normally, only the server that owns the lock can unlock the key. However, other servers can steal a lock by passing the serverId that owns the lock to the LockKey() or UnlockKey() functions. This should only be done in cases where you know the lock can be stolen safely (ex. the server that owns the lock is offline). You can retrieve the current owner of a lock, along with additional lock data using GetLockDataForKey().

Locking Patterns

For simple lock cases, it is best to use the LockKeyOrStealSafely() function:

Airship.Players.onPlayerJoined.Connect(async (player) => {
	const result = await Platform.Server.DataStore.LockKeyOrStealSafely(
		`progress:${player.userId}`
	);
	if (!result) player.Kick("Unable to load progress.");
	
	// You can now safely read and write to this key. No other server
	// can read or modify it.
	this.progress[player.userId] = await Platform.Server.DataStore.GetKey(
		`progress:${player.userId}`
	);
});

Airship.Players.onPlayerDisconnected.Connect(async (player) => {
	await Platform.Server.DataStore.SetKey(
		`progress:${player.userId}`,
		this.progress[player.userId],
	);
	delete this.progress[player.userId];
	// Release the key when the player disconnects.
	await Platform.Server.DataStore.UnlockKey(`progress:${player.userId}`);
});

Platform.Server.Transfer.onShutdown.Connect(() => {
	Promise.allSettled(ObjectUtils.keys(this.progress).map(async userId => {
		await Platform.Server.DataStore.SetKey(
			`progress:${player.userId}`,
			this.progress[player.userId],
		);
		await Platform.Server.DataStore.UnlockKey(
			`progress:${player.userId}`
		);
	})).expect();
});
PreviousData StoreNextCache Store

Last updated 5 months ago