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 | |
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
-rw-r--r-- | docs/ChangeLog | 100 | ||||
-rw-r--r-- | include/channels.h | 26 | ||||
-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 |
7 files changed, 249 insertions, 27 deletions
diff --git a/docs/ChangeLog b/docs/ChangeLog index 085f93e01..5f0f5698b 100644 --- a/docs/ChangeLog +++ b/docs/ChangeLog @@ -1,3 +1,97 @@ +1.0 alpha 9.5 + +* Added support for /connect (no sync yet!) +* Added extra module support and improved api +* Improved developer docs, see http://www.inspircd.org/docs/ +* FINALLY fixed crash-on-disconnect bug +* Fixed many stability bugs +* Fixed length and buffer overrun issues that caused user records to become corrupted without crashes (!) + +1.0 alpha 9 + +* Added /WHOWAS +* Made ircd cache message of the day in a vector (faster!) +* Added support for multiple lines of /NAMES on large channels +* Added hostname/ip caching to speed up connects +* Added '/stats z' +* Added Server class +* Added more code to example module demonstrating use of Server class +* Added Admin class (holds /admin info for modules) +* Added methods to Server class +* Added m_cloaking.so module, provides host masking +* Added /AWAY +* added /ISON command (for mIRC etc basic notify) +* Added /USERS stub +* Added /SUMMON stub +* attemted to fix weird crash on /kill +* added pause= value to /die and /restart in config +* Attempted to fix closed client sessions not being detected +* Added wildcard support +* Added channel bans +* Changed user and channel structs to classes (finally) +* Fixed parameter error in QUIT code (was showing junk chars on BSD) +* fixed some ugly pointer bugs (thanks dblack and a|KK|y!) +* Added /INVITE command and relevent structures +* Added CONNECT ALLOW and CONNECT DENY config tags +* Added PASS command +* Fixed: /LUSERS cant count :P +* added /TRACE command +* Implemented channel mode +m +* Added channel modes, +k, +l, +i, +m etc +* Added user and channel modes +i, +p, +s +* Implemented usermode +s +* Fixed dodgy mode glitches (the ones Craig loves to play with, awww) +* Added code to tidy up bans (e.g. max nick length) - i blame mIRC! +* fixed multiple /MODE +l bugs (thanks to akky and BOFH bugging meh!) +* Fixed ident max length to 10 +* fixed random crash on kill_link (AGAIN) - was /stats +* improved speed 10x (because i can...) +* optimisations galore! +* Added FileReader file-caching class +* Changed m_randquote to use FileReader class +* Neater source tree (binaries in bin, source in src, headers in include, etc) +* Added /WHOWAS +* Tidied up makefiles +* Much nicer configure program +* makeconf program (very nice config maker by Craig) + + +1.0 alpha 8 + +* Added Admin class (holds /admin info for modules) +* Added methods to Server class +* Added m_cloaking.so module, provides host masking +* Added Server class +* Added more code to example module demonstrating use of Server class +* ./configure improved by Craig (better prompts, dir creation) +* /stats z added detail +* Added '/stats z' +* Added hostname/ip caching to speed up connects +* Made ircd cache message of the day in a vector (faster!) +* Added support for multiple lines of /NAMES on large channels + +1.0 alpha 7 + +* Added /USERHOST command +* Added '/STATS O' +* removed random debug output +* Fixed random crash on nickchange +* Fine tuned ability to handle >300 users +* added '/stats L' (connect-info) +* '/stats u' support added (server uptime) +* added '/stats M' command +* Added extra dynamic module support, new methods to Module class + +1.0 alpha 6 + +* Changed command table to a vector of command_t types +* Dynamix module support, preliminary release +* Fixes random crash on nickchange +* Fixed wallops and command parameter counting bugs +* fixed "user lingering" problem in kill_link +* updated example config +* developed a simple sample module (m_foobar.so) + 1.0 alpha 5 * Changed channel array to a hash_map similar to the one used for users, faster and more efficient @@ -47,3 +141,9 @@ * Fixed close() on nonblocking sockets problem * Added /KILL command >:) * Added /KICK command + +1.0 alpha 2 + +* addition of /oper and several Channel Modes. +* new config file format + diff --git a/include/channels.h b/include/channels.h index 9f97c3b8b..de629c399 100644 --- a/include/channels.h +++ b/include/channels.h @@ -7,6 +7,7 @@ #include "base.h" #include <time.h> #include <vector> +#include <string> #ifndef __CHANNELS_H__ #define __CHANNELS_H__ @@ -51,6 +52,18 @@ class InviteItem : public HostItem }; +/** Holds a custom parameter to a module-defined channel mode + * e.g. for +L this would hold the channel name. + */ + +class ModeParameter : public classbase +{ + public: + char mode; + char parameter[MAXBUF]; + char channel[CHANMAX]; +}; + /** Holds a complete ban list */ typedef std::vector<BanItem> BanList; @@ -77,6 +90,7 @@ class chanrec : public classbase * Plugins may use this field in any way they see fit. */ char custom_modes[MAXMODES]; /* modes handled by modules */ + /** Channel topic. * If this is an empty string, no channel topic is set. */ @@ -141,6 +155,18 @@ class chanrec : public classbase */ void SetCustomModeParam(char mode,char* parameter,bool mode_on); + /** Returns true if a custom mode is set on a channel + */ + bool IsCustomModeSet(char mode); + + /** Returns the parameter for a custom mode on a channel. + * For example if "+L #foo" is set, and you pass this method + * 'L', it will return '#foo'. If the mode is not set on the + * channel, or the mode has no parameters associated with it, + * it will return an empty string. + */ + std::string GetModeParameter(char mode); + /** Creates a channel record and initialises it with default values */ chanrec(); 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); } |