Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Done:
* PASS (connection password)
* PING/PONG
* PRIVMSG
* NOTICE
* MODE
* JOIN
* TOPIC
Expand Down Expand Up @@ -50,7 +51,7 @@ Planned:
* Server-to-server messages for JOIN, NJOIN, MODE, PRIVSG and NOTICE
* SQUIT and QUIT for links
* Server to server communication
* More basic commands: NOTICE, LINKS, TRACE, ADMIN, INFO
* More basic commands: LINKS, TRACE, ADMIN, INFO
* Log files and logging options
* Local ops (+O)
* Stats command
Expand Down
31 changes: 31 additions & 0 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,37 @@ Commands.prototype = {
}
},

// TODO: The RFC says the sender nick and actual user nick should be checked
// TODO: Message validation
NOTICE: function(user, target, message) {
// ERR_NOTOPLEVEL
// ERR_WILDTOPLEVEL
// ERR_TOOMANYTARGETS
// ERR_NOSUCHNICK
// RPL_AWAY
if (!target || target.length === 0) {
user.send(this.server.host, irc.errors.noRecipient, ':No recipient given');
} else if (!message || message.length === 0) {
user.send(this.server.host, irc.errors.noTextToSend, ':No text to send');
} else if (this.server.channelTarget(target)) {
var channel = this.server.channels.find(target);
if (!channel) {
user.send(this.server.host, irc.errors.noSuchNick, user.nick, target, ':No such nick/channel');
} else if (channel.isModerated && !user.isVoiced(channel)) {
user.send(this.server.host, irc.errors.cannotSend, channel.name, ':Cannot send to channel');
} else if (user.channels.indexOf(channel) === -1) {
if (channel.modes.indexOf('n') !== -1) {
user.send(this.server.host, irc.errors.cannotSend, channel.name, ':Cannot send to channel');
return;
}
} else {
this.server.channels.notice(user, channel, message);
}
} else {
user.notice(target, message);
}
},

INVITE: function(user, nick, channelName) {
var channel = this.server.channels.find(channelName),
targetUser = this.server.users.find(nick);
Expand Down
9 changes: 9 additions & 0 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ ChannelDatabase.prototype = {
});
},

notice: function(user, channel, message) {
if (!channel) return;
channel.users.forEach(function(channelUser) {
if (channelUser !== user) {
channelUser.send(user.mask, 'NOTICE', channel.name, ':' + message);
}
});
},

expandMask: function(mask) {
return mask.replace(/\./g, '\\.').
replace(/\*/g, '.*');
Expand Down
14 changes: 14 additions & 0 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ User.prototype = {
}
},

notice: function(nick, message) {
var user = this.server.users.find(nick);
this.updated = new Date();

if (user) {
if (user.isAway) {
this.send(this.server.host, irc.reply.away, this.nick, user.nick, ':' + user.awayMessage);
}
user.send(this.mask, 'NOTICE', user.nick, ':' + message);
} else {
this.send(this.server.host, irc.errors.noSuchNick, this.nick, nick, ':No such nick/channel');
}
},

addModes: function(user, modes, arg) {
var thisUser = this;
modes.slice(1).split('').forEach(function(mode) {
Expand Down