Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / include / querycmds.h
1 /*
2  * querycmds.h
3  *
4  * $Id$
5  */
6 #ifndef INCLUDED_querycmds_h
7 #define INCLUDED_querycmds_h
8
9 #ifndef INCLUDED_ircd_features_h
10 #include "ircd_features.h"      /* feature_str() */
11 #endif
12
13 struct Client;
14
15 /*
16  * Structs
17  */
18
19 struct UserStatistics {
20   /* Local connections: */
21   unsigned int unknowns;  /* IsUnknown() || IsConnecting() || IsHandshake() */
22   unsigned int local_servers;   /* IsServer() && MyConnect() */
23   unsigned int local_clients;   /* IsUser() && MyConnect() */
24
25   /* Global counts: */
26   unsigned int servers;         /* IsServer() || IsMe() */
27   unsigned int clients;         /* IsUser() */
28
29   /* Global user mode changes: */
30   unsigned int inv_clients;     /* IsUser() && IsInvisible() */
31   unsigned int opers;           /* IsUser() && IsOper() */
32
33   /* Misc: */
34   unsigned int channels;
35 };
36
37 extern struct UserStatistics UserStats;
38
39 /*
40  * Macros
41  */
42
43 /* Macros for remote connections: */
44 #define Count_newremoteclient(UserStats, cptr)  (++UserStats.clients, ++(cli_serv(cptr)->clients))
45 #define Count_newremoteserver(UserStats)  (++UserStats.servers)
46
47 #define Count_remoteclientquits(UserStats,cptr)                \
48   do { \
49     --UserStats.clients; \
50     if (!IsServer(cptr)) \
51       --(cli_serv(cli_user(cptr)->server)->clients); \
52   } while (0)
53
54 #define Count_remoteserverquits(UserStats)      (--UserStats.servers)
55
56 /* Macros for local connections: */
57 #define Count_newunknown(UserStats)                     (++UserStats.unknowns)
58 #define Count_unknownbecomesclient(cptr, UserStats) \
59   do { \
60     --UserStats.unknowns; ++UserStats.local_clients; ++UserStats.clients; \
61     if (match(feature_str(FEAT_DOMAINNAME), cli_sockhost(cptr)) == 0) \
62       ++current_load.local_count; \
63     if (UserStats.local_clients > max_client_count) \
64       max_client_count = UserStats.local_clients; \
65     if (UserStats.local_clients + UserStats.local_servers > max_connection_count) \
66     { \
67       max_connection_count = UserStats.local_clients + UserStats.local_servers; \
68       if (max_connection_count % 10 == 0) \
69         sendto_opmask_butone(0, SNO_OLDSNO, "Maximum connections: %d (%d clients)", \
70             max_connection_count, max_client_count); \
71     } \
72   } while(0)
73 #define Count_unknownbecomesserver(UserStats)   do { --UserStats.unknowns; ++UserStats.local_servers; ++UserStats.servers; } while(0)
74 #define Count_clientdisconnects(cptr, UserStats) \
75   do \
76   { \
77     --UserStats.local_clients; --UserStats.clients; \
78     if (match(feature_str(FEAT_DOMAINNAME), cli_sockhost(cptr)) == 0) \
79       --current_load.local_count; \
80   } while(0)
81 #define Count_serverdisconnects(UserStats)              do { --UserStats.local_servers; --UserStats.servers; } while(0)
82 #define Count_unknowndisconnects(UserStats)             (--UserStats.unknowns)
83
84 /*
85  * Prototypes
86  */
87
88
89 #endif /* INCLUDED_querycmds_h */