From ec126582ac8a9c63adb9fa9d47033ef0511ec4e3 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 16 Dec 2005 10:38:28 +0000 Subject: [PATCH] Moved more command parsing stuff to CommandParser git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2514 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/command_parse.h | 11 +++++- include/helperfuncs.h | 2 -- src/command_parse.cpp | 77 +++++++++++++++++++++++++++++++++++++++++ src/commands.cpp | 11 +++--- src/helperfuncs.cpp | 74 --------------------------------------- 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 #include #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,""); + this->CreateCommand("NICK",handle_nick,0,1,""); + this->CreateCommand("QUIT",handle_quit,0,0,""); + this->CreateCommand("VERSION",handle_version,0,0,""); + this->CreateCommand("PING",handle_ping,0,1,""); + this->CreateCommand("PONG",handle_pong,0,1,""); + this->CreateCommand("ADMIN",handle_admin,0,0,""); + this->CreateCommand("PRIVMSG",handle_privmsg,0,2,""); + this->CreateCommand("INFO",handle_info,0,0,""); + this->CreateCommand("TIME",handle_time,0,0,""); + this->CreateCommand("WHOIS",handle_whois,0,1,""); + this->CreateCommand("WALLOPS",handle_wallops,'o',1,""); + this->CreateCommand("NOTICE",handle_notice,0,2,""); + this->CreateCommand("JOIN",handle_join,0,1,""); + this->CreateCommand("NAMES",handle_names,0,0,""); + this->CreateCommand("PART",handle_part,0,1,""); + this->CreateCommand("KICK",handle_kick,0,2,""); + this->CreateCommand("MODE",handle_mode,0,1,""); + this->CreateCommand("TOPIC",handle_topic,0,1,""); + this->CreateCommand("WHO",handle_who,0,1,""); + this->CreateCommand("MOTD",handle_motd,0,0,""); + this->CreateCommand("RULES",handle_rules,0,0,""); + this->CreateCommand("OPER",handle_oper,0,2,""); + this->CreateCommand("LIST",handle_list,0,0,""); + this->CreateCommand("DIE",handle_die,'o',1,""); + this->CreateCommand("RESTART",handle_restart,'o',1,""); + this->CreateCommand("KILL",handle_kill,'o',2,""); + this->CreateCommand("REHASH",handle_rehash,'o',0,""); + this->CreateCommand("LUSERS",handle_lusers,0,0,""); + this->CreateCommand("STATS",handle_stats,0,1,""); + this->CreateCommand("USERHOST",handle_userhost,0,1,""); + this->CreateCommand("AWAY",handle_away,0,0,""); + this->CreateCommand("ISON",handle_ison,0,0,""); + this->CreateCommand("SUMMON",handle_summon,0,0,""); + this->CreateCommand("USERS",handle_users,0,0,""); + this->CreateCommand("INVITE",handle_invite,0,0,""); + this->CreateCommand("PASS",handle_pass,0,1,""); + this->CreateCommand("TRACE",handle_trace,'o',0,""); + this->CreateCommand("WHOWAS",handle_whowas,0,1,""); + this->CreateCommand("CONNECT",handle_connect,'o',1,""); + this->CreateCommand("SQUIT",handle_squit,'o',0,""); + this->CreateCommand("MODULES",handle_modules,0,0,""); + this->CreateCommand("LINKS",handle_links,0,0,""); + this->CreateCommand("MAP",handle_map,0,0,""); + this->CreateCommand("KLINE",handle_kline,'o',1,""); + this->CreateCommand("GLINE",handle_gline,'o',1,""); + this->CreateCommand("ZLINE",handle_zline,'o',1,""); + this->CreateCommand("QLINE",handle_qline,'o',1,""); + this->CreateCommand("ELINE",handle_eline,'o',1,""); + this->CreateCommand("LOADMODULE",handle_loadmodule,'o',1,""); + this->CreateCommand("UNLOADMODULE",handle_unloadmodule,'o',1,""); + this->CreateCommand("SERVER",handle_server,0,0,""); + this->CreateCommand("COMMANDS",handle_commands,0,0,""); +} + 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 all_opers; extern std::vector 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 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,""); - createcommand("NICK",handle_nick,0,1,""); - createcommand("QUIT",handle_quit,0,0,""); - createcommand("VERSION",handle_version,0,0,""); - createcommand("PING",handle_ping,0,1,""); - createcommand("PONG",handle_pong,0,1,""); - createcommand("ADMIN",handle_admin,0,0,""); - createcommand("PRIVMSG",handle_privmsg,0,2,""); - createcommand("INFO",handle_info,0,0,""); - createcommand("TIME",handle_time,0,0,""); - createcommand("WHOIS",handle_whois,0,1,""); - createcommand("WALLOPS",handle_wallops,'o',1,""); - createcommand("NOTICE",handle_notice,0,2,""); - createcommand("JOIN",handle_join,0,1,""); - createcommand("NAMES",handle_names,0,0,""); - createcommand("PART",handle_part,0,1,""); - createcommand("KICK",handle_kick,0,2,""); - createcommand("MODE",handle_mode,0,1,""); - createcommand("TOPIC",handle_topic,0,1,""); - createcommand("WHO",handle_who,0,1,""); - createcommand("MOTD",handle_motd,0,0,""); - createcommand("RULES",handle_rules,0,0,""); - createcommand("OPER",handle_oper,0,2,""); - createcommand("LIST",handle_list,0,0,""); - createcommand("DIE",handle_die,'o',1,""); - createcommand("RESTART",handle_restart,'o',1,""); - createcommand("KILL",handle_kill,'o',2,""); - createcommand("REHASH",handle_rehash,'o',0,""); - createcommand("LUSERS",handle_lusers,0,0,""); - createcommand("STATS",handle_stats,0,1,""); - createcommand("USERHOST",handle_userhost,0,1,""); - createcommand("AWAY",handle_away,0,0,""); - createcommand("ISON",handle_ison,0,0,""); - createcommand("SUMMON",handle_summon,0,0,""); - createcommand("USERS",handle_users,0,0,""); - createcommand("INVITE",handle_invite,0,0,""); - createcommand("PASS",handle_pass,0,1,""); - createcommand("TRACE",handle_trace,'o',0,""); - createcommand("WHOWAS",handle_whowas,0,1,""); - createcommand("CONNECT",handle_connect,'o',1,""); - createcommand("SQUIT",handle_squit,'o',0,""); - createcommand("MODULES",handle_modules,0,0,""); - createcommand("LINKS",handle_links,0,0,""); - createcommand("MAP",handle_map,0,0,""); - createcommand("KLINE",handle_kline,'o',1,""); - createcommand("GLINE",handle_gline,'o',1,""); - createcommand("ZLINE",handle_zline,'o',1,""); - createcommand("QLINE",handle_qline,'o',1,""); - createcommand("ELINE",handle_eline,'o',1,""); - createcommand("LOADMODULE",handle_loadmodule,'o',1,""); - createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,""); - createcommand("SERVER",handle_server,0,0,""); - createcommand("COMMANDS",handle_commands,0,0,""); -} - 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]; -- 2.39.5