#include "modes/umode_i.h"
/* +o (operator) */
#include "modes/umode_o.h"
+/* +n (notice mask - our implementation of snomasks) */
+#include "modes/umode_n.h"
extern int MODCOUNT;
extern std::vector<Module*> modules;
return MODEACTION_DENY;
}
+ModePair ModeHandler::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
+{
+ if (dest)
+ {
+ return std::make_pair(dest->IsModeSet(this->mode), "");
+ }
+ else
+ {
+ return std::make_pair(channel->IsModeSet(this->mode), "");
+ }
+}
+
void ModeHandler::DisplayList(userrec* user, chanrec* channel)
{
}
{
return "";
}
- n->uc_modes = ((ucrec*)(*i))->uc_modes | MASK;
+ n->uc_modes = n->uc_modes | MASK;
switch (MASK)
{
case UCMODE_OP:
{
/* Display user's current mode string */
WriteServ(user->fd,"221 %s :+%s",targetuser->nick,targetuser->FormatModes());
+ WriteServ(user->fd, "008 %s :+%s", targetuser->nick, targetuser->FormatNoticeMasks());
return;
}
+
/* No such nick/channel */
WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, text);
return;
}
-void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool servermode)
+void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool servermode)
{
std::string target = parameters[0];
ModeType type = MODETYPE_USER;
* (e.g. are they a (half)op?
*/
- if (cstatus(user, targetchannel) < STATUS_HOP)
+ if ((IS_LOCAL(user)) && (cstatus(user, targetchannel) < STATUS_HOP))
{
/* We don't have halfop */
log(DEBUG,"The user is not a halfop or above, checking other reasons for being able to set the modes");
WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
return;
}
+
+ /* Special case for displaying the list for listmodes,
+ * e.g. MODE #chan b, or MODE #chan +b without a parameter
+ */
+ if ((type== MODETYPE_CHANNEL) && (pcnt == 2))
+ {
+ const char* mode = parameters[1];
+ if (*mode == '+')
+ mode++;
+
+ unsigned char handler_id = ((*mode) - 65) | mask;
+ ModeHandler* mh = modehandlers[handler_id];
+
+ if ((mh) && (mh->IsListMode()))
+ {
+ mh->DisplayList(user, targetchannel);
+ }
+ }
+
std::string mode_sequence = parameters[1];
std::string parameter = "";
std::ostringstream parameter_list;
std::string output_sequence = "";
bool adding = true, state_change = false;
- int handler_id = 0;
+ unsigned char handler_id = 0;
int parameter_counter = 2; /* Index of first parameter */
for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
/* It's an oper only mode, check if theyre an oper. If they arent,
* eat any parameter that came with the mode, and continue to next
*/
- if ((modehandlers[handler_id]->NeedsOper()) && (!*user->oper))
+ if ((IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!*user->oper))
continue;
/* Call the handler for the mode */
}
-void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
+void cmd_mode::Handle (const char** parameters, int pcnt, userrec *user)
{
if (!user)
return;
}
}
-void ModeParser::BuildModeString(userrec* user)
-{
-}
-
bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
{
unsigned char mask = 0;
* If they do that, thats their problem, and if i ever EVER see an
* official InspIRCd developer do that, i'll beat them with a paddle!
*/
- if ((modeletter < 'A') || (modeletter > 'z'))
+ if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
return false;
mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
- pos = (modeletter-65) | mask;
+ pos = (mh->GetModeChar()-65) | mask;
if (modehandlers[pos])
return false;
modehandlers[pos] = mh;
- log(DEBUG,"ModeParser::AddMode: added mode %c",modeletter);
+ log(DEBUG,"ModeParser::AddMode: added mode %c",mh->GetModeChar());
+ return true;
+}
+
+ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
+{
+ unsigned char mask = 0;
+ unsigned char pos = 0;
+
+ if ((modeletter < 'A') || (modeletter > 'z'))
+ return NULL;
+
+ mt == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
+ pos = (modeletter-65) | mask;
+
+ return modehandlers[pos];
+}
+
+bool ModeParser::AddModeWatcher(ModeWatcher* mw)
+{
+ unsigned char mask = 0;
+ unsigned char pos = 0;
+
+ if (!mw)
+ return false;
+
+ if ((mw->GetModeChar() < 'A') || (mw->GetModeChar() > 'z'))
+ return false;
+
+ mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
+ pos = (mw->GetModeChar()-65) | mask;
+
+ modewatchers[pos].push_back(mw);
+ log(DEBUG,"ModeParser::AddModeWatcher: watching mode %c",mw->GetModeChar());
+
+ return true;
+}
+
+bool ModeParser::DelModeWatcher(ModeWatcher* mw)
+{
+ unsigned char mask = 0;
+ unsigned char pos = 0;
+
+ if (!mw)
+ return false;
+
+ if ((mw->GetModeType() < 'A') || (mw->GetModeType() > 'z'))
+ return false;
+
+ mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
+ pos = (mw->GetModeChar()-65) | mask;
+
+ ModeWatchIter a = find(modewatchers[pos].begin(),modewatchers[pos].end(),mw);
+
+ if (a == modewatchers[pos].end())
+ return false;
+
+ modewatchers[pos].erase(a);
+ log(DEBUG,"ModeParser::DelModeWatcher: stopped watching mode %c",mw->GetModeChar());
+
return true;
}
this->AddMode(new ModeUserWallops, 'w');
this->AddMode(new ModeUserInvisible, 'i');
this->AddMode(new ModeUserOperator, 'o');
-
- /* TODO: User modes +swio */
+ this->AddMode(new ModeUserServerNoticeMask, 'n');
}