/[cvs]/eggdrop1.9/src/traffic.c
ViewVC logotype

Contents of /eggdrop1.9/src/traffic.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Tue Dec 16 21:45:35 2003 UTC (15 years, 9 months ago) by wcc
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
File MIME type: text/x-chdr
FILE REMOVED
* src/ cleanups.

1 /*
2 * traffic.c --
3 */
4 /*
5 * Copyright (C) 2002, 2003, 2004 Eggheads Development Team
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 /*
22 * $Id: traffic.c,v 1.5 2003/12/11 00:49:11 wcc Exp $
23 */
24
25 #include "main.h"
26 #include "dccutil.h" /* dprintf */
27 #include "modules.h" /* add_hook() */
28 #include "traffic.h" /* prototypes */
29
30 #ifndef lint
31 static const char rcsid[] = "$Id: traffic.c,v 1.5 2003/12/11 00:49:11 wcc Exp $";
32 #endif
33
34 egg_traffic_t traffic; /* traffic information */
35
36 /* converts bytes to a human readable string
37 */
38 static char traffictxt[80];
39 static char *btos(unsigned long bytes)
40 {
41 char unit[10];
42 float xbytes;
43
44 sprintf(unit, "Bytes");
45 xbytes = bytes;
46 if (xbytes > 1024.0) {
47 sprintf(unit, "KBytes");
48 xbytes = xbytes / 1024.0;
49 }
50 if (xbytes > 1024.0) {
51 sprintf(unit, "MBytes");
52 xbytes = xbytes / 1024.0;
53 }
54 if (xbytes > 1024.0) {
55 sprintf(unit, "GBytes");
56 xbytes = xbytes / 1024.0;
57 }
58 if (xbytes > 1024.0) {
59 sprintf(unit, "TBytes");
60 xbytes = xbytes / 1024.0;
61 }
62 if (bytes > 1024)
63 sprintf(traffictxt, "%.2f %s", xbytes, unit);
64 else
65 sprintf(traffictxt, "%lu Bytes", bytes);
66
67 return traffictxt;
68 }
69
70 /* update outgoing traffic stats (used in main.c loop)
71 */
72 void traffic_update_out(struct dcc_table *type, int size)
73 {
74 if (!type->name) /* sanity check */
75 return;
76
77 if (!strncmp(type->name, "BOT", 3))
78 traffic.out_today.bn += size;
79 else if (!strcmp(type->name, "SERVER"))
80 traffic.out_today.irc += size;
81 else if (!strncmp(type->name, "CHAT", 4))
82 traffic.out_today.dcc += size;
83 else if (!strncmp(type->name, "FILES", 5))
84 traffic.out_today.dcc += size;
85 else
86 traffic.out_today.unknown += size;
87 }
88
89 /* update incoming traffic stats (used in main.c loop)
90 */
91 void traffic_update_in(struct dcc_table *type, int size)
92 {
93 if (!type->name) /* sanity check */
94 return;
95
96 if (!strncmp(type->name, "BOT", 3))
97 traffic.in_today.bn += size;
98 else if (!strcmp(type->name, "SERVER"))
99 traffic.in_today.irc += size;
100 else if (!strncmp(type->name, "CHAT", 4))
101 traffic.in_today.dcc += size;
102 else if (!strncmp(type->name, "FILES", 5))
103 traffic.in_today.dcc += size;
104 else
105 traffic.in_today.unknown += size;
106 }
107
108 /* init our traffic stats
109 */
110 void traffic_init()
111 {
112 add_hook(HOOK_DAILY, (Function) traffic_reset);
113 }
114
115 /* resets our traffic stats (called in main.c)
116 */
117 void traffic_reset()
118 {
119 traffic.out_total.irc += traffic.out_today.irc;
120 traffic.out_total.bn += traffic.out_today.bn;
121 traffic.out_total.dcc += traffic.out_today.dcc;
122 traffic.out_total.filesys += traffic.out_today.filesys;
123 traffic.out_total.unknown += traffic.out_today.unknown;
124
125 traffic.in_total.irc += traffic.in_today.irc;
126 traffic.in_total.bn += traffic.in_today.bn;
127 traffic.in_total.dcc += traffic.in_today.dcc;
128 traffic.in_total.filesys += traffic.in_today.filesys;
129 traffic.in_total.unknown += traffic.in_today.unknown;
130
131 memset(&traffic.out_today, 0, sizeof(traffic.out_today));
132 memset(&traffic.in_today, 0, sizeof(traffic.in_today));
133 }
134
135 /* traffic dcc command
136 */
137 int cmd_traffic(struct userrec *u, int idx, char *par)
138 {
139 unsigned long itmp, itmp2;
140
141 dprintf(idx, "Traffic since last restart\n");
142 dprintf(idx, "==========================\n");
143
144 /* IRC */
145 if (traffic.out_total.irc > 0 || traffic.in_total.irc > 0 ||
146 traffic.out_today.irc > 0 || traffic.in_today.irc > 0) {
147 dprintf(idx, "IRC:\n");
148 dprintf(idx, " out: %s", btos(traffic.out_total.irc
149 + traffic.out_today.irc));
150 dprintf(idx, " (%s today)\n", btos(traffic.out_today.irc));
151 dprintf(idx, " in: %s", btos(traffic.in_total.irc
152 + traffic.in_today.irc));
153 dprintf(idx, " (%s today)\n", btos(traffic.in_today.irc));
154 }
155
156 /*
157 if (traffic.out_total.bn > 0 || traffic.in_total.bn > 0 ||
158 traffic.out_today.bn > 0 || traffic.in_today.bn > 0) {
159 dprintf(idx, "Botnet:\n");
160 dprintf(idx, " out: %s", btos(traffic.out_total.bn
161 + traffic.out_today.bn));
162 dprintf(idx, " (%s today)\n", btos(traffic.out_today.bn));
163 dprintf(idx, " in: %s", btos(traffic.in_total.bn + traffic.in_today.bn));
164 dprintf(idx, " (%s today)\n", btos(traffic.in_today.bn));
165 }
166 */
167
168 /* Partyline */
169 if (traffic.out_total.dcc > 0 || traffic.in_total.dcc > 0 ||
170 traffic.out_today.dcc > 0 || traffic.in_today.dcc > 0) {
171 itmp = traffic.out_total.dcc + traffic.out_today.dcc;
172 itmp2 = traffic.out_today.dcc;
173
174 dprintf(idx, "Partyline:\n");
175 dprintf(idx, " out: %s", btos(itmp));
176 dprintf(idx, " (%s today)\n", btos(itmp2));
177 dprintf(idx, " in: %s", btos(traffic.in_total.dcc +
178 traffic.in_today.dcc));
179 dprintf(idx, " (%s today)\n", btos(traffic.in_today.dcc));
180 }
181
182 /* unknown */
183 if (traffic.out_total.unknown > 0 || traffic.out_today.unknown > 0) {
184 dprintf(idx, "Misc:\n");
185 dprintf(idx, " out: %s", btos(traffic.out_total.unknown +
186 traffic.out_today.unknown));
187 dprintf(idx, " (%s today)\n", btos(traffic.out_today.unknown));
188 dprintf(idx, " in: %s", btos(traffic.in_total.unknown +
189 traffic.in_today.unknown));
190 dprintf(idx, " (%s today)\n", btos(traffic.in_today.unknown));
191 }
192
193 dprintf(idx, "---\n");
194 dprintf(idx, "Total:\n");
195
196 /* compute total */
197 itmp = traffic.out_total.irc + traffic.out_total.bn +
198 traffic.out_total.dcc + traffic.out_total.unknown +
199 traffic.out_today.irc + traffic.out_today.bn +
200 traffic.out_today.dcc + traffic.out_today.unknown;
201
202 itmp2 = traffic.out_today.irc + traffic.out_today.bn +
203 traffic.out_today.dcc + traffic.out_today.unknown;
204
205 dprintf(idx, " out: %s", btos(itmp));
206 dprintf(idx, " (%s today)\n", btos(itmp2));
207 dprintf(idx, " in: %s", btos(traffic.in_total.irc + traffic.in_total.bn +
208 traffic.in_total.dcc + traffic.in_total.unknown +
209 traffic.in_today.irc + traffic.in_today.bn + traffic.in_today.dcc +
210 traffic.in_today.unknown));
211
212 dprintf(idx, " (%s today)\n", btos(traffic.in_today.irc +
213 traffic.in_today.bn + traffic.in_today.dcc +
214 traffic.in_today.unknown));
215
216 return 1;
217 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23