MCPcopy Create free account
hub / github.com/cuberite/cuberite / LoadGroups

Method LoadGroups

src/GroupManager.cpp:105–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104
105void cGroupManager::LoadGroups()
106{
107 cIniFile IniFile;
108 if (!IniFile.ReadFile("groups.ini"))
109 {
110 LOGWARNING("Regenerating groups.ini, all groups will be reset");
111 IniFile.AddHeaderComment(" This is the MCServer permissions manager groups file");
112 IniFile.AddHeaderComment(" It stores all defined groups such as Administrators, Players, or Moderators");
113
114 IniFile.SetValue("Owner", "Permissions", "*", true);
115 IniFile.SetValue("Owner", "Color", "2", true);
116
117 IniFile.SetValue("Moderator", "Permissions", "core.time,core.item,core.teleport,core.ban,core.unban,core.save-all,core.toggledownfall");
118 IniFile.SetValue("Moderator", "Color", "2", true);
119 IniFile.SetValue("Moderator", "Inherits", "Player", true);
120
121 IniFile.SetValue("Player", "Permissions", "core.portal", true);
122 IniFile.SetValue("Player", "Color", "f", true);
123 IniFile.SetValue("Player", "Inherits", "Default", true);
124
125 IniFile.SetValue("Default", "Permissions", "core.help,core.plugins,core.spawn,core.worlds,core.back,core.motd,core.build,core.locate,core.viewdistance", true);
126 IniFile.SetValue("Default", "Color", "f", true);
127
128 IniFile.WriteFile("groups.ini");
129 }
130
131 unsigned int NumKeys = IniFile.GetNumKeys();
132 for (size_t i = 0; i < NumKeys; i++)
133 {
134 AString KeyName = IniFile.GetKeyName( i );
135 cGroup* Group = GetGroup( KeyName.c_str() );
136
137 Group->ClearPermission(); // Needed in case the groups are reloaded.
138
139 LOGD("Loading group: %s", KeyName.c_str() );
140
141 Group->SetName(KeyName);
142 AString Color = IniFile.GetValue(KeyName, "Color", "-");
143 if ((Color != "-") && (Color.length() >= 1))
144 {
145 Group->SetColor(cChatColor::Color + Color[0]);
146 }
147 else
148 {
149 Group->SetColor(cChatColor::White);
150 }
151
152 AString Commands = IniFile.GetValue(KeyName, "Commands", "");
153 if (!Commands.empty())
154 {
155 AStringVector Split = StringSplitAndTrim(Commands, ",");
156 for (size_t i = 0; i < Split.size(); i++)
157 {
158 Group->AddCommand(Split[i]);
159 }
160 }
161
162 AString Permissions = IniFile.GetValue(KeyName, "Permissions", "");

Callers 1

ReloadGroupsMethod · 0.80

Calls 15

StringSplitAndTrimFunction · 0.85
ReadFileMethod · 0.80
AddHeaderCommentMethod · 0.80
SetValueMethod · 0.80
WriteFileMethod · 0.80
GetNumKeysMethod · 0.80
GetKeyNameMethod · 0.80
c_strMethod · 0.80
ClearPermissionMethod · 0.80
GetValueMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected