412af8dd25e01ee659634f57b9a9c6c8b29af34c
1 var util
= require('util'),
2 EventBinder
= require('./eventbinder.js'),
5 var IrcServer = function (irc_connection
) {
6 this.irc_connection
= irc_connection
;
14 list_start
: onListStart
,
15 list_channel
: onListChannel
,
17 motd_start
: onMotdStart
,
21 password_mismatch
: onPasswordMismatch
,
22 channel_redirect
: onChannelRedirect
,
23 no_such_nick
: onNoSuchNick
,
24 cannot_send_to_channel
: onCannotSendToChan
,
25 too_many_channels
: onTooManyChannels
,
26 user_not_in_channel
: onUserNotInChannel
,
27 not_on_channel
: onNotOnChannel
,
28 channel_is_full
: onChannelIsFull
,
29 invite_only_channel
: onInviteOnlyChannel
,
30 banned_from_channel
: onBannedFromChannel
,
31 bad_channel_key
: onBadChannelKey
,
32 chanop_privs_needed
: onChanopPrivsNeeded
,
33 nickname_in_use
: onNicknameInUse
35 EventBinder
.bindIrcEvents('server:*', this.irc_events
, this, this.irc_connection
);
41 module
.exports
= IrcServer
;
44 IrcServer
.prototype.dispose = function (){
45 EventBinder
.unbindIrcEvents('server:*', this.irc_events
, this.irc_connection
);
46 this.irc_connection
= undefined;
51 function onConnect(event
) {
52 this.irc_connection
.clientEvent('connect', {
57 function onOptions(event
) {
58 this.irc_connection
.clientEvent('options', {
59 options
: event
.options
,
64 function onListStart(event
) {
65 this.irc_connection
.clientEvent('list_start', {});
66 this.list_buffer
= [];
69 function onListChannel(event
) {
71 this.list_buffer
.push({
72 channel
: event
.channel
,
73 num_users
: event
.num_users
,
77 if (this.list_buffer
.length
> 200) {
78 buf
= _
.sortBy(this.list_buffer
, function (channel
) {
79 // sortBy sorts in ascending order, we want to sort by descending, hence using 0 - num_users.
80 return 0 - channel
.num_users
;
82 this.irc_connection
.clientEvent('list_channel', {
85 this.list_buffer
= [];
89 function onListEnd(event
) {
92 buf
= _
.sortBy(this.list_buffer
, function (channel
) {
93 // sortBy sorts in ascending order, we want to sort by descending, hence using 0 - num_users.
94 return 0 - channel
.num_users
;
96 this.irc_connection
.clientEvent('list_channel', {
99 this.list_buffer
= [];
102 this.irc_connection
.clientEvent('list_end', {});
105 function onMotdStart(event
) {
106 this.motd_buffer
= '';
109 function onMotd(event
) {
110 this.motd_buffer
+= event
.motd
;
113 function onMotdEnd(event
) {
114 this.irc_connection
.clientEvent('motd', {
115 msg
: this.motd_buffer
119 function onError(event
) {
120 this.irc_connection
.clientEvent('irc_error', {
126 function onPasswordMismatch(event
) {
127 this.irc_connection
.clientEvent('irc_error', {
128 error
: 'password_mismatch'
132 function onChannelRedirect(event
) {
133 this.irc_connection
.clientEvent('channel_redirect', {
139 function onNoSuchNick(event
) {
140 this.irc_connection
.clientEvent('irc_error', {
141 error
: 'no_such_nick',
147 function onCannotSendToChan(event
) {
148 this.irc_connection
.clientEvent('irc_error', {
149 error
: 'cannot_send_to_chan',
150 channel
: event
.channel
,
155 function onTooManyChannels(event
) {
156 this.irc_connection
.clientEvent('irc_error', {
157 error
: 'too_many_channels',
158 channel
: event
.channel
,
163 function onUserNotInChannel(event
) {
164 this.irc_connection
.clientEvent('irc_error', {
165 error
: 'user_not_in_channel',
167 channel
: event
.channel
,
172 function onNotOnChannel(event
) {
173 this.irc_connection
.clientEvent('irc_error', {
174 error
: 'not_on_channel',
175 channel
: event
.channel
,
180 function onChannelIsFull(event
) {
181 this.irc_connection
.clientEvent('irc_error', {
182 error
: 'channel_is_full',
183 channel
: event
.channel
,
188 function onInviteOnlyChannel(event
) {
189 this.irc_connection
.clientEvent('irc_error', {
190 error
: 'invite_only_channel',
191 channel
: event
.channel
,
196 function onBannedFromChannel(event
) {
197 this.irc_connection
.clientEvent('irc_error', {
198 error
: 'banned_from_channel',
199 channel
: event
.channel
,
204 function onBadChannelKey(event
) {
205 this.irc_connection
.clientEvent('irc_error', {
206 error
: 'bad_channel_key',
207 channel
: event
.channel
,
212 function onChanopPrivsNeeded(event
) {
213 this.irc_connection
.clientEvent('irc_error', {
214 error
: 'chanop_privs_needed',
215 channel
: event
.channel
,
220 function onNicknameInUse(event
) {
221 this.irc_connection
.clientEvent('irc_error', {
222 error
: 'nickname_in_use',