ManaPlus
Namespaces | Macros | Functions | Variables
groupdb.cpp File Reference

(986a3bf)

#include "resources/db/groupdb.h"
#include "configuration.h"
#include "being/localplayer.h"
#include "utils/checkutils.h"
#include "net/net.h"
#include "resources/beingcommon.h"
#include "resources/groupinfo.h"
#include "debug.h"
#include "resources/servercommands.inc"
#include "resources/serverpermissions.inc"

Go to the source code of this file.

Namespaces

 anonymous_namespace{groupdb.cpp}
 

Macros

#define servercommandFirst(name)
 
#define servercommand(name)
 
#define servercommand2(name1, name2)
 
#define serverpermissionFirst(name)
 
#define serverpermission(name)
 

Functions

static ServerCommandTypeT parseCommand (const std::string &str, const int id)
 
static ServerPermissionTypeT parsePermission (const std::string &str, const int id)
 
static ServerCommandEnable::Type parseUseFlag (const std::string &str, const int id)
 
static void loadCommands (xmlNodePtr rootNode, const int id, GroupInfo *groupInfo)
 
static void loadPermissions (xmlNodePtr rootNode, const int id, GroupInfo *groupInfo)
 
static void loadSubNodes (xmlNodePtr groupNode, const int id, GroupInfo *groupInfo)
 
static void parseInherit (xmlNodePtr groupNode, const int id, GroupInfo *groupInfo)
 

Variables

GroupDb::GroupInfos anonymous_namespace{groupdb.cpp}::mGroups
 
const GroupInfo anonymous_namespace{groupdb.cpp}::mEmptyGroup
 
bool anonymous_namespace{groupdb.cpp}::mLoaded = false
 

Macro Definition Documentation

◆ servercommand

#define servercommand (   name)
Value:
if (str == #name) \
return ServerCommandType::name; \
else

Definition at line 63 of file groupdb.cpp.

◆ servercommand2

#define servercommand2 (   name1,
  name2 
)
Value:
if (str == #name2) \
return ServerCommandType::name1; \
else

Definition at line 67 of file groupdb.cpp.

◆ servercommandFirst

#define servercommandFirst (   name)
Value:
if (str == #name) \
return ServerCommandType::name; \
else

Definition at line 59 of file groupdb.cpp.

◆ serverpermission

#define serverpermission (   name)
Value:
if (str == #name) \
return ServerPermissionType::name; \
else

Definition at line 94 of file groupdb.cpp.

◆ serverpermissionFirst

#define serverpermissionFirst (   name)
Value:
if (str == #name) \
return ServerPermissionType::name; \
else

Definition at line 90 of file groupdb.cpp.

Function Documentation

◆ loadCommands()

static void loadCommands ( xmlNodePtr  rootNode,
const int  id,
GroupInfo groupInfo 
)
static

Definition at line 149 of file groupdb.cpp.

152 {
153  for_each_xml_child_node(node, rootNode)
154  {
155  if (xmlNameEqual(node, "command"))
156  {
157  const std::string nameStr = XML::getProperty(node,
158  "name",
159  "");
160  const std::string useStr = XML::getProperty(node,
161  "use",
162  "");
163  ServerCommandTypeT name = parseCommand(nameStr, id);
164  if (name == ServerCommandType::Max)
165  continue;
166  ServerCommandEnable::Type useFlag = parseUseFlag(useStr, id);
167  if (useFlag == ServerCommandEnable::No)
168  continue;
169  groupInfo->mCommands[CAST_SIZE(name)] = useFlag;
170  }
171  }
172 }
#define CAST_SIZE
Definition: cast.h:34
static ServerCommandTypeT parseCommand(const std::string &str, const int id)
Definition: groupdb.cpp:72
static ServerCommandEnable::Type parseUseFlag(const std::string &str, const int id)
Definition: groupdb.cpp:117
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
ServerCommandType ::T ServerCommandTypeT
ServerCommandEnable::Type mCommands[static_cast< size_t >(ServerCommandType::Max)]
Definition: groupinfo.h:43

References CAST_SIZE, for_each_xml_child_node, XML::getProperty(), ServerCommandType::Max, GroupInfo::mCommands, ServerCommandEnable::No, parseCommand(), and parseUseFlag().

Referenced by loadSubNodes().

◆ loadPermissions()

static void loadPermissions ( xmlNodePtr  rootNode,
const int  id,
GroupInfo groupInfo 
)
static

Definition at line 177 of file groupdb.cpp.

180 {
181  for_each_xml_child_node(node, rootNode)
182  {
183  if (xmlNameEqual(node, "permission"))
184  {
185  const std::string nameStr = XML::getProperty(node,
186  "name",
187  "");
188  ServerPermissionTypeT perm = parsePermission(nameStr, id);
189  if (perm == ServerPermissionType::Max)
190  continue;
191  if (!XML::getBoolProperty(node,
192  "enable",
193  true))
194  {
195  continue;
196  }
197  groupInfo->mPermissions[CAST_SIZE(perm)] = Enable_true;
198  }
199  }
200 }
const bool Enable_true
Definition: enable.h:30
static ServerPermissionTypeT parsePermission(const std::string &str, const int id)
Definition: groupdb.cpp:99
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
ServerPermissionType ::T ServerPermissionTypeT
Enable mPermissions[static_cast< size_t >(ServerPermissionType::Max)]
Definition: groupinfo.h:44

References CAST_SIZE, Enable_true, for_each_xml_child_node, XML::getBoolProperty(), XML::getProperty(), ServerPermissionType::Max, GroupInfo::mPermissions, and parsePermission().

Referenced by loadSubNodes().

◆ loadSubNodes()

static void loadSubNodes ( xmlNodePtr  groupNode,
const int  id,
GroupInfo groupInfo 
)
static

Definition at line 205 of file groupdb.cpp.

208 {
209  for_each_xml_child_node(node, groupNode)
210  {
211  if (xmlNameEqual(node, "commands"))
212  loadCommands(node, id, groupInfo);
213  if (xmlNameEqual(node, "permissions"))
214  loadPermissions(node, id, groupInfo);
215  }
216 }
static void loadCommands(xmlNodePtr rootNode, const int id, GroupInfo *groupInfo)
Definition: groupdb.cpp:149
static void loadPermissions(xmlNodePtr rootNode, const int id, GroupInfo *groupInfo)
Definition: groupdb.cpp:177

References for_each_xml_child_node, loadCommands(), and loadPermissions().

Referenced by GroupDb::loadXmlFile().

◆ parseCommand()

static ServerCommandTypeT parseCommand ( const std::string &  str,
const int  id 
)
static

Definition at line 72 of file groupdb.cpp.

74 {
75 #include "resources/servercommands.inc"
76  {
77  reportAlways("GroupsDb: unknown command name: '%s' in group id '%d'.",
78  str.c_str(),
79  id)
80  }
81 
83 }
#define reportAlways(...)
Definition: checkutils.h:253

References ServerCommandType::Max, and reportAlways.

Referenced by loadCommands().

◆ parseInherit()

static void parseInherit ( xmlNodePtr  groupNode,
const int  id,
GroupInfo groupInfo 
)
static

Definition at line 221 of file groupdb.cpp.

224 {
225  const std::string inherit = XML::langProperty(groupNode,
226  "inherit",
227  "");
228  STD_VECTOR<int> parts;
229  splitToIntVector(parts, inherit, ',');
230  FOR_EACH (STD_VECTOR<int>::const_iterator, it, parts)
231  {
232  const int id2 = *it;
233  GroupDb::GroupInfos::const_iterator it2 = mGroups.find(id2);
234  if (it2 == mGroups.end())
235  {
236  reportAlways("Unknown inherit group id '%d' in group '%d'",
237  id2,
238  id)
239  continue;
240  }
241  GroupInfo *const groupInfo2 = (*it2).second;
242  for (size_t f = 0; f < CAST_SIZE(ServerCommandType::Max); f ++)
243  {
244  ServerCommandEnable::Type enable = groupInfo2->mCommands[f];
245  if (enable != ServerCommandEnable::No)
246  groupInfo->mCommands[f] = enable;
247  }
248  for (size_t f = 0; f < CAST_SIZE(ServerPermissionType::Max); f ++)
249  {
250  if (groupInfo2->mPermissions[f] == Enable_true)
251  groupInfo->mPermissions[f] = Enable_true;
252  }
253  }
254 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
GroupDb::GroupInfos mGroups
Definition: groupdb.cpp:41
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)

References CAST_SIZE, Enable_true, FOR_EACH, XML::langProperty(), ServerCommandType::Max, ServerPermissionType::Max, GroupInfo::mCommands, anonymous_namespace{groupdb.cpp}::mGroups, GroupInfo::mPermissions, ServerCommandEnable::No, reportAlways, and splitToIntVector().

Referenced by GroupDb::loadXmlFile().

◆ parsePermission()

static ServerPermissionTypeT parsePermission ( const std::string &  str,
const int  id 
)
static

Definition at line 99 of file groupdb.cpp.

101 {
102 #include "resources/serverpermissions.inc"
103  {
104  reportAlways("GroupsDb: unknown permission name: "
105  "'%s' in group id '%d'.",
106  str.c_str(),
107  id)
108  }
109 
111 }

References ServerPermissionType::Max, and reportAlways.

Referenced by loadPermissions().

◆ parseUseFlag()

static ServerCommandEnable::Type parseUseFlag ( const std::string &  str,
const int  id 
)
static

Definition at line 117 of file groupdb.cpp.

119 {
120  if (str == "self")
121  {
123  }
124  else if (str == "other")
125  {
127  }
128  else if (str == "both")
129  {
131  }
132  else if (str == "false")
133  {
135  }
136  else
137  {
138  reportAlways("GroupsDb: unknown use flag: '%s' in group id '%d'."
139  "Possible values 'self', 'other', 'both'.",
140  str.c_str(),
141  id)
143  }
144 }

References ServerCommandEnable::Both, ServerCommandEnable::No, ServerCommandEnable::Other, reportAlways, and ServerCommandEnable::Self.

Referenced by loadCommands().