Author: Bleep <tomh@inxpress.net>
[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 struct Client;
10
11 /*
12  * Structs
13  */
14
15 struct UserStatistics {
16   /* Local connections: */
17   unsigned int unknowns;  /* IsUnknown() || IsConnecting() || IsHandshake() */
18   unsigned int local_servers;   /* IsServer() && MyConnect() */
19   unsigned int local_clients;   /* IsUser() && MyConnect() */
20
21   /* Global counts: */
22   unsigned int servers;         /* IsServer() || IsMe() */
23   unsigned int clients;         /* IsUser() */
24
25   /* Global user mode changes: */
26   unsigned int inv_clients;     /* IsUser() && IsInvisible() */
27   unsigned int opers;           /* IsUser() && IsOper() */
28
29   /* Misc: */
30   unsigned int channels;
31 };
32
33 extern struct UserStatistics UserStats;
34
35 /*
36  * Macros
37  */
38
39 /* Macros for remote connections: */
40 #define Count_newremoteclient(UserStats, cptr)  (++UserStats.clients, ++cptr->serv->clients)
41 #define Count_newremoteserver(UserStats)  (++UserStats.servers)
42 #if 0
43 #define Count_remoteclientquits(UserStats)      (--UserStats.clients)
44 #endif
45
46 #define Count_remoteclientquits(UserStats,cptr)                \
47   do { \
48     --UserStats.clients; \
49     if (!IsServer(cptr)) \
50       --cptr->user->server->serv->clients; \
51   } while (0)
52
53 #define Count_remoteserverquits(UserStats)      (--UserStats.servers)
54
55 /* Macros for local connections: */
56 #define Count_newunknown(UserStats)                     (++UserStats.unknowns)
57 #define Count_unknownbecomesclient(cptr, UserStats) \
58   do { \
59     --UserStats.unknowns; ++UserStats.local_clients; ++UserStats.clients; \
60     if (match("*" DOMAINNAME, cptr->sockhost) == 0) \
61       ++current_load.local_count; \
62     if (UserStats.local_clients > max_client_count) \
63       max_client_count = UserStats.local_clients; \
64     if (UserStats.local_clients + UserStats.local_servers > max_connection_count) \
65     { \
66       max_connection_count = UserStats.local_clients + UserStats.local_servers; \
67       if (max_connection_count % 10 == 0) \
68         sendto_ops("Maximum connections: %d (%d clients)", \
69             max_connection_count, max_client_count); \
70     } \
71   } while(0)
72 #define Count_unknownbecomesserver(UserStats)   do { --UserStats.unknowns; ++UserStats.local_servers; ++UserStats.servers; } while(0)
73 #define Count_clientdisconnects(cptr, UserStats) \
74   do \
75   { \
76     --UserStats.local_clients; --UserStats.clients; \
77     if (match("*" DOMAINNAME, cptr->sockhost) == 0) \
78       --current_load.local_count; \
79   } while(0)
80 #define Count_serverdisconnects(UserStats)              do { --UserStats.local_servers; --UserStats.servers; } while(0)
81 #define Count_unknowndisconnects(UserStats)             (--UserStats.unknowns)
82
83 /*
84  * Prototypes
85  */
86
87
88 #endif /* INCLUDED_querycmds_h */