Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 643d3edb authored by deuce's avatar deuce

Step one of irc.js overhaul... parse messages from server better.

Next up, send messages better.
parent b51a6f30
......@@ -51,9 +51,6 @@ ARGPARSE: for (cmdarg=0;cmdarg<argc;cmdarg++) {
}
}
/* Where we store sysop-defined numeric formats */
Numeric_Format = new Array;
/* Load the defined theme. -- Cyan */
load(irc_theme);
......@@ -145,43 +142,36 @@ while(!quit) {
sock.close();
clean_exit();
function handle_command(prefix,command,message) {
function handle_command(tag, prefix, command, message) {
var from_nick=null;
var full_message=null;
var tmp_str=null;
var tmp_str2=null;
var i=0;
if (command.match(/^[0-9]+/) && Numeric_Format[command]) {
var narg = message.split(" ");
var narg_string = IRC_string(message);
return 0;
}
switch(command) {
switch(command) {
case "PING":
sock.send("PONG "+message[0]+"\r\n");
break;
case "NOTICE":
message.shift();
message.shift(); // Target
from_nick=get_highlighted_nick(prefix,message);
full_message=message.join(" ");
full_message=full_message.substr(1);
full_message=full_message.replace(/\x01/g,"");
screen.print_line(format(NOTICE_FORMAT,from_nick,full_message));
break;
case "KICK":
tmp_str=message.shift();
tmp_str2=message.shift();
tmp_str=message.shift(); // Channel
tmp_str2=message.shift(); // User
from_nick=get_nick(prefix);
full_message=message.join(" ").substr(1);
full_message=message.join(" ");
if(tmp_str2.toUpperCase()==nick.toUpperCase()) {
channels.part(tmp_str,"");
}
screen.print_line(format(KICK_FORMAT,tmp_str2,tmp_str,full_message));
break;
case "PRIVMSG":
if(message[1].substr(0,2)==":\x01") {
if(message[1][0]=="\x01") {
// CTCP
handle_ctcp(prefix,message);
}
......@@ -197,7 +187,7 @@ function handle_command(prefix,command,message) {
}
else {
from_nick=format(MSG_FORMAT,from_nick);
if(message[0].slice(0,1)=="#" || message[0].slice(0,1)=="&") {
if(message[0][0]=="#" || message[0][0]=="&") {
from_nick=from_nick+"\x01N\x01C"+message[0]+":\x01N\x01W ";
}
else
......@@ -208,8 +198,7 @@ function handle_command(prefix,command,message) {
from_nick=format(FROM_NICK_CURCHAN,from_nick);
}
}
message.shift();
message[0]=message[0].substr(1);
message.shift(); // Receiver
screen.print_line(from_nick+" "+message.join(" "));
}
break;
......@@ -217,20 +206,19 @@ function handle_command(prefix,command,message) {
from_nick=get_highlighted_nick(prefix,message);
tmp_str=get_nick(prefix);
if(tmp_str.toUpperCase()==nick.toUpperCase()) {
channels.joined(message[0].substr(1));
channels.joined(message[0]);
}
else {
channels.nick_add(tmp_str,message[0].substr(1));
channels.nick_add(tmp_str,message[0]);
}
prefix=prefix.split("!")[1];
screen.print_line(format(JOIN_FORMAT,from_nick,prefix,message[0].substr(1)));
screen.print_line(format(JOIN_FORMAT,from_nick,prefix,message[0]));
break;
case "QUIT":
from_nick=get_highlighted_nick(prefix,message);
tmp_str=get_nick(prefix);
prefix=prefix.split("!")[1];
full_message=message.shift();
full_message=full_message.substr(1);
screen.print_line(format(QUIT_FORMAT,from_nick,channels.current.display,full_message+" "+message.join(" ")));
channels.nick_quit(tmp_str);
break;
......@@ -239,8 +227,6 @@ function handle_command(prefix,command,message) {
tmp_str2=get_nick(prefix);
prefix=prefix.split("!")[1];
tmp_str=message.shift();
if(tmp_str.substr(0,1)==':')
tmp_str=tmp_str.substr(1);
tmp_str=tmp_str.split("!",1)[0]
screen.print_line(format(NICK_FORMAT,from_nick,tmp_str));
if(tmp_str2.toUpperCase()==nick.toUpperCase()) {
......@@ -250,25 +236,23 @@ function handle_command(prefix,command,message) {
channels.nick_change(tmp_str2,tmp_str);
break;
case "SQUIT":
if(prefix.slice(0,1)==":") {
if(prefix.length > 0) {
from_nick=get_nick(prefix);
tmp_str=message.shift();
tmp_str2=message.shift();
tmp_str2=tmp_str2.substr(1);
screen.print_line(format(SQUIT_FROM_NICK,from_nick,tmp_str,tmp_str2+message.join(" ")));
}
else {
tmp_str=message.shift();
tmp_str2=message.shift();
tmp_str2=tmp_str2.substr(1);
screen.print_line(SQUIT_FROM_SERVER,tmp_str,tmp_str2+message.join(" "));
}
case "PART":
from_nick=get_highlighted_nick(prefix,message);
tmp_str=get_nick(prefix);
prefix=prefix.split("!")[1];
screen.print_line(format(PART_FORMAT,from_nick,prefix,message[0].substr(1)));
channels.nick_part(tmp_str,message[0].substr(1));
screen.print_line(format(PART_FORMAT,from_nick,prefix,message[0]));
channels.nick_part(tmp_str,message[0]);
break;
case "MODE":
from_nick=get_highlighted_nick(prefix,message);
......@@ -285,7 +269,6 @@ function handle_command(prefix,command,message) {
from_nick=get_highlighted_nick(prefix,message);
tmp_str=message.shift();
tmp_str2=message.join(" ");
tmp_str2=tmp_str2.substr(1);
for(i=0;i<channels.length;i++) {
if(tmp_str.toUpperCase()==channels.channel[i].name) {
channels.channel[i].topic=tmp_str2;
......@@ -296,25 +279,7 @@ function handle_command(prefix,command,message) {
break;
// Numeric reply codes.
// <word1> <word2> <word3> <word4> <word5> <word6> <word7> :Message
case "211": // Trace Server
while(message.length < 9) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word1> <word2> <word3> <word4> <word5> <word6> :Message
case "352": // WHO reply
case "206": // Trace Server
case "213": // Stats CLINE
......@@ -322,58 +287,13 @@ function handle_command(prefix,command,message) {
case "215": // Stats ILINE
case "216": // Stats KLINE
case "218": // Stats YLINE
while(message.length < 8) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word1> <word2> <word3> <word4> <word5> :Message
case "241": // Stats LLINE
while(message.length < 7) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word1> <word2> <word3> <word4> :Message
case "311": // WHOIS reply
case "314": // WHOWAS reply
case "367": // Ban List
case "200": // Trace Link
case "243": // Stats OLINE
case "244": // Stats HLINE
while(message.length < 6) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word1> <word2> <word3> :Message
case "317": // WHOISIDLE Reply
case "324": // Channel Modes
case "201": // Trace Connecting
......@@ -383,37 +303,12 @@ function handle_command(prefix,command,message) {
case "205": // Trace User
case "208": // New type of trace
case "261": // Trace LOG
while(message.length < 5) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word1> <word2> :Message
case "312": // WHOISSERVER Reply
case "322": // LIST data
case "341": // Invite being sent
case "351": // (server) VERSION reply
case "364": // Links
case "212": // Stats Command
while(message.length < 4) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word> :Message
case "313": // WHOISOPERATOR Reply
case "319": // WHOISCHANNELS Reply
case "301": // AWAY Reply
......@@ -432,22 +327,6 @@ function handle_command(prefix,command,message) {
case "253": // # unknown connections
case "254": // # channels
case "256": // Admin info
while(message.length < 3) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01C!! \x01N\x01C"+tmp_str+" - "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
case "376": // MOTD End
if (loading) {
loading = false;
channels.join(default_channel);
}
// :Message
case "001": // Sent on successful registration
case "002": // Sent on successful registration
case "003": // Sent on successful registration
......@@ -476,47 +355,46 @@ function handle_command(prefix,command,message) {
case "375": // MOTD Start
case "372": // MOTD
case "333": // Extended TOPIC info (apparently)
while(message.length < 2) {
message.push("");
message.shift(); // Client
screen.print_line("\x01H\x01C!! \x01N\x01C"+message.join(" ")+"\x01N\x01W");
break;
// Things that actually need dealing with...
case "376": // MOTD End
if (loading) {
loading = false;
channels.join(default_channel);
}
message.shift();
tmp_str=message.shift();
tmp_str="\x01H\x01C!! \x01N\x01C"+tmp_str.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str);
message.shift(); // Client
screen.print_line("\x01H\x01C!! \x01N\x01C"+message.join(" ")+"\x01N\x01W");
break;
case "331": // No Topic
case "332": // Topic
while(message.length < 2) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str2=message.join(" ");
tmp_str2=tmp_str2.substr(1);
for(i=0;i<channels.length;i++) {
if(tmp_str.toUpperCase()==channels.channel[i].name) {
channels.channel[i].topic=tmp_str2;
if(message[1].toUpperCase()==channels.channel[i].name) {
channels.channel[i].topic=message[2];
screen.update_statline();
}
}
break;
case "353": // Name reply
while(message.length < 3) {
message.push("");
}
message.shift();
message.shift();
tmp_str=message.shift();
message[0]=message[0].substr(1);
for(i=0;i<message.length;i++) {
if(message[i].slice(0,1)=="@" || message[i].slice(0,1)=="+") {
message[i]=message[i].substr(1);
message.shift(); // Client
message.shift(); // Symbol
tmp_str=message.shift().toUpperCase(); // Channel
for(i=0;i<message.length;i++) {
switch(message[i][0]) {
case '~': // Founder
case '&': // Protected
case '@': // Op
case '%': // Half-op
case '+': // Voice
message[i]=message[i].substr(1);
break;
}
}
for(i=0;i<channels.length;i++) {
if(tmp_str.toUpperCase()==channels.channel[i].name) {
if(tmp_str == channels.channel[i].name) {
channels.channel[i].nick=message;
}
}
......@@ -527,29 +405,14 @@ function handle_command(prefix,command,message) {
break;
// Error Codes
// <word1> <word2> :Message errors
case "441": // Nick not on channel
case "443": // User already on channel (invite)
while(message.length < 4) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str=tmp_str+" "+message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01R!! \x01N\x01R"+tmp_str+" "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// <word> :Message errors.
case "433": // Nickname already in use
while(message.length < 2) {
message.push("");
}
message.shift();
message.shift(); // Client
nick=message.shift()+"_";
sock.send("NICK " + nick + "\r\n");
break;
// <word1> <word2> :Message errors
case "441": // Nick not on channel
case "443": // User already on channel (invite)
case "401": // No such nick
case "402": // No such server
case "403": // No such channel
......@@ -573,17 +436,6 @@ function handle_command(prefix,command,message) {
case "474": // Banned from channel
case "475": // Bad channel key (+k)
case "482": // Not ChanOP so can't do that.
while(message.length < 3) {
message.push("");
}
message.shift();
tmp_str=message.shift();
tmp_str2=message.shift();
tmp_str2="\x01H\x01R!! \x01N\x01R"+tmp_str+" - "+tmp_str2.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str2);
break;
// :Message errors.
case "422": // MOTD is missing
case "409": // No origin
case "411": // No recipient
......@@ -602,40 +454,83 @@ function handle_command(prefix,command,message) {
case "491": // No O-lines for your host
case "501": // Unknown MODE flag
case "502": // Can't change other users mode
while(message.length < 3) {
message.push("");
message.shift(); // Client
if (message.length > 1) {
tmp_str=message.shift();
screen.print_line("\x01H\x01R!! \x01N\x01R"+tmp_str+" - "+message.join(" ")+"\x01N\x01W");
}
else {
screen.print_line("\x01H\x01R!! \x01N\x01R"+message.join(" ")+"\x01N\x01W");
}
message.shift();
message.shift();
tmp_str=message.shift();
tmp_str="\x01H\x01R!! \x01N\x01R"+tmp_str.substr(1)+" "+message.join(" ")+"\x01N\x01W";
screen.print_line(tmp_str);
break;
default:
screen.print_line("\x01N\x01R"+prefix+" "+command+" "+message.join(" ")+"\x01N\x01W");
}
}
function receive_command() {
function get_command()
{
var tag = "";
var prefix="";
var command=null;
var message;
if(sock.poll(0)) {
message=sock.recvline();
if(!message)
var line;
var message = [];
var i;
if(sock.poll(0)) {
line=sock.recvline();
if(!line)
return;
message=message.split(" ");
if(message[0].substr(0,1)==":") {
prefix=message.shift();
if (line[0] == '@') {
tag = line.slice(1, line.indexOf(" "));
line = line.substr(tag.length + 2);
}
command=message.shift();
handle_command(prefix,command,message);
if (line[0] == ':') {
prefix = line.slice(1, line.indexOf(" "));
line = line.substr(prefix.length + 2);
}
message.push(tag);
message.push(prefix);
while (line.length > 0) {
if (line[0] == ':') {
message.push(line.substr(1));
line = '';
}
else {
i = line.indexOf(' ');
if (i == -1) {
message.push(line);
line = '';
}
else {
message.push(line.slice(0, i));
line = line.substr(i + 1);
}
}
}
return message;
}
}
function receive_command() {
var tag = "";
var prefix="";
var command=null;
var message;
var message = get_command();
if (message == undefined)
return;
tag = message.shift();
prefix = message.shift();
command = message.shift();
handle_command(tag, prefix, command, message);
}
function wait_for(commands) {
var tag = '';
var prefix="";
var command=null;
var message="";
......@@ -655,14 +550,12 @@ function wait_for(commands) {
bbs.hangup();
clean_exit();
}
if(sock.poll(0)) {
message=sock.recvline().split(" ");
if(message[0].substr(0,1)==":") {
prefix=message.shift();
}
command=message.shift();
handle_command(prefix,command,message);
message = get_command();
if (message != undefined) {
tag = message.shift();
prefix = message.shift();
command = message.shift();
handle_command(tag,prefix,command,message);
for(i=0;i<commands.length;i++) {
if(command==commands[i]) {
return command;
......@@ -814,7 +707,7 @@ function get_highlighted_nick(prefix,message) {
var from_nick=null;
// Check if your nick is in the text...
from_nick=prefix.substr(1);
from_nick=prefix;
from_nick=from_nick.split("!",1)[0];
re=new RegExp("\\b"+nick+"\\b","i");
for(j=0;j<message.length;j++) {
......@@ -832,8 +725,9 @@ function get_highlighted_nick(prefix,message) {
function get_nick(prefix) {
// Check if your nick is in the text...
var to_nick=prefix.substr(1);
to_nick=to_nick.split("!",1)[0];
var to_nick;
to_nick=prefix.split("!",1)[0];
return to_nick;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment