1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/* Definitions of IRC message functions and list of messages.
*
* (C) 2003-2012 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#include "services.h"
#include "modules.h"
#include "users.h"
#include "protocol.h"
#include "config.h"
#include "extern.h"
#include "uplink.h"
#include "opertype.h"
bool OnStats(const Anope::string &source, const std::vector<Anope::string> ¶ms)
{
if (params.size() < 1)
return true;
User *u = finduser(source);
switch (params[0][0])
{
case 'l':
if (u && u->HasMode(UMODE_OPER))
{
ircdproto->SendNumeric(211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
ircdproto->SendNumeric(211, source, "%s %d %d %d %d %d %d %ld", Config->Uplinks[CurrentUplink]->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - start_time));
}
ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
break;
case 'o':
case 'O':
/* Check whether the user is an operator */
if (u && !u->HasMode(UMODE_OPER) && Config->HideStatsO)
ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
else
{
for (unsigned i = 0; i < Config->Opers.size(); ++i)
{
Oper *o = Config->Opers[i];
NickAlias *na = findnick(o->name);
if (na)
ircdproto->SendNumeric(243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str());
}
ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
}
break;
case 'u':
{
time_t uptime = Anope::CurTime - start_time;
ircdproto->SendNumeric(242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60);
ircdproto->SendNumeric(250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt);
ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
break;
} /* case 'u' */
default:
ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
}
return true;
}
bool OnTime(const Anope::string &source, const std::vector<Anope::string> &)
{
if (source.empty())
return true;
time_t t;
time(&t);
struct tm *tm = localtime(&t);
char buf[64];
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
ircdproto->SendNumeric(391, source, "%s :%s", Config->ServerName.c_str(), buf);
return true;
}
bool OnVersion(const Anope::string &source, const std::vector<Anope::string> &)
{
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
ircdproto->SendNumeric(351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str());
return true;
}
/* XXX We should cache the file somewhere not open/read/close it on every request */
bool OnMotd(const Anope::string &source, const std::vector<Anope::string> &)
{
if (source.empty())
return true;
FILE *f = fopen(Config->MOTDFilename.c_str(), "r");
if (f)
{
ircdproto->SendNumeric(375, source, ":- %s Message of the Day", Config->ServerName.c_str());
char buf[BUFSIZE];
while (fgets(buf, sizeof(buf), f))
{
buf[strlen(buf) - 1] = 0;
ircdproto->SendNumeric(372, source, ":- %s", buf);
}
fclose(f);
ircdproto->SendNumeric(376, source, ":End of /MOTD command.");
}
else
ircdproto->SendNumeric(422, source, ":- MOTD file not found! Please contact your IRC administrator.");
return true;
}
#define ProtocolFunc(x) \
inline bool x(const Anope::string &source, const std::vector<Anope::string> ¶ms) \
{ \
return ircdmessage->x(source, params); \
}
ProtocolFunc(On436)
ProtocolFunc(OnAway)
ProtocolFunc(OnJoin)
ProtocolFunc(OnKick)
ProtocolFunc(OnKill)
ProtocolFunc(OnMode)
ProtocolFunc(OnNick)
ProtocolFunc(OnUID)
ProtocolFunc(OnPart)
ProtocolFunc(OnPing)
ProtocolFunc(OnPrivmsg)
ProtocolFunc(OnQuit)
ProtocolFunc(OnServer)
ProtocolFunc(OnSQuit)
ProtocolFunc(OnTopic)
ProtocolFunc(OnWhois)
ProtocolFunc(OnCapab)
ProtocolFunc(OnSJoin)
ProtocolFunc(OnError)
void init_core_messages()
{
static Message message_stats("STATS", OnStats);
static Message message_time("TIME", OnTime);
static Message message_verssion("VERSION", OnVersion);
static Message message_motd("MOTD", OnMotd);
static Message message_436("436", On436);
static Message message_away("AWAY", OnAway);
static Message message_join("JOIN", OnJoin);
static Message message_kick("KICK", OnKick);
static Message message_kill("KILL", OnKill);
static Message message_mode("MODE", OnMode);
static Message message_nick("NICK", OnNick);
static Message message_uid("UID", OnUID);
static Message message_part("PART", OnPart);
static Message message_ping("PING", OnPing);
static Message message_privmsg("PRIVMSG", OnPrivmsg);
static Message message_quit("QUIT", OnQuit);
static Message message_server("SERVER", OnServer);
static Message message_squit("SQUIT", OnSQuit);
static Message message_topic("TOPIC", OnTopic);
static Message message_whois("WHOIS", OnWhois);
static Message message_capab("CAPAB", OnCapab);
static Message message_sjoin("SJOIN", OnSJoin);
static Message message_error("ERROR", OnError);
}
|