diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-04-03 19:10:18 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-08 23:13:24 +0200 |
commit | ebe5b201aab71cf2ead1e068889be736314fbb73 (patch) | |
tree | 33bc1cc227073304f5e25731fa35a60cfd2712a3 /include | |
parent | 0ce252f05ced1a0dddfc9c353d68007a3faba239 (diff) |
Migrate u_listmode.h into the core, change +b to use it
Diffstat (limited to 'include')
-rw-r--r-- | include/builtinmodes.h | 17 | ||||
-rw-r--r-- | include/channels.h | 39 | ||||
-rw-r--r-- | include/configreader.h | 4 | ||||
-rw-r--r-- | include/inspircd.h | 5 | ||||
-rw-r--r-- | include/listmode.h | 186 |
5 files changed, 192 insertions, 59 deletions
diff --git a/include/builtinmodes.h b/include/builtinmodes.h index ab1da8740..a4a950922 100644 --- a/include/builtinmodes.h +++ b/include/builtinmodes.h @@ -22,22 +22,17 @@ #include "mode.h" #include "channels.h" +#include "listmode.h" /** Channel mode +b */ -class ModeChannelBan : public ModeHandler +class ModeChannelBan : public ListModeBase { - private: - BanItem b; public: - ModeChannelBan(); - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding); - std::string& AddBan(User *user,std::string& dest,Channel *chan,int status); - std::string& DelBan(User *user,std::string& dest,Channel *chan,int status); - void DisplayList(User* user, Channel* channel); - void DisplayEmptyList(User* user, Channel* channel); - void RemoveMode(User* user, irc::modestacker* stack = NULL); - void RemoveMode(Channel* channel, irc::modestacker* stack = NULL); + ModeChannelBan() + : ListModeBase(NULL, "ban", 'b', "End of channel ban list", 367, 368, true, "maxbans") + { + } }; /** Channel mode +i diff --git a/include/channels.h b/include/channels.h index 3a6b38640..43302552e 100644 --- a/include/channels.h +++ b/include/channels.h @@ -29,28 +29,6 @@ /** Holds an entry for a ban list, exemption list, or invite list. * This class contains a single element in a channel list, such as a banlist. */ -class HostItem -{ - public: - /** Time the item was added - */ - time_t set_time; - /** Who added the item - */ - std::string set_by; - /** The actual item data - */ - std::string data; - - HostItem() { /* stub */ } - virtual ~HostItem() { /* stub */ } -}; - -/** A subclass of HostItem designed to hold channel bans (+b) - */ -class BanItem : public HostItem -{ -}; /** Holds all relevent information for a channel. * This class represents a channel, and contains its name, modes, topic, topic set time, @@ -66,10 +44,6 @@ class CoreExport Channel : public Extensible, public InviteBase */ void SetDefaultModes(); - /** Maximum number of bans (cached) - */ - int maxbans; - /** Modes for the channel. * This is not a null terminated string! It is a bitset where * each item in it represents if a mode is set. For example @@ -116,10 +90,6 @@ class CoreExport Channel : public Extensible, public InviteBase */ std::string setby; /* 128 */ - /** The list of all bans set on the channel. - */ - BanList bans; - /** Sets or unsets a custom mode in the channels info * @param mode The mode character to set or unset * @param value True if you want to set the mode or false if you want to remove it @@ -301,11 +271,6 @@ class CoreExport Channel : public Extensible, public InviteBase /** Write a line of text that already includes the source */ void RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text); - /** Returns the maximum number of bans allowed to be set on this channel - * @return The maximum number of bans allowed - */ - long GetMaxBans(); - /** Return the channel's modes with parameters. * @param showkey If this is set to true, the actual key is shown, * otherwise it is replaced with '<KEY>' @@ -388,10 +353,6 @@ class CoreExport Channel : public Extensible, public InviteBase /** Get the status of an "action" type extban */ ModResult GetExtBanStatus(User *u, char type); - - /** Clears the cached max bans value - */ - void ResetMaxBans(); }; #endif diff --git a/include/configreader.h b/include/configreader.h index d3b3edd84..5541a2c42 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -459,10 +459,6 @@ class CoreExport ServerConfig */ std::map<irc::string, bool> ulines; - /** Max banlist sizes for channels (the std::string is a glob) - */ - std::map<std::string, int> maxbans; - /** If set to true, no user DNS lookups are to be performed */ bool NoUserDns; diff --git a/include/inspircd.h b/include/inspircd.h index 1ca3d077b..fa00902a4 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -821,11 +821,6 @@ class CoreExport InspIRCd */ void Cleanup(); - /** Resets the cached max bans value on all channels. - * Called by rehash. - */ - void ResetMaxBans(); - /** Return a time_t as a human-readable string. */ std::string TimeString(time_t curtime); diff --git a/include/listmode.h b/include/listmode.h new file mode 100644 index 000000000..40c28f67f --- /dev/null +++ b/include/listmode.h @@ -0,0 +1,186 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +/** The base class for list modes, should be inherited. + */ +class ListModeBase : public ModeHandler +{ + public: + /** An item in a listmode's list + */ + class ListItem + { + public: + std::string nick; + std::string mask; + std::string time; + }; + + /** Items stored in the channel's list + */ + typedef std::list<ListItem> ModeList; + + private: + /** The number of items a listmode's list may contain + */ + class ListLimit + { + public: + std::string mask; + unsigned int limit; + }; + + /** Max items per channel by name + */ + typedef std::list<ListLimit> limitlist; + + protected: + /** Numeric to use when outputting the list + */ + unsigned int listnumeric; + /** Numeric to indicate end of list + */ + unsigned int endoflistnumeric; + /** String to send for end of list + */ + std::string endofliststring; + /** Automatically tidy up entries + */ + bool tidy; + /** Config tag to check for max items per channel + */ + std::string configtag; + /** Limits on a per-channel basis read from the tag + * specified in ListModeBase::configtag + */ + limitlist chanlimits; + + /** Storage key + */ + SimpleExtItem<ModeList> extItem; + + public: + /** Constructor. + * @param Instance The creator of this class + * @param modechar Mode character + * @param eolstr End of list string + * @param lnum List numeric + * @param eolnum End of list numeric + * @param autotidy Automatically tidy list entries on add + * @param ctag Configuration tag to get limits from + */ + ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag = "banlist"); + + /** Get limit of this mode on a channel + * @param channel The channel to inspect + * @return Maximum number of modes of this type that can be placed on the given channel + */ + unsigned int GetLimit(Channel* channel); + + /** Retrieves the list of all modes set on the given channel + * @param channel Channel to get the list from + * @return A list with all modes of this type set on the given channel, can be NULL + */ + ModeList* GetList(Channel* channel); + + /** Display the list for this mode + * See mode.h + * @param user The user to send the list to + * @param channel The channel the user is requesting the list for + */ + virtual void DisplayList(User* user, Channel* channel); + + /** Tell a user that a list contains no elements. + * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor) + * @param user The user issuing the command + * @param channel The channel that has the empty list + * See mode.h + */ + virtual void DisplayEmptyList(User* user, Channel* channel); + + /** Remove all instances of the mode from a channel. + * See mode.h + * @param channel The channel to remove all instances of the mode from + */ + virtual void RemoveMode(Channel* channel, irc::modestacker* stack); + + /** Listmodes don't get set on users, no-op + */ + virtual void RemoveMode(User*, irc::modestacker* stack); + + /** Perform a rehash of this mode's configuration data + */ + virtual void DoRehash(); + + /** Populate the Implements list with the correct events for a List Mode + */ + virtual void DoImplements(Module* m); + + /** Handle the list mode. + * See mode.h + */ + virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding); + + /** Syncronize channel item list with another server. + * See modules.h + * @param chan Channel to syncronize + * @param proto Protocol module pointer + * @param opaque Opaque connection handle + */ + virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque); + + /** Validate parameters. + * Overridden by implementing module. + * @param source Source user adding the parameter + * @param channel Channel the parameter is being added to + * @param parameter The actual parameter being added + * @return true if the parameter is valid + */ + virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter); + + /** Tell the user the list is too long. + * Overridden by implementing module. + * @param source Source user adding the parameter + * @param channel Channel the parameter is being added to + * @param parameter The actual parameter being added + */ + virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter); + + /** Tell the user an item is already on the list. + * Overridden by implementing module. + * @param source Source user adding the parameter + * @param channel Channel the parameter is being added to + * @param parameter The actual parameter being added + */ + virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter); + + /** Tell the user that the parameter is not in the list. + * Overridden by implementing module. + * @param source Source user removing the parameter + * @param channel Channel the parameter is being removed from + * @param parameter The actual parameter being removed + */ + virtual void TellNotSet(User* source, Channel* channel, std::string& parameter); +}; + +inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel) +{ + return extItem.get(channel); +} |