diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-04 13:41:01 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-04 13:41:01 +0000 |
commit | e9a6ab44bf17e5fe61d76964b9cb09d42f0d627c (patch) | |
tree | 1ec8f417d0e102f00d42bf4cf4957f849fc32f61 /src | |
parent | 6d853575a51230b5b8905933423ed8cd94058435 (diff) |
Added support for module-based chanmodes with parameters and the ability to query the mode states.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@374 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/InspIRCd.layout | 28 | ||||
-rw-r--r-- | src/channels.cpp | 50 | ||||
-rw-r--r-- | src/inspircd.cpp | 51 | ||||
-rw-r--r-- | src/inspircd_io.cpp | 6 | ||||
-rw-r--r-- | src/modules.cpp | 15 |
5 files changed, 123 insertions, 27 deletions
diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index f7ca3b7c0..00d38f213 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -13,16 +13,16 @@ LeftChar=1 [Editor_1] Open=1 Top=1 -CursorCol=33 -CursorRow=4922 -TopLine=4883 +CursorCol=1 +CursorRow=2300 +TopLine=2255 LeftChar=1 [Editor_2] Open=1 Top=0 CursorCol=1 -CursorRow=87 +CursorRow=43 TopLine=1 LeftChar=1 @@ -39,7 +39,7 @@ Open=1 Top=0 CursorCol=1 CursorRow=88 -TopLine=60 +TopLine=219 LeftChar=1 [Editor_5] @@ -101,9 +101,9 @@ LeftChar=1 [Editor_12] Open=1 Top=0 -CursorCol=17 -CursorRow=79 -TopLine=69 +CursorCol=1 +CursorRow=93 +TopLine=58 LeftChar=1 [Editor_13] @@ -204,14 +204,14 @@ LeftChar=1 [Editor_25] Open=1 Top=0 -CursorCol=1 -CursorRow=37 -TopLine=1 +CursorCol=2 +CursorRow=62 +TopLine=17 LeftChar=1 [Editor_26] Open=1 Top=0 -CursorCol=1 -CursorRow=71 -TopLine=32 +CursorCol=48 +CursorRow=58 +TopLine=14 LeftChar=1 diff --git a/src/channels.cpp b/src/channels.cpp index afa748f08..f6658db95 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -2,6 +2,7 @@ #include "channels.h" #include "inspircd.h" #include <stdio.h> +#include <string> chanrec::chanrec() { @@ -40,9 +41,56 @@ void chanrec::SetCustomMode(char mode,bool mode_on) } } +vector<ModeParameter> custom_mode_params; + void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on) { -} + log(DEBUG,"SetCustomModeParam called"); + ModeParameter M; + M.mode = mode; + strcpy(M.channel,this->name); + strcpy(M.parameter,parameter); + if (mode_on) + { + log(DEBUG,"Custom mode parameter %c %s added",mode,parameter); + custom_mode_params.push_back(M); + } + else + { + if (custom_mode_params.size()) + { + for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++) + { + if ((i->mode == mode) && (!strcasecmp(this->name,i->channel))) + { + log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter); + custom_mode_params.erase(i); + return; + } + } + } + log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!"); + } +} +bool chanrec::IsCustomModeSet(char mode) +{ + log(DEBUG,"Checking ISCustomModeSet: %c %s",mode,this->custom_modes); + return (strchr(this->custom_modes,mode) != 0); +} +std::string chanrec::GetModeParameter(char mode) +{ + if (custom_mode_params.size()) + { + for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++) + { + if ((i->mode == mode) && (!strcasecmp(this->name,i->channel))) + { + return std::string(i->parameter); + } + } + } + return std::string(""); +} diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 590daea9d..f66f4fc74 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2003 ChatSpike-Dev. + * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. * E-mail: * <brain@chatspike.net> * <Craig@chatspike.net> @@ -1248,7 +1248,7 @@ chanrec* add_channel(userrec *user, char* cname, char* key) log(DEBUG,"add_channel: %s %s",user->nick,cname); - if ((has_channel(user,FindChan(cname))) && (FindChan(cname))) + if ((FindChan(cname)) && (has_channel(user,FindChan(cname)))) { return NULL; // already on the channel! } @@ -2086,6 +2086,7 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int } break; + case 'k': if ((param >= pcnt)) break; @@ -2098,18 +2099,31 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int if (!strcmp(chan->key,"")) { strcat(outlist,"k"); - strcpy(outpars[pc++],parameters[param++]); - strcpy(chan->key,parameters[param-1]); + char key[MAXBUF]; + strcpy(key,parameters[param++]); + if (strlen(key)>32) { + key[31] = '\0'; + } + strcpy(outpars[pc++],key); + strcpy(chan->key,key); k_set = true; } } else { + /* checks on -k are case sensitive and only accurate to the + first 32 characters */ + char key[MAXBUF]; + strcpy(key,parameters[param++]); + if (strlen(key)>32) { + key[31] = '\0'; + } /* only allow -k if correct key given */ - if (strcmp(chan->key,"")) + if (!strcmp(chan->key,key)) { strcat(outlist,"k"); strcpy(chan->key,""); + strcpy(outpars[pc++],key); } } break; @@ -2240,15 +2254,28 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int if (ModeDefined(modechar,MT_CHANNEL)) { log(DEBUG,"A module has claimed this mode"); - if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir)) + if (param<pcnt) { - p.push_back(parameters[param]); - } - if ((ModeDefinedOff(modechar,MT_CHANNEL)>0) && (!mdir)) - { - p.push_back(parameters[param]); + if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir)) + { + p.push_back(parameters[param]); + } + if ((ModeDefinedOff(modechar,MT_CHANNEL)>0) && (!mdir)) + { + p.push_back(parameters[param]); + } } bool handled = false; + if (param>=pcnt) + { + log(DEBUG,"Not enough parameters for module-mode %c",modechar); + // we're supposed to have a parameter, but none was given... so dont handle the mode. + if (((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(modechar,MT_CHANNEL)>0) && (!mdir))) + { + handled = true; + param++; + } + } for (int i = 0; i <= MODCOUNT; i++) { if (!handled) @@ -2270,7 +2297,7 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int } chan->SetCustomMode(modechar,mdir); // include parameters in output if mode has them - if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) || (ModeDefinedOff(modechar,MT_CHANNEL)>0)) + if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir)) { chan->SetCustomModeParam(modelist[ptr],parameters[param],mdir); strcpy(outpars[pc++],parameters[param++]); diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index 0fd69d5e0..11471538d 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -24,16 +24,22 @@ #include "inspircd_io.h" #include "inspircd_util.h" +extern FILE *log_file; + void WriteOpers(char* text, ...); void Exit (int status) { + if (log_file) + fclose(log_file); send_error("Server shutdown."); exit (status); } void Killed(int status) { + if (log_file) + fclose(log_file); send_error("Server terminated."); exit(status); } diff --git a/src/modules.cpp b/src/modules.cpp index fe4b69315..8e591ba0c 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -229,6 +229,21 @@ Admin Server::GetAdmin() bool Server::AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off) { + if (type == MT_SERVER) + { + log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion"); + return false; + } + if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT)) + { + log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported"); + return false; + } + if ((params_when_on>1) || (params_when_off>1)) + { + log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported"); + return false; + } return DoAddExtendedMode(modechar,type,default_on,params_when_on,params_when_off); } |