]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
Add <gecos> field to <server> in XML stats output, also add to ProtoServer. Fixes...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / protocolinterface.cpp
1 #include "inspircd.h"
2 #include "m_spanningtree/main.h"
3 #include "m_spanningtree/utils.h"
4 #include "m_spanningtree/treeserver.h"
5 #include "m_spanningtree/treesocket.h"
6 #include "m_spanningtree/protocolinterface.h"
7
8 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
9 {
10         sl.clear();
11         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
12         {
13                 ProtoServer ps;
14                 ps.servername = i->second->GetName();
15                 TreeServer* s = i->second->GetParent();
16                 ps.parentname = s ? s->GetName() : ServerInstance->Config->ServerName;
17                 ps.usercount = i->second->GetUserCount();
18                 ps.opercount = i->second->GetOperCount();
19                 ps.gecos = i->second->GetDesc();
20                 ps.latencyms = i->second->rtt;
21                 sl.push_back(ps);
22         }
23 }
24
25 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
26 {
27         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
28 }
29
30 void SpanningTreeProtocolInterface::SendMetaData(void* target, int type, const std::string &key, const std::string &data)
31 {
32         parameterlist params;
33
34         switch (type)
35         {
36                 case TYPE_USER:
37                         params.push_back(((User*)target)->uuid);
38                 break;
39                 case TYPE_CHANNEL:
40                         params.push_back(((Channel*)target)->name);
41                 break;
42                 case TYPE_SERVER:
43                         params.push_back("*");
44                 break;
45         }
46         params.push_back(key);
47         params.push_back(":" + data);
48
49         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
50 }
51
52 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
53 {
54         parameterlist params;
55
56         params.push_back(channel->name);
57         params.push_back(ConvToStr(ServerInstance->Time()));
58         params.push_back(ServerInstance->Config->ServerName);
59         params.push_back(":" + topic);
60
61         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
62 }
63
64 void SpanningTreeProtocolInterface::SendMode(const std::string &target, parameterlist &modedata)
65 {
66         if (modedata.empty())
67                 return;
68
69         std::string outdata;
70
71         /* Warning: in-place translation is only safe for type TR_NICK */
72         for (size_t n = 0; n < modedata.size(); n++)
73         {
74                 ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], outdata);
75                 modedata[n] = outdata;
76         }
77
78         std::string uidtarget;
79         ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
80         modedata.insert(modedata.begin(), uidtarget);
81
82         User* a = ServerInstance->FindNick(uidtarget);
83         if (a)
84         {
85                 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
86                 return;
87         }
88         else
89         {
90                 Channel* c = ServerInstance->FindChan(target);
91                 if (c)
92                 {
93                         modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
94                         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
95                 }
96         }
97 }
98
99 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
100 {
101         parameterlist p;
102         p.push_back(modes);
103         p.push_back(":" + text);
104         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
105 }
106
107 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
108 {
109         parameterlist p;
110         p.push_back(snomask);
111         p.push_back(":" + text);
112         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
113 }
114
115 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
116 {
117         parameterlist p;
118         p.push_back(target->uuid);
119         p.push_back(rawline);
120         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
121 }
122
123 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
124 {
125         std::string cname = target->name;
126         if (status)
127                 cname = status + cname;
128         TreeServerList list;
129         CUList exempt_list;
130         Utils->GetListOfServersForChannel(target,list,status,exempt_list);
131         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
132         {
133                 TreeSocket* Sock = i->second->GetSocket();
134                 if (Sock)
135                         Sock->WriteLine(text);
136         }
137 }
138
139
140 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
141 {
142         SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
143 }
144
145 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
146 {
147         SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
148 }
149
150 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
151 {
152         TreeServer* serv = Utils->FindServer(target->server);
153         if (serv)
154         {
155                 TreeSocket* sock = serv->GetSocket();
156                 if (sock)
157                 {
158                         sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text);
159                 }
160         }
161 }
162
163 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
164 {
165         TreeServer* serv = Utils->FindServer(target->server);
166         if (serv)
167         {
168                 TreeSocket* sock = serv->GetSocket();
169                 if (sock)
170                 {
171                         sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text);
172                 }
173         }
174 }
175
176 void SpanningTreeProtocolInterface::Introduce(User* user)
177 {
178         if (IS_LOCAL(user))
179         {
180                 std::deque<std::string> params;
181                 params.push_back(user->uuid);
182                 params.push_back(ConvToStr(user->age));
183                 params.push_back(user->nick);
184                 params.push_back(user->host);
185                 params.push_back(user->dhost);
186                 params.push_back(user->ident);
187                 params.push_back("+"+std::string(user->FormatModes()));
188                 params.push_back(user->GetIPString());
189                 params.push_back(ConvToStr(user->signon));
190                 params.push_back(":"+std::string(user->fullname));
191                 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
192         }
193
194         TreeServer* SourceServer = Utils->FindServer(user->server);
195         if (SourceServer)
196         {
197                 SourceServer->SetUserCount(1); // increment by 1
198         }
199 }