|
@@ -11,6 +11,21 @@ var users = [];
|
|
var servers = [];
|
|
var servers = [];
|
|
var channels = [];
|
|
var channels = [];
|
|
var me = null;
|
|
var me = null;
|
|
|
|
+var events = {};
|
|
|
|
+
|
|
|
|
+function addInternalEvents(){
|
|
|
|
+ events.netSynced.unshift(function(){
|
|
|
|
+ for(var i=0; i<users.length; i++){
|
|
|
|
+ var user = users[i];
|
|
|
|
+ if(user.uplink == me){
|
|
|
|
+ uplink.introduceUser(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for(var i=0; i<channels.length; i++){
|
|
|
|
+ uplink.syncChannel(channels[i]);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
|
|
function findServer(s){
|
|
function findServer(s){
|
|
for(var i=0; i<servers.length; i++){
|
|
for(var i=0; i<servers.length; i++){
|
|
@@ -56,6 +71,7 @@ function removeServer(server){
|
|
for(var i=servers.length-1; i>=0; i--){ // finally, remove the given server
|
|
for(var i=servers.length-1; i>=0; i--){ // finally, remove the given server
|
|
if(servers[i] == server){
|
|
if(servers[i] == server){
|
|
console.log('Removing server '+servers[i].name);
|
|
console.log('Removing server '+servers[i].name);
|
|
|
|
+ events.doEvent('serverDelete', server);
|
|
servers.splice(i, 1);
|
|
servers.splice(i, 1);
|
|
delete server;
|
|
delete server;
|
|
break;
|
|
break;
|
|
@@ -77,6 +93,7 @@ function getChannel(name){
|
|
channel = new IRCchannel;
|
|
channel = new IRCchannel;
|
|
channel.name = name;
|
|
channel.name = name;
|
|
channels.push(channel);
|
|
channels.push(channel);
|
|
|
|
+ events.doEvent('channelCreate', channel);
|
|
}
|
|
}
|
|
return channel;
|
|
return channel;
|
|
}
|
|
}
|
|
@@ -97,6 +114,8 @@ function newUser(nick, distance, TS, ident, host, uid, account, umodes, vhost, c
|
|
user = new IRCuser;
|
|
user = new IRCuser;
|
|
user.introduce(nick, distance, TS, ident, host, uid, account, umodes, vhost, cloakedHost, ip, realname, uplink);
|
|
user.introduce(nick, distance, TS, ident, host, uid, account, umodes, vhost, cloakedHost, ip, realname, uplink);
|
|
users.push(user);
|
|
users.push(user);
|
|
|
|
+ events.doEvent('userCreate', user);
|
|
|
|
+ return user;
|
|
}
|
|
}
|
|
|
|
|
|
function newServer(name, sid, desc, distance, uplink){
|
|
function newServer(name, sid, desc, distance, uplink){
|
|
@@ -107,6 +126,8 @@ function newServer(name, sid, desc, distance, uplink){
|
|
server = new IRCserver;
|
|
server = new IRCserver;
|
|
server.introduce(name, sid, desc, distance, uplink);
|
|
server.introduce(name, sid, desc, distance, uplink);
|
|
servers.push(server);
|
|
servers.push(server);
|
|
|
|
+ events.doEvent('serverCreate', server);
|
|
|
|
+ return server;
|
|
}
|
|
}
|
|
|
|
|
|
function ircSendData(tags, from, cmd, args){
|
|
function ircSendData(tags, from, cmd, args){
|
|
@@ -147,6 +168,7 @@ function ircDataReceived(data){
|
|
|
|
|
|
function makeTagsString(tags){
|
|
function makeTagsString(tags){
|
|
return '';
|
|
return '';
|
|
|
|
+ //TODO
|
|
}
|
|
}
|
|
|
|
|
|
function ircMessage(data){
|
|
function ircMessage(data){
|
|
@@ -155,6 +177,7 @@ function ircMessage(data){
|
|
}
|
|
}
|
|
|
|
|
|
function ircConnectionClosed(e){
|
|
function ircConnectionClosed(e){
|
|
|
|
+ events.doEvent('uplinkLost', me);
|
|
console.log('Closed: '+e);
|
|
console.log('Closed: '+e);
|
|
process.exit(1);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
@@ -172,6 +195,7 @@ function quitUser(user){
|
|
for(var i=0; i<users.length; i++){
|
|
for(var i=0; i<users.length; i++){
|
|
if(users[i] == user){
|
|
if(users[i] == user){
|
|
users.splice(i, 1);
|
|
users.splice(i, 1);
|
|
|
|
+ events.doEvent('userDelete', user);
|
|
delete user;
|
|
delete user;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -197,6 +221,10 @@ function storeChannelData(channel){
|
|
setInterval(removeEmptyChannels, 1000);
|
|
setInterval(removeEmptyChannels, 1000);
|
|
|
|
|
|
var irc = {
|
|
var irc = {
|
|
|
|
+ 'users': users,
|
|
|
|
+ 'channels': channels,
|
|
|
|
+ 'servers': servers,
|
|
|
|
+ 'getChannel': getChannel,
|
|
'setConnection': function(host, port, protocol){
|
|
'setConnection': function(host, port, protocol){
|
|
uplink = require('./protocol/' + protocol);
|
|
uplink = require('./protocol/' + protocol);
|
|
me = new IRCserver;
|
|
me = new IRCserver;
|
|
@@ -223,11 +251,23 @@ var irc = {
|
|
me: me,
|
|
me: me,
|
|
maxUsers: 0
|
|
maxUsers: 0
|
|
});
|
|
});
|
|
|
|
+ addInternalEvents();
|
|
|
|
+ uplink.setEvents(events);
|
|
connection = new net.Socket();
|
|
connection = new net.Socket();
|
|
connection.connect(port, host, uplink.connected.bind(this));
|
|
connection.connect(port, host, uplink.connected.bind(this));
|
|
connection.on('data', ircDataReceived);
|
|
connection.on('data', ircDataReceived);
|
|
connection.on('close', ircConnectionClosed);
|
|
connection.on('close', ircConnectionClosed);
|
|
},
|
|
},
|
|
|
|
+ 'setEvents': function(newEvents){
|
|
|
|
+ events = newEvents;
|
|
|
|
+ },
|
|
|
|
+ 'makeUser': function(nick, ident, host, realname){
|
|
|
|
+ var user = new IRCuser;
|
|
|
|
+ var uid = uplink.makeUid();
|
|
|
|
+ user.introduce(nick, 0, Math.floor(new Date() / 1000).toString(10), ident, host, uid, null, '+SoB'/*TODO*/, null, null, null, realname, me);
|
|
|
|
+ users.push(user);
|
|
|
|
+ return user;
|
|
|
|
+ },
|
|
'messagedata': function() {
|
|
'messagedata': function() {
|
|
this.text = '';
|
|
this.text = '';
|
|
this.args = [];
|
|
this.args = [];
|