]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/protocol.h
Use CommandBase::Params instead of std::vector<std::string>.
[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 class ProtocolServer
28 {
29  public:
30         /** Send metadata related to this server to the target server
31          * @param key The 'key' of the data
32          * @param data The string representation of the data
33          */
34         virtual void SendMetaData(const std::string& key, const std::string& data) = 0;
35 };
36
37 class CoreExport ProtocolInterface
38 {
39  public:
40         typedef ProtocolServer Server;
41
42         class ServerInfo
43         {
44          public:
45                 std::string servername;
46                 std::string parentname;
47                 std::string description;
48                 unsigned int usercount;
49                 unsigned int opercount;
50                 unsigned int latencyms;
51         };
52
53         typedef std::vector<ServerInfo> ServerList;
54
55         virtual ~ProtocolInterface() { }
56
57         /** Send an ENCAP message to all servers matching a wildcard string.
58          * See the protocol documentation for the purpose of ENCAP.
59          * @param targetmask The target server mask (can contain wildcards)
60          * @param cmd The ENCAP subcommand
61          * @param params List of string parameters which are dependant on the subcommand
62          * @param source The source of the message (prefix), must be a local user or NULL which means use local server
63          * @return Always true if the target mask contains wildcards; otherwise true if the server name was found,
64          * and the message was sent, false if it was not found.
65          * ENCAP (should) be used instead of creating new protocol messages for easier third party application support.
66          */
67         virtual bool SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const CommandBase::Params& params, User* source = NULL) { return false; }
68
69         /** Send an ENCAP message to all servers.
70          * See the protocol documentation for the purpose of ENCAP.
71          * @param cmd The ENCAP subcommand
72          * @param params List of string parameters which are dependant on the subcommand
73          * @param source The source of the message (prefix), must be a local user or a user behind 'omit'
74          * or NULL which is equivalent to the local server
75          * @param omit If non-NULL the message won't be sent in the direction of this server, useful for forwarding messages
76          */
77         virtual void BroadcastEncap(const std::string& cmd, const CommandBase::Params& params, User* source = NULL, User* omit = NULL) { }
78
79         /** Send metadata for a channel to other linked servers.
80          * @param chan The channel to send metadata for
81          * @param key The 'key' of the data, e.g. "swhois" for swhois desc on a user
82          * @param data The string representation of the data
83          */
84         virtual void SendMetaData(Channel* chan, const std::string& key, const std::string& data) { }
85
86         /** Send metadata for a user to other linked servers.
87          * @param user The user to send metadata for
88          * @param key The 'key' of the data, e.g. "swhois" for swhois desc on a user
89          * @param data The string representation of the data
90          */
91         virtual void SendMetaData(User* user, const std::string& key, const std::string& data) { }
92
93         /** Send metadata related to the server to other linked servers.
94          * @param key The 'key' of the data
95          * @param data The string representation of the data
96          */
97         virtual void SendMetaData(const std::string& key, const std::string& data) { }
98
99         /** Send a notice to users with a given snomask.
100          * @param snomask The snomask required for the message to be sent.
101          * @param text The message to send.
102          */
103         virtual void SendSNONotice(char snomask, const std::string& text) { }
104
105         /** Send a message to a channel.
106          * @param target The channel to message.
107          * @param status The status character (e.g. %) required to recieve.
108          * @param text The message to send.
109          * @param type The message type (MSG_PRIVMSG or MSG_NOTICE)
110          */
111         virtual void SendMessage(Channel* target, char status, const std::string& text, MessageType type = MSG_PRIVMSG) { }
112
113         /** Send a message to a user.
114          * @param target The user to message.
115          * @param text The message to send.
116          * @param type The message type (MSG_PRIVMSG or MSG_NOTICE)
117          */
118         virtual void SendMessage(User* target, const std::string& text, MessageType type = MSG_PRIVMSG) { }
119
120         /** Send a notice to a channel.
121          * @param target The channel to message.
122          * @param status The status character (e.g. %) required to recieve.
123          * @param text The message to send.
124          */
125         void SendChannelNotice(Channel* target, char status, const std::string &text)
126         {
127                 SendMessage(target, status, text, MSG_NOTICE);
128         }
129
130         /** Send a notice to a user.
131          * @param target The user to message.
132          * @param text The message to send.
133          */
134         void SendUserNotice(User* target, const std::string &text)
135         {
136                 SendMessage(target, text, MSG_NOTICE);
137         }
138
139         /** Fill a list of servers and information about them.
140          * @param sl The list of servers to fill.
141          * XXX: document me properly, this is shit.
142          */
143         virtual void GetServerList(ServerList& sl) { }
144 };