EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommandDispatcher Class Reference

#include "CommandDispatcher.h"

Collaboration diagram for CommandDispatcher:

Classes

class  CommandRecord
 

Public Types

typedef PyResult(* CommandFunc )(Client *who, CommandDB *db, PyServiceMgr *services, const Seperator &args)
 

Public Member Functions

 CommandDispatcher (PyServiceMgr &services)
 
virtual ~CommandDispatcher ()
 
void Close ()
 
PyResult Execute (Client *from, const char *msg)
 
void AddCommand (const char *cmd, const char *desc, int64 required_role, CommandFunc function)
 
void ListCommands ()
 

Protected Attributes

PyServiceMgrm_services
 
CommandDB m_db
 
std::map< std::string,
CommandRecord * > 
m_commands
 

Detailed Description

Definition at line 12 of file CommandDispatcher.h.

Member Typedef Documentation

typedef PyResult(* CommandDispatcher::CommandFunc)(Client *who, CommandDB *db, PyServiceMgr *services, const Seperator &args)

Definition at line 15 of file CommandDispatcher.h.

Constructor & Destructor Documentation

CommandDispatcher::CommandDispatcher ( PyServiceMgr services)

Definition at line 34 of file CommandDispatcher.cpp.

References m_commands.

35 : m_services( services )
36 {
37  m_commands.clear();
38 }
std::map< std::string, CommandRecord * > m_commands
PyServiceMgr & m_services
CommandDispatcher::~CommandDispatcher ( )
virtual

Definition at line 40 of file CommandDispatcher.cpp.

References m_commands, and SafeDelete().

40  {
41  for (auto cur : m_commands)
42  SafeDelete(cur.second);
43  m_commands.clear();
44 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< std::string, CommandRecord * > m_commands

Here is the call graph for this function:

Member Function Documentation

void CommandDispatcher::AddCommand ( const char *  cmd,
const char *  desc,
int64  required_role,
CommandFunc  function 
)

Definition at line 89 of file CommandDispatcher.cpp.

References m_commands, and SafeDelete().

90 {
91  std::map<std::string, CommandRecord*>::iterator itr = m_commands.find( cmd );
92  if (itr != m_commands.end())
93  SafeDelete( itr->second );
94 
95  m_commands[cmd] = new CommandRecord( cmd, desc, required_role, function );
96 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< std::string, CommandRecord * > m_commands

Here is the call graph for this function:

void CommandDispatcher::Close ( )

Definition at line 107 of file CommandDispatcher.cpp.

References m_commands, and SafeDelete().

Referenced by main().

107  {
108  for (auto cur : m_commands)
109  SafeDelete(cur.second);
110  m_commands.clear();
111 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< std::string, CommandRecord * > m_commands

Here is the call graph for this function:

Here is the caller graph for this function:

PyResult CommandDispatcher::Execute ( Client from,
const char *  msg 
)
Todo:
fix this shit... if (from->IsInSpace()) { if (!from->DestinyMgr()) from->SendErrorMsg( "Internal Server Error. Ref: ServerError 31110 " ); if (from->DestinyMgr()->IsWarping() && ((from->GetAccountRole() & Acct::Role::GML) != Acct::Role::GML)) { sLog.Error( "CommandDispatcher", " Command Requested by %s while warping. --Access denied.", from->GetName() ); from->SendErrorMsg( "ServerError 31113 - Cannot Request Commands While Warping." ); } }

Definition at line 46 of file CommandDispatcher.cpp.

References _log, UserError::AddFormatValue(), Seperator::arg(), Seperator::argCount(), CommandDispatcher::CommandRecord::command, CommandDispatcher::CommandRecord::function, Client::GetAccountRole(), Client::GetName(), m_commands, m_db, m_services, and CommandDispatcher::CommandRecord::required_role.

Referenced by LSCService::ExecuteCommand(), and SlashService::SlashCommand().

47 {
58  Seperator sep( &msg[1] );
59  if (!sep.argCount()) {
60  //empty command, return list of commands
61  std::string reason = "Commands: ";
62 
63  std::map<std::string, CommandRecord *>::const_iterator cur = m_commands.begin();
64  reason += "[";
65  for(; cur != m_commands.end(); cur++)
66  reason += "'" + cur->second->command + "',";
67  reason += "]";
68 
69  throw UserError ("").AddFormatValue ("reason", new PyString (reason));
70  }
71 
72  std::map<std::string, CommandRecord*>::const_iterator itr = m_commands.find( sep.arg( 0 ) );
73  if (m_commands.end() == itr ) {
74  _log(COMMAND__ERROR, "Unable to find command '%s' for %s", sep.arg( 0 ).c_str(), from->GetName() );
75  throw CustomError ("Unknown command '%s'", sep.arg (0).c_str ());
76  }
77 
78  CommandRecord* rec = itr->second;
79 
80  _log(COMMAND__INFO, "Request access to command '%s' with role %p for '%s' with role %p.", rec->command.c_str(), rec->required_role, from->GetName(), from->GetAccountRole() );
81  if ((from->GetAccountRole() & rec->required_role) != rec->required_role) {
82  _log(COMMAND__ERROR, "Access denied to %s for command '%s'. --have role %p, need role %p", from->GetName(), rec->command.c_str(), from->GetAccountRole(), rec->required_role );
83  throw CustomError ("Access denied to command '%s'", sep.arg (0).c_str ());
84  }
85 
86  return ( *rec->function )( from, &m_db, &m_services, sep );
87 }
int64 GetAccountRole() const
Definition: Client.h:118
#define _log(type, fmt,...)
Definition: logsys.h:124
Python string.
Definition: PyRep.h:430
UserError & AddFormatValue(const char *name, PyRep *value)
Fluent version of the protected AddKeyword, allows for adding a keyword to the exception.
Separates string to arguments.
Definition: Seperator.h:36
Advanced version of UserError that allows to send a full custom message.
Definition: PyExceptions.h:453
std::map< std::string, CommandRecord * > m_commands
PyServiceMgr & m_services
const char * GetName() const
Definition: Client.h:94
Python object "ccp_exceptions.UserError".
Definition: PyExceptions.h:121

Here is the call graph for this function:

Here is the caller graph for this function:

void CommandDispatcher::ListCommands ( )

Definition at line 98 of file CommandDispatcher.cpp.

References m_commands, and sLog.

Referenced by ConsoleCommand::Process().

98  {
99  sLog.Green(" EVEmu", "Currently Loaded %u Commands:", m_commands.size());
100  std::map<std::string, CommandDispatcher::CommandRecord*>::iterator itr = m_commands.begin();
101  for (; itr != m_commands.end(); ++itr) {
102  sLog.Magenta(" Call and Role", "%s - %p (%li)",
103  itr->first.c_str(), itr->second->required_role, itr->second->required_role);
104  }
105 }
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::map< std::string, CommandRecord * > m_commands

Here is the caller graph for this function:

Member Data Documentation

std::map<std::string, CommandRecord *> CommandDispatcher::m_commands
protected
CommandDB CommandDispatcher::m_db
protected

Definition at line 40 of file CommandDispatcher.h.

Referenced by Execute().

PyServiceMgr& CommandDispatcher::m_services
protected

Definition at line 39 of file CommandDispatcher.h.

Referenced by Execute().


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