Skip to content

server.player.playerdb

fn load_player #

fn load_player(dir string, key string) ?PlayerData

fn save_player #

fn save_player(dir string, key string, data PlayerData) !

save_player writes player data atomically - the JSON goes to a temp file first, then a rename swaps it over the target. A crash mid-write can only ever leave a stale but valid save behind, never a truncated one.

interface Provider #

interface Provider {
	load(key string) ?PlayerData
mut:
	save(key string, data PlayerData) !
}

Provider stores player save data. FileProvider is the default local JSON backed implementation; embedders may supply another backend through HubOptions without changing session code.

struct FileProvider #

struct FileProvider {
pub:
	dir string
}

FileProvider wraps the existing load_player/save_player behavior.

fn (FileProvider) load #

fn (p FileProvider) load(key string) ?PlayerData

fn (FileProvider) save #

fn (mut p FileProvider) save(key string, data PlayerData) !

struct InvItem #

struct InvItem {
pub mut:
	slot             int = -1
	id               int
	meta             int
	count            int
	block_runtime_id int
	raw_extra_data   []u8
}

struct PlayerData #

struct PlayerData {
pub mut:
	x              f32
	y              f32
	z              f32
	yaw            f32
	pitch          f32
	gamemode       int
	items          []InvItem
	has_last_death bool
	last_death_x   f32
	last_death_y   f32
	last_death_z   f32
}