From f1497cd0fff233213cfbd01154be050cefc1c03e Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Tue, 13 Dec 2022 04:39:15 +0700 Subject: [PATCH] Add proper `IsEqual()` method to `UserID` --- sources/Users/Tests/TEST_User.uc | 4 ++-- sources/Users/UserID.uc | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sources/Users/Tests/TEST_User.uc b/sources/Users/Tests/TEST_User.uc index 6467052..86cd7fb 100644 --- a/sources/Users/Tests/TEST_User.uc +++ b/sources/Users/Tests/TEST_User.uc @@ -55,9 +55,9 @@ protected static function Test_UserID() testID3 = UserID(__().memory.Allocate(class'UserID')); testID2.Initialize(P("76561198025127722")); testID3.Initialize(P("76561198044316328")); - TEST_ExpectTrue(testID.IsEqualTo(testID2)); + TEST_ExpectTrue(testID.IsEqual(testID2)); TEST_ExpectTrue(testID.IsEqualToSteamID(testID2.GetSteamID())); - TEST_ExpectFalse(testID3.IsEqualTo(testID)); + TEST_ExpectFalse(testID3.IsEqual(testID)); Issue("Steam data returned by `UserID` is incorrect."); SteamID = testID3.GetSteamID(); diff --git a/sources/Users/UserID.uc b/sources/Users/UserID.uc index 0667199..e89e903 100644 --- a/sources/Users/UserID.uc +++ b/sources/Users/UserID.uc @@ -244,21 +244,23 @@ public final function SteamID GetSteamID() return initializedData; } -/** - * Checks if two `UserID`s are the same. - * - * @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 IsEqualTo(UserID otherID) +public function bool IsEqual(Object other) { + local UserID otherID; + if (!IsInitialized()) return false; + otherID = UserID(other); + if (otherID == none) return false; if (!otherID.IsInitialized()) return false; + return (initializedData.steamID32 == otherID.initializedData.steamID32); } +protected function int CalculateHashCode() +{ + return initializedData.steamID32; +} + /** * Checks if caller `UserID`s is the same as what's described by * given `SteamID`.