anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

users.h (11926B)

      1 /*
      2  *
      3  * (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
      4  * (C) 2003-2022 Anope Team <team@anope.org>
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #ifndef USERS_H
     13 #define USERS_H
     14 
     15 #include "anope.h"
     16 #include "modes.h"
     17 #include "extensible.h"
     18 #include "serialize.h"
     19 #include "commands.h"
     20 #include "account.h"
     21 #include "sockets.h"
     22 
     23 typedef Anope::hash_map<User *> user_map;
     24 
     25 extern CoreExport user_map UserListByNick, UserListByUID;
     26 
     27 extern CoreExport int OperCount;
     28 extern CoreExport unsigned MaxUserCount;
     29 extern CoreExport time_t MaxUserTime;
     30 
     31 /* Online user and channel data. */
     32 class CoreExport User : public virtual Base, public Extensible, public CommandReply
     33 {
     34 	/* true if the user was quit or killed */
     35 	bool quit;
     36 	/* Users that are in the process of quitting */
     37 	static std::list<User *> quitting_users;
     38 
     39  public:
     40 	typedef std::map<Anope::string, Anope::string> ModeList;
     41  protected:
     42 	Anope::string vident;
     43 	Anope::string ident;
     44 	Anope::string uid;
     45 	/* If the user is on the access list of the nick they're on */
     46 	bool on_access;
     47 	/* Map of user modes and the params this user has (if any) */
     48 	ModeList modes;
     49 	/* NickCore account the user is currently logged in as, if they are logged in */
     50 	Serialize::Reference<NickCore> nc;
     51 
     52 	/* # of invalid password attempts */
     53 	unsigned short invalid_pw_count;
     54 	/* Time of last invalid password */
     55 	time_t invalid_pw_time;
     56 
     57 
     58  public: // XXX: exposing a tiny bit too much
     59 	/* User's current nick */
     60 	Anope::string nick;
     61 
     62 	/* User's real hostname */
     63 	Anope::string host;
     64 	/* User's virtual hostname */
     65 	Anope::string vhost;
     66 	/* User's cloaked hostname */
     67 	Anope::string chost;
     68 	/* Realname */
     69 	Anope::string realname;
     70 	/* SSL Fingerprint */
     71 	Anope::string fingerprint;
     72 	/* User's IP */
     73 	sockaddrs ip;
     74 	/* Server user is connected to */
     75 	Server *server;
     76 	/* When the user signed on. Set on connect and never modified. */
     77 	time_t signon;
     78 	/* Timestamp of the nick. Updated when the nick changes. */
     79 	time_t timestamp;
     80 	/* Is the user as super admin? */
     81 	bool super_admin;
     82 
     83 	/* Channels the user is in */
     84 	typedef std::map<Channel *, ChanUserContainer *> ChanUserList;
     85 	ChanUserList chans;
     86 
     87 	/* Last time this user sent a memo command used */
     88 	time_t lastmemosend;
     89 	/* Last time this user registered */
     90 	time_t lastnickreg;
     91 	/* Last time this user sent an email */
     92 	time_t lastmail;
     93 
     94  protected:
     95 	/** Create a new user object, initialising necessary fields and
     96 	 * adds it to the hash
     97 	 *
     98 	 * @param snick The nickname of the user.
     99 	 * @param sident The username of the user
    100 	 * @param shost The hostname of the user
    101 	 * @param svhost The vhost of the user
    102 	 * @param sip The ip of the user
    103 	 * @param sserver The server of the user
    104 	 * @param srealname The realname/gecos of the user
    105 	 * @param ts User's timestamp
    106 	 * @param smodes User's modes
    107 	 * @param suid The unique identifier of the user.
    108 	 * @param nc The account the user is identified as, if any
    109 	 */
    110 	User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc);
    111 
    112 	/** Destroy a user.
    113 	 */
    114 	virtual ~User();
    115 
    116  public:
    117 	static User* OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc);
    118 
    119 	/** Update the nickname of a user record accordingly, should be
    120 	 * called from ircd protocol.
    121 	 * @param newnick The new username
    122 	 * @param ts The time the nick was changed, User::timestamp will be updated to this.
    123 	 */
    124 	void ChangeNick(const Anope::string &newnick, time_t ts = Anope::CurTime);
    125 
    126 	/** Update the displayed (vhost) of a user record.
    127 	 * This is used (if set) instead of real host.
    128 	 * @param host The new displayed host to give the user.
    129 	 */
    130 	void SetDisplayedHost(const Anope::string &host);
    131 
    132 	/** Get the displayed vhost of a user record.
    133 	 * @return The displayed vhost of the user, where ircd-supported, or the user's real host.
    134 	 */
    135 	const Anope::string &GetDisplayedHost() const;
    136 
    137 	/** Update the cloaked host of a user
    138 	 * @param host The cloaked host
    139 	 */
    140 	void SetCloakedHost(const Anope::string &newhost);
    141 
    142 	/** Get the cloaked host of a user
    143 	 * @return The cloaked host
    144 	 */
    145 	const Anope::string &GetCloakedHost() const;
    146 
    147 	/** Retrieves the UID of the user, if set, else the nick.
    148 	 * @return The UID of the user.
    149 	 */
    150 	const Anope::string &GetUID() const;
    151 
    152 	/** Update the displayed ident (username) of a user record.
    153 	 * @param ident The new ident to give this user.
    154 	 */
    155 	void SetVIdent(const Anope::string &ident);
    156 
    157 	/** Get the displayed ident (username) of this user.
    158 	 * @return The displayed ident of this user.
    159 	 */
    160 	const Anope::string &GetVIdent() const;
    161 
    162 	/** Update the real ident (username) of a user record.
    163 	 * @param ident The new ident to give this user.
    164 	 * NOTE: Where possible, you should use the Get/SetVIdent() equivalents.
    165 	 */
    166 	void SetIdent(const Anope::string &ident);
    167 
    168 	/** Get the real ident (username) of this user.
    169 	 * @return The displayed ident of this user.
    170 	 * NOTE: Where possible, you should use the Get/SetVIdent() equivalents.
    171 	 */
    172 	const Anope::string &GetIdent() const;
    173 
    174 	/** Get the full mask (nick!ident@realhost) of a user
    175 	 */
    176 	Anope::string GetMask() const;
    177 
    178 	/** Get the full display mask (nick!vident@vhost/chost)
    179 	 */
    180 	Anope::string GetDisplayedMask() const;
    181 
    182 	/** Updates the realname of the user record.
    183 	 */
    184 	void SetRealname(const Anope::string &realname);
    185 
    186 	/**
    187 	 * Send a message (notice or privmsg, depending on settings) to a user
    188 	 * @param source Sender
    189 	 * @param fmt Format of the Message
    190 	 * @param ... any number of parameters
    191 	 */
    192 	void SendMessage(BotInfo *source, const char *fmt, ...);
    193 	void SendMessage(BotInfo *source, const Anope::string &msg) anope_override;
    194 
    195 	/** Identify the user to a nick.
    196 	 * updates last_seen, logs the user in,
    197 	 * send messages, checks for mails, set vhost and more
    198 	 * @param na the nick to identify to, should be the same as
    199 	 * the user's current nick
    200 	 */
    201 	void Identify(NickAlias *na);
    202 
    203 	/** Login the user to an account
    204 	 * @param core The account
    205 	 */
    206 	void Login(NickCore *core);
    207 
    208 	/** Logout the user
    209 	 */
    210 	void Logout();
    211 
    212 	/** Get the account the user is logged in using
    213 	 * @return The account or NULL
    214 	 */
    215 	NickCore *Account() const;
    216 
    217 	/** Check if the user is identified for their nick
    218 	 * @param check_nick True to check if the user is identified to the nickname they are on too
    219 	 * @return true or false
    220 	 */
    221 	bool IsIdentified(bool check_nick = false) const;
    222 
    223 	/** Check if the user is recognized for their nick (on the nicks access list)
    224 	 * @param check_secure Only returns true if the user has secure off
    225 	 * @return true or false
    226 	 */
    227 	bool IsRecognized(bool check_secure = true) const;
    228 
    229 	/** Check if the user is a services oper
    230 	 * @return true if they are an oper
    231 	 */
    232 	bool IsServicesOper();
    233 
    234 	/** Check whether this user has access to run the given command string.
    235 	  * @param cmdstr The string to check, e.g. botserv/set/private.
    236 	  * @return True if this user may run the specified command, false otherwise.
    237 	  */
    238 	bool HasCommand(const Anope::string &cmdstr);
    239 
    240 	/** Check whether this user has access to the given special permission.
    241 	  * @param privstr The priv to check for, e.g. users/auspex.
    242 	  * @return True if this user has the specified priv, false otherwise.
    243 	  */
    244 	bool HasPriv(const Anope::string &privstr);
    245 
    246 	/** Update the last usermask stored for a user, and check to see if they are recognized
    247 	 */
    248 	void UpdateHost();
    249 
    250 	/** Check if the user has a mode
    251 	 * @param name Mode name
    252 	 * @return true or false
    253 	 */
    254 	bool HasMode(const Anope::string &name) const;
    255 
    256 	/** Set a mode internally on the user, the IRCd is not informed
    257 	 * @param setter who/what is setting the mode
    258 	 * @param um The user mode
    259 	 * @param Param The param, if there is one
    260 	 */
    261 	void SetModeInternal(const MessageSource &setter, UserMode *um, const Anope::string &param = "");
    262 
    263 	/** Remove a mode internally on the user, the IRCd is not informed
    264 	 * @param setter who/what is setting the mode
    265 	 * @param um The user mode
    266 	 */
    267 	void RemoveModeInternal(const MessageSource &setter, UserMode *um);
    268 
    269 	/** Set a mode on the user
    270 	 * @param bi The client setting the mode
    271 	 * @param um The user mode
    272 	 * @param Param Optional param for the mode
    273 	 */
    274 	void SetMode(BotInfo *bi, UserMode *um, const Anope::string &param = "");
    275 
    276 	/** Set a mode on the user
    277 	 * @param bi The client setting the mode
    278 	 * @param name The mode name
    279 	 * @param Param Optional param for the mode
    280 	 */
    281 	void SetMode(BotInfo *bi, const Anope::string &name, const Anope::string &param = "");
    282 
    283 	/** Remove a mode on the user
    284 	 * @param bi The client setting the mode
    285 	 * @param um The user mode
    286 	 * @param param Optional param for the mode
    287 	 */
    288 	void RemoveMode(BotInfo *bi, UserMode *um, const Anope::string &param = "");
    289 
    290 	/** Remove a mode from the user
    291 	 * @param bi The client setting the mode
    292 	 * @param name The mode name
    293 	 * @param param Optional param for the mode
    294 	 */
    295 	void RemoveMode(BotInfo *bi, const Anope::string &name, const Anope::string &param = "");
    296 
    297 	/** Set a string of modes on a user
    298 	 * @param bi The client setting the modes
    299 	 * @param umodes The modes
    300 	 */
    301 	void SetModes(BotInfo *bi, const char *umodes, ...);
    302 
    303 	/** Set a string of modes on a user internally
    304 	 * @param setter who/what is setting the mode
    305 	 * @param umodes The modes
    306 	 */
    307 	void SetModesInternal(const MessageSource &source, const char *umodes, ...);
    308 
    309 	/** Get modes set for this user.
    310 	 * @return A string of modes set on the user
    311 	 */
    312 	Anope::string GetModes() const;
    313 
    314 	const ModeList &GetModeList() const;
    315 
    316 	/** Find the channel container for Channel c that the user is on
    317 	 * This is preferred over using FindUser in Channel, as there are usually more users in a channel
    318 	 * than channels a user is in
    319 	 * @param c The channel
    320 	 * @return The channel container, or NULL
    321 	 */
    322 	ChanUserContainer *FindChannel(Channel *c) const;
    323 
    324 	/** Check if the user is protected from kicks and negative mode changes
    325 	 * @return true or false
    326 	 */
    327 	bool IsProtected();
    328 
    329 	/** Kill a user
    330 	 * @param source The user/server doing the kill
    331 	 * @param reason The reason for the kill
    332 	 */
    333 	void Kill(const MessageSource &source, const Anope::string &reason);
    334 
    335 	/** Process a kill for a user
    336 	 * @param source The user/server doing the kill
    337 	 * @param reason The reason for the kill
    338 	 */
    339 	void KillInternal(const MessageSource &source, const Anope::string &reason);
    340 
    341 	/** Processes a quit for the user, and marks them as quit
    342 	 * @param reason The reason for the quit
    343 	 */
    344 	void Quit(const Anope::string &reason = "");
    345 
    346 	bool Quitting() const;
    347 
    348 	/* Returns a mask that will most likely match any address the
    349 	 * user will have from that location.  For IP addresses, wildcards the
    350 	 * last octet (e.g. 35.1.1.1 -> 35.1.1.*). for named addresses, wildcards
    351 	 * the leftmost part of the name unless the  name only contains two parts.
    352 	 * If the username begins with a ~, replace with *.
    353 	 */
    354 	Anope::string Mask() const;
    355 
    356 	/** Notes the usage of an incorrect password. If too many
    357 	 * incorrect passwords are used the user might be killed.
    358 	 * @return true if the user was killed
    359 	 */
    360 	bool BadPassword();
    361 
    362 	/** Finds a user by nick, or possibly UID
    363 	 * @param name The nick, or possibly UID, to lookup
    364 	 * @param nick_only set to true to only look up by nick, not UID
    365 	 * @return the user, if they exist
    366 	 */
    367 	static User* Find(const Anope::string &name, bool nick_only = false);
    368 
    369 	/** Quits all users who are pending to be quit
    370 	 */
    371 	static void QuitUsers();
    372 };
    373 
    374 #endif // USERS_H