anope

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

servers.h (4647B)

      1 /*
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at 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 SERVERS_H
     13 #define SERVERS_H
     14 
     15 #include "services.h"
     16 #include "anope.h"
     17 #include "extensible.h"
     18 
     19 /* Anope. We are at the top of the server tree, our uplink is
     20  * almost always me->GetLinks()[0]. We never have an uplink. */
     21 extern CoreExport Server *Me;
     22 
     23 namespace Servers
     24 {
     25 	/* Gets our uplink. Note we don't actually have an "uplink", this is just
     26 	 * the only server whose uplink *is* Me that is not a juped server.
     27 	 * @return Our uplink, or NULL if not uplinked to anything
     28 	 */
     29 	extern CoreExport Server* GetUplink();
     30 
     31 	/* Server maps by name and id */
     32 	extern CoreExport Anope::map<Server *> ByName;
     33 	extern CoreExport Anope::map<Server *> ByID;
     34 
     35 	/* CAPAB/PROTOCTL given by the uplink */
     36 	extern CoreExport std::set<Anope::string> Capab;
     37 }
     38 
     39 /** Class representing a server
     40  */
     41 class CoreExport Server : public Extensible
     42 {
     43  private:
     44 	/* Server name */
     45 	Anope::string name;
     46 	/* Hops between services and server */
     47 	unsigned int hops;
     48 	/* Server description */
     49 	Anope::string description;
     50 	/* Server ID */
     51 	Anope::string sid;
     52 	/* Links for this server */
     53 	std::vector<Server *> links;
     54 	/* Uplink for this server */
     55 	Server *uplink;
     56 	/* Server is syncing */
     57 	bool syncing;
     58 	/* The server is juped */
     59 	bool juped;
     60 	/* The server is about to quit */
     61 	bool quitting;
     62 	/* Reason this server was quit */
     63 	Anope::string quit_reason;
     64 
     65  public:
     66 	/** Constructor
     67 	 * @param uplink The uplink this server is from, is only NULL when creating Me
     68 	 * @param name The server name
     69 	 * @param hops Hops from services server
     70 	 * @param description Server rdescription
     71 	 * @param sid Server sid/numeric
     72 	 * @param jupe If the server is juped
     73 	 */
     74 	Server(Server *uplink, const Anope::string &name, unsigned hops, const Anope::string &description, const Anope::string &sid = "", bool jupe = false);
     75 
     76  private:
     77 	/** Destructor
     78 	 */
     79 	~Server();
     80 
     81  public:
     82 	/* Number of users on the server */
     83 	unsigned users;
     84 
     85 	/** Delete this server with a reason
     86 	 * @param reason The reason
     87 	 */
     88 	void Delete(const Anope::string &reason);
     89 
     90 	/** Get the name for this server
     91 	 * @return The name
     92 	 */
     93 	const Anope::string &GetName() const;
     94 
     95 	/** Get the number of hops this server is from services
     96 	 * @return Number of hops
     97 	 */
     98 	unsigned GetHops() const;
     99 
    100 	/** Set the server description
    101 	 * @param desc The new description
    102 	 */
    103 	void SetDescription(const Anope::string &desc);
    104 
    105 	/** Get the server description
    106 	 * @return The server description
    107 	 */
    108 	const Anope::string &GetDescription() const;
    109 
    110 	/** Change this servers SID
    111 	 * @param sid The new SID
    112 	 */
    113 	void SetSID(const Anope::string &sid);
    114 
    115 	/** Get the server numeric/SID, else the server name
    116 	 * @return The numeric/SID
    117 	 */
    118 	const Anope::string &GetSID() const;
    119 
    120 	/** Retrieves the reason this server is quitting
    121 	 */
    122 	const Anope::string &GetQuitReason() const;
    123 
    124 	/** Get the list of links this server has, or NULL if it has none
    125 	 * @return A list of servers
    126 	 */
    127 	const std::vector<Server *> &GetLinks() const;
    128 
    129 	/** Get the uplink server for this server, if this is our uplink will be Me
    130 	 * @return The servers uplink
    131 	 */
    132 	Server *GetUplink();
    133 
    134 	/** Adds a link to this server
    135 	 * @param s The linking server
    136 	 */
    137 	void AddLink(Server *s);
    138 
    139 	/** Delinks a server from this server
    140 	 * @param s The server
    141 	 */
    142 	void DelLink(Server *s);
    143 
    144 	/** Finish syncing this server and optionally all links to it
    145 	 * @param sync_links True to sync the links for this server too (if any)
    146 	 */
    147 	void Sync(bool sync_links);
    148 
    149 	/** Check if this server is synced
    150 	 * @return true or false
    151 	 */
    152 	bool IsSynced() const;
    153 
    154 	/** Unsync the server. Only used for Me->Unsync()
    155 	 */
    156 	void Unsync();
    157 
    158 	/** Check if this server is ULined
    159 	 * @return true or false
    160 	 */
    161 	bool IsULined() const;
    162 
    163 	/** Check if this server is juped (a pseudoserver other than us)
    164 	 * @return true if this server is a juped server
    165 	 */
    166 	bool IsJuped() const;
    167 
    168 	/** Check if the server is quitting
    169 	 * @return true if this server is quitting.
    170 	 */
    171 	bool IsQuitting() const;
    172 
    173 	/** Send a message to all users on this server
    174 	 * @param source The source of the message
    175 	 * @param message The message
    176 	 */
    177 	void Notice(BotInfo *source, const Anope::string &message);
    178 
    179 	/** Find a server
    180 	 * @param name The name or SID/numeric
    181 	 * @param name_only set to true to only look up by name, not SID
    182 	 * @return The server
    183 	 */
    184 	static Server *Find(const Anope::string &name, bool name_only = false);
    185 };
    186 
    187 #endif // SERVERS_H