diff options
-rw-r--r-- | include/command_parse.h | 11 | ||||
-rw-r--r-- | include/helperfuncs.h | 2 | ||||
-rw-r--r-- | src/command_parse.cpp | 77 | ||||
-rw-r--r-- | src/commands.cpp | 11 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 74 | ||||
-rw-r--r-- | src/inspircd.cpp | 1 |
6 files changed, 92 insertions, 84 deletions
diff --git a/include/command_parse.h b/include/command_parse.h index 80d39af64..b199123ee 100644 --- a/include/command_parse.h +++ b/include/command_parse.h @@ -21,16 +21,25 @@ #include <iostream> #include <string> #include "users.h" +#include "ctables.h" +#include "typedefs.h" class CommandParser { + private: + int CommandParser::ProcessParameters(char **command_p,char *parameters); + void CommandParser::ProcessCommand(userrec *user, char* cmd); + void SetupCommandTable(); public: + command_table cmdlist; + + CommandParser(); void CallHandler(std::string &commandname,char **parameters, int pcnt, userrec *user); bool IsValidCommand(std::string &commandname, int pcnt, userrec * user); int LoopCall(handlerfunc fn, char **parameters, int pcnt, userrec *u, int start, int end, int joins); void ProcessBuffer(const char* cmdbuf,userrec *user); bool RemoveCommands(const char* source); - void CommandParser::ProcessCommand(userrec *user, char* cmd); + bool CreateCommand(char* cmd, handlerfunc f, char flags, int minparams,char* source); }; #endif diff --git a/include/helperfuncs.h b/include/helperfuncs.h index 8b0c06600..6b804c8c7 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -68,8 +68,6 @@ long local_count(); void ShowMOTD(userrec *user); void ShowRULES(userrec *user); bool AllModulesReportReady(userrec* user); -void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source); -void SetupCommandTable(void); bool DirValid(char* dirandfile); std::string GetFullProgDir(char** argv, int argc); diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 8d0752206..9e8a0f9f4 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -699,3 +699,80 @@ void CommandParser::ProcessBuffer(const char* cmdbuf,userrec *user) } } +void CommandParser::CreateCommand(char* cmd, handlerfunc f, char flags, int minparams,char* source) +{ + command_t comm; + /* create the command and push it onto the table */ + strlcpy(comm.command,cmd,MAXBUF); + strlcpy(comm.source,source,MAXBUF); + comm.handler_function = f; + comm.flags_needed = flags; + comm.min_params = minparams; + comm.use_count = 0; + comm.total_bytes = 0; + cmdlist.push_back(comm); + log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams); +} + +CommandParser::CommandParser() +{ + this->SetupCommandTable(); +} + +void CommandParser::SetupCommandTable() +{ + this->CreateCommand("USER",handle_user,0,4,"<core>"); + this->CreateCommand("NICK",handle_nick,0,1,"<core>"); + this->CreateCommand("QUIT",handle_quit,0,0,"<core>"); + this->CreateCommand("VERSION",handle_version,0,0,"<core>"); + this->CreateCommand("PING",handle_ping,0,1,"<core>"); + this->CreateCommand("PONG",handle_pong,0,1,"<core>"); + this->CreateCommand("ADMIN",handle_admin,0,0,"<core>"); + this->CreateCommand("PRIVMSG",handle_privmsg,0,2,"<core>"); + this->CreateCommand("INFO",handle_info,0,0,"<core>"); + this->CreateCommand("TIME",handle_time,0,0,"<core>"); + this->CreateCommand("WHOIS",handle_whois,0,1,"<core>"); + this->CreateCommand("WALLOPS",handle_wallops,'o',1,"<core>"); + this->CreateCommand("NOTICE",handle_notice,0,2,"<core>"); + this->CreateCommand("JOIN",handle_join,0,1,"<core>"); + this->CreateCommand("NAMES",handle_names,0,0,"<core>"); + this->CreateCommand("PART",handle_part,0,1,"<core>"); + this->CreateCommand("KICK",handle_kick,0,2,"<core>"); + this->CreateCommand("MODE",handle_mode,0,1,"<core>"); + this->CreateCommand("TOPIC",handle_topic,0,1,"<core>"); + this->CreateCommand("WHO",handle_who,0,1,"<core>"); + this->CreateCommand("MOTD",handle_motd,0,0,"<core>"); + this->CreateCommand("RULES",handle_rules,0,0,"<core>"); + this->CreateCommand("OPER",handle_oper,0,2,"<core>"); + this->CreateCommand("LIST",handle_list,0,0,"<core>"); + this->CreateCommand("DIE",handle_die,'o',1,"<core>"); + this->CreateCommand("RESTART",handle_restart,'o',1,"<core>"); + this->CreateCommand("KILL",handle_kill,'o',2,"<core>"); + this->CreateCommand("REHASH",handle_rehash,'o',0,"<core>"); + this->CreateCommand("LUSERS",handle_lusers,0,0,"<core>"); + this->CreateCommand("STATS",handle_stats,0,1,"<core>"); + this->CreateCommand("USERHOST",handle_userhost,0,1,"<core>"); + this->CreateCommand("AWAY",handle_away,0,0,"<core>"); + this->CreateCommand("ISON",handle_ison,0,0,"<core>"); + this->CreateCommand("SUMMON",handle_summon,0,0,"<core>"); + this->CreateCommand("USERS",handle_users,0,0,"<core>"); + this->CreateCommand("INVITE",handle_invite,0,0,"<core>"); + this->CreateCommand("PASS",handle_pass,0,1,"<core>"); + this->CreateCommand("TRACE",handle_trace,'o',0,"<core>"); + this->CreateCommand("WHOWAS",handle_whowas,0,1,"<core>"); + this->CreateCommand("CONNECT",handle_connect,'o',1,"<core>"); + this->CreateCommand("SQUIT",handle_squit,'o',0,"<core>"); + this->CreateCommand("MODULES",handle_modules,0,0,"<core>"); + this->CreateCommand("LINKS",handle_links,0,0,"<core>"); + this->CreateCommand("MAP",handle_map,0,0,"<core>"); + this->CreateCommand("KLINE",handle_kline,'o',1,"<core>"); + this->CreateCommand("GLINE",handle_gline,'o',1,"<core>"); + this->CreateCommand("ZLINE",handle_zline,'o',1,"<core>"); + this->CreateCommand("QLINE",handle_qline,'o',1,"<core>"); + this->CreateCommand("ELINE",handle_eline,'o',1,"<core>"); + this->CreateCommand("LOADMODULE",handle_loadmodule,'o',1,"<core>"); + this->CreateCommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>"); + this->CreateCommand("SERVER",handle_server,0,0,"<core>"); + this->CreateCommand("COMMANDS",handle_commands,0,0,"<core>"); +} + diff --git a/src/commands.cpp b/src/commands.cpp index 7709c94e0..ca06e5ead 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -82,7 +82,6 @@ const long duration_y = duration_w * 52; extern user_hash clientlist; extern chan_hash chanlist; extern whowas_hash whowas; -extern command_table cmdlist; extern std::vector<userrec*> all_opers; extern std::vector<userrec*> local_users; @@ -1402,14 +1401,14 @@ void handle_stats(char **parameters, int pcnt, userrec *user) /* stats m (list number of times each command has been used, plus bytecount) */ if (*parameters[0] == 'm') { - for (unsigned int i = 0; i < cmdlist.size(); i++) + for (unsigned int i = 0; i < Parser->cmdlist.size(); i++) { - if (cmdlist[i].handler_function) + if (Parser->cmdlist[i].handler_function) { - if (cmdlist[i].use_count) + if (Parser->cmdlist[i].use_count) { /* RPL_STATSCOMMANDS */ - WriteServ(user->fd,"212 %s %s %d %d",user->nick,cmdlist[i].command,cmdlist[i].use_count,cmdlist[i].total_bytes); + WriteServ(user->fd,"212 %s %s %d %d",user->nick,Parser->cmdlist[i].command,Parser->cmdlist[i].use_count,Parser->cmdlist[i].total_bytes); } } } @@ -1422,7 +1421,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) rusage R; WriteServ(user->fd,"249 %s :Users(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,clientlist.size(),clientlist.size()*sizeof(userrec),clientlist.bucket_count()); WriteServ(user->fd,"249 %s :Channels(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,chanlist.size(),chanlist.size()*sizeof(chanrec),chanlist.bucket_count()); - WriteServ(user->fd,"249 %s :Commands(VECTOR) %d (%d bytes)",user->nick,cmdlist.size(),cmdlist.size()*sizeof(command_t)); + WriteServ(user->fd,"249 %s :Commands(VECTOR) %d (%d bytes)",user->nick,Parser->cmdlist.size(),Parser->cmdlist.size()*sizeof(command_t)); WriteServ(user->fd,"249 %s :MOTD(VECTOR) %d, RULES(VECTOR) %d",user->nick,Config->MOTD.size(),Config->RULES.size()); WriteServ(user->fd,"249 %s :Modules(VECTOR) %d (%d)",user->nick,modules.size(),modules.size()*sizeof(Module)); WriteServ(user->fd,"249 %s :ClassFactories(VECTOR) %d (%d)",user->nick,factory.size(),factory.size()*sizeof(ircd_module)); diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index b47d7a1af..3e188ee88 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -61,7 +61,6 @@ static char already_sent[65536]; extern std::vector<userrec*> all_opers; extern user_hash clientlist; extern chan_hash chanlist; -extern command_table cmdlist; extern Module* IOHookModule; void log(int level,char *text, ...) @@ -1104,79 +1103,6 @@ bool AllModulesReportReady(userrec* user) return true; } -void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source) -{ - command_t comm; - /* create the command and push it onto the table */ - strlcpy(comm.command,cmd,MAXBUF); - strlcpy(comm.source,source,MAXBUF); - comm.handler_function = f; - comm.flags_needed = flags; - comm.min_params = minparams; - comm.use_count = 0; - comm.total_bytes = 0; - cmdlist.push_back(comm); - log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams); -} - - -void SetupCommandTable(void) -{ - createcommand("USER",handle_user,0,4,"<core>"); - createcommand("NICK",handle_nick,0,1,"<core>"); - createcommand("QUIT",handle_quit,0,0,"<core>"); - createcommand("VERSION",handle_version,0,0,"<core>"); - createcommand("PING",handle_ping,0,1,"<core>"); - createcommand("PONG",handle_pong,0,1,"<core>"); - createcommand("ADMIN",handle_admin,0,0,"<core>"); - createcommand("PRIVMSG",handle_privmsg,0,2,"<core>"); - createcommand("INFO",handle_info,0,0,"<core>"); - createcommand("TIME",handle_time,0,0,"<core>"); - createcommand("WHOIS",handle_whois,0,1,"<core>"); - createcommand("WALLOPS",handle_wallops,'o',1,"<core>"); - createcommand("NOTICE",handle_notice,0,2,"<core>"); - createcommand("JOIN",handle_join,0,1,"<core>"); - createcommand("NAMES",handle_names,0,0,"<core>"); - createcommand("PART",handle_part,0,1,"<core>"); - createcommand("KICK",handle_kick,0,2,"<core>"); - createcommand("MODE",handle_mode,0,1,"<core>"); - createcommand("TOPIC",handle_topic,0,1,"<core>"); - createcommand("WHO",handle_who,0,1,"<core>"); - createcommand("MOTD",handle_motd,0,0,"<core>"); - createcommand("RULES",handle_rules,0,0,"<core>"); - createcommand("OPER",handle_oper,0,2,"<core>"); - createcommand("LIST",handle_list,0,0,"<core>"); - createcommand("DIE",handle_die,'o',1,"<core>"); - createcommand("RESTART",handle_restart,'o',1,"<core>"); - createcommand("KILL",handle_kill,'o',2,"<core>"); - createcommand("REHASH",handle_rehash,'o',0,"<core>"); - createcommand("LUSERS",handle_lusers,0,0,"<core>"); - createcommand("STATS",handle_stats,0,1,"<core>"); - createcommand("USERHOST",handle_userhost,0,1,"<core>"); - createcommand("AWAY",handle_away,0,0,"<core>"); - createcommand("ISON",handle_ison,0,0,"<core>"); - createcommand("SUMMON",handle_summon,0,0,"<core>"); - createcommand("USERS",handle_users,0,0,"<core>"); - createcommand("INVITE",handle_invite,0,0,"<core>"); - createcommand("PASS",handle_pass,0,1,"<core>"); - createcommand("TRACE",handle_trace,'o',0,"<core>"); - createcommand("WHOWAS",handle_whowas,0,1,"<core>"); - createcommand("CONNECT",handle_connect,'o',1,"<core>"); - createcommand("SQUIT",handle_squit,'o',0,"<core>"); - createcommand("MODULES",handle_modules,0,0,"<core>"); - createcommand("LINKS",handle_links,0,0,"<core>"); - createcommand("MAP",handle_map,0,0,"<core>"); - createcommand("KLINE",handle_kline,'o',1,"<core>"); - createcommand("GLINE",handle_gline,'o',1,"<core>"); - createcommand("ZLINE",handle_zline,'o',1,"<core>"); - createcommand("QLINE",handle_qline,'o',1,"<core>"); - createcommand("ELINE",handle_eline,'o',1,"<core>"); - createcommand("LOADMODULE",handle_loadmodule,'o',1,"<core>"); - createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>"); - createcommand("SERVER",handle_server,0,0,"<core>"); - createcommand("COMMANDS",handle_commands,0,0,"<core>"); -} - bool DirValid(char* dirandfile) { char work[MAXBUF]; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 38f35aa39..aee1666d0 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -97,7 +97,6 @@ CommandParser *Parser = new CommandParser; user_hash clientlist; chan_hash chanlist; whowas_hash whowas; -command_table cmdlist; servernamelist servernames; char lowermap[255]; |