+ if (user->registered != REG_ALL)
+ return MOD_RES_PASSTHRU;
+
+ /* We dont have any commands looking like this? Stop processing. */
+ i = Aliases.find(command.c_str());
+ if (i == Aliases.end())
+ return MOD_RES_PASSTHRU;
+ /* Avoid iterating on to different aliases if no patterns match. */
+ upperbound = Aliases.upper_bound(command.c_str());
+
+ irc::string c = command.c_str();
+ /* The parameters for the command in their original form, with the command stripped off */
+ std::string compare = original_line.substr(command.length());
+ while (*(compare.c_str()) == ' ')
+ compare.erase(compare.begin());
+
+ while (i != upperbound)
+ {
+ if (i->second.UserCommand)
+ {
+ if (DoAlias(user, NULL, &(i->second), compare, original_line))
+ {
+ return MOD_RES_DENY;
+ }
+ }
+
+ i++;
+ }
+
+ // If we made it here, no aliases actually matched.
+ return MOD_RES_PASSTHRU;
+ }
+
+ virtual void OnUserMessage(User *user, void *dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
+ {
+ if (target_type != TYPE_CHANNEL)
+ {
+ return;
+ }
+
+ // fcommands are only for local users. Spanningtree will send them back out as their original cmd.
+ if (!user || !IS_LOCAL(user))
+ {
+ return;
+ }
+
+ /* Stop here if the user is +B and allowbot is set to no. */
+ if (!AllowBots && user->IsModeSet('B'))
+ {
+ return;
+ }
+
+ Channel *c = (Channel *)dest;
+ std::string scommand;
+
+ // text is like "!moo cows bite me", we want "!moo" first
+ irc::spacesepstream ss(text);
+ ss.GetToken(scommand);
+ irc::string fcommand = scommand.c_str();
+
+ if (fcommand.empty())
+ {
+ return; // wtfbbq
+ }
+
+ // we don't want to touch non-fantasy stuff
+ if (*fcommand.c_str() != fprefix)
+ {
+ return;
+ }
+
+ // nor do we give a shit about the prefix
+ fcommand.erase(fcommand.begin());
+
+ std::multimap<irc::string, Alias>::iterator i = Aliases.find(fcommand);
+
+ if (i == Aliases.end())
+ return;
+
+ /* Avoid iterating on to other aliases if no patterns match */
+ std::multimap<irc::string, Alias>::iterator upperbound = Aliases.upper_bound(fcommand);
+
+
+ /* The parameters for the command in their original form, with the command stripped off */
+ std::string compare = text.substr(fcommand.length() + 1);
+ while (*(compare.c_str()) == ' ')
+ compare.erase(compare.begin());
+
+ while (i != upperbound)
+ {
+ if (i->second.ChannelCommand)
+ {
+ // We use substr(1) here to remove the fantasy prefix
+ if (DoAlias(user, c, &(i->second), compare, text.substr(1)))
+ return;
+ }
+
+ i++;
+ }
+ }
+
+
+ int DoAlias(User *user, Channel *c, Alias *a, const std::string compare, const std::string safe)
+ {
+ User *u = NULL;
+
+ /* Does it match the pattern? */
+ if (!a->format.empty())
+ {
+ if (a->CaseSensitive)
+ {
+ if (!InspIRCd::Match(compare, a->format, rfc_case_sensitive_map))
+ return 0;
+ }
+ else
+ {
+ if (!InspIRCd::Match(compare, a->format))
+ return 0;
+ }
+ }
+
+ if ((a->OperOnly) && (!IS_OPER(user)))