]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added more code for custom channel/user modes via modules
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 19 Apr 2003 12:41:44 +0000 (12:41 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 19 Apr 2003 12:41:44 +0000 (12:41 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@175 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
include/modules.h
src/InspIRCd.dev
src/InspIRCd.layout
src/Makefile.FreeBSD
src/Makefile.Linux
src/channels.cpp [new file with mode: 0644]
src/inspircd.cpp
src/modules.cpp

index ffa98403392cde5a83d9c9cbbadcbf62f843779f..a800c73a97e2fc5469dc53ec0605c4b7a209df07 100644 (file)
@@ -133,18 +133,17 @@ class chanrec : public classbase
         */
        BanList bans;
 
+       /** Sets or unsets a custom mode in the channels info
+        */
+       SetCustomMode(char mode,bool mode_on);
+
+       /** Sets or unsets the parameterrs for a custom mode in a channels info
+        */
+       SetCustomModeParam(char mode,char* parameter,bool mode_on);
        /** Creates a channel record and initialises it with default values
         */
-       chanrec()
-       {
-               strcpy(name,"");
-               strcpy(custom_modes,"");
-               strcpy(topic,"");
-               strcpy(setby,"");
-               strcpy(key,"");
-               created = topicset = limit = 0;
-               topiclock = noexternal = inviteonly = moderated = secret = c_private = false;
-       }
+       chanrec();
 
        virtual ~chanrec() { /* stub */ }
 };
index 378c7ba31d62aa7156a5aa10470020a1e451583f..9a1c4cfef51c6a5ceb95d6393b79f9bc00038543 100644 (file)
@@ -145,8 +145,9 @@ class Module : public classbase
         * parameters for the mode as strings. If mode_on is false, the mode is being removed, and parameters
         * may contain the parameters for the mode, dependent on wether they were defined when a mode handler
         * was set up with Server::AddExtendedMode
+        * If the mode is not a channel mode, chanrec* chan is null, and should not be read from or written to.
         */
-       virtual bool OnExtendedMode(char modechar, int type, bool mode_on, string_list &params);
+       virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params);
         
 };
 
@@ -265,7 +266,9 @@ class Server : public classbase
         * use this parameter. The function returns false if the mode is unavailable, and will not
         * attempt to allocate another character, as this will confuse users. This also means that
         * as only one module can claim a specific mode character, the core does not need to keep track
-        * of which modules own which modes, which speeds up operation of the server.
+        * of which modules own which modes, which speeds up operation of the server. In this version,
+        * a mode can have at most one parameter, attempting to use more parameters will have undefined
+        * effects.
         */
        virtual bool AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off);
         
index 158897e8b498b503539b693bd66ae56f7612532f..df23f865d4dd1d4164dbb84cc0ec2a63ecea6010 100644 (file)
@@ -1,7 +1,7 @@
 [Project]
 FileName=InspIRCd.dev
 Name=InspIRCd
-UnitCount=25
+UnitCount=26
 Type=1
 Ver=1
 ObjFiles=
@@ -244,3 +244,11 @@ CompileCpp=1
 OverrideBuildCmd=0
 BuildCmd=
 
+[Unit26]
+FileName=channels.cpp
+Folder=Source
+Compile=1
+CompileCpp=1
+OverrideBuildCmd=0
+BuildCmd=
+
index d220c38d24930d344690429240b98c172b982e11..4f5a21d68b6f95386ad023df414884f0cb96c5d7 100644 (file)
@@ -1,6 +1,6 @@
 [Editors]
-Focused=1
-Order=1,7,3,2,0,6,5,4,-1
+Focused=25
+Order=1,7,3,2,0,6,5,4,-1,25
 
 [Editor_0]
 Open=1
@@ -12,10 +12,10 @@ LeftChar=1
 
 [Editor_1]
 Open=1
-Top=1
-CursorCol=1
-CursorRow=3902
-TopLine=3851
+Top=0
+CursorCol=11
+CursorRow=1918
+TopLine=1871
 LeftChar=1
 
 [Editor_2]
@@ -37,8 +37,8 @@ LeftChar=1
 [Editor_4]
 Open=1
 Top=0
-CursorCol=51
-CursorRow=36
+CursorCol=19
+CursorRow=59
 TopLine=1
 LeftChar=1
 
@@ -54,7 +54,7 @@ LeftChar=1
 Open=1
 Top=0
 CursorCol=1
-CursorRow=1
+CursorRow=9
 TopLine=1
 LeftChar=1
 
@@ -99,11 +99,11 @@ TopLine=1
 LeftChar=1
 
 [Editor_12]
-Open=0
+Open=1
 Top=0
 CursorCol=1
-CursorRow=1
-TopLine=1
+CursorRow=142
+TopLine=120
 LeftChar=1
 
 [Editor_13]
@@ -139,11 +139,11 @@ TopLine=1
 LeftChar=1
 
 [Editor_17]
-Open=0
+Open=1
 Top=0
-CursorCol=9
-CursorRow=60
-TopLine=30
+CursorCol=1
+CursorRow=1
+TopLine=1
 LeftChar=1
 
 [Editor_18]
@@ -165,10 +165,10 @@ LeftChar=1
 [Editor_20]
 Open=1
 Top=0
-CursorCol=68
-CursorRow=135
-TopLine=94
-LeftChar=3
+CursorCol=13
+CursorRow=271
+TopLine=232
+LeftChar=1
 
 [Editor_21]
 Open=0
@@ -179,11 +179,11 @@ TopLine=1
 LeftChar=1
 
 [Editor_22]
-Open=0
+Open=1
 Top=0
 CursorCol=1
 CursorRow=1
-TopLine=1
+TopLine=35
 LeftChar=1
 
 [Editor_23]
@@ -201,3 +201,10 @@ CursorCol=1
 CursorRow=1
 TopLine=1
 LeftChar=1
+[Editor_25]
+Open=1
+Top=1
+CursorCol=1
+CursorRow=26
+TopLine=1
+LeftChar=1
index 8e8bdce4d81eef724ea0ac8b337d0d8987badf11..981b075f7b51ebd40080679b784dfa153e28eb1f 100644 (file)
@@ -8,7 +8,7 @@
 CC = im a cheezeball
 
 SRC_1 = inspircd.cpp inspircd_util.cpp inspircd_io.cpp connection.cpp
-SRC_2 = dynamic.cpp users.cpp modules.cpp wildcard.cpp servers.cpp
+SRC_2 = dynamic.cpp users.cpp modules.cpp wildcard.cpp servers.cpp channels.cpp
 
 SRC = $(SRC_1) $(SRC_2)
 OBJS = $(SRC:.cpp=.o)
index 8e8bdce4d81eef724ea0ac8b337d0d8987badf11..981b075f7b51ebd40080679b784dfa153e28eb1f 100644 (file)
@@ -8,7 +8,7 @@
 CC = im a cheezeball
 
 SRC_1 = inspircd.cpp inspircd_util.cpp inspircd_io.cpp connection.cpp
-SRC_2 = dynamic.cpp users.cpp modules.cpp wildcard.cpp servers.cpp
+SRC_2 = dynamic.cpp users.cpp modules.cpp wildcard.cpp servers.cpp channels.cpp
 
 SRC = $(SRC_1) $(SRC_2)
 OBJS = $(SRC:.cpp=.o)
diff --git a/src/channels.cpp b/src/channels.cpp
new file mode 100644 (file)
index 0000000..2a9a354
--- /dev/null
@@ -0,0 +1,26 @@
+#include "inspircd_config.h" 
+#include "channels.h"
+#include "inspircd.h"
+#include <stdio.h>
+
+chanrec::chanrec()
+{
+       strcpy(name,"");
+       strcpy(custom_modes,"");
+       strcpy(topic,"");
+       strcpy(setby,"");
+       strcpy(key,"");
+       created = topicset = limit = 0;
+       topiclock = noexternal = inviteonly = moderated = secret = c_private = false;
+}
+
+chanrec::SetCustomMode(char mode,bool mode_on)
+{
+}
+
+chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
+{
+}
+
+
+
index 621ca21c5f8498c5d6015d3f50e887c4b9c68cc2..79e3c8b736da6cc36ca81622ce98aee4facf3f5a 100644 (file)
@@ -1892,6 +1892,37 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                        chan->c_private = mdir;
                                break;
                                
+                               default:
+                                       string_list p;
+                                       p.clear();
+                                       if (ModeDefined(modelist[ptr],MT_CHANNEL))
+                                       {
+                                               if ((ModeDefinedOn(modelist[ptr],MT_CHANNEL)>0) && (mdir))
+                                               {
+                                               p.push_back(parameters[param]);
+                                               }
+                                               if ((ModeDefinedOff(modelist[ptr],MT_CHANNEL)>0) && (!mdir))
+                                               {
+                                               p.push_back(parameters[param]);
+                                               }
+                                               for (int i = 0; i <= MODCOUNT; i++)
+                                       {
+                                               if (modules[i]->OnExtendedMode(user,chan,modechar,MT_CHANNEL,mdir,p))
+                                               {
+                                                       strcat(outlist,modelist[ptr]);
+                                                               chan->SetCustomMode(modelist[ptr],mdir);
+                                                               // include parameters in output if mode has them
+                                                               if ((ModeDefinedOn(modelist[ptr],MT_CHANNEL)>0) ||
+                                                                  (ModeDefinedOff(modelist[ptr],MT_CHANNEL)>0))
+                                                               {
+                                                                       chan->SetCustomModeParam(modelist[ptr],parameters[param],mdir);
+                                       strcpy(outpars[pc++],parameters[param++]);
+                               }
+                                               }
+                                       }
+                               }
+                               break;
+                               
                        }
                }
        }
index 4452f0423a84c6e7305cec44010c92303e6b12d4..34c9bf125e6709985dfffdb4f7e5455f247f7951 100644 (file)
 #include "modules.h"
 #include "inspircd_io.h"
 
+// class type for holding an extended mode character - internal to core
+
+class ExtMode
+{
+public:
+       char modechar;
+       int type;
+       bool default_on;
+       int params_when_on;
+       int params_when_off;
+       void SetInfo(char mc, int ty, bool d_on, int p_on, int p_off) : modechar(mc), type(ty), default_on(d_on), params_when_on(p_on), params_when_off(p_off) { };
+};                                     
+
+typedef vector<ExtMode> ExtModeList;
+typedef ExtModeList::iterator ExtModeListIter;
+
+ExtModeList EMode;
+
+// returns true if an extended mode character is in use
+bool ModeDefined(char modechar, int type)
+{
+       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
+       {
+               if ((i->modechar == modechar) && (i->type == type))
+               {
+                       return true;
+               }
+       }
+       return false;
+}
+
+// returns number of parameters for a custom mode when it is switched on
+int ModeDefinedOn(char modechar, int type)
+{
+       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
+       {
+               if ((i->modechar == modechar) && (i->type == type))
+               {
+                       return i->params_when_on;
+               }
+       }
+       return 0;
+}
+
+// returns number of parameters for a custom mode when it is switched on
+int ModeDefinedOff(char modechar, int type)
+{
+       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
+       {
+               if ((i->modechar == modechar) && (i->type == type))
+               {
+                       return i->params_when_off;
+               }
+       }
+       return 0;
+}
+
+// returns true if an extended mode character is in use
+bool AddExtendedMode(char modechar, int type, bool default_on, int params_on, int params_off)
+{
+       ExtMode Mode;
+       Mode.SetInfo(modechar,type,default_on,params_on,params_off);
+       EMode.push_back(Mode);
+       return true;
+}
+
+
 // version is a simple class for holding a modules version number
 
 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
@@ -34,7 +101,7 @@ void Module::OnPacketTransmit(char *p) { }
 void Module::OnPacketReceive(char *p) { }
 void Module::OnRehash() { }
 void Module::OnServerRaw(string &raw, bool inbound) { }
-bool Module::OnExtendedMode(char modechar, int type, bool mode_on, string_list &params) { }
+bool Module::OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params) { }
 Version Module::GetVersion() { return Version(1,0,0,0); }
 
 // server is a wrapper class that provides methods to all of the C-style
@@ -150,22 +217,23 @@ Admin Server::GetAdmin()
 }
 
 
-ConfigReader::ConfigReader()
+
+bool Server::AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off)
 {
-       fname = CONFIG_FILE;
 }
 
 
-ConfigReader::~ConfigReader()
+ConfigReader::ConfigReader()
 {
+       fname = CONFIG_FILE;
 }
 
 
-bool Server::AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off)
+ConfigReader::~ConfigReader()
 {
 }
 
+
 ConfigReader::ConfigReader(string filename) : fname(filename) { };
 
 string ConfigReader::ReadValue(string tag, string name, int index)