1 /* Some utterly useless dog */
3 #include "../core/schedule.h"
4 #include "../lib/irc_string.h"
5 #include "../localuser/localuserchannel.h"
6 #include "../control/control.h"
7 #include "../usercount/usercount.h"
13 int cmd_serverlist(void *sender
, int cargc
, char **cargv
);
14 void serverlist_hook_newserver(int hook
, void *arg
);
15 void serverlist_hook_lostserver(int hook
, void *arg
);
16 int serverlist_versionreply(void *source
, int cargc
, char **cargv
);
23 } serverinfo
[MAXSERVERS
];
25 void serverlist_doversion(void);
29 registercontrolhelpcmd("serverlist",NO_OPER
,1,&cmd_serverlist
,"Usage: serverlist [pattern]\nShows all currently connected servers");
30 /* hooks for serverlist */
31 registerhook(HOOK_SERVER_NEWSERVER
, &serverlist_hook_newserver
);
32 registerhook(HOOK_SERVER_LOSTSERVER
, &serverlist_hook_lostserver
);
35 for (i
= 0; i
< MAXSERVERS
; i
++) {
36 if (serverlist
[i
].linkstate
== LS_LINKED
)
37 serverinfo
[i
].used
= 1;
39 serverinfo
[i
].used
= 0;
41 serverinfo
[i
].ts
= getnettime();
42 serverinfo
[i
].version1
= NULL
;
43 serverinfo
[i
].version2
= NULL
;
45 registernumerichandler(351, &serverlist_versionreply
, 2);
51 for (i
= 0; i
< MAXSERVERS
; i
++) {
52 if (serverinfo
[i
].used
) {
53 freesstring(serverinfo
[i
].version1
);
54 freesstring(serverinfo
[i
].version2
);
57 deregisternumerichandler(351, &serverlist_versionreply
);
59 deregisterhook(HOOK_SERVER_NEWSERVER
, &serverlist_hook_newserver
);
60 deregisterhook(HOOK_SERVER_LOSTSERVER
, &serverlist_hook_lostserver
);
62 deregistercontrolcmd("serverlist",cmd_serverlist
);
65 int cmd_serverlist(void *sender
, int cargc
, char **cargv
) {
66 nick
*np
= (nick
*)sender
;
67 int a
, i
, ucount
, acount
, scount
;
69 controlreply(np
, "%-7s %-30s %5s/%5s/%-5s %-15s %-20s", "Numeric", "Hostname", "EClients", "Clients", "MaxCl", "Connected for", "Version");
73 for (i
= 0; i
< MAXSERVERS
; i
++) {
74 if (serverlist
[i
].linkstate
== LS_LINKED
&& (cargc
< 1 || match2strings(cargv
[0], serverlist
[i
].name
->content
))) {
77 for (a
= 0; a
< serverlist
[i
].maxusernum
; a
++)
78 if (servernicks
[i
][a
] != NULL
)
84 controlreply(np
, "%-7d %-30s %5d/%5d/%-5d %-15s %-20s - %s", i
, serverlist
[i
].name
->content
,
85 servercount
[i
], ucount
, serverlist
[i
].maxusernum
, longtoduration(getnettime() - serverinfo
[i
].ts
, 0),
86 serverinfo
[i
].version1
? serverinfo
[i
].version1
->content
: "Unknown",
87 serverinfo
[i
].version2
? serverinfo
[i
].version2
->content
: "Unknown");
91 controlreply(np
, "--- End of list. %d users and %d servers on the net.", acount
, scount
);
93 /* update version info for next time */
94 serverlist_doversion();
99 int serverlist_versionreply(void *source
, int cargc
, char **cargv
) {
105 num
= numerictolong(cargv
[0], 2);
107 if (serverinfo
[num
].used
) {
108 freesstring(serverinfo
[num
].version1
);
109 freesstring(serverinfo
[num
].version2
);
111 serverinfo
[num
].version1
= getsstring(cargv
[3], strlen(cargv
[3]));
112 serverinfo
[num
].version2
= getsstring(cargv
[5], strlen(cargv
[5]));
117 void serverlist_doversion(void) {
119 char *num1
, *numeric
;
124 for (i
= 0; i
< MAXSERVERS
; i
++) {
125 if (serverlist
[i
].linkstate
== LS_LINKED
&& serverinfo
[i
].version1
== NULL
) {
126 numeric
= longtonumeric(mynick
->numeric
,5);
127 num1
= (char*)malloc(strlen(numeric
) + 1); /* bleh.. longtonumeric() is using static variables */
128 strcpy(num1
, numeric
);
130 irc_send("%s V :%s", num1
, longtonumeric(i
,2));
136 void serverlist_hook_newserver(int hook
, void *arg
) {
137 char *num1
, *numeric
;
138 long num
= (long)arg
;
143 serverinfo
[num
].used
= 1;
144 serverinfo
[num
].ts
= getnettime();
145 serverinfo
[num
].version1
= NULL
;
146 serverinfo
[num
].version2
= NULL
;
148 numeric
= longtonumeric(mynick
->numeric
,5);
149 num1
= (char*)malloc(strlen(numeric
) + 1); /* bleh.. longtonumeric() is using static variables */
150 strcpy(num1
, numeric
);
152 irc_send("%s V :%s", num1
, longtonumeric(num
,2));
157 void serverlist_hook_lostserver(int hook
, void *arg
) {
158 long num
= (long)arg
;
160 serverinfo
[num
].used
= 0;
161 freesstring(serverinfo
[num
].version1
);
162 freesstring(serverinfo
[num
].version2
);