-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathircwho.js
117 lines (101 loc) · 2.09 KB
/
ircwho.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* ircmsg.js */
/* $Id: ircwho.js,v 1.4 2016/05/13 01:33:20 deuce Exp $ */
if(this.IRCLIB_REVISION==undefined)
load("irclib.js"); // Thanks Cyan!
var ircserver="vert.synchro.net";
var channel="#synchronet";
var port=6667;
var nick="sw";
var msg;
var join=false;
var passedmsg=0;
for(i=0;i<argc;i++) {
switch(argv[i]) {
case "-s":
ircserver=argv[++i];
break;
case "-j":
join=true;
break;
case "-c":
channel=argv[++i];
break;
case "-p":
port=argv[++i];
break;
case "-n":
nick=argv[++i];
break;
}
}
my_server = IRC_client_connect(ircserver,nick,undefined,undefined,port);
if (!my_server) {
wrlog("!Couldn't connect to " + ircserver);
exit();
}
var done=0;
while(!done) {
while(!done && (response=my_server.recvline())) {
var resp=response.split(/\s+/);
if(resp[1]=='433') {
/* Nick in use... */
nick+='_';
my_server.send("NICK " + nick + "\r\n");
}
if(resp[1]=='422' || resp[1]=='376')
done=1;
}
}
if(join) {
my_server.send("JOIN " + channel + "\r\n");
while(my_server.poll(5) && (response=my_server.recvline()));
}
send("NAMES "+channel);
var sent_heads=0;
while(my_server.poll(5) && (response=my_server.recvline())) {
var resp=response.split(/\s+/);
if(resp[1]=='353') {
if(this.http_request!=undefined) {
if(!sent_heads) {
writeln("<html><head><title>Users on "+channel+" now</title></head><body>");
sent_heads=1;
}
}
logusers(response);
}
if(resp[1]=='366')
break;
}
IRC_quit(my_server);
if(!sent_heads && this.http_request!=undefined)
writeln("</body></html>");
function send(msg)
{
if(my_server.send(msg+"\r\n") != msg.length + 2)
alert("send failure");
}
function logusers(resp)
{
var txt=resp.split(/:/,3);
var names=txt[2].split(/\s+/);
for(name in names.sort(sortfunc)) {
writeln(names[name]);
if(this.http_request!=undefined)
writeln("<BR>");
}
}
function sortfunc(a, b)
{
if(a.toUpperCase() < b.toUpperCase())
return -1;
if(a.toUpperCase() > b.toUpperCase())
return 1;
return 0;
}
function wrlog(msg)
{
log(msg);
writeln(msg);
if(http_request!=undefined)
writeln("<BR>");
}