diff --git a/sources/Players/Tests/TEST_Player.uc b/sources/Players/Tests/TEST_Player.uc index b85cb56..f85beea 100644 --- a/sources/Players/Tests/TEST_Player.uc +++ b/sources/Players/Tests/TEST_Player.uc @@ -22,45 +22,45 @@ class TEST_Player extends TestCase protected static function TESTS() { - Test_PlayerID(); + Test_UserID(); } -protected static function Test_PlayerID() +protected static function Test_UserID() { - local APlayerID.SteamData steamData; - local APlayerID testID, testID2, testID3; - testID = APlayerID(_().memory.Allocate(class'APlayerID')); - Context("Testing Acedia's player ID (`APlayerID`)."); - Issue("`APlayerID` initialization works incorrectly."); + local UserID.SteamID SteamID; + local UserID testID, testID2, testID3; + testID = UserID(_().memory.Allocate(class'UserID')); + Context("Testing Acedia's player ID (`UserID`)."); + Issue("`UserID` initialization works incorrectly."); TEST_ExpectFalse(testID.IsInitialized()); TEST_ExpectTrue(testID.Initialize("76561198025127722")); TEST_ExpectTrue(testID.IsInitialized()); TEST_ExpectFalse(testID.Initialize("76561198044316328")); - Issue("`APlayerID` incorrectly handles SteamID."); + Issue("`UserID` incorrectly handles SteamID."); TEST_ExpectTrue(testID.GetUniqueID() == "76561198025127722"); TEST_ExpectTrue(testID.GetSteamID() == "STEAM_1:0:32430997"); TEST_ExpectTrue(testID.GetSteamID3() == "U:1:64861994"); TEST_ExpectTrue(testID.GetSteamID32() == 64861994); TEST_ExpectTrue(testID.GetSteamID64() == "76561198025127722"); - Issue("Two `APlayerID` equality check is incorrect."); - testID2 = APlayerID(_().memory.Allocate(class'APlayerID')); - testID3 = APlayerID(_().memory.Allocate(class'APlayerID')); + Issue("Two `UserID` equality check is incorrect."); + testID2 = UserID(_().memory.Allocate(class'UserID')); + testID3 = UserID(_().memory.Allocate(class'UserID')); testID2.Initialize("76561198025127722"); testID3.Initialize("76561198044316328"); TEST_ExpectTrue(testID.IsEqual(testID2)); - TEST_ExpectTrue(testID.IsEqualToSteamData(testID2.GetSteamData())); + TEST_ExpectTrue(testID.IsEqualToSteamID(testID2.GetSteamID())); TEST_ExpectFalse(testID3.IsEqual(testID)); - Issue("Steam data returned by `APlayerID` is incorrect."); - steamData = testID3.GetSteamData(); - TEST_ExpectTrue(steamData.accountType == 1); - TEST_ExpectTrue(steamData.universe == 1); - TEST_ExpectTrue(steamData.instance == 1); - TEST_ExpectTrue(steamData.steamID32 == 84050600); - TEST_ExpectTrue(steamData.steamID64 == "76561198044316328"); + Issue("Steam data returned by `UserID` is incorrect."); + SteamID = testID3.GetSteamID(); + TEST_ExpectTrue(SteamID.accountType == 1); + TEST_ExpectTrue(SteamID.universe == 1); + TEST_ExpectTrue(SteamID.instance == 1); + TEST_ExpectTrue(SteamID.steamID32 == 84050600); + TEST_ExpectTrue(SteamID.steamID64 == "76561198044316328"); } defaultproperties diff --git a/sources/Players/APlayerID.uc b/sources/Players/UserID.uc similarity index 79% rename from sources/Players/APlayerID.uc rename to sources/Players/UserID.uc index a510fd2..be6322d 100644 --- a/sources/Players/APlayerID.uc +++ b/sources/Players/UserID.uc @@ -21,15 +21,15 @@ * You should have received a copy of the GNU General Public License * along with Acedia. If not, see . */ -class APlayerID extends AcediaObject; +class UserID extends AcediaObject; /** - * Stead data corresponding to a SteamID that relevant `APlayerID` was + * Stead data corresponding to a SteamID that relevant `UserID` was * initialized with. * * For more info read: https://developer.valvesoftware.com/wiki/SteamID */ -struct SteamData +struct SteamID { var public byte accountType; var public byte universe; @@ -40,12 +40,12 @@ struct SteamData // Other 4 fields fully define a SteamID and `steamID64` can be // generated from them, but it is easier to simply cache it in // a separate variable. - // `SteamData` is considered valid iff `steamID64` is equal to + // `SteamID` is considered valid iff `steamID64` is equal to // Steam64 ID that can be generated from other variables. var string steamID64; }; -var protected SteamData initializedData; -// To make it safe to pass `APlayerID` to users, prevent any modifications +var protected SteamID initializedData; +// To make it safe to pass `UserID` to users, prevent any modifications // after `initialized` is set to `true`. var protected bool initialized; @@ -124,20 +124,20 @@ private final function string GetSteamAccountTypeCharacter() } /** - * Helper function that generates `SteamData` structure from + * Helper function that generates `SteamID` structure from * a given Steam64 ID. * * In case invalid ID is given this method will not raise any warning and * returned value should be considered undefined. * * @param steamID64 Steam64 ID's decimal representation in a plain string. - * @return `SteamData` generated from a given Steam64 ID `steamID64`. + * @return `SteamID` generated from a given Steam64 ID `steamID64`. */ -public static final function SteamData GetSteamDataFromSteamID64( +public static final function SteamID GetSteamIDFromSteamID64( string steamID64) { local int i; - local SteamData newSteamData; + local SteamID newSteamID; local array characters; local array digits; @@ -145,25 +145,25 @@ public static final function SteamData GetSteamDataFromSteamID64( for (i = 0; i < characters.length; i += 1) { digits[digits.length] = _().text.CharacterToInt(characters[i]); } - newSteamData.steamID64 = steamID64; + newSteamID.steamID64 = steamID64; // Refer to https://developer.valvesoftware.com/wiki/SteamID // The lowest bit represents Y. // The next 31 bits represents the account number. // ^ these two can be combined into a "SteamID32". - newSteamData.steamID32 = ReadBitsFromDigitArray(digits, 32); + newSteamID.steamID32 = ReadBitsFromDigitArray(digits, 32); // The next 20 bits represents the instance of the account. - newSteamData.instance = ReadBitsFromDigitArray(digits, 20); + newSteamID.instance = ReadBitsFromDigitArray(digits, 20); // The next 4 bits represents the type of account. - newSteamData.accountType = ReadBitsFromDigitArray(digits, 4); + newSteamID.accountType = ReadBitsFromDigitArray(digits, 4); // The next 8 bits represents the "Universe" the steam account belongs to. - newSteamData.universe = ReadBitsFromDigitArray(digits, 8); - return newSteamData; + newSteamID.universe = ReadBitsFromDigitArray(digits, 8); + return newSteamID; } /** - * Initializes caller `APlayerID` from a given `string` ID. + * Initializes caller `UserID` from a given `string` ID. * - * Each `APLayerID` can only be initialized once and becomes immutable + * Each `UserID` can only be initialized once and becomes immutable * afterwards. * * @param steamID64 `string` with unique ID, provided by the game @@ -171,7 +171,7 @@ public static final function SteamData GetSteamDataFromSteamID64( * like http://steamcommunity.com/profiles/76561198025127722) * * @return `true` if initialization was successful and `false` otherwise - * (can only happen if caller `APlayerID` was already initialized). + * (can only happen if caller `UserID` was already initialized). */ public final function bool Initialize(string steamID64) { @@ -179,13 +179,13 @@ public final function bool Initialize(string steamID64) return false; } - initializedData = GetSteamDataFromSteamID64(steamID64); + initializedData = GetSteamIDFromSteamID64(steamID64); initialized = true; return true; } /** - * Checks if caller `APlayerID` was already initialized + * Checks if caller `UserID` was already initialized * (and is, therefore, immutable). * * @return `true` if it was initialized and `false` otherwise. @@ -196,28 +196,28 @@ public final function bool IsInitialized() } /** - * Returns steam data (see `APlayerID.SteamData`) of the caller `APlayerData`. + * Returns steam data (see `UserID.SteamID`) of the caller `APlayerData`. * * Only returns a valid value if caller `APLayerData` was already initialized. * - * @return `APlayerID.SteamData` of a caller `APlayerID`; - * structure will be filled with default values if caller `APlayerID` + * @return `UserID.SteamID` of a caller `UserID`; + * structure will be filled with default values if caller `UserID` * was not initialized. */ -public final function SteamData GetSteamData() +public final function SteamID GetSteamID() { return initializedData; } /** - * Checks if two `APlayerID`s are the same. + * Checks if two `UserID`s are the same. * - * @param otherID `APlayerID` to compare caller object to. - * @return `true` if caller `APlayerID` is identical to `otherID` and - * `false` otherwise. If at least one of the `APlayerID`s being compared is + * @param otherID `UserID` to compare caller object to. + * @return `true` if caller `UserID` is identical to `otherID` and + * `false` otherwise. If at least one of the `UserID`s being compared is * uninitialized, the result will be `false`. */ -public final function bool IsEqual(APlayerID otherID) +public final function bool IsEqual(UserID otherID) { if (!IsInitialized()) return false; if (!otherID.IsInitialized()) return false; @@ -225,24 +225,24 @@ public final function bool IsEqual(APlayerID otherID) } /** - * Checks if caller `APlayerID`s is the same as what's described by - * given `SteamData`. + * Checks if caller `UserID`s is the same as what's described by + * given `SteamID`. * - * NOTE: only part of the `otherSteamData` might be used for comparison. - * It is up to user to ensure that given `otherSteamData` is valid. + * NOTE: only part of the `otherSteamID` might be used for comparison. + * It is up to user to ensure that given `otherSteamID` is valid. * - * @param otherSteamData `SteamData` to compare caller `APlayerID` to. - * @return `true` if caller `APlayerID` is identical to ID described by - * `otherSteamData` and `false` otherwise. - * If caller `APlayerID` is uninitialized, the result will be `false`. + * @param otherSteamID `SteamID` to compare caller `UserID` to. + * @return `true` if caller `UserID` is identical to ID described by + * `otherSteamID` and `false` otherwise. + * If caller `UserID` is uninitialized, the result will be `false`. */ -public final function bool IsEqualToSteamData(SteamData otherSteamData) +public final function bool IsEqualToSteamID(SteamID otherSteamID) { if (!IsInitialized()) { return false; } - return (initializedData.steamID32 == otherSteamData.steamID32); + return (initializedData.steamID32 == otherSteamID.steamID32); } /**