Browse Source

Refactor local group loading

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
4c4b9f7a33
  1. 64
      sources/Users/Users_Feature.uc

64
sources/Users/Users_Feature.uc

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