TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
rbac_commandscript Class Reference

Public Member Functions

 rbac_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static RBACCommandDataReadParams (ChatHandler *handler, char const *args, bool checkParams=true)
 
static bool HandleRBACPermGrantCommand (ChatHandler *handler, char const *args)
 
static bool HandleRBACPermDenyCommand (ChatHandler *handler, char const *args)
 
static bool HandleRBACPermRevokeCommand (ChatHandler *handler, char const *args)
 
static bool HandleRBACPermListCommand (ChatHandler *handler, char const *args)
 
static bool HandleRBACListPermissionsCommand (ChatHandler *handler, char const *args)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

rbac_commandscript::rbac_commandscript ( )
inline
50 : CommandScript("rbac_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> rbac_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

53  {
54  static std::vector<ChatCommand> rbacAccountCommandTable =
55  {
60  };
61 
62  static std::vector<ChatCommand> rbacCommandTable =
63  {
64  { "account", rbac::RBAC_PERM_COMMAND_RBAC_ACC, true, NULL, "", rbacAccountCommandTable },
66  };
67 
68  static std::vector<ChatCommand> commandTable =
69  {
70  { "rbac", rbac::RBAC_PERM_COMMAND_RBAC, true, NULL, "", rbacCommandTable },
71  };
72 
73  return commandTable;
74  }
static bool HandleRBACPermGrantCommand(ChatHandler *handler, char const *args)
Definition: cs_rbac.cpp:172
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleRBACPermDenyCommand(ChatHandler *handler, char const *args)
Definition: cs_rbac.cpp:211
Definition: RBAC.h:107
Definition: RBAC.h:108
static bool HandleRBACPermListCommand(ChatHandler *handler, char const *args)
Definition: cs_rbac.cpp:285
static bool HandleRBACPermRevokeCommand(ChatHandler *handler, char const *args)
Definition: cs_rbac.cpp:250
Definition: RBAC.h:113
static bool HandleRBACListPermissionsCommand(ChatHandler *handler, char const *args)
Definition: cs_rbac.cpp:338

+ Here is the call graph for this function:

static bool rbac_commandscript::HandleRBACListPermissionsCommand ( ChatHandler handler,
char const args 
)
inlinestatic
339  {
340  uint32 id = 0;
341  if (char* param1 = strtok((char*)args, " "))
342  id = atoi(param1);
343 
344  if (!id)
345  {
346  rbac::RBACPermissionsContainer const& permissions = sAccountMgr->GetRBACPermissionList();
348  for (rbac::RBACPermissionsContainer::const_iterator it = permissions.begin(); it != permissions.end(); ++it)
349  {
350  rbac::RBACPermission const* permission = it->second;
351  handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
352  }
353  }
354  else
355  {
356  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(id);
357  if (!permission)
358  {
360  handler->SetSentErrorMessage(true);
361  return false;
362  }
363 
365  handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
367  rbac::RBACPermissionContainer const& permissions = permission->GetLinkedPermissions();
368  for (rbac::RBACPermissionContainer::const_iterator it = permissions.begin(); it != permissions.end(); ++it)
369  if (rbac::RBACPermission const* rbacPermission = sAccountMgr->GetRBACPermission(*it))
370  handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, rbacPermission->GetId(), rbacPermission->GetName().c_str());
371  }
372 
373  return true;
374  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:102
Definition: Language.h:101
Definition: Language.h:96
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:755
RBACPermissionContainer const & GetLinkedPermissions() const
Gets the Permissions linked to this permission.
Definition: RBAC.h:760
std::map< uint32, rbac::RBACPermission * > RBACPermissionsContainer
Definition: AccountMgr.h:49
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:757
uint32_t uint32
Definition: Define.h:150
Definition: Language.h:104
Definition: RBAC.h:748
#define sAccountMgr
Definition: AccountMgr.h:98
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
std::set< uint32 > RBACPermissionContainer
Definition: RBAC.h:746

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool rbac_commandscript::HandleRBACPermDenyCommand ( ChatHandler handler,
char const args 
)
inlinestatic
212  {
213  RBACCommandData* command = ReadParams(handler, args);
214 
215  if (!command)
216  {
217  handler->SetSentErrorMessage(true);
218  return false;
219  }
220 
221  rbac::RBACCommandResult result = command->rbac->DenyPermission(command->id, command->realmId);
222  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id);
223 
224  switch (result)
225  {
227  handler->PSendSysMessage(LANG_RBAC_PERM_DENIED_IN_LIST, command->id, permission->GetName().c_str(),
228  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
229  break;
231  handler->PSendSysMessage(LANG_RBAC_PERM_DENIED_IN_GRANTED_LIST, command->id, permission->GetName().c_str(),
232  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
233  break;
234  case rbac::RBAC_OK:
235  handler->PSendSysMessage(LANG_RBAC_PERM_DENIED, command->id, permission->GetName().c_str(),
236  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
237  break;
239  handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id);
240  break;
241  default:
242  break;
243  }
244 
245  delete command;
246 
247  return true;
248  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: RBAC.h:743
Definition: RBAC.h:738
Definition: Language.h:96
RBACCommandResult
Definition: RBAC.h:736
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:755
Definition: Language.h:108
int32 realmId
Definition: cs_rbac.cpp:42
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:793
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:791
uint32 id
Definition: cs_rbac.cpp:41
Definition: RBAC.h:739
Definition: Language.h:109
Definition: cs_rbac.cpp:32
Definition: Language.h:110
Definition: RBAC.h:748
Definition: RBAC.h:741
#define sAccountMgr
Definition: AccountMgr.h:98
static RBACCommandData * ReadParams(ChatHandler *handler, char const *args, bool checkParams=true)
Definition: cs_rbac.cpp:76
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
RBACCommandResult DenyPermission(uint32 permissionId, int32 realmId=0)
Definition: RBAC.cpp:85
rbac::RBACData * rbac
Definition: cs_rbac.cpp:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool rbac_commandscript::HandleRBACPermGrantCommand ( ChatHandler handler,
char const args 
)
inlinestatic
173  {
174  RBACCommandData* command = ReadParams(handler, args);
175 
176  if (!command)
177  {
178  handler->SetSentErrorMessage(true);
179  return false;
180  }
181 
182  rbac::RBACCommandResult result = command->rbac->GrantPermission(command->id, command->realmId);
183  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id);
184 
185  switch (result)
186  {
188  handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED_IN_LIST, command->id, permission->GetName().c_str(),
189  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
190  break;
192  handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED_IN_DENIED_LIST, command->id, permission->GetName().c_str(),
193  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
194  break;
195  case rbac::RBAC_OK:
196  handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED, command->id, permission->GetName().c_str(),
197  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
198  break;
200  handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id);
201  break;
202  default:
203  break;
204  }
205 
206  delete command;
207 
208  return true;
209  }
Definition: Language.h:106
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: RBAC.h:743
Definition: RBAC.h:738
Definition: Language.h:96
Definition: Language.h:107
RBACCommandResult
Definition: RBAC.h:736
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:755
RBACCommandResult GrantPermission(uint32 permissionId, int32 realmId=0)
Definition: RBAC.cpp:41
int32 realmId
Definition: cs_rbac.cpp:42
Definition: Language.h:105
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:793
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:791
Definition: RBAC.h:742
uint32 id
Definition: cs_rbac.cpp:41
Definition: RBAC.h:739
Definition: cs_rbac.cpp:32
Definition: RBAC.h:748
#define sAccountMgr
Definition: AccountMgr.h:98
static RBACCommandData * ReadParams(ChatHandler *handler, char const *args, bool checkParams=true)
Definition: cs_rbac.cpp:76
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
rbac::RBACData * rbac
Definition: cs_rbac.cpp:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool rbac_commandscript::HandleRBACPermListCommand ( ChatHandler handler,
char const args 
)
inlinestatic
286  {
287  RBACCommandData* command = ReadParams(handler, args, false);
288 
289  if (!command)
290  {
291  handler->SetSentErrorMessage(true);
292  return false;
293  }
294 
295  handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_GRANTED, command->rbac->GetId(), command->rbac->GetName().c_str());
296  rbac::RBACPermissionContainer const& granted = command->rbac->GetGrantedPermissions();
297  if (granted.empty())
298  handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY));
299  else
300  {
301  for (rbac::RBACPermissionContainer::const_iterator itr = granted.begin(); itr != granted.end(); ++itr)
302  {
303  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr);
304  handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
305  }
306  }
307 
308  handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_DENIED, command->rbac->GetId(), command->rbac->GetName().c_str());
309  rbac::RBACPermissionContainer const& denied = command->rbac->GetDeniedPermissions();
310  if (denied.empty())
311  handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY));
312  else
313  {
314  for (rbac::RBACPermissionContainer::const_iterator itr = denied.begin(); itr != denied.end(); ++itr)
315  {
316  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr);
317  handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
318  }
319  }
320  handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_BY_SEC_LEVEL, command->rbac->GetId(), command->rbac->GetName().c_str(), command->rbac->GetSecurityLevel());
321  rbac::RBACPermissionContainer const& defaultPermissions = sAccountMgr->GetRBACDefaultPermissions(command->rbac->GetSecurityLevel());
322  if (defaultPermissions.empty())
323  handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY));
324  else
325  {
326  for (rbac::RBACPermissionContainer::const_iterator itr = defaultPermissions.begin(); itr != defaultPermissions.end(); ++itr)
327  {
328  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr);
329  handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
330  }
331  }
332 
333  delete command;
334 
335  return true;
336  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
RBACPermissionContainer const & GetDeniedPermissions() const
Returns all the denied permissions.
Definition: RBAC.h:822
uint8 GetSecurityLevel() const
Returns the security level assigned.
Definition: RBAC.h:910
Definition: Language.h:99
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:755
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:793
Definition: Language.h:100
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:791
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:757
Definition: cs_rbac.cpp:32
Definition: Language.h:103
Definition: Language.h:104
Definition: Language.h:98
Definition: RBAC.h:748
#define sAccountMgr
Definition: AccountMgr.h:98
static RBACCommandData * ReadParams(ChatHandler *handler, char const *args, bool checkParams=true)
Definition: cs_rbac.cpp:76
RBACPermissionContainer const & GetGrantedPermissions() const
Returns all the granted permissions.
Definition: RBAC.h:820
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
std::set< uint32 > RBACPermissionContainer
Definition: RBAC.h:746
rbac::RBACData * rbac
Definition: cs_rbac.cpp:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool rbac_commandscript::HandleRBACPermRevokeCommand ( ChatHandler handler,
char const args 
)
inlinestatic
251  {
252  RBACCommandData* command = ReadParams(handler, args);
253 
254  if (!command)
255  {
256  handler->SetSentErrorMessage(true);
257  return false;
258  }
259 
260  rbac::RBACCommandResult result = command->rbac->RevokePermission(command->id, command->realmId);
261  rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id);
262 
263  switch (result)
264  {
266  handler->PSendSysMessage(LANG_RBAC_PERM_REVOKED_NOT_IN_LIST, command->id, permission->GetName().c_str(),
267  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
268  break;
269  case rbac::RBAC_OK:
270  handler->PSendSysMessage(LANG_RBAC_PERM_REVOKED, command->id, permission->GetName().c_str(),
271  command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
272  break;
274  handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id);
275  break;
276  default:
277  break;
278  }
279 
280  delete command;
281 
282  return true;
283  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: RBAC.h:743
Definition: RBAC.h:738
Definition: Language.h:96
RBACCommandResult
Definition: RBAC.h:736
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:755
int32 realmId
Definition: cs_rbac.cpp:42
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:793
std::string const & GetName() const
Gets the Name of the Object.
Definition: RBAC.h:791
Definition: Language.h:112
uint32 id
Definition: cs_rbac.cpp:41
Definition: Language.h:111
Definition: cs_rbac.cpp:32
Definition: RBAC.h:748
#define sAccountMgr
Definition: AccountMgr.h:98
RBACCommandResult RevokePermission(uint32 permissionId, int32 realmId=0)
Definition: RBAC.cpp:139
static RBACCommandData * ReadParams(ChatHandler *handler, char const *args, bool checkParams=true)
Definition: cs_rbac.cpp:76
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
rbac::RBACData * rbac
Definition: cs_rbac.cpp:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static RBACCommandData* rbac_commandscript::ReadParams ( ChatHandler handler,
char const args,
bool  checkParams = true 
)
inlinestatic
77  {
78  if (!args)
79  return NULL;
80 
81  char* param1 = strtok((char*)args, " ");
82  char* param2 = strtok(NULL, " ");
83  char* param3 = strtok(NULL, " ");
84 
85  int32 realmId = -1;
86  uint32 accountId = 0;
87  std::string accountName;
88  uint32 id = 0;
89  RBACCommandData* data = NULL;
90  rbac::RBACData* rdata = NULL;
91  bool useSelectedPlayer = false;
92 
93  if (checkParams)
94  {
95  if (!param3)
96  {
97  if (param2)
98  realmId = atoi(param2);
99 
100  if (param1)
101  id = atoi(param1);
102 
103  useSelectedPlayer = true;
104  }
105  else
106  {
107  id = atoi(param2);
108  realmId = atoi(param3);
109  }
110 
111  if (!id)
112  {
114  handler->SetSentErrorMessage(true);
115  return NULL;
116  }
117 
118  if (realmId < -1 || !realmId)
119  {
121  handler->SetSentErrorMessage(true);
122  return NULL;
123  }
124  }
125  else if (!param1)
126  useSelectedPlayer = true;
127 
128  if (useSelectedPlayer)
129  {
130  Player* player = handler->getSelectedPlayer();
131  if (!player)
132  return NULL;
133 
134  rdata = player->GetSession()->GetRBACData();
135  accountId = rdata->GetId();
136  AccountMgr::GetName(accountId, accountName);
137  }
138  else
139  {
140  accountName = param1;
141 
142  if (Utf8ToUpperOnlyLatin(accountName))
143  accountId = AccountMgr::GetId(accountName);
144 
145  if (!accountId)
146  {
147  handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
148  handler->SetSentErrorMessage(true);
149  return NULL;
150  }
151  }
152 
153  if (checkParams && handler->HasLowerSecurityAccount(NULL, accountId, true))
154  return NULL;
155 
156  data = new RBACCommandData();
157 
158  if (!rdata)
159  {
160  data->rbac = new rbac::RBACData(accountId, accountName, realm.Id.Realm, AccountMgr::GetSecurity(accountId, realm.Id.Realm));
161  data->rbac->LoadFromDB();
162  data->needDelete = true;
163  }
164  else
165  data->rbac = rdata;
166 
167  data->id = id;
168  data->realmId = realmId;
169  return data;
170  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
uint32 Realm
Definition: Realm.h:53
Realm realm
Definition: World.cpp:3485
Definition: Language.h:96
arena_t NULL
Definition: jemalloc_internal.h:624
void LoadFromDB()
Loads all permissions assigned to current account.
Definition: RBAC.cpp:172
Definition: RBAC.h:783
int32 realmId
Definition: cs_rbac.cpp:42
Definition: Language.h:97
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
uint32 GetId() const
Gets the Id of the Object.
Definition: RBAC.h:793
static uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:284
uint32 id
Definition: cs_rbac.cpp:41
static uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:275
Battlenet::RealmHandle Id
Definition: Realm.h:86
Definition: cs_rbac.cpp:32
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition: Chat.cpp:97
Player * getSelectedPlayer()
Definition: Chat.cpp:579
Definition: Language.h:412
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
bool needDelete
Definition: cs_rbac.cpp:44
rbac::RBACData * rbac
Definition: cs_rbac.cpp:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: