rage-inducing fix

This commit is contained in:
Evert Prants 2016-09-24 01:35:30 +03:00
parent 7d90a97620
commit fe58bec86f
3 changed files with 48 additions and 31 deletions

View File

@ -485,6 +485,9 @@ class Buffer {
let mesg = {message: message, sender: sender, type: type, time: time || new Date()} let mesg = {message: message, sender: sender, type: type, time: time || new Date()}
this.messages.push(mesg); this.messages.push(mesg);
if(type == "regular")
console.log(sender);
if(this.active) if(this.active)
this.appendMessage(mesg); this.appendMessage(mesg);
else else
@ -616,8 +619,12 @@ class InputHandler {
if(!buf) return; if(!buf) return;
if(inp.trim() == "") return; if(inp.trim() == "") return;
let listargs = inp.split(' ');
irc.socket.emit("userinput", {target: buf.name, server: buf.server, message: inp, splitup: inp.split(" ")}); if(listargs[0].indexOf('/') == 0)
return;
irc.socket.emit("userinput", {target: buf.name, targetType: buf.type, server: buf.server, message: inp, splitup: inp.split(" ")});
this.history.push(inp); this.history.push(inp);
clientdom.input.value = ""; clientdom.input.value = "";
} }
@ -723,7 +730,7 @@ class IRCChatWindow {
if(buf) { if(buf) {
if(autoswitch) if(autoswitch)
this.render(buf); this.render(buf);
return; return buf;
} }
buf = new Buffer(server, name, name, type); buf = new Buffer(server, name, name, type);
@ -731,6 +738,8 @@ class IRCChatWindow {
if(autoswitch) if(autoswitch)
this.render(buf); this.render(buf);
return buf;
} }
closeBuffer(buffer) { closeBuffer(buffer) {
@ -934,7 +943,10 @@ window.onload = function() {
irc.chat.handleQuit(data.server, data.user, data.reason); irc.chat.handleQuit(data.server, data.user, data.reason);
break; break;
case "message": case "message":
irc.chat.messageBuffer(data.to, data.server, {message: data.message, type: data.messageType, from: data.user.nickname}); if(data.to == irc.serverData[data.server].my_nick)
irc.chat.messageBuffer(data.user.nickname, data.server, {message: data.message, type: data.messageType, from: data.user.nickname});
else
irc.chat.messageBuffer(data.to, data.server, {message: data.message, type: data.messageType, from: data.user.nickname});
break; break;
case "channel_nicks": case "channel_nicks":
irc.chat.buildNicklist(data.channel, data.server, data.nicks); irc.chat.buildNicklist(data.channel, data.server, data.nicks);
@ -951,6 +963,7 @@ window.onload = function() {
irc.chat.nickChange(data.server, data.nick, data.newNick); irc.chat.nickChange(data.server, data.nick, data.newNick);
break; break;
case "server_message": case "server_message":
if(data['error']) data.messageType = "error";
if(irc.chat.getBuffersByServer(data.server).length == 0) { if(irc.chat.getBuffersByServer(data.server).length == 0) {
if(!irc.serverChatQueue[data.server]) { if(!irc.serverChatQueue[data.server]) {
irc.serverChatQueue[data.server] = []; irc.serverChatQueue[data.server] = [];

View File

@ -43,6 +43,14 @@ class IRCConnectionHandler {
this.conn = connection; this.conn = connection;
} }
handleUserLine(data) {
if(data.targetType == "channel" || data.targetType == "message") {
this.conn.socket.write('PRIVMSG {0} :{1}\r\n'.format(data.target, data.message));
this.conn.emit('pass_to_client', {type: "message", messageType: "privmsg", to: data.target,
user: {nickname: this.conn.config.nickname}, message: data.message, server: data.server});
}
}
handleServerLine(line) { handleServerLine(line) {
console.log(line); console.log(line);
if(this.conn.queue["supportsmsg"] && line.command != "005") { if(this.conn.queue["supportsmsg"] && line.command != "005") {
@ -61,15 +69,17 @@ class IRCConnectionHandler {
switch(line.command) { switch(line.command) {
case "error": case "error":
this.conn.emit("error", {type: "irc_error", raw: line.raw}); this.conn.emit("connerror", {type: "irc_error", raw: line.raw});
break; break;
case "001": case "001":
this.conn.data.actualServer = line.user.host; this.conn.data.actualServer = line.user.hostname;
break break
case "005": case "005":
if(!this.conn.queue["supportsmsg"]) if(!this.conn.queue["supportsmsg"])
this.conn.queue["supportsmsg"] = true; this.conn.queue["supportsmsg"] = true;
this.conn.authenticated = true;
let argv = line.arguments.slice(1); let argv = line.arguments.slice(1);
for(let a in argv) { for(let a in argv) {
let t = argv[a]; let t = argv[a];
@ -219,12 +229,12 @@ class IRCConnection extends EventEmitter {
this.socket.setTimeout(3000); this.socket.setTimeout(3000);
this.socket.on('error', (data) => { this.socket.on('error', (data) => {
this.emit('error', {type: "sock_error", message: "A socket error occured.", raw: data}); this.emit('connerror', {type: "sock_error", message: "A socket error occured.", raw: data});
}); });
this.socket.on('lookup', (err, address, family, host) => { this.socket.on('lookup', (err, address, family, host) => {
if(err) { if(err) {
this.emit('error', {type: "resolve_error", message: "Failed to resolve host."}); this.emit('connerror', {type: "resolve_error", message: "Failed to resolve host."});
} else { } else {
this.emit('lookup', {address: address, family: address, host: host}); this.emit('lookup', {address: address, family: address, host: host});
this.config.address = address; this.config.address = address;
@ -249,9 +259,7 @@ class IRCConnection extends EventEmitter {
}); });
this.socket.on('close', (data) => { this.socket.on('close', (data) => {
if(this.queue['close']) if(!this.queue['close'])
this.emit('closed', {type: "sock_closed_success", raw: data, message: "Connection closed."});
else
this.emit('closed', {type: "sock_closed", raw: data, message: "Connection closed."}); this.emit('closed', {type: "sock_closed", raw: data, message: "Connection closed."});
this.connected = false; this.connected = false;

View File

@ -38,13 +38,10 @@ io.sockets.on('connection', function (socket) {
console.log('clientID: '+socket.id+' connection: ', socket.request.connection._peername); console.log('clientID: '+socket.id+' connection: ', socket.request.connection._peername);
connections[socket.id] = {} connections[socket.id] = {}
socket.on('userinput', function(data) {
console.log(data);
})
socket.on('disconnect', function() { socket.on('disconnect', function() {
for (let d in connections[socket.id]) for (let d in connections[socket.id])
connections[socket.id][d].disconnect(); if(connections[socket.id][d].connected == true)
connections[socket.id][d].disconnect();
delete connections[socket.id]; delete connections[socket.id];
@ -53,6 +50,14 @@ io.sockets.on('connection', function (socket) {
socket.on('error', (e) => { socket.on('error', (e) => {
console.log(e); console.log(e);
});
socket.on('userinput', (data) => {
let serv = connections[socket.id][data.server];
if(!serv) return;
if(serv.authenticated == false) return;
serv.handler.handleUserLine(data);
}) })
socket.on('irc_create', function(connectiondata) { socket.on('irc_create', function(connectiondata) {
@ -65,25 +70,22 @@ io.sockets.on('connection', function (socket) {
connections[socket.id][connectiondata.server] = newConnection; connections[socket.id][connectiondata.server] = newConnection;
newConnection.on('authenticated', () => { newConnection.on('authenticated', () => {
console.log("******** AUTH DONE **********");
console.log("******** AUTH DONE **********");
console.log("******** AUTH DONE **********");
console.log("******** AUTH DONE **********");
console.log("******** AUTH DONE **********");
socket.emit('act_client', {type: "event_connect", address: connectiondata.server, network: newConnection.data.network, socket.emit('act_client', {type: "event_connect", address: connectiondata.server, network: newConnection.data.network,
supportedModes: newConnection.data.supportedModes, nickname: newConnection.config.nickname}); supportedModes: newConnection.data.supportedModes, nickname: newConnection.config.nickname});
}); });
newConnection.on('error', (data) => { newConnection.on('connerror', (data) => {
let message = "An error occured"; let message = "An error occured";
let inconnect = false; let inconnect = false;
if(!newConnection.authenticated) { console.log(newConnection.authenticated);
if(newConnection.authenticated == false) {
message = "Failed to connect to the server!"; message = "Failed to connect to the server!";
inconnect = true; inconnect = true;
} }
socket.emit('act_client', {type: (inconnect ? 'server_message' : 'connect_message'), message: message, type: 'error', error: true}); socket.emit('act_client', {type: (inconnect == true ? 'server_message' : 'connect_message'), message: message, error: true});
}); });
newConnection.on('pass_to_client', (data) => { newConnection.on('pass_to_client', (data) => {
@ -94,18 +96,12 @@ io.sockets.on('connection', function (socket) {
let message = "Connection closed"; let message = "Connection closed";
let inconnect = false; let inconnect = false;
switch(data.type) { if(newConnection.authenticated == false) {
case "sock_closed_success":
inconnect = true;
break;
}
if(!newConnection.authenticated) {
message = "Failed to connect to the server!"; message = "Failed to connect to the server!";
inconnect = true; inconnect = true;
} }
socket.emit('act_client', {type: (inconnect ? 'server_message' : 'connect_message'), message: message, type: 'error', error: true}); socket.emit('act_client', {type: (inconnect == true ? 'server_message' : 'connect_message'), message: message, error: true});
}); });
}); });
}); });