621d888512ecf7eb7678ca063cdef0da5c41bea8
[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 #if 0
47 #define Count_remoteclientquits(UserStats)      (--UserStats.clients)
48 #endif
49
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 #define Count_remoteserverquits(UserStats)      (--UserStats.servers)
58
59 /* Macros for local connections: */
60 #define Count_newunknown(UserStats)                     (++UserStats.unknowns)
61 #define Count_unknownbecomesclient(cptr, UserStats) \
62   do { \
63     --UserStats.unknowns; ++UserStats.local_clients; ++UserStats.clients; \
64     if (match(feature_str(FEAT_DOMAINNAME), cli_sockhost(cptr)) == 0) \
65       ++current_load.local_count; \
66     if (UserStats.local_clients > max_client_count) \
67       max_client_count = UserStats.local_clients; \
68     if (UserStats.local_clients + UserStats.local_servers > max_connection_count) \
69     { \
70       max_connection_count = UserStats.local_clients + UserStats.local_servers; \
71       if (max_connection_count % 10 == 0) \
72         sendto_opmask_butone(0, SNO_OLDSNO, "Maximum connections: %d (%d clients)", \
73             max_connection_count, max_client_count); \
74     } \
75   } while(0)
76 #define Count_unknownbecomesserver(UserStats)   do { --UserStats.unknowns; ++UserStats.local_servers; ++UserStats.servers; } while(0)
77 #define Count_clientdisconnects(cptr, UserStats) \
78   do \
79   { \
80     --UserStats.local_clients; --UserStats.clients; \
81     if (match(feature_str(FEAT_DOMAINNAME), cli_sockhost(cptr)) == 0) \
82       --current_load.local_count; \
83   } while(0)
84 #define Count_serverdisconnects(UserStats)              do { --UserStats.local_servers; --UserStats.servers; } while(0)
85 #define Count_unknowndisconnects(UserStats)             (--UserStats.unknowns)
86
87 /*
88  * Prototypes
89  */
90
91
92 #endif /* INCLUDED_querycmds_h */