]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/metadata.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / metadata.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013 Adam <Adam@anope.org>
6  *   Copyright (C) 2012-2015 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "commands.h"
28
29 CmdResult CommandMetadata::Handle(User* srcuser, Params& params)
30 {
31         if (params[0] == "*")
32         {
33                 std::string value = params.size() < 3 ? "" : params[2];
34                 FOREACH_MOD(OnDecodeMetaData, (NULL,params[1],value));
35                 return CMD_SUCCESS;
36         }
37
38         if (params[0][0] == '#')
39         {
40                 // Channel METADATA has an additional parameter: the channel TS
41                 // :22D METADATA #channel 12345 extname :extdata
42                 if (params.size() < 3)
43                         throw ProtocolException("Insufficient parameters for channel METADATA");
44
45                 Channel* c = ServerInstance->FindChan(params[0]);
46                 if (!c)
47                         return CMD_FAILURE;
48
49                 time_t ChanTS = ServerCommand::ExtractTS(params[1]);
50                 if (c->age < ChanTS)
51                         // Their TS is newer than ours, discard this command and do not propagate
52                         return CMD_FAILURE;
53
54                 std::string value = params.size() < 4 ? "" : params[3];
55
56                 ExtensionItem* item = ServerInstance->Extensions.GetItem(params[2]);
57                 if ((item) && (item->type == ExtensionItem::EXT_CHANNEL))
58                         item->FromNetwork(c, value);
59                 FOREACH_MOD(OnDecodeMetaData, (c,params[2],value));
60         }
61         else
62         {
63                 User* u = ServerInstance->FindUUID(params[0]);
64                 if (u)
65                 {
66                         ExtensionItem* item = ServerInstance->Extensions.GetItem(params[1]);
67                         std::string value = params.size() < 3 ? "" : params[2];
68
69                         if ((item) && (item->type == ExtensionItem::EXT_USER))
70                                 item->FromNetwork(u, value);
71                         FOREACH_MOD(OnDecodeMetaData, (u,params[1],value));
72                 }
73         }
74
75         return CMD_SUCCESS;
76 }
77
78 CommandMetadata::Builder::Builder(User* user, const std::string& key, const std::string& val)
79         : CmdBuilder("METADATA")
80 {
81         push(user->uuid);
82         push(key);
83         push_last(val);
84 }
85
86 CommandMetadata::Builder::Builder(Channel* chan, const std::string& key, const std::string& val)
87         : CmdBuilder("METADATA")
88 {
89         push(chan->name);
90         push_int(chan->age);
91         push(key);
92         push_last(val);
93 }
94
95 CommandMetadata::Builder::Builder(const std::string& key, const std::string& val)
96         : CmdBuilder("METADATA")
97 {
98         push("*");
99         push(key);
100         push_last(val);
101 }