Anope IRC Services  Version 2.0
ratbox.cpp
Go to the documentation of this file.
1 /* Ratbox IRCD functions
2  *
3  * (C) 2003-2014 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 #include "module.h"
13 
15 
16 static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid");
17 
18 class RatboxProto : public IRCDProto
19 {
20  public:
21  RatboxProto(Module *creator) : IRCDProto(creator, "Ratbox 3.0+")
22  {
23  DefaultPseudoclientModes = "+oiS";
24  CanSNLine = true;
25  CanSQLine = true;
26  CanSZLine = true;
27  RequiresID = true;
28  MaxModes = 4;
29  }
30 
31  void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { hybrid->SendSVSKillInternal(source, targ, reason); }
32  void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); }
33  void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
34  void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); }
35  void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); }
36  void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); }
37  void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); }
38  void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); }
39  void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); }
40  void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { hybrid->SendJoin(user, c, status); }
41  void SendServer(const Server *server) anope_override { hybrid->SendServer(server); }
42  void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override { hybrid->SendModeInternal(source, u, buf); }
43  void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); }
44  bool IsIdentValid(const Anope::string &ident) anope_override { return hybrid->IsIdentValid(ident); }
45 
47  {
48  UplinkSocket::Message(source) << "OPERWALL :" << buf;
49  }
50 
52  {
53  UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID();
54  /*
55  QS - Can handle quit storm removal
56  EX - Can do channel +e exemptions
57  CHW - Can do channel wall @#
58  IE - Can do invite exceptions
59  GLN - Can do GLINE message
60  KNOCK - supports KNOCK
61  TB - supports topic burst
62  ENCAP - supports ENCAP
63  */
64  UplinkSocket::Message() << "CAPAB :QS EX CHW IE GLN TB ENCAP";
65  /* Make myself known to myself in the serverlist */
66  SendServer(Me);
67  /*
68  * SVINFO
69  * parv[0] = sender prefix
70  * parv[1] = TS_CURRENT for the server
71  * parv[2] = TS_MIN for the server
72  * parv[3] = server is standalone or connected to non-TS only
73  * parv[4] = server's idea of UTC time
74  */
75  UplinkSocket::Message() << "SVINFO 6 3 0 :" << Anope::CurTime;
76  }
77 
79  {
80  Anope::string modes = "+" + u->GetModes();
81  UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname;
82  }
83 
85  {
86  if (na->nc->HasExt("UNCONFIRMED"))
87  return;
88 
89  UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display;
90  }
91 
93  {
94  UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID();
95  }
96 
98  {
99  BotInfo *bi = source.GetBot();
100  bool needjoin = c->FindUser(bi) == NULL;
101 
102  if (needjoin)
103  {
104  ChannelStatus status;
105 
106  status.AddMode('o');
107  bi->Join(c, &status);
108  }
109 
110  IRCDProto::SendTopic(source, c);
111 
112  if (needjoin)
113  bi->Part(c);
114  }
115 };
116 
118 {
119  IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
120 
121  // Debug: Received: :00BAAAAAB ENCAP * LOGIN Adam
122  void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
123  {
124  if (params[1] == "LOGIN" || params[1] == "SU")
125  {
126  User *u = source.GetUser();
127 
128  NickCore *nc = NickCore::Find(params[2]);
129  if (!nc)
130  return;
131  u->Login(nc);
132 
133  /* Sometimes a user connects, we send them the usual "this nickname is registered" mess (if
134  * their server isn't syncing) and then we receive this.. so tell them about it.
135  */
136  if (u->server->IsSynced())
137  u->SendMessage(Config->GetClient("NickServ"), _("You have been logged in as \002%s\002."), nc->display.c_str());
138  }
139  }
140 };
141 
143 {
145 
146  void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
147  {
148  UplinkSID = params[3];
149  }
150 };
151 
153 {
155 
156  // SERVER hades.arpa 1 :ircd-ratbox test server
157  void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
158  {
159  // Servers other then our immediate uplink are introduced via SID
160  if (params[1] != "1")
161  return;
162  new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID);
163  IRCD->SendPing(Me->GetName(), params[0]);
164  }
165 };
166 
168 {
170 
171  /*
172  * params[0] = channel
173  * params[1] = ts
174  * params[2] = topic OR who set the topic
175  * params[3] = topic if params[2] isnt the topic
176  */
177  void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
178  {
179  time_t topic_time = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime;
180  Channel *c = Channel::Find(params[0]);
181 
182  if (!c)
183  return;
184 
185  const Anope::string &setter = params.size() == 4 ? params[2] : "",
186  topic = params.size() == 4 ? params[3] : params[2];
187 
188  c->ChangeTopicInternal(setter, topic, topic_time);
189  }
190 };
191 
193 {
195 
196  // :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB :Adam
197  void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
198  {
199  /* Source is always the server */
200  User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7], NULL);
201  }
202 };
203 
204 class ProtoRatbox : public Module
205 {
207 
209 
210  /* Core message handlers */
230 
231  /* Hybrid message handlers */
234 
235  /* Our message handlers */
241 
242  void AddModes()
243  {
244  /* user modes */
245  ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a'));
247  // c/C = con
248  // d = debug?
249  ModeManager::AddUserMode(new UserMode("DEAF", 'D'));
250  // f = full?
251  ModeManager::AddUserMode(new UserMode("CALLERID", 'g'));
252  ModeManager::AddUserMode(new UserMode("INVIS", 'i'));
253  // k = skill?
254  ModeManager::AddUserMode(new UserModeOperOnly("LOCOPS", 'l'));
255  // n = nchange
256  ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o'));
257  // r = rej
258  ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's'));
259  ModeManager::AddUserMode(new UserModeNoone("PROTECTED", 'S'));
260  // u = unauth?
261  ModeManager::AddUserMode(new UserMode("WALLOPS", 'w'));
262  // x = external?
263  // y = spy?
264  ModeManager::AddUserMode(new UserModeOperOnly("OPERWALLS", 'z'));
265  // Z = spy?
266 
267  /* b/e/I */
269  ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e'));
270  ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I'));
271 
272  /* v/h/o/a/q */
273  ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0));
274  ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 1));
275 
276  /* l/k */
277  ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
279 
280  /* channel modes */
281  ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i'));
282  ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm'));
283  ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n'));
284  ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
285  ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'r'));
286  ModeManager::AddChannelMode(new ChannelMode("SECRET", 's'));
287  ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't'));
288  ModeManager::AddChannelMode(new ChannelMode("SSL", 'S'));
289  }
290 
291  public:
292  ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
293  ircd_proto(this),
294  message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this),
295  message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this),
296  message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this),
297  message_time(this), message_topic(this), message_version(this), message_whois(this),
298 
299  message_bmask("IRCDMessage", "ratbox/bmask", "hybrid/bmask"), message_join("IRCDMessage", "ratbox/join", "hybrid/join"),
300  message_nick("IRCDMessage", "ratbox/nick", "hybrid/nick"), message_pong("IRCDMessage", "ratbox/pong", "hybrid/pong"),
301  message_sid("IRCDMessage", "ratbox/sid", "hybrid/sid"), message_sjoin("IRCDMessage", "ratbox/sjoin", "hybrid/sjoin"),
302  message_tmode("IRCDMessage", "ratbox/tmode", "hybrid/tmode"),
303 
304  message_encap(this), message_pass(this), message_server(this), message_tburst(this), message_uid(this)
305  {
306 
307  if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK)
308  throw ModuleException("Unable to load hybrid");
309  m_hybrid = ModuleManager::FindModule("hybrid");
310  if (!m_hybrid)
311  throw ModuleException("Unable to find hybrid");
312  if (!hybrid)
313  throw ModuleException("No protocol interface for hybrid");
314 
315  this->AddModes();
316  }
317 
319  {
320  m_hybrid = ModuleManager::FindModule("hybrid");
321  ModuleManager::UnloadModule(m_hybrid, NULL);
322  }
323 };
324 
ServiceAlias message_sjoin
Definition: ratbox.cpp:232
ServiceAlias message_nick
Definition: ratbox.cpp:232
Definition: bots.h:24
bool CanSZLine
Definition: protocol.h:61
void SendLogout(User *u) anope_override
Definition: ratbox.cpp:92
IRCDMessageServer message_server
Definition: ratbox.cpp:238
Definition: servers.h:42
IRCDMessageServer(Module *creator)
Definition: ratbox.cpp:154
bool CanSNLine
Definition: protocol.h:55
static Module * FindModule(const Anope::string &name)
void SendAkillDel(const XLine *x) anope_override
Definition: ratbox.cpp:38
void AddModes()
Definition: ratbox.cpp:242
bool IsSynced() const
Definition: servers.cpp:298
void Run(MessageSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ratbox.cpp:197
~ProtoRatbox()
Definition: ratbox.cpp:318
void Join(Channel *c, ChannelStatus *status=NULL)
Definition: bots.cpp:193
Message::Ping message_ping
Definition: ratbox.cpp:221
void Run(MessageSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ratbox.cpp:157
RatboxProto ircd_proto
Definition: ratbox.cpp:208
Message::Part message_part
Definition: ratbox.cpp:220
IRCDMessageUID message_uid
Definition: ratbox.cpp:240
static ModuleReturn UnloadModule(Module *m, User *u)
void Run(MessageSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ratbox.cpp:122
void Run(MessageSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ratbox.cpp:177
virtual void SendTopic(const MessageSource &, Channel *)
Definition: protocol.cpp:170
const Anope::string & GetSID() const
Definition: servers.cpp:203
Message::Version message_version
Definition: ratbox.cpp:228
Message::SQuit message_squit
Definition: ratbox.cpp:224
Message::Mode message_mode
Definition: ratbox.cpp:217
Message::Topic message_topic
Definition: ratbox.cpp:227
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)
Definition: users.cpp:116
IRCDMessageEncap message_encap
Definition: ratbox.cpp:236
Definition: users.h:34
void SendSGLineDel(const XLine *x) anope_override
Definition: ratbox.cpp:36
Message::Privmsg message_privmsg
Definition: ratbox.cpp:222
Anope::string DefaultPseudoclientModes
Definition: protocol.h:47
void SendChannel(Channel *c) anope_override
Definition: ratbox.cpp:43
Message::Away message_away
Definition: ratbox.cpp:211
void SendTopic(const MessageSource &source, Channel *c) anope_override
Definition: ratbox.cpp:97
Message::Time message_time
Definition: ratbox.cpp:226
ServiceAlias message_join
Definition: ratbox.cpp:232
bool RequiresID
Definition: protocol.h:69
CoreExport time_t CurTime
Definition: main.cpp:41
Message::Capab message_capab
Definition: ratbox.cpp:212
Message::Invite message_invite
Definition: ratbox.cpp:214
void SendClientIntroduction(User *u) anope_override
Definition: ratbox.cpp:78
void SendServer(const Server *server) anope_override
Definition: ratbox.cpp:41
IRCDMessagePass(Module *creator)
Definition: ratbox.cpp:144
Message::Stats message_stats
Definition: ratbox.cpp:225
void SendSQLineDel(const XLine *x) anope_override
Definition: ratbox.cpp:39
ServiceAlias message_pong
Definition: ratbox.cpp:232
void SendSGLine(User *u, const XLine *x) anope_override
Definition: ratbox.cpp:35
bool CanSQLine
Definition: protocol.h:57
Definition: Config.cs:26
void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override
Definition: ratbox.cpp:31
unsigned MaxModes
Definition: protocol.h:73
void Run(MessageSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ratbox.cpp:146
void SendSQLine(User *u, const XLine *x) anope_override
Definition: ratbox.cpp:34
static bool AddUserMode(UserMode *um)
Definition: modes.cpp:391
void SetFlag(IRCDMessageFlag f)
Definition: protocol.h:282
void AddMode(char c)
Definition: modes.cpp:70
virtual void SendPing(const Anope::string &servname, const Anope::string &who)
Definition: protocol.cpp:262
IRCDMessagePass message_pass
Definition: ratbox.cpp:237
void SendConnect() anope_override
Definition: ratbox.cpp:51
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
Definition: ratbox.cpp:40
Message::Notice message_notice
Definition: ratbox.cpp:219
Definition: modes.h:68
Module * m_hybrid
Definition: ratbox.cpp:206
Anope::string display
Definition: account.h:113
Message::Error message_error
Definition: ratbox.cpp:213
void Part(Channel *c, const Anope::string &reason="")
Definition: bots.cpp:211
static Anope::map< std::pair< bool, Anope::string > > modes
Definition: cs_mode.cpp:745
#define anope_override
Definition: services.h:56
Message::Whois message_whois
Definition: ratbox.cpp:229
void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
Definition: ratbox.cpp:33
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
std::basic_string< char, ci_char_traits, std::allocator< char > > string
Definition: hashcomp.h:133
#define MODULE_INIT(x)
Definition: modules.h:45
Server * server
Definition: users.h:77
static ServiceReference< IRCDProto > hybrid("IRCDProto","hybrid")
IRCDMessageTBurst message_tburst
Definition: ratbox.cpp:239
Message::Kick message_kick
Definition: ratbox.cpp:215
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
Definition: ratbox.cpp:46
IRCDMessageTBurst(Module *creator)
Definition: ratbox.cpp:169
void Login(NickCore *core)
Definition: users.cpp:391
CoreExport int CurrentUplink
Definition: main.cpp:43
Message::Quit message_quit
Definition: ratbox.cpp:223
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
const Anope::string & GetName() const
Definition: servers.cpp:175
static bool AddChannelMode(ChannelMode *cm)
Definition: modes.cpp:418
static ModuleReturn LoadModule(const Anope::string &modname, User *u)
ServiceAlias message_sid
Definition: ratbox.cpp:232
void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
Definition: ratbox.cpp:42
void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
Definition: ratbox.cpp:32
Message::Kill message_kill
Definition: ratbox.cpp:216
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
Definition: xline.h:18
void SendLogin(User *u, NickAlias *na) anope_override
Definition: ratbox.cpp:84
CoreExport Server * Me
Definition: servers.cpp:24
const char * c_str() const
Definition: anope.h:117
ServiceAlias message_tmode
Definition: ratbox.cpp:232
ProtoRatbox(const Anope::string &modname, const Anope::string &creator)
Definition: ratbox.cpp:292
IRCDMessageEncap(Module *creator)
Definition: ratbox.cpp:119
IRCDMessageUID(Module *creator)
Definition: ratbox.cpp:194
ServiceAlias message_bmask
Definition: ratbox.cpp:232
void SendAkill(User *u, XLine *x) anope_override
Definition: ratbox.cpp:37
static NickCore * Find(const Anope::string &nick)
Definition: nickcore.cpp:258
void SendMessage(BotInfo *source, const char *fmt,...)
Definition: users.cpp:320
#define _(x)
Definition: services.h:50
static Anope::string UplinkSID
Definition: ratbox.cpp:14
Message::MOTD message_motd
Definition: ratbox.cpp:218
RatboxProto(Module *creator)
Definition: ratbox.cpp:21
bool IsIdentValid(const Anope::string &ident) anope_override
Definition: ratbox.cpp:44