diff --git a/sources/Users/User.uc b/sources/Users/User.uc index db9ba36..18ecc36 100644 --- a/sources/Users/User.uc +++ b/sources/Users/User.uc @@ -2,7 +2,7 @@ * Object that is supposed to store a persistent data about the * certain player. That is data that will be remembered even after player * reconnects or server changes map/restarts. - * Copyright 2020 - 2021 Anton Tarasenko + * Copyright 2020-2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -34,10 +34,20 @@ var private JSONPointer persistentSettingsPointer; 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 - * right after `EPlayer` was created. + * Initializes caller `User` with id and it's session key. * * Initialization should (and can) only be done once. * 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; key = initKey; + if (initID != none) { + initID.NewRef(); + } } /** @@ -56,6 +69,9 @@ public final function Initialize(UserID initID, int initKey) */ public final function UserID GetID() { + if (id != none) { + id.NewRef(); + } return id; } @@ -88,6 +104,7 @@ public final function int GetKey() public final function DBReadTask ReadGroupOfPersistentData(BaseText groupName) { local DBReadTask task; + if (groupName == none) return none; if (!SetupDatabaseVariables()) return none; @@ -120,6 +137,7 @@ public final function DBReadTask ReadPersistentData( BaseText dataName) { local DBReadTask task; + if (groupName == none) return none; if (dataName == none) return none; if (!SetupDatabaseVariables()) return none; @@ -157,6 +175,7 @@ public final function DBWriteTask WritePersistentData( { local DBWriteTask task; local HashTable emptyObject; + if (groupName == none) return none; if (dataName == none) return none; if (!SetupDatabaseVariables()) return none; diff --git a/sources/Users/UserAPI.uc b/sources/Users/UserAPI.uc index d6d7ec6..35fd4d0 100644 --- a/sources/Users/UserAPI.uc +++ b/sources/Users/UserAPI.uc @@ -1,6 +1,6 @@ /** * API that allows easy access to `User` persistent data and `UserID`s. - * Copyright 2020 - 2021 Anton Tarasenko + * Copyright 2020-2021 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -44,7 +44,16 @@ public final function UserDatabase GetDatabase() */ public final function User Fetch(UserID userID) { - return class'UserDatabase'.static.GetInstance().FetchUser(userID); + local User result; + local UserDatabase userDB; + + userDB = class'UserDatabase'.static.GetInstance(); + if (userDB == none) { + return none; + } + result = userDB.FetchUser(userID); + userDB.FreeSelf(); + return result; } /** @@ -58,9 +67,20 @@ public final function User FetchByIDHash(BaseText idHash) { local UserID userID; local UserDatabase userDB; + local User result; + userDB = class'UserDatabase'.static.GetInstance(); + if (userDB == none) { + return none; + } userID = userDB.FetchUserID(idHash); - return userDB.FetchUser(userID); + userDB.FreeSelf(); + if (userID == none) { + return none; + } + result = userDB.FetchUser(userID); + userID.FreeSelf(); + return result; } /** @@ -73,7 +93,16 @@ public final function User FetchByIDHash(BaseText idHash) */ public final function User FetchByKey(int userKey) { - return class'UserDatabase'.static.GetInstance().FetchUserByKey(userKey); + local User result; + local UserDatabase userDB; + + userDB = class'UserDatabase'.static.GetInstance(); + if (userDB != none) { + return none; + } + result = userDB.FetchUserByKey(userKey); + userDB.FreeSelf(); + return result; } /** @@ -101,7 +130,7 @@ public final function Text GetUserDataLink() */ public final function bool PersistentStorageExists() { - return (_.db.Load(P(userDataDBLink)) != none); + return _.db.ExistsLocal(P(userDataDBLink)); } defaultproperties diff --git a/sources/Users/UserDatabase.uc b/sources/Users/UserDatabase.uc index eee877a..6990f34 100644 --- a/sources/Users/UserDatabase.uc +++ b/sources/Users/UserDatabase.uc @@ -52,6 +52,7 @@ public final static function UserDatabase GetInstance() default.activeDatabase = UserDatabase(__().memory.Allocate(class'UserDatabase')); } + default.activeDatabase.NewRef(); return default.activeDatabase; } @@ -80,6 +81,7 @@ public final function UserID FetchUserID(BaseText idHash) if (storedUserIDs[i].IsEqualToSteamID(steamID)) { _.memory.Free(steamID.steamID64); + storedUserIDs[i].NewRef(); return storedUserIDs[i]; } } @@ -88,6 +90,7 @@ public final function UserID FetchUserID(BaseText idHash) if (newUserID.IsInitialized()) { storedUserIDs[storedUserIDs.length] = newUserID; + newUserID.newRef(); return newUserID; } _.memory.Free(steamID.steamID64); diff --git a/sources/Users/UserID.uc b/sources/Users/UserID.uc index 7d7ca42..97e90a2 100644 --- a/sources/Users/UserID.uc +++ b/sources/Users/UserID.uc @@ -1,6 +1,6 @@ /** * Acedia's class for storing user's ID. - * Copyright 2020 - 2021 Anton Tarasenko + * Copyright 2020-2021 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. *