]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/clientprotocolevent.h
Merge branch 'insp20' into insp3.
[user/henk/code/inspircd.git] / include / clientprotocolevent.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
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 namespace ClientProtocol
23 {
24         namespace Events
25         {
26                 struct Join;
27                 class Mode;
28         }
29 }
30
31 struct ClientProtocol::Events::Join : public ClientProtocol::Messages::Join, public ClientProtocol::Event
32 {
33         Join()
34                 : ClientProtocol::Event(ServerInstance->GetRFCEvents().join, *this)
35         {
36         }
37
38         Join(Membership* Memb)
39                 : ClientProtocol::Messages::Join(Memb)
40                 , ClientProtocol::Event(ServerInstance->GetRFCEvents().join, *this)
41         {
42         }
43
44         Join(Membership* Memb, const std::string& Sourcestr)
45                 : ClientProtocol::Messages::Join(Memb, Sourcestr)
46                 , ClientProtocol::Event(ServerInstance->GetRFCEvents().join, *this)
47         {
48         }
49 };
50
51 class ClientProtocol::Events::Mode : public ClientProtocol::Event
52 {
53         std::list<ClientProtocol::Messages::Mode> modelist;
54         std::vector<Message*> modemsgplist;
55         const Modes::ChangeList& modechanges;
56
57  public:
58         static void BuildMessages(User* source, Channel* Chantarget, User* Usertarget, const Modes::ChangeList& changelist, std::list<ClientProtocol::Messages::Mode>& modelist, std::vector<Message*>& modemsgplist)
59         {
60                 // Build as many MODEs as necessary
61                 for (Modes::ChangeList::List::const_iterator i = changelist.getlist().begin(); i != changelist.getlist().end(); i = modelist.back().GetEndIterator())
62                 {
63                         modelist.push_back(ClientProtocol::Messages::Mode(source, Chantarget, Usertarget, changelist, i));
64                         modemsgplist.push_back(&modelist.back());
65                 }
66         }
67
68         Mode(User* source, Channel* Chantarget, User* Usertarget, const Modes::ChangeList& changelist)
69                 : ClientProtocol::Event(ServerInstance->GetRFCEvents().mode)
70                 , modechanges(changelist)
71         {
72                 BuildMessages(source, Chantarget, Usertarget, changelist, modelist, modemsgplist);
73                 SetMessageList(modemsgplist);
74         }
75
76         const Modes::ChangeList& GetChangeList() const { return modechanges; }
77         const std::list<ClientProtocol::Messages::Mode>& GetMessages() const { return modelist; }
78 };