@ -2,7 +2,7 @@
* Object that is supposed to store a persistent data about the
* Object that is supposed to store a persistent data about the
* certain player. That is data that will be remembered even after player
* certain player. That is data that will be remembered even after player
* reconnects or server changes map/restarts.
* reconnects or server changes map/restarts.
* Copyright 2020 - 2021 Anton Tarasenko
* Copyright 2020-2022 Anton Tarasenko
*------------------------------------------------------------------------------
*------------------------------------------------------------------------------
* This file is part of Acedia.
* This file is part of Acedia.
*
*
@ -34,10 +34,20 @@ var private JSONPointer persistentSettingsPointer;
var private LoggerAPI.Definition errNoUserDataDatabase;
var private LoggerAPI.Definition errNoUserDataDatabase;
// TODO: redo this comment
protected function Finalizer()
{
if (id != none) {
id.FreeSelf();
}
if (persistentSettingsPointer != none) {
persistentSettingsPointer.FreeSelf();
}
id = none;
persistentSettingsPointer = none;
}
/**
/**
* Initializes caller `User` with id and it's session key. Should be called
* Initializes caller `User` with id and it's session key.
* right after `EPlayer` was created.
*
*
* Initialization should (and can) only be done once.
* Initialization should (and can) only be done once.
* Before a `Initialize()` call, any other method calls on such `User`
* Before a `Initialize()` call, any other method calls on such `User`
@ -47,6 +57,9 @@ public final function Initialize(UserID initID, int initKey)
{
{
id = initID;
id = initID;
key = initKey;
key = initKey;
if (initID != none) {
initID.NewRef();
}
}
}
/**
/**
@ -56,6 +69,9 @@ public final function Initialize(UserID initID, int initKey)
*/
*/
public final function UserID GetID()
public final function UserID GetID()
{
{
if (id != none) {
id.NewRef();
}
return id;
return id;
}
}
@ -88,6 +104,7 @@ public final function int GetKey()
public final function DBReadTask ReadGroupOfPersistentData(BaseText groupName)
public final function DBReadTask ReadGroupOfPersistentData(BaseText groupName)
{
{
local DBReadTask task;
local DBReadTask task;
if (groupName == none) return none;
if (groupName == none) return none;
if (!SetupDatabaseVariables()) return none;
if (!SetupDatabaseVariables()) return none;
@ -120,6 +137,7 @@ public final function DBReadTask ReadPersistentData(
BaseText dataName)
BaseText dataName)
{
{
local DBReadTask task;
local DBReadTask task;
if (groupName == none) return none;
if (groupName == none) return none;
if (dataName == none) return none;
if (dataName == none) return none;
if (!SetupDatabaseVariables()) return none;
if (!SetupDatabaseVariables()) return none;
@ -157,6 +175,7 @@ public final function DBWriteTask WritePersistentData(
{
{
local DBWriteTask task;
local DBWriteTask task;
local HashTable emptyObject;
local HashTable emptyObject;
if (groupName == none) return none;
if (groupName == none) return none;
if (dataName == none) return none;
if (dataName == none) return none;
if (!SetupDatabaseVariables()) return none;
if (!SetupDatabaseVariables()) return none;