]>
Commit | Line | Data |
---|---|---|
189935b1 | 1 | /** @file |
2 | * @brief Interface and declarations for client counting functions. | |
3 | * @version $Id: querycmds.h,v 1.7 2004/10/03 17:02:23 entrope Exp $ | |
4 | */ | |
5 | #ifndef INCLUDED_querycmds_h | |
6 | #define INCLUDED_querycmds_h | |
7 | ||
8 | #ifndef INCLUDED_ircd_features_h | |
9 | #include "ircd_features.h" /* feature_str() */ | |
10 | #endif | |
11 | ||
12 | struct Client; | |
13 | ||
14 | /* | |
15 | * Structs | |
16 | */ | |
17 | ||
18 | /** Counts types of clients, servers, etc.\ on the network. */ | |
19 | struct UserStatistics { | |
20 | /* Local connections: */ | |
21 | unsigned int unknowns; /**< Clients of types: unknown, connecting, handshake */ | |
22 | unsigned int local_servers; /**< Directly connected servers. */ | |
23 | unsigned int local_clients; /**< Directly connected clients. */ | |
24 | ||
25 | /* Global counts: */ | |
26 | unsigned int servers; /**< Known servers, including #me. */ | |
27 | unsigned int clients; /**< Registered users. */ | |
28 | ||
29 | /* Global user mode changes: */ | |
30 | unsigned int inv_clients; /**< Registered invisible users. */ | |
31 | unsigned int opers; /**< Registered IRC operators. */ | |
32 | ||
33 | /* Misc: */ | |
34 | unsigned int channels; /**< Existing channels. */ | |
35 | }; | |
36 | ||
37 | extern struct UserStatistics UserStats; | |
38 | ||
39 | /* | |
40 | * Macros | |
41 | */ | |
42 | ||
43 | /* Macros for remote connections: */ | |
44 | /** Count \a cptr as a new remote client. */ | |
45 | #define Count_newremoteclient(UserStats, cptr) (++UserStats.clients, ++(cli_serv(cptr)->clients)) | |
46 | /** Count a new remote server. */ | |
47 | #define Count_newremoteserver(UserStats) (++UserStats.servers) | |
48 | ||
49 | /** Count a remote user quit. */ | |
50 | #define Count_remoteclientquits(UserStats,cptr) \ | |
51 | do { \ | |
52 | --UserStats.clients; \ | |
53 | if (!IsServer(cptr)) \ | |
54 | --(cli_serv(cli_user(cptr)->server)->clients); \ | |
55 | } while (0) | |
56 | ||
57 | /** Count a remote server quit. */ | |
58 | #define Count_remoteserverquits(UserStats) (--UserStats.servers) | |
59 | ||
60 | /* Macros for local connections: */ | |
61 | /** Count a new local unknown connection. */ | |
62 | #define Count_newunknown(UserStats) (++UserStats.unknowns) | |
63 | /** Update counters when \a cptr goes from unknown to registered. */ | |
64 | #define Count_unknownbecomesclient(cptr, UserStats) \ | |
65 | do { \ | |
66 | --UserStats.unknowns; ++UserStats.local_clients; ++UserStats.clients; \ | |
67 | if (match(feature_str(FEAT_DOMAINNAME), cli_sockhost(cptr)) == 0) \ | |
68 | ++current_load.local_count; \ | |
69 | if (UserStats.local_clients > max_client_count) \ | |
70 | max_client_count = UserStats.local_clients; \ | |
71 | if (UserStats.local_clients + UserStats.local_servers > max_connection_count) \ | |
72 | { \ | |
73 | max_connection_count = UserStats.local_clients + UserStats.local_servers; \ | |
74 | if (max_connection_count % 10 == 0) \ | |
75 | sendto_opmask_butone(0, SNO_OLDSNO, "Maximum connections: %d (%d clients)", \ | |
76 | max_connection_count, max_client_count); \ | |
77 | } \ | |
78 | } while(0) | |
79 | /** Update counters when \a cptr goes from unknown to server. */ | |
80 | #define Count_unknownbecomesserver(UserStats) do { --UserStats.unknowns; ++UserStats.local_servers; ++UserStats.servers; } while(0) | |
81 | /** Update counters when \a cptr (a local user) disconnects. */ | |
82 | #define Count_clientdisconnects(cptr, UserStats) \ | |
83 | do \ | |
84 | { \ | |
85 | --UserStats.local_clients; --UserStats.clients; \ | |
86 | if (match(feature_str(FEAT_DOMAINNAME), cli_sockhost(cptr)) == 0) \ | |
87 | --current_load.local_count; \ | |
88 | } while(0) | |
89 | /** Update counters when a local server disconnects. */ | |
90 | #define Count_serverdisconnects(UserStats) do { --UserStats.local_servers; --UserStats.servers; } while(0) | |
91 | /** Update counters when an unknown client disconnects. */ | |
92 | #define Count_unknowndisconnects(UserStats) (--UserStats.unknowns) | |
93 | ||
94 | /* | |
95 | * Prototypes | |
96 | */ | |
97 | ||
98 | ||
99 | #endif /* INCLUDED_querycmds_h */ |