anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
protocol.h (12072B)
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 PROTOCOL_H 13 #define PROTOCOL_H 14 15 #include "services.h" 16 #include "anope.h" 17 #include "service.h" 18 #include "modes.h" 19 20 /* Encapsulates the IRCd protocol we are speaking. */ 21 class CoreExport IRCDProto : public Service 22 { 23 Anope::string proto_name; 24 25 protected: 26 IRCDProto(Module *creator, const Anope::string &proto_name); 27 public: 28 virtual ~IRCDProto(); 29 30 virtual void SendSVSKillInternal(const MessageSource &, User *, const Anope::string &); 31 virtual void SendModeInternal(const MessageSource &, const Channel *, const Anope::string &); 32 virtual void SendModeInternal(const MessageSource &, User *, const Anope::string &); 33 virtual void SendKickInternal(const MessageSource &, const Channel *, User *, const Anope::string &); 34 virtual void SendNoticeInternal(const MessageSource &, const Anope::string &dest, const Anope::string &msg); 35 virtual void SendPrivmsgInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf); 36 virtual void SendQuitInternal(User *, const Anope::string &buf); 37 virtual void SendPartInternal(User *, const Channel *chan, const Anope::string &buf); 38 virtual void SendGlobopsInternal(const MessageSource &, const Anope::string &buf); 39 virtual void SendCTCPInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf); 40 virtual void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf); 41 42 const Anope::string &GetProtocolName(); 43 virtual bool Parse(const Anope::string &, Anope::map<Anope::string> &, Anope::string &, Anope::string &, std::vector<Anope::string> &); 44 virtual Anope::string Format(const Anope::string &source, const Anope::string &message); 45 46 /* Modes used by default by our clients */ 47 Anope::string DefaultPseudoclientModes; 48 /* Can we force change a users's nick? */ 49 bool CanSVSNick; 50 /* Can we force join or part users? */ 51 bool CanSVSJoin; 52 /* Can we set vhosts/vidents on users? */ 53 bool CanSetVHost, CanSetVIdent; 54 /* Can we ban specific gecos from being used? */ 55 bool CanSNLine; 56 /* Can we ban specific nicknames from being used? */ 57 bool CanSQLine; 58 /* Can we ban specific channel names from being used? */ 59 bool CanSQLineChannel; 60 /* Can we ban by IP? */ 61 bool CanSZLine; 62 /* Can we place temporary holds on specific nicknames? */ 63 bool CanSVSHold; 64 /* See os_oline */ 65 bool CanSVSO; 66 /* See ns_cert */ 67 bool CanCertFP; 68 /* Whether this IRCd requires unique IDs for each user or server. See TS6/P10. */ 69 bool RequiresID; 70 /* If this IRCd has unique ids, whether the IDs and nicknames are ambiguous */ 71 bool AmbiguousID; 72 /* The maximum number of modes we are allowed to set with one MODE command */ 73 unsigned MaxModes; 74 /* The maximum number of bytes a line may have */ 75 unsigned MaxLine; 76 77 /* Retrieves the next free UID or SID */ 78 virtual Anope::string UID_Retrieve(); 79 virtual Anope::string SID_Retrieve(); 80 81 /** Sets the server in NOOP mode. If NOOP mode is enabled, no users 82 * will be able to oper on the server. 83 * @param s The server 84 * @param mode Whether to turn NOOP on or off 85 */ 86 virtual void SendSVSNOOP(const Server *s, bool mode) { } 87 88 /** Sets the topic on a channel 89 * @param bi The bot to set the topic from 90 * @param c The channel to set the topic on. The topic being set is Channel::topic 91 */ 92 virtual void SendTopic(const MessageSource &, Channel *); 93 94 /** Sets a vhost on a user. 95 * @param u The user 96 * @param vident The ident to set 97 * @param vhost The vhost to set 98 */ 99 virtual void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) { } 100 virtual void SendVhostDel(User *) { } 101 102 /** Sets an akill. This is a recursive function that can be called multiple times 103 * for the same xline, but for different users, if the xline is not one that can be 104 * enforced by the IRCd, such as a nick/user/host/realname combination ban. 105 * @param u The user affected by the akill, if known 106 * @param x The akill 107 */ 108 virtual void SendAkill(User *, XLine *) = 0; 109 virtual void SendAkillDel(const XLine *) = 0; 110 111 /* Realname ban */ 112 virtual void SendSGLine(User *, const XLine *) { } 113 virtual void SendSGLineDel(const XLine *) { } 114 115 /* IP ban */ 116 virtual void SendSZLine(User *u, const XLine *) { } 117 virtual void SendSZLineDel(const XLine *) { } 118 119 /* Nick ban (and sometimes channel) */ 120 virtual void SendSQLine(User *, const XLine *x) { } 121 virtual void SendSQLineDel(const XLine *x) { } 122 123 virtual void SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason); 124 125 /** Kills a user 126 * @param source Who is doing the kill 127 * @param user The user to be killed 128 * @param fmt Kill reason 129 */ 130 virtual void SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...); 131 132 virtual void SendMode(const MessageSource &source, const Channel *dest, const char *fmt, ...); 133 virtual void SendMode(const MessageSource &source, User *u, const char *fmt, ...); 134 135 /** Introduces a client to the rest of the network 136 * @param u The client to introduce 137 */ 138 virtual void SendClientIntroduction(User *u) = 0; 139 140 virtual void SendKick(const MessageSource &source, const Channel *chan, User *user, const char *fmt, ...); 141 142 virtual void SendNotice(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); 143 virtual void SendPrivmsg(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); 144 virtual void SendAction(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); 145 virtual void SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); 146 147 virtual void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) = 0; 148 virtual void SendGlobalPrivmsg(BotInfo *bi, const Server *desc, const Anope::string &msg) = 0; 149 150 virtual void SendQuit(User *u, const char *fmt, ...); 151 virtual void SendPing(const Anope::string &servname, const Anope::string &who); 152 virtual void SendPong(const Anope::string &servname, const Anope::string &who); 153 154 /** Joins one of our users to a channel. 155 * @param u The user to join 156 * @param c The channel to join the user to 157 * @param status The status to set on the user after joining. This may or may not already internally 158 * be set on the user. This may include the modes in the join, but will usually place them on the mode 159 * stacker to be set "soon". 160 */ 161 virtual void SendJoin(User *u, Channel *c, const ChannelStatus *status) = 0; 162 virtual void SendPart(User *u, const Channel *chan, const char *fmt, ...); 163 164 /** Force joins a user that isn't ours to a channel. 165 * @param bi The source of the message 166 * @param u The user to join 167 * @param chan The channel to join the user to 168 * @param param Channel key? 169 */ 170 virtual void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) { } 171 172 /** Force parts a user that isn't ours from a channel. 173 * @param source The source of the message 174 * @param u The user to part 175 * @param chan The channel to part the user from 176 * @param param part reason, some IRCds don't support this 177 */ 178 virtual void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) { } 179 180 virtual void SendInvite(const MessageSource &source, const Channel *c, User *u); 181 virtual void SendGlobops(const MessageSource &source, const char *fmt, ...); 182 183 /** Sets oper flags on a user, currently only supported by Unreal 184 */ 185 virtual void SendSVSO(BotInfo *, const Anope::string &, const Anope::string &) { } 186 187 /** Sends a nick change of one of our clients. 188 */ 189 virtual void SendNickChange(User *u, const Anope::string &newnick); 190 191 /** Forces a nick change of a user that isn't ours (SVSNICK) 192 */ 193 virtual void SendForceNickChange(User *u, const Anope::string &newnick, time_t when); 194 195 /** Used to introduce ourselves to our uplink. Usually will SendServer(Me) and any other 196 * initial handshake requirements. 197 */ 198 virtual void SendConnect() = 0; 199 200 /** Called right before we begin our burst, after we have handshaked successfully with the uplink. 201 * At this point none of our servers, users, or channels exist on the uplink 202 */ 203 virtual void SendBOB() { } 204 virtual void SendEOB() { } 205 206 virtual void SendSVSHold(const Anope::string &, time_t) { } 207 virtual void SendSVSHoldDel(const Anope::string &) { } 208 209 virtual void SendSWhois(const MessageSource &, const Anope::string &, const Anope::string &) { } 210 211 /** Introduces a server to the uplink 212 */ 213 virtual void SendServer(const Server *) = 0; 214 virtual void SendSquit(Server *, const Anope::string &message); 215 216 virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...); 217 218 virtual void SendLogin(User *u, NickAlias *na) = 0; 219 virtual void SendLogout(User *u) = 0; 220 221 /** Send a channel creation message to the uplink. 222 * On most TS6 IRCds this is a SJOIN with no nick 223 */ 224 virtual void SendChannel(Channel *c) { } 225 226 /** Make the user an IRC operator 227 * Normally this is a simple +o, though some IRCds require us to send the oper type 228 */ 229 virtual void SendOper(User *u); 230 231 virtual void SendSASLMechanisms(std::vector<Anope::string> &) { } 232 virtual void SendSASLMessage(const SASL::Message &) { } 233 virtual void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) { } 234 235 virtual bool IsNickValid(const Anope::string &); 236 virtual bool IsChannelValid(const Anope::string &); 237 virtual bool IsIdentValid(const Anope::string &); 238 virtual bool IsHostValid(const Anope::string &); 239 virtual bool IsExtbanValid(const Anope::string &) { return false; } 240 241 /** Retrieve the maximum number of list modes settable on this channel 242 * Defaults to Config->ListSize 243 */ 244 virtual unsigned GetMaxListFor(Channel *c); 245 virtual unsigned GetMaxListFor(Channel *c, ChannelMode *cm); 246 247 virtual Anope::string NormalizeMask(const Anope::string &mask); 248 }; 249 250 class CoreExport MessageSource 251 { 252 Anope::string source; 253 User *u; 254 Server *s; 255 256 public: 257 MessageSource(const Anope::string &); 258 MessageSource(User *u); 259 MessageSource(Server *s); 260 const Anope::string &GetName() const; 261 const Anope::string &GetSource() const; 262 User *GetUser() const; 263 BotInfo *GetBot() const; 264 Server *GetServer() const; 265 }; 266 267 enum IRCDMessageFlag 268 { 269 IRCDMESSAGE_SOFT_LIMIT, 270 IRCDMESSAGE_REQUIRE_SERVER, 271 IRCDMESSAGE_REQUIRE_USER 272 }; 273 274 class CoreExport IRCDMessage : public Service 275 { 276 Anope::string name; 277 unsigned param_count; 278 std::set<IRCDMessageFlag> flags; 279 public: 280 IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0); 281 unsigned GetParamCount() const; 282 virtual void Run(MessageSource &, const std::vector<Anope::string> ¶ms) = 0; 283 virtual void Run(MessageSource &, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags); 284 285 void SetFlag(IRCDMessageFlag f) { flags.insert(f); } 286 bool HasFlag(IRCDMessageFlag f) const { return flags.count(f); } 287 }; 288 289 /** MessageTokenizer allows tokens in the IRC wire format to be read from a string */ 290 class CoreExport MessageTokenizer 291 { 292 private: 293 /** The message we are parsing tokens from. */ 294 Anope::string message; 295 296 /** The current position within the message. */ 297 Anope::string::size_type position; 298 299 public: 300 /** Create a tokenstream and fill it with the provided data. */ 301 MessageTokenizer(const Anope::string &msg); 302 303 /** Retrieve the next \<middle> token in the message. 304 * @param token The next token available, or an empty string if none remain. 305 * @return True if a token was retrieved; otherwise, false. 306 */ 307 bool GetMiddle(Anope::string &token); 308 309 /** Retrieve the next \<trailing> token in the message. 310 * @param token The next token available, or an empty string if none remain. 311 * @return True if a token was retrieved; otherwise, false. 312 */ 313 bool GetTrailing(Anope::string &token); 314 }; 315 316 extern CoreExport IRCDProto *IRCD; 317 318 #endif // PROTOCOL_H