Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

XAdmin.xAdminConfigIni


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
// ====================================================================
//  Class:  XAdmin.xAdminConfigIni
//  Parent: Engine.xAdminConfigBase
//
//  Retains the list of Admin Users and Groups and keeps them into an
//  Ini file.
// ====================================================================

class xAdminConfigIni extends xAdminConfigBase
	Config(xAdmin)
	ParseConfig;

struct AdminUser
{
	var string			AdminName;
	var string			Password;
	var string			Privileges;
	var array<string>	Groups;			// A User can be part of multiple groups
	var array<string>	ManagedGroups;
};

struct AdminGroup
{
	var string	GroupName;
	var string	Privileges;
	var byte	GameSecLevel;
};

var config array<AdminUser>		AdminUsers;
var config array<AdminGroup>	AdminGroups;

// TODO: Define when it should return false
static function bool Load(xAdminUserList Users, xAdminGroupList Groups, bool bDontAddDefaultAdmin)
{
local int i;
local xAdminUser	NewUser;
local xAdminGroup	NewGroup;
local AdminUser		User;
local AdminGroup	Group;
local bool			bDirty;

	Log("Loading Admins & Groups");

	// Start with converting groups
	for (i = 0; i<Default.AdminGroups.Length; i++)
	{
		// Make sure a group wasnt already added with a given name (manual tampering of ini file)
		Group = Default.AdminGroups[i];
		if (Groups.FindByName(Group.GroupName) == None)
		{
			NewGroup = Groups.CreateGroup(Group.GroupName, Group.Privileges, Group.GameSecLevel);
			Groups.Add(NewGroup);
		}
	}
	// If there are No Groups, Create a default Group (Admin)
	if (Groups.Count() == 0 || Groups.FindByName("Admin") == None)
	{
		Log("Creating Admin Group");
		Groups.Add(Groups.CreateGroup("Admin", "", 255));
		Groups.Add(Groups.CreateGroup("MatchSetup", "Xm", 240));
		bDirty = true;
	}

	// Then, convert each User
	for (i = 0; i<Default.AdminUsers.Length; i++)
	{
		// Make sure that a user with that name wasnt already added
		User = Default.AdminUsers[i];
		if (Users.FindByName(User.AdminName) == None)
		{
			NewUser = Users.Create(User.AdminName, User.Password, User.Privileges);
			if (NewUser != None)
			{
				NewUser.AddGroupsByName(Groups, User.Groups);
				NewUser.AddManagedGroupsByName(Groups, User.ManagedGroups);

				Users.Add(NewUser);
			}
		}
	}
	// if there are no Users, Create a default User (Admin)
	if (Users.Count() == 0 && !bDontAddDefaultAdmin)
	{
		NewUser = Users.Create("Admin", "Admin", "");
		NewUser.AddGroup(Groups.FindByName("Admin"));
		Users.Add(NewUser);
		bDirty = true;
	}

	if (bDirty)
		Save(Users, Groups);

	return true;
}

static function bool Save(xAdminUserList Users, xAdminGroupList Groups)
{
local int i, j, GrpLen, UserLen;
local xAdminUser User;
local xAdminGroup Group;

	// Fix the sizes of the current structure lists
	Default.AdminUsers.Length = Users.Count();
	Default.AdminGroups.Length = Groups.Count();

	// Rebuild the list of AdminGroups based on current internal list
	GrpLen = 0;
	for (i=0; i<Groups.Count(); i++)
	{
		Group = Groups.Get(i);
		if (Group.GroupName != "URL::Admin")
		{
			Default.AdminGroups[GrpLen].GroupName = Group.GroupName;
			Default.AdminGroups[GrpLen].Privileges = Group.Privileges;
			Default.AdminGroups[GrpLen].GameSecLevel = Group.GameSecLevel;
			GrpLen++;
		}
	}
	Default.AdminGroups.Length = GrpLen;

	// Rebuild the list of AdminUsers based on current internal list
	UserLen = 0;
	for (i=0; i<Users.Count(); i++)
	{
		User = Users.Get(i);
		if (User.GetGroup("URL::Admin") == None)
		{
			Default.AdminUsers[UserLen].AdminName = User.UserName;
			Default.AdminUsers[UserLen].Password = User.Password;
			Default.AdminUsers[UserLen].Privileges = User.Privileges;

			if (User.Groups != None && User.Groups.Count() > 0)
			{
				Default.AdminUsers[UserLen].Groups.Length = User.Groups.Count();
				for (j = 0; j<User.Groups.Count(); j++)
					Default.AdminUsers[UserLen].Groups[j] = User.Groups.Get(j).GroupName;
			}
			if (User.ManagedGroups != None && User.ManagedGroups.Count() > 0)
			{
				Default.AdminUsers[UserLen].ManagedGroups.Length = User.ManagedGroups.Count();
				for (j = 0; j<User.ManagedGroups.Count(); j++)
					Default.AdminUsers[UserLen].ManagedGroups[j] = User.ManagedGroups.Get(j).GroupName;
			}
			UserLen++;
		}
	}
	Default.AdminUsers.Length = UserLen;

	StaticSaveConfig();
	return true;
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Di 5.9.2006 22:36:22.000 - Creation time: Do 14.8.2014 09:58:55.801 - Created with UnCodeX