users.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
00004  * (C) 2003-2013 Anope Team
00005  * Contact us at team@anope.org
00006  *
00007  * Please read COPYING and README for further details.
00008  *
00009  * Based on the original code of Epona by Lara.
00010  * Based on the original code of Services by Andy Church.
00011  *
00012  */
00013 
00014 #ifndef USERS_H
00015 #define USERS_H
00016 
00017 #include "anope.h"
00018 #include "modes.h"
00019 #include "extensible.h"
00020 #include "serialize.h"
00021 #include "commands.h"
00022 #include "account.h"
00023 
00024 typedef Anope::hash_map<User *> user_map;
00025 
00026 extern CoreExport user_map UserListByNick, UserListByUID;
00027 
00028 extern CoreExport int OperCount;
00029 extern CoreExport unsigned MaxUserCount;
00030 extern CoreExport time_t MaxUserTime;
00031 
00032 /* Online user and channel data. */
00033 class CoreExport User : public virtual Base, public Extensible, public CommandReply
00034 {
00035         /* true if the user was quit or killed */
00036         bool quit;
00037         /* Users that are in the process of quitting */
00038         static std::list<User *> quitting_users;
00039  protected:
00040         Anope::string vident;
00041         Anope::string ident;
00042         Anope::string uid;
00043         /* If the user is on the access list of the nick theyre on */
00044         bool on_access;
00045         /* Map of user modes and the params this user has (if any) */
00046         std::map<Anope::string, Anope::string> modes;
00047         /* NickCore account the user is currently loggged in as, if they are logged in */
00048         Serialize::Reference<NickCore> nc;
00049 
00050         /* # of invalid password attempts */
00051         unsigned short invalid_pw_count;
00052         /* Time of last invalid password */
00053         time_t invalid_pw_time;
00054 
00055 
00056  public: // XXX: exposing a tiny bit too much
00057         /* User's current nick */
00058         Anope::string nick;
00059 
00060         /* User's real hostname */
00061         Anope::string host;
00062         /* User's virtual hostname */
00063         Anope::string vhost;
00064         /* User's cloaked hostname */
00065         Anope::string chost;
00066         /* Realname */
00067         Anope::string realname;
00068         /* SSL Fingerprint */
00069         Anope::string fingerprint;
00070         /* User's IP */
00071         Anope::string ip;
00072         /* Server user is connected to */
00073         Server *server;
00074         /* When the user signed on. Set on connect and never modified. */
00075         time_t signon;
00076         /* Timestamp of the nick. Updated when the nick changes. */
00077         time_t timestamp;
00078         /* Is the user as super admin? */
00079         bool super_admin;
00080 
00081         /* Channels the user is in */
00082         typedef std::list<ChanUserContainer *> ChanUserList;
00083         ChanUserList chans;
00084 
00085         /* Last time this user sent a memo command used */
00086         time_t lastmemosend;
00087         /* Last time this user registered */
00088         time_t lastnickreg;
00089         /* Last time this user sent an email */
00090         time_t lastmail;
00091 
00106         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 ssignon, const Anope::string &smodes, const Anope::string &suid = "");
00107 
00108  protected:
00111         virtual ~User();
00112 
00113  public:
00119         void ChangeNick(const Anope::string &newnick, time_t ts = Anope::CurTime);
00120 
00125         void SetDisplayedHost(const Anope::string &host);
00126 
00130         const Anope::string &GetDisplayedHost() const;
00131 
00135         void SetCloakedHost(const Anope::string &newhost);
00136 
00140         const Anope::string &GetCloakedHost() const;
00141 
00145         const Anope::string &GetUID() const;
00146 
00150         void SetVIdent(const Anope::string &ident);
00151 
00155         const Anope::string &GetVIdent() const;
00156 
00161         void SetIdent(const Anope::string &ident);
00162 
00167         const Anope::string &GetIdent() const;
00168 
00171         Anope::string GetMask() const;
00172 
00175         Anope::string GetDisplayedMask() const;
00176 
00179         void SetRealname(const Anope::string &realname);
00180 
00187         void SendMessage(const BotInfo *source, const char *fmt, ...);
00188         void SendMessage(const BotInfo *source, const Anope::string &msg) anope_override;
00189 
00194         void Collide(NickAlias *na);
00195 
00201         void Identify(NickAlias *na);
00202 
00206         void Login(NickCore *core);
00207 
00210         void Logout();
00211 
00215         virtual NickCore *Account() const;
00216 
00221         bool IsIdentified(bool check_nick = false) const;
00222 
00227         bool IsRecognized(bool check_nick = true) const;
00228 
00232         bool IsServicesOper();
00233 
00238         bool HasCommand(const Anope::string &cmdstr);
00239 
00244         bool HasPriv(const Anope::string &privstr);
00245 
00248         void UpdateHost();
00249 
00254         bool HasMode(const Anope::string &name) const;
00255 
00260         void SetModeInternal(UserMode *um, const Anope::string &param = "");
00261 
00265         void RemoveModeInternal(UserMode *um);
00266 
00272         void SetMode(const BotInfo *bi, UserMode *um, const Anope::string &param = "");
00273 
00279         void SetMode(const BotInfo *bi, const Anope::string &name, const Anope::string &param = "");
00280 
00285         void RemoveMode(const BotInfo *bi, UserMode *um);
00286 
00291         void RemoveMode(const BotInfo *bi, const Anope::string &name);
00292 
00297         void SetModes(const BotInfo *bi, const char *umodes, ...);
00298 
00302         void SetModesInternal(const char *umodes, ...);
00303 
00307         Anope::string GetModes() const;
00308 
00315         ChanUserContainer *FindChannel(const Channel *c) const;
00316 
00320         bool IsProtected() const;
00321 
00326         void Kill(const Anope::string &source, const Anope::string &reason);
00327 
00332         void KillInternal(const Anope::string &source, const Anope::string &reason);
00333 
00337         void Quit(const Anope::string &reason = "");
00338 
00339         bool Quitting() const;
00340 
00341         /* Returns a mask that will most likely match any address the
00342          * user will have from that location.  For IP addresses, wildcards the
00343          * appropriate subnet mask (e.g. 35.1.1.1 -> 35.*; 128.2.1.1 -> 128.2.*);
00344          * for named addresses, wildcards the leftmost part of the name unless the
00345          * name only contains two parts.  If the username begins with a ~, delete
00346          * it.
00347          */
00348         Anope::string Mask() const;
00349 
00354         bool BadPassword();
00355 
00361         static User* Find(const Anope::string &name, bool nick_only = false);
00362 
00365         static void QuitUsers();
00366 };
00367 
00368 #endif // USERS_H