]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/protocol.h
Merge pull request #677 from Robby-/master-dnsblzline
[user/henk/code/inspircd.git] / include / protocol.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #pragma once
22
23 #include "hashcomp.h"
24
25 class User;
26
27 typedef std::vector<std::string> parameterlist;
28
29 class ProtocolServer
30 {
31  public:
32         /** Send metadata related to this server to the target server
33          * @param key The 'key' of the data
34          * @param data The string representation of the data
35          */
36         virtual void SendMetaData(const std::string& key, const std::string& data) = 0;
37 };
38
39 class CoreExport ProtocolInterface
40 {
41  public:
42         typedef ProtocolServer Server;
43
44         class ServerInfo
45         {
46          public:
47                 std::string servername;
48                 std::string parentname;
49                 std::string gecos;
50                 unsigned int usercount;
51                 unsigned int opercount;
52                 unsigned int latencyms;
53         };
54
55         typedef std::vector<ServerInfo> ServerList;
56
57         virtual ~ProtocolInterface() { }
58
59         /** Send an ENCAP message to all servers matching a wildcard string.
60          * See the protocol documentation for the purpose of ENCAP.
61          * @param targetmask The target server mask (can contain wildcards)
62          * @param cmd The ENCAP subcommand
63          * @param params List of string parameters which are dependant on the subcommand
64          * @param source The source of the message (prefix), must be a local user or NULL which means use local server
65          * @return Always true if the target mask contains wildcards; otherwise true if the server name was found,
66          * and the message was sent, false if it was not found.
67          * ENCAP (should) be used instead of creating new protocol messages for easier third party application support.
68          */
69         virtual bool SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const parameterlist& params, User* source = NULL) { return false; }
70
71         /** Send an ENCAP message to all servers.
72          * See the protocol documentation for the purpose of ENCAP.
73          * @param cmd The ENCAP subcommand
74          * @param params List of string parameters which are dependant on the subcommand
75          * @param source The source of the message (prefix), must be a local user or a user behind 'omit'
76          * or NULL which is equivalent to the local server
77          * @param omit If non-NULL the message won't be sent in the direction of this server, useful for forwarding messages
78          */
79         virtual void BroadcastEncap(const std::string& cmd, const parameterlist& params, User* source = NULL, User* omit = NULL) { }
80
81         /** Send metadata for a channel to other linked servers.
82          * @param chan The channel to send metadata for
83          * @param key The 'key' of the data, e.g. "swhois" for swhois desc on a user
84          * @param data The string representation of the data
85          */
86         virtual void SendMetaData(Channel* chan, const std::string& key, const std::string& data) { }
87
88         /** Send metadata for a user to other linked servers.
89          * @param user The user to send metadata for
90          * @param key The 'key' of the data, e.g. "swhois" for swhois desc on a user
91          * @param data The string representation of the data
92          */
93         virtual void SendMetaData(User* user, const std::string& key, const std::string& data) { }
94
95         /** Send metadata related to the server to other linked servers.
96          * @param key The 'key' of the data
97          * @param data The string representation of the data
98          */
99         virtual void SendMetaData(const std::string& key, const std::string& data) { }
100
101         /** Send a notice to users with a given snomask.
102          * @param snomask The snomask required for the message to be sent.
103          * @param text The message to send.
104          */
105         virtual void SendSNONotice(char snomask, const std::string& text) { }
106
107         /** Send a message to a channel.
108          * @param target The channel to message.
109          * @param status The status character (e.g. %) required to recieve.
110          * @param text The message to send.
111          * @param type The message type (MSG_PRIVMSG or MSG_NOTICE)
112          */
113         virtual void SendMessage(Channel* target, char status, const std::string& text, MessageType type = MSG_PRIVMSG) { }
114
115         /** Send a message to a user.
116          * @param target The user to message.
117          * @param text The message to send.
118          * @param type The message type (MSG_PRIVMSG or MSG_NOTICE)
119          */
120         virtual void SendMessage(User* target, const std::string& text, MessageType type = MSG_PRIVMSG) { }
121
122         /** Send a notice to a channel.
123          * @param target The channel to message.
124          * @param status The status character (e.g. %) required to recieve.
125          * @param text The message to send.
126          */
127         void SendChannelNotice(Channel* target, char status, const std::string &text)
128         {
129                 SendMessage(target, status, text, MSG_NOTICE);
130         }
131
132         /** Send a notice to a user.
133          * @param target The user to message.
134          * @param text The message to send.
135          */
136         void SendUserNotice(User* target, const std::string &text)
137         {
138                 SendMessage(target, text, MSG_NOTICE);
139         }
140
141         /** Fill a list of servers and information about them.
142          * @param sl The list of servers to fill.
143          * XXX: document me properly, this is shit.
144          */
145         virtual void GetServerList(ServerList& sl) { }
146 };