diff --git a/sources/Users/Users_Feature.uc b/sources/Users/Users_Feature.uc index 46b9ddb..c5f1a2b 100644 --- a/sources/Users/Users_Feature.uc +++ b/sources/Users/Users_Feature.uc @@ -32,6 +32,8 @@ var private array loadedUserGroups; // a set data structure (has user id as keys and always `none` as a value). var private HashTable loadedGroupToUsersMap; +var private LoggerAPI.Definition warnNoLocalGroup; + protected function OnEnabled() { _.users._reloadFeature(); @@ -57,12 +59,6 @@ protected function SwapConfig(FeatureConfig config) } private final function LoadLocalData() -{ - LoadLocalGroupNames(); - LoadLocalGroupToUserMap(); -} - -private final function LoadLocalGroupNames() { local int i, j; local bool isDuplicate; @@ -89,43 +85,59 @@ private final function LoadLocalGroupNames() } nextUserGroup.FreeSelf(); } + LoadLocalGroupToUserMap(); } private final function LoadLocalGroupToUserMap() { - local int i, j; - local Text newSteamID; - local HashTable newPlayerSet; - local UserGroup nextGroupConfig; - local array nextGroupUserArray; + local int i; _.memory.Free(loadedGroupToUsersMap); loadedGroupToUsersMap = _.collections.EmptyHashTable(); class'UserGroup'.static.Initialize(); // Go over every group - for (i = 0; i < loadedUserGroups.length; i += 1) + for (i = 0; i < loadedUserGroups.length; i += 1) { + LoadLocalGroup(loadedUserGroups[i], true); + } +} + +private final function LoadLocalGroup( + BaseText groupName, + optional bool localGroupIsExpected) +{ + local int i; + local Text newSteamID, lowerCaseGroupName; + local HashTable newPlayerSet; + local UserGroup groupConfig; + local array groupUserArray; + + if (groupName == none) { + return; + } + groupConfig = UserGroup( + class'UserGroup'.static.GetConfigInstance(loadedUserGroups[i])); + if (groupConfig == none) { - nextGroupConfig = UserGroup( - class'UserGroup'.static.GetConfigInstance(loadedUserGroups[i])); - if (nextGroupConfig == none) - { - // !!! Log missing group - continue; - } - // Copy player IDs from `string` array into `HashTable` - // that is serving as a set data structure - newPlayerSet = _.collections.EmptyHashTable(); - nextGroupUserArray = nextGroupConfig.user; - for (j = 0; j < nextGroupUserArray.length; j += 1) - { - newSteamID = _.text.FromString(nextGroupUserArray[j]); - newPlayerSet.SetItem(newSteamID, none); - newSteamID.FreeSelf(); + if (localGroupIsExpected) { + _.logger.Auto(warnNoLocalGroup).Arg(groupName.Copy()); } - loadedGroupToUsersMap.SetItem(loadedUserGroups[i], newPlayerSet); - newPlayerSet.FreeSelf(); - nextGroupConfig.FreeSelf(); + return; } + // Copy player IDs from `string` array into `HashTable` + // that is serving as a set data structure + newPlayerSet = _.collections.EmptyHashTable(); + groupUserArray = groupConfig.user; + for (i = 0; i < groupUserArray.length; i += 1) + { + newSteamID = _.text.FromString(groupUserArray[i]); + newPlayerSet.SetItem(newSteamID, none); + newSteamID.FreeSelf(); + } + lowerCaseGroupName = groupName.LowerCopy(); + loadedGroupToUsersMap.SetItem(lowerCaseGroupName, newPlayerSet); + lowerCaseGroupName.FreeSelf(); + newPlayerSet.FreeSelf(); + groupConfig.FreeSelf(); } private final function SaveLocalData() @@ -209,25 +221,22 @@ public final function array GetAvailableGroups() */ public final function bool AddGroup(BaseText groupName) { - local bool groupExists; - local Text lowerCaseGroupName; - local HashTable newUserSet; + local bool groupExists; + local Text lowerCaseGroupName; if (groupName == none) { return false; } lowerCaseGroupName = groupName.LowerCopy(); groupExists = loadedGroupToUsersMap.HasKey(lowerCaseGroupName); - if (!groupExists) + if (groupExists) { lowerCaseGroupName.FreeSelf(); return false; } loadedUserGroups[loadedUserGroups.length] = lowerCaseGroupName; // Try loading local `UserGroup`? - newUserSet = _.collections.EmptyHashTable(); - loadedGroupToUsersMap.SetItem(lowerCaseGroupName, newUserSet); - newUserSet.FreeSelf(); + LoadLocalGroup(lowerCaseGroupName); return true; } @@ -834,4 +843,5 @@ public final function bool IsUserGroupDataLoaded() defaultproperties { configClass = class'Users' + warnNoLocalGroup = (l=LOG_Warning,m="Expected config to contain `UserGroup` named \"%1\", but it is missing. \"AcediaUsers.ini\" might be misconfigured.") } \ No newline at end of file