#include <sys/errno.h>
#include <time.h>
#include <string>
-#ifdef GCC3
-#include <ext/hash_map>
-#else
-#include <hash_map>
-#endif
+#include "hash_map.h"
#include <map>
#include <sstream>
#include <vector>
#include "helperfuncs.h"
#include "mode.h"
+/* +s (secret) */
#include "modes/cmode_s.h"
+/* +p (private) */
#include "modes/cmode_p.h"
+/* +b (bans) */
+#include "modes/cmode_b.h"
+/* +m (moderated) */
+#include "modes/cmode_m.h"
extern int MODCOUNT;
extern std::vector<Module*> modules;
extern time_t TIME;
-ModeHandler::ModeHandler(char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly) : mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly)
+ModeHandler::ModeHandler(char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly)
+ : mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly)
{
}
return NULL;
}
-char* ModeParser::AddBan(userrec *user,char *dest,chanrec *chan,int status)
-{
- BanItem b;
- int toomanyexclamation = 0;
- int toomanyat = 0;
-
- if ((!user) || (!dest) || (!chan) || (!*dest))
- {
- log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
- return NULL;
- }
-
- for (char* i = dest; *i; i++)
- {
- if ((*i < 32) || (*i > 126))
- {
- return NULL;
- }
- else if (*i == '!')
- {
- toomanyexclamation++;
- }
- else if (*i == '@')
- {
- toomanyat++;
- }
- }
-
- if (toomanyexclamation != 1 || toomanyat != 1)
- /*
- * this stops sillyness like n!u!u!u@h, though note that most
- * ircds don't actually verify banmask validity. --w00t
- */
- return NULL;
-
- long maxbans = GetMaxBans(chan->name);
- if ((unsigned)chan->bans.size() > (unsigned)maxbans)
- {
- WriteServ(user->fd,"478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);
- return NULL;
- }
-
- log(DEBUG,"AddBan: %s %s",chan->name,user->nick);
-
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
- if (MOD_RESULT)
- return NULL;
-
- TidyBan(dest);
- for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
- {
- if (!strcasecmp(i->data,dest))
- {
- // dont allow a user to set the same ban twice
- return NULL;
- }
- }
-
- b.set_time = TIME;
- strlcpy(b.data,dest,MAXBUF);
- if (*user->nick)
- {
- strlcpy(b.set_by,user->nick,NICKMAX-1);
- }
- else
- {
- strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
- }
- chan->bans.push_back(b);
- return dest;
-}
-
-char* ModeParser::TakeBan(userrec *user,char *dest,chanrec *chan,int status)
-{
- if ((!user) || (!dest) || (!chan) || (!*dest)) {
- log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
- return 0;
- }
-
- log(DEBUG,"del_ban: %s %s",chan->name,user->nick);
- for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
- {
- if (!strcasecmp(i->data,dest))
- {
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
- if (MOD_RESULT)
- return NULL;
- chan->bans.erase(i);
- return dest;
- }
- }
- return NULL;
-}
-
void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool servermode)
{
std::string target = parameters[0];
if (modehandlers[handler_id]->GetNumParams(adding))
{
- log(DEBUG,"ModeHandler* for this mode says it has parameters");
+ log(DEBUG,"ModeHandler* for this mode says it has parameters. pcnt=%d parameter_counter=%d",pcnt,parameter_counter);
- if (pcnt < parameter_counter)
+ if (parameter_counter < pcnt)
{
parameter = parameters[parameter_counter++];
}
else
{
- parameter = "";
+ /* No parameter, continue to the next mode */
+ continue;
}
}
ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding);
+
+ if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter == ""))
+ {
+ /* The handler nuked the parameter and they are supposed to have one.
+ * We CANT continue now, even if they actually returned MODEACTION_ALLOW,
+ * so we bail to the next mode character.
+ */
+ continue;
+ }
+
if (ma == MODEACTION_ALLOW)
{
log(DEBUG,"ModeAction was allow");
void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
{
- chanrec* chan;
- int MOD_RESULT;
- int can_change;
- int direction = 1;
- char outpars[MAXBUF];
- bool next_ok = true;
-
if (!user)
return;
return;
}
+void ModeParser::CleanMask(std::string &mask)
+{
+ std::string::size_type pos_of_pling = mask.find_first_of('!');
+ std::string::size_type pos_of_at = mask.find_first_of('@');
+ std::string::size_type pos_of_dot = mask.find_first_of('.');
+ std::string::size_type pos_of_colon = mask.find_first_of(':'); /* Because ipv6 addresses are colon delimited */
+
+ if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos))
+ {
+ /* Just a nick, or just a host */
+ if ((pos_of_dot == std::string::npos) && (pos_of_colon == std::string::npos))
+ {
+ /* It has no '.' in it, it must be a nick. */
+ mask.append("!*@*");
+ }
+ else
+ {
+ /* Got a dot in it? Has to be a host */
+ mask = "*!*@" + mask;
+ }
+ }
+ else if ((pos_of_pling == std::string::npos) && (pos_of_at != std::string::npos))
+ {
+ /* Has an @ but no !, its a user@host */
+ mask = "*!" + mask;
+ }
+ else if ((pos_of_pling != std::string::npos) && (pos_of_at == std::string::npos))
+ {
+ /* Has a ! but no @, it must be a nick!ident */
+ mask.append("@*");
+ }
+}
+
bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
{
unsigned char mask = 0;
+ unsigned char pos = 0;
+
+ /* Yes, i know, this might let people declare modes like '_' or '^'.
+ * 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'))
+ return false;
+
mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
- modehandlers[(modeletter-65) | mask] = mh;
+ pos = (modeletter-65) | mask;
+
+ if (modehandlers[pos])
+ return false;
+
+ modehandlers[pos] = mh;
+ log(DEBUG,"ModeParser::AddMode: added mode %c",modeletter);
return true;
}
/* Initialise the RFC mode letters */
this->AddMode(new ModeChannelSecret, 's');
this->AddMode(new ModeChannelPrivate, 'p');
+ this->AddMode(new ModeChannelBan, 'b');
+ this->AddMode(new ModeChannelModerated, 'm');
}
+