summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/InspIRCd.layout60
-rw-r--r--src/channels.cpp22
-rw-r--r--src/inspircd.cpp90
-rw-r--r--src/modules.cpp15
-rw-r--r--src/modules/m_testcommand.cpp25
5 files changed, 156 insertions, 56 deletions
diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout
index b762b7480..48ccce82f 100644
--- a/src/InspIRCd.layout
+++ b/src/InspIRCd.layout
@@ -1,9 +1,9 @@
[Editors]
Focused=1
-Order=7,3,2,0,6,5,4,25,24,-1,1
+Order=7,3,2,6,25,24,-1,1,4,5
[Editor_0]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
@@ -13,10 +13,10 @@ LeftChar=1
[Editor_1]
Open=1
Top=1
-CursorCol=14
-CursorRow=2883
-TopLine=2857
-LeftChar=1
+CursorCol=16
+CursorRow=2043
+TopLine=1993
+LeftChar=19
[Editor_2]
Open=1
@@ -37,9 +37,9 @@ LeftChar=1
[Editor_4]
Open=1
Top=0
-CursorCol=14
-CursorRow=128
-TopLine=77
+CursorCol=9
+CursorRow=232
+TopLine=198
LeftChar=1
[Editor_5]
@@ -83,7 +83,7 @@ TopLine=1
LeftChar=1
[Editor_10]
-Open=0
+Open=1
Top=0
CursorCol=1
CursorRow=1
@@ -99,11 +99,11 @@ TopLine=1
LeftChar=1
[Editor_12]
-Open=0
+Open=1
Top=0
-CursorCol=1
-CursorRow=142
-TopLine=120
+CursorCol=17
+CursorRow=79
+TopLine=69
LeftChar=1
[Editor_13]
@@ -115,7 +115,7 @@ TopLine=20
LeftChar=1
[Editor_14]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=23
@@ -123,7 +123,7 @@ TopLine=1
LeftChar=1
[Editor_15]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
@@ -131,7 +131,7 @@ TopLine=1
LeftChar=1
[Editor_16]
-Open=1
+Open=0
Top=0
CursorCol=21
CursorRow=22
@@ -141,9 +141,9 @@ LeftChar=1
[Editor_17]
Open=1
Top=0
-CursorCol=1
-CursorRow=1
-TopLine=1
+CursorCol=4
+CursorRow=84
+TopLine=27
LeftChar=1
[Editor_18]
@@ -155,7 +155,7 @@ TopLine=1
LeftChar=1
[Editor_19]
-Open=0
+Open=1
Top=0
CursorCol=1
CursorRow=1
@@ -165,10 +165,10 @@ LeftChar=1
[Editor_20]
Open=1
Top=0
-CursorCol=4
-CursorRow=308
-TopLine=285
-LeftChar=1
+CursorCol=2
+CursorRow=172
+TopLine=129
+LeftChar=2
[Editor_21]
Open=0
@@ -204,14 +204,14 @@ LeftChar=1
[Editor_25]
Open=1
Top=0
-CursorCol=2
-CursorRow=22
+CursorCol=1
+CursorRow=37
TopLine=1
LeftChar=1
[Editor_26]
Open=1
Top=0
-CursorCol=19
-CursorRow=51
-TopLine=28
+CursorCol=1
+CursorRow=71
+TopLine=32
LeftChar=1
diff --git a/src/channels.cpp b/src/channels.cpp
index 1d1b3edbe..afa748f08 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -16,6 +16,28 @@ chanrec::chanrec()
void chanrec::SetCustomMode(char mode,bool mode_on)
{
+ if (mode_on) {
+ char m[3];
+ m[0] = mode;
+ m[1] = '\0';
+ if (!strchr(this->custom_modes,mode))
+ {
+ strncat(custom_modes,m,MAXMODES);
+ }
+ log(DEBUG,"Custom mode %c set",mode);
+ }
+ else {
+ char temp[MAXMODES];
+ int count = 0;
+ for (int q = 0; q < strlen(custom_modes); q++) {
+ if (custom_modes[q] != mode) {
+ temp[count++] = mode;
+ }
+ }
+ temp[count] = '\0';
+ strncpy(custom_modes,temp,MAXMODES);
+ log(DEBUG,"Custom mode %c removed",mode);
+ }
}
void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 444287834..a515ab212 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -854,10 +854,12 @@ char* cmode(userrec *user, chanrec *chan)
}
char scratch[MAXMODES];
+char sparam[MAXMODES];
char* chanmodes(chanrec *chan)
{
strcpy(scratch,"");
+ strcpy(sparam,"");
if (chan->noexternal)
{
strcat(scratch,"n");
@@ -892,16 +894,22 @@ char* chanmodes(chanrec *chan)
}
if (strcmp(chan->key,""))
{
- strcat(scratch," ");
- strcat(scratch,chan->key);
+ strcat(sparam,chan->key);
}
if (chan->limit)
{
char foo[24];
sprintf(foo," %d",chan->limit);
- strcat(scratch,foo);
+ strcat(sparam,foo);
}
- log(DEBUG,"chanmodes: %s %s",chan->name,scratch);
+ if (strlen(chan->custom_modes))
+ {
+ // TODO: Tack on mode parameters here -
+ // IN ORDER OF CUSTOM_MODES!
+ strncat(scratch,chan->custom_modes,MAXMODES);
+ }
+ log(DEBUG,"chanmodes: %s %s%s",chan->name,scratch,sparam);
+ strncat(scratch,sparam,MAXMODES);
return scratch;
}
@@ -1037,6 +1045,9 @@ chanrec* add_channel(userrec *user, char* cname, char* key)
int i = 0;
chanrec* Ptr;
int created = 0;
+
+ // we MUST declare this wherever we use FOREACH_RESULT
+ int MOD_RESULT = 0;
if ((!cname) || (!user))
{
@@ -1053,9 +1064,15 @@ chanrec* add_channel(userrec *user, char* cname, char* key)
{
return NULL; // already on the channel!
}
-
+
+
if (!FindChan(cname))
{
+ FOREACH_RESULT(OnUserPreJoin(user,NULL,cname));
+ if (MOD_RESULT) {
+ return NULL;
+ }
+
/* create a new one */
log(DEBUG,"add_channel: creating: %s",cname);
{
@@ -1082,6 +1099,11 @@ chanrec* add_channel(userrec *user, char* cname, char* key)
Ptr = FindChan(cname);
if (Ptr)
{
+ FOREACH_RESULT(OnUserPreJoin(user,Ptr,cname));
+ if (MOD_RESULT) {
+ return NULL;
+ }
+
log(DEBUG,"add_channel: joining to: %s",Ptr->name);
if (strcmp(Ptr->key,""))
{
@@ -1984,34 +2006,58 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
break;
default:
+ log(DEBUG,"Preprocessing custom mode %c",modechar);
string_list p;
p.clear();
- if (ModeDefined(modelist[ptr],MT_CHANNEL))
+ if (((!strchr(chan->custom_modes,modechar)) && (!mdir)) || ((strchr(chan->custom_modes,modechar)) && (mdir)))
{
- if ((ModeDefinedOn(modelist[ptr],MT_CHANNEL)>0) && (mdir))
+ log(DEBUG,"Mode %c isnt set on %s but trying to remove!",modechar,chan->name);
+ break;
+ }
+ if (ModeDefined(modechar,MT_CHANNEL))
+ {
+ log(DEBUG,"A module has claimed this mode");
+ if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir))
{
- p.push_back(parameters[param]);
+ p.push_back(parameters[param]);
}
- if ((ModeDefinedOff(modelist[ptr],MT_CHANNEL)>0) && (!mdir))
+ if ((ModeDefinedOff(modechar,MT_CHANNEL)>0) && (!mdir))
{
- p.push_back(parameters[param]);
+ p.push_back(parameters[param]);
}
- for (int i = 0; i <= MODCOUNT; i++)
+ bool handled = false;
+ for (int i = 0; i <= MODCOUNT; i++)
{
- if (modules[i]->OnExtendedMode(user,chan,modechar,MT_CHANNEL,mdir,p))
+ if (!handled)
{
- char app[] = {modechar, 0};
- strcat(outlist, app);
- 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))
+ if (modules[i]->OnExtendedMode(user,chan,modechar,MT_CHANNEL,mdir,p))
{
- chan->SetCustomModeParam(modelist[ptr],parameters[param],mdir);
- strcpy(outpars[pc++],parameters[param++]);
- }
- }
+ log(DEBUG,"OnExtendedMode returned nonzero for a module");
+ char app[] = {modechar, 0};
+ if (ptr>0)
+ {
+ if ((modelist[ptr-1] == '+') || (modelist[ptr-1] == '-'))
+ {
+ strcat(outlist, app);
+ }
+ else if (!strchr(outlist,modechar))
+ {
+ strcat(outlist, app);
+ }
+ }
+ chan->SetCustomMode(modechar,mdir);
+ // include parameters in output if mode has them
+ if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) || (ModeDefinedOff(modechar,MT_CHANNEL)>0))
+ {
+ chan->SetCustomModeParam(modelist[ptr],parameters[param],mdir);
+ strcpy(outpars[pc++],parameters[param++]);
+ }
+ // break, because only one module can handle the mode.
+ handled = true;
+ }
+ }
+ }
}
- }
break;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index f65f8b1bd..fe4b69315 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -33,8 +33,10 @@ ExtModeList EMode;
// returns true if an extended mode character is in use
bool ModeDefined(char modechar, int type)
{
+ log(DEBUG,"Size of extmodes vector is %d",EMode.size());
for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
{
+ log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
if ((i->modechar == modechar) && (i->type == type))
{
return true;
@@ -44,7 +46,7 @@ bool ModeDefined(char modechar, int type)
}
// returns number of parameters for a custom mode when it is switched on
-bool ModeDefinedOn(char modechar, int type)
+int ModeDefinedOn(char modechar, int type)
{
for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
{
@@ -57,7 +59,7 @@ bool ModeDefinedOn(char modechar, int type)
}
// returns number of parameters for a custom mode when it is switched on
-bool ModeDefinedOff(char modechar, int type)
+int ModeDefinedOff(char modechar, int type)
{
for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
{
@@ -70,9 +72,12 @@ bool ModeDefinedOff(char modechar, int type)
}
// 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)
+bool DoAddExtendedMode(char modechar, int type, bool default_on, int params_on, int params_off)
{
- EMode.push_back( ExtMode (modechar,type,default_on,params_on,params_off));
+ if (ModeDefined(modechar,type)) {
+ return false;
+ }
+ EMode.push_back(ExtMode(modechar,type,default_on,params_on,params_off));
return true;
}
@@ -95,6 +100,7 @@ void Module::OnPacketTransmit(char *p) { }
void Module::OnPacketReceive(char *p) { }
void Module::OnRehash() { }
void Module::OnServerRaw(std::string &raw, bool inbound) { }
+int Module::OnUserPreJoin(userrec* user, chanrec* chan, char* cname) { return 0; }
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); }
@@ -223,6 +229,7 @@ Admin Server::GetAdmin()
bool Server::AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off)
{
+ return DoAddExtendedMode(modechar,type,default_on,params_when_on,params_when_off);
}
diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp
index ad7afbc97..3b6b646a9 100644
--- a/src/modules/m_testcommand.cpp
+++ b/src/modules/m_testcommand.cpp
@@ -53,6 +53,31 @@ class ModuleTestCommand : public Module
// anyone can issue the command, and the
// command takes only one parameter.
Srv->AddCommand("WOOT",handle_woot,0,1);
+
+ // Add a mode +Z for channels with no parameters
+ Srv->AddExtendedMode('Z',MT_CHANNEL,false,0,0);
+ }
+
+ virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params)
+ {
+ if (modechar != 'Z') {
+ // this mode isn't ours, we have to bail and return 0 to not handle it.
+ Srv->Log(DEBUG,"Extended mode event triggered, but this is not a mode i've claimed!");
+ return 0;
+ }
+
+
+ // TODO: Add checking here - should bail with 0 value if the mode is already on or off
+ if (mode_on) {
+ Srv->Log(DEBUG,"Custom mode is being added to channel");
+ }
+ else {
+ Srv->Log(DEBUG,"Custom mode is being taken from a channel");
+ }
+ Srv->Log(DEBUG,chan->name);
+
+ // must return 1 to handle the mode!
+ return 1;
}
virtual ~ModuleTestCommand()