![]() |
Command Class ReferenceCommand base class.
More...
|
Public Member Functions | |
Command () | |
Command (const std::string &cmd, bool need_wiz=false) | |
Command (const std::string &cmd, char cc, bool need_wiz=false) | |
virtual | ~Command () |
void | AddArgument (const std::string &, bool wiz=false) |
bool | CheckArgument (InSocket *, const std::string &, std::string &) |
strbool_m & | GetArguments () |
int | Match (InSocket *, const std::string &cmd, const std::string ¶ms) |
0-no match,1-partial match,2-exact match | |
virtual void | Execute (InSocket *, const std::string &arg, Parse &)=0 |
Execute command. | |
virtual void | OnLine (InSocket *, const std::string &line, int state) |
Additional callback, reply to command prompt. | |
virtual std::string | Category ()=0 |
Get command category. | |
virtual std::string | Description () |
Command description. | |
const std::string & | GetCommand () |
char | GetCommandChar () |
bool | NeedWiz () |
Static Public Member Functions | |
static Command * | GetCommandFromChar (char cc) |
Private Attributes | |
std::string | m_cmd |
char | m_cc |
strbool_m | m_args |
bool | m_need_wiz |
Static Private Attributes | |
static std::map< char, Command * > | m_ccs |
Definition at line 35 of file Command.h.
Command::Command | ( | ) |
Definition at line 31 of file Command.cpp.
00031 : m_cmd(""),m_cc(0),m_need_wiz(false) 00032 { 00033 }
Command::Command | ( | const std::string & | cmd, | |
bool | need_wiz = false | |||
) |
Command::Command | ( | const std::string & | cmd, | |
char | cc, | |||
bool | need_wiz = false | |||
) |
Definition at line 41 of file Command.cpp.
References m_ccs.
00041 : m_cmd(cmd),m_cc(cc),m_need_wiz(w) 00042 { 00043 if (m_ccs[cc] != NULL) 00044 { 00045 fprintf(stderr, "Two commands using the same char: %c - exiting...\n", cc); 00046 exit(-1); 00047 } 00048 m_ccs[cc] = this; 00049 }
Command::~Command | ( | ) | [virtual] |
void Command::AddArgument | ( | const std::string & | , | |
bool | wiz = false | |||
) |
Definition at line 89 of file Command.cpp.
References m_args.
Referenced by Create::Create(), List::List(), and Setcmd::Setcmd().
00090 { 00091 m_args[arg] = wiz; 00092 }
bool Command::CheckArgument | ( | InSocket * | , | |
const std::string & | , | |||
std::string & | ||||
) |
Definition at line 95 of file Command.cpp.
References Player::IsWizard(), and m_args.
00096 { 00097 Player pl(from -> GetDatabase(),from -> GetAccountName()); 00098 bool wiz = pl.IsWizard(); 00099 if (!m_args.size()) 00100 { 00101 complete = arg; 00102 return true; 00103 } 00104 std::string found; 00105 int count = 0; 00106 for (strbool_m::iterator it = m_args.begin(); it != m_args.end(); it++) 00107 { 00108 std::string str = (*it).first; 00109 bool need_wiz = (*it).second; 00110 if (!need_wiz || wiz) 00111 { 00112 if (str.size() >= arg.size() && 00113 !strncasecmp(str.substr(0, arg.size()).c_str(), arg.c_str(), arg.size())) 00114 { 00115 found = str; 00116 count++; 00117 } 00118 } 00119 } 00120 if (count == 1) 00121 { 00122 complete = found; 00123 return true; 00124 } 00125 if (!count) 00126 { 00127 from -> Send("Please specify:\n"); 00128 for (strbool_m::iterator it = m_args.begin(); it != m_args.end(); it++) 00129 { 00130 std::string str = (*it).first; 00131 bool need_wiz = (*it).second; 00132 if (!need_wiz || wiz) 00133 { 00134 from -> Send(" " + str + "\n"); 00135 } 00136 } 00137 } 00138 else 00139 { 00140 from -> Send("Please be more specific:\n"); 00141 for (strbool_m::iterator it = m_args.begin(); it != m_args.end(); it++) 00142 { 00143 std::string str = (*it).first; 00144 bool need_wiz = (*it).second; 00145 if (!need_wiz || wiz) 00146 { 00147 if (str.size() >= arg.size() && 00148 !strncasecmp(str.substr(0, arg.size()).c_str(), arg.c_str(), arg.size())) 00149 { 00150 from -> Send(" " + str + "\n"); 00151 } 00152 } 00153 } 00154 } 00155 from -> SetPrompt(); 00156 return false; 00157 }
strbool_m& Command::GetArguments | ( | ) | [inline] |
int Command::Match | ( | InSocket * | , | |
const std::string & | cmd, | |||
const std::string & | params | |||
) |
0-no match,1-partial match,2-exact match
Definition at line 57 of file Command.cpp.
References Player::IsWizard(), m_cmd, and m_need_wiz.
00058 { 00059 Player pl(from -> GetDatabase(),from -> GetAccountName()); 00060 if (m_need_wiz && !pl.IsWizard()) 00061 return 0; 00062 if (cmd.size() > m_cmd.size()) 00063 return 0; 00064 if (!strcasecmp(cmd.c_str(), m_cmd.c_str())) 00065 return 2; 00066 if (!strncasecmp(cmd.c_str(), m_cmd.c_str(), cmd.size())) 00067 return 1; 00068 return 0; 00069 }
virtual void Command::Execute | ( | InSocket * | , | |
const std::string & | arg, | |||
Parse & | ||||
) | [pure virtual] |
void Command::OnLine | ( | InSocket * | , | |
const std::string & | line, | |||
int | state | |||
) | [virtual] |
virtual std::string Command::Category | ( | ) | [pure virtual] |
virtual std::string Command::Description | ( | ) | [inline, virtual] |
const std::string& Command::GetCommand | ( | ) | [inline] |
Definition at line 59 of file Command.h.
References m_cmd.
Referenced by Forward::Execute().
00059 { return m_cmd; }
char Command::GetCommandChar | ( | ) | [inline] |
Command * Command::GetCommandFromChar | ( | char | cc | ) | [static] |
Definition at line 72 of file Command.cpp.
References m_ccs.
Referenced by FutureHandler::DoCommand().
00073 { 00074 for (std::map<char,Command *>::iterator it = m_ccs.begin(); it != m_ccs.end(); it++) 00075 { 00076 if ((*it).first == cc) 00077 return (*it).second; 00078 } 00079 return NULL; 00080 }
bool Command::NeedWiz | ( | ) | [inline] |
std::string Command::m_cmd [private] |
char Command::m_cc [private] |
std::map< char, Command * > Command::m_ccs [static, private] |
strbool_m Command::m_args [private] |
Definition at line 70 of file Command.h.
Referenced by AddArgument(), CheckArgument(), and GetArguments().
bool Command::m_need_wiz [private] |