- if (!pcnt)
- {
- // no parameters, show the current silence list.
- // Use Extensible::GetExt to fetch the silence list
- silencelist* sl;
- user->GetExt("silence_list", sl);
- // if the user has a silence list associated with their user record, show it
- if (sl)
- {
- for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
- {
- user->WriteNumeric(271, "%s %s %s %s",user->nick, user->nick,c->first.c_str(), DecompPattern(c->second).c_str());
- }
- }
- user->WriteNumeric(272, "%s :End of Silence List",user->nick);
-
- return CMD_LOCALONLY;
- }
- else if (pcnt > 0)
- {
- // one or more parameters, add or delete entry from the list (only the first parameter is used)
- std::string mask = parameters[0] + 1;
- char action = *parameters[0];
- // Default is private and notice so clients do not break
- int pattern = CompilePattern("pn");
-
- // if pattern supplied, use it
- if (pcnt > 1) {
- pattern = CompilePattern(parameters[1]);
- }
-
- if (!mask.length())
- {
- // 'SILENCE +' or 'SILENCE -', assume *!*@*
- mask = "*!*@*";
- }
-
- ModeParser::CleanMask(mask);
-
- if (action == '-')
- {
- // fetch their silence list
- silencelist* sl;
- user->GetExt("silence_list", sl);
- // does it contain any entries and does it exist?
- if (sl)
- {
- for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
- {
- // search through for the item
- irc::string listitem = i->first.c_str();
- if (listitem == mask && i->second == pattern)
- {
- sl->erase(i);
- user->WriteNumeric(950, "%s %s :Removed %s %s from silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
- if (!sl->size())
- {
- delete sl;
- user->Shrink("silence_list");
- }
- return CMD_SUCCESS;
- }
- }
- }
- user->WriteNumeric(952, "%s %s :%s %s does not exist on your silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
- }
- else if (action == '+')
- {
- // fetch the user's current silence list
- silencelist* sl;
- user->GetExt("silence_list", sl);
- // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
- if (!sl)
- {
- sl = new silencelist;
- user->Extend("silence_list", sl);
- }
- if (sl->size() > maxsilence)
- {
- user->WriteNumeric(952, "%s %s :Your silence list is full",user->nick, user->nick);
- return CMD_FAILURE;
- }
- for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
- {
- irc::string listitem = n->first.c_str();
- if (listitem == mask && n->second == pattern)
- {
- user->WriteNumeric(952, "%s %s :%s %s is already on your silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
- return CMD_FAILURE;
- }
- }
- if (((pattern & SILENCE_EXCLUDE) > 0))
- {
- sl->push_front(silenceset(mask,pattern));
- }
- else
- {
- sl->push_back(silenceset(mask,pattern));
- }
- user->WriteNumeric(951, "%s %s :Added %s %s to silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
- return CMD_SUCCESS;
- }
- }
- return CMD_LOCALONLY;