]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/server.h
Allow modules to prevent a failed connection from being closed.
[user/henk/code/inspircd.git] / include / modules / server.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #pragma once
21
22 #include "event.h"
23
24 namespace ServerProtocol
25 {
26         class BroadcastEventListener;
27         class LinkEventListener;
28         class MessageEventListener;
29         class SyncEventListener;
30 }
31
32 class ServerProtocol::BroadcastEventListener
33         : public Events::ModuleEventListener
34 {
35  public:
36         BroadcastEventListener(Module* mod)
37                 : ModuleEventListener(mod, "event/server-broadcast")
38         {
39         }
40
41         /** Fired when a channel message is being broadcast across the network.
42          * @param channel The channel which is having a message sent to it.
43          * @param server The server which might have a message broadcast to it.
44          * @return Either MOD_RES_ALLOW to always send the message to the server, MOD_RES_DENY to never
45          *         send the message to the server or MOD_RES_PASSTHRU if no module handled the event.
46          */
47         virtual ModResult OnBroadcastMessage(Channel* channel, const Server* server) { return MOD_RES_PASSTHRU; }
48 };
49
50 class ServerProtocol::LinkEventListener
51         : public Events::ModuleEventListener
52 {
53  public:
54         LinkEventListener(Module* mod)
55                 : ModuleEventListener(mod, "event/server-link")
56         {
57         }
58
59         /** Fired when a server finishes burst
60          * @param server Server that recently linked and finished burst
61          */
62         virtual void OnServerLink(const Server* server) { }
63
64          /** Fired when a server splits
65           * @param server Server that split
66           */
67         virtual void OnServerSplit(const Server* server) { }
68 };
69
70 class ServerProtocol::MessageEventListener
71         : public Events::ModuleEventListener
72 {
73  public:
74         MessageEventListener(Module* mod)
75                 : ModuleEventListener(mod, "event/server-message")
76         {
77         }
78
79         /** Fired when a server message is being sent by a user.
80          * @param source The user who sent the message.
81          * @param name The name of the command which was sent.
82          * @param tags The tags which will be sent with the message.
83          */
84         virtual void OnBuildMessage(User* source, const char* name, ClientProtocol::TagMap& tags) { }
85
86         /** Fired when a server message is being sent by a server.
87          * @param source The server who sent the message.
88          * @param name The name of the command which was sent.
89          * @param tags The tags which will be sent with the message.
90          */
91         virtual void OnBuildMessage(Server* source, const char* name, ClientProtocol::TagMap& tags) { }
92 };
93
94 class ServerProtocol::SyncEventListener
95         : public Events::ModuleEventListener
96 {
97  public:
98         SyncEventListener(Module* mod)
99                 : ModuleEventListener(mod, "event/server-sync")
100         {
101         }
102
103         /** Allows modules to synchronize user metadata during a netburst. This will
104          * be called for every user visible on your side of the burst.
105          * @param user The user being synchronized.
106          * @param server The target of the burst.
107          */
108         virtual void OnSyncUser(User* user, ProtocolServer& server) { }
109
110         /** Allows modules to synchronize channel metadata during a netburst. This will
111          * be called for every channel visible on your side of the burst.
112          * @param chan The channel being synchronized.
113          * @param server The target of the burst.
114          */
115         virtual void OnSyncChannel(Channel* chan, ProtocolServer& server) { }
116
117         /** Allows modules to synchronize network metadata during a netburst.
118          * @param server The target of the burst.
119          */
120         virtual void OnSyncNetwork(ProtocolServer& server) { }
121 };
122
123 /** Compatibility struct for <3.3.0 modules. */
124 class ServerEventListener
125         : public ServerProtocol::BroadcastEventListener
126         , public ServerProtocol::LinkEventListener
127         , public ServerProtocol::SyncEventListener
128 {
129  public:
130         ServerEventListener(Module* mod)
131                 : ServerProtocol::BroadcastEventListener(mod)
132                 , ServerProtocol::LinkEventListener(mod)
133                 , ServerProtocol::SyncEventListener(mod)
134         {
135         }
136 };