Code formatting
[KiwiIRC.git] / client / src / models / network.js
1 (function () {
2
3 _kiwi.model.Network = Backbone.Model.extend({
4 defaults: {
5 connection_id: 0,
6 /**
7 * The name of the network
8 * @type String
9 */
10 name: 'Network',
11
12 /**
13 * The address (URL) of the network
14 * @type String
15 */
16 address: '',
17
18 /**
19 * The port for the network
20 * @type Int
21 */
22 port: 6667,
23
24 /**
25 * If this network uses SSL
26 * @type Bool
27 */
28 ssl: false,
29
30 /**
31 * The password to connect to this network
32 * @type String
33 */
34 password: '',
35
36 /**
37 * The current nickname
38 * @type String
39 */
40 nick: '',
41
42 /**
43 * The channel prefix for this network
44 * @type String
45 */
46 channel_prefix: '#',
47
48 /**
49 * The user prefixes for channel owner/admin/op/voice etc. on this network
50 * @type Array
51 */
52 user_prefixes: [
53 {symbol: '~', mode: 'q'},
54 {symbol: '&', mode: 'a'},
55 {symbol: '@', mode: 'o'},
56 {symbol: '%', mode: 'h'},
57 {symbol: '+', mode: 'v'}
58 ],
59
60 /**
61 * List of nicks we are ignoring
62 * @type Array
63 */
64 ignore_list: []
65 },
66
67
68 initialize: function () {
69 // If we already have a connection, bind our events
70 if (typeof this.get('connection_id') !== 'undefined') {
71 this.gateway = _kiwi.global.components.Network(this.get('connection_id'));
72 this.bindGatewayEvents();
73 }
74
75 // Create our panel list (tabs)
76 this.panels = new _kiwi.model.PanelList([], this);
77 //this.panels.network = this;
78
79 // Automatically create a server tab
80 var server_panel = new _kiwi.model.Server({name: 'Server', network: this});
81 this.panels.add(server_panel);
82 this.panels.server = this.panels.active = server_panel;
83 },
84
85
86 reconnect: function(callback_fn) {
87 var that = this,
88 server_info = {
89 nick: this.get('nick'),
90 host: this.get('address'),
91 port: this.get('port'),
92 ssl: this.get('ssl'),
93 password: this.get('password')
94 };
95
96 _kiwi.gateway.makeIrcConnection(server_info, function(err, connection_id) {
97 if (!err) {
98 that.gateway.dispose();
99
100 that.set('connection_id', connection_id);
101 that.gateway = _kiwi.global.components.Network(that.get('connection_id'));
102 that.bindGatewayEvents();
103
104 callback_fn && callback_fn(err);
105
106 } else {
107 console.log("_kiwi.gateway.socket.on('error')", {reason: err});
108 callback_fn && callback_fn(err);
109 }
110 });
111 },
112
113
114 bindGatewayEvents: function () {
115 //this.gateway.on('all', function() {console.log('ALL', this.get('connection_id'), arguments);});
116
117 this.gateway.on('connect', onConnect, this);
118 this.gateway.on('disconnect', onDisconnect, this);
119
120 this.gateway.on('nick', function(event) {
121 if (event.nick === this.get('nick')) {
122 this.set('nick', event.newnick);
123 }
124 }, this);
125
126 this.gateway.on('options', onOptions, this);
127 this.gateway.on('motd', onMotd, this);
128 this.gateway.on('channel:join', onJoin, this);
129 this.gateway.on('channel:part', onPart, this);
130 this.gateway.on('channel:kick', onKick, this);
131 this.gateway.on('quit', onQuit, this);
132 this.gateway.on('message', onMessage, this);
133 this.gateway.on('nick', onNick, this);
134 this.gateway.on('ctcp_request', onCtcpRequest, this);
135 this.gateway.on('ctcp_response', onCtcpResponse, this);
136 this.gateway.on('topic', onTopic, this);
137 this.gateway.on('topicsetby', onTopicSetBy, this);
138 this.gateway.on('userlist', onUserlist, this);
139 this.gateway.on('userlist_end', onUserlistEnd, this);
140 this.gateway.on('banlist', onBanlist, this);
141 this.gateway.on('mode', onMode, this);
142 this.gateway.on('whois', onWhois, this);
143 this.gateway.on('whowas', onWhowas, this);
144 this.gateway.on('away', onAway, this);
145 this.gateway.on('list_start', onListStart, this);
146 this.gateway.on('irc_error', onIrcError, this);
147 this.gateway.on('unknown_command', onUnknownCommand, this);
148 this.gateway.on('channel_info', onChannelInfo, this);
149 this.gateway.on('wallops', onWallops, this);
150 },
151
152
153 /**
154 * Create panels and join the channel
155 * This will not wait for the join event to create a panel. This
156 * increases responsiveness in case of network lag
157 */
158 createAndJoinChannels: function (channels) {
159 var that = this,
160 panels = [];
161
162 // Multiple channels may come as comma-delimited
163 if (typeof channels === 'string') {
164 channels = channels.split(',');
165 }
166
167 $.each(channels, function (index, channel_name_key) {
168 // We may have a channel key so split it off
169 var spli = channel_name_key.trim().split(' '),
170 channel_name = spli[0],
171 channel_key = spli[1] || '';
172
173 // Trim any whitespace off the name
174 channel_name = channel_name.trim();
175
176 // Add channel_prefix in front of the first channel if missing
177 if (that.get('channel_prefix').indexOf(channel_name[0]) === -1) {
178 // Could be many prefixes but '#' is highly likely the required one
179 channel_name = '#' + channel_name;
180 }
181
182 // Check if we have the panel already. If not, create it
183 channel = that.panels.getByName(channel_name);
184 if (!channel) {
185 channel = new _kiwi.model.Channel({name: channel_name, network: that});
186 that.panels.add(channel);
187 }
188
189 panels.push(channel);
190
191 that.gateway.join(channel_name, channel_key);
192 });
193
194
195 return panels;
196 },
197
198
199 /**
200 * Join all the open channels we have open
201 * Reconnecting to a network would typically call this.
202 */
203 rejoinAllChannels: function() {
204 var that = this;
205
206 this.panels.forEach(function(panel) {
207 if (!panel.isChannel())
208 return;
209
210 that.gateway.join(panel.get('name'));
211 });
212 },
213
214 isChannelName: function (channel_name) {
215 var channel_prefix = this.get('channel_prefix');
216
217 if (!channel_name || !channel_name.length) return false;
218 return (channel_prefix.indexOf(channel_name[0]) > -1);
219 },
220
221 // Check a nick alongside our ignore list
222 isNickIgnored: function (nick) {
223 var idx, list = this.get('ignore_list');
224 var pattern, regex;
225
226 for (idx = 0; idx < list.length; idx++) {
227 pattern = list[idx].replace(/([.+^$[\]\\(){}|-])/g, "\\$1")
228 .replace('*', '.*')
229 .replace('?', '.');
230
231 regex = new RegExp(pattern, 'i');
232 if (regex.test(nick)) return true;
233 }
234
235 return false;
236 }
237 });
238
239
240
241 function onDisconnect(event) {
242 $.each(this.panels.models, function (index, panel) {
243 if (!panel.isApplet()) {
244 panel.addMsg('', styleText('network_disconnected', {text: translateText('client_models_network_disconnected', [])}), 'action quit');
245 }
246 });
247 }
248
249
250
251 function onConnect(event) {
252 var panels, channel_names;
253
254 // Update our nick with what the network gave us
255 this.set('nick', event.nick);
256
257 // If this is a re-connection then we may have some channels to re-join
258 this.rejoinAllChannels();
259
260 // Auto joining channels
261 if (this.auto_join && this.auto_join.channel) {
262 panels = this.createAndJoinChannels(this.auto_join.channel + ' ' + (this.auto_join.key || ''));
263
264 // Show the last channel if we have one
265 if (panels)
266 panels[panels.length - 1].view.show();
267
268 delete this.auto_join;
269 }
270 }
271
272
273
274 function onOptions(event) {
275 var that = this;
276
277 $.each(event.options, function (name, value) {
278 switch (name) {
279 case 'CHANTYPES':
280 that.set('channel_prefix', value.join(''));
281 break;
282 case 'NETWORK':
283 that.set('name', value);
284 break;
285 case 'PREFIX':
286 that.set('user_prefixes', value);
287 break;
288 }
289 });
290
291 this.set('cap', event.cap);
292 }
293
294
295
296 function onMotd(event) {
297 this.panels.server.addMsg(this.get('name'), styleText('motd', {text: event.msg}), 'motd');
298 }
299
300
301
302 function onJoin(event) {
303 var c, members, user;
304 c = this.panels.getByName(event.channel);
305 if (!c) {
306 c = new _kiwi.model.Channel({name: event.channel, network: this});
307 this.panels.add(c);
308 }
309
310 members = c.get('members');
311 if (!members) return;
312
313 user = new _kiwi.model.Member({
314 nick: event.nick,
315 ident: event.ident,
316 hostname: event.hostname,
317 user_prefixes: this.get('user_prefixes')
318 });
319 members.add(user, {kiwi: event});
320 }
321
322
323
324 function onPart(event) {
325 var channel, members, user,
326 part_options = {};
327
328 part_options.type = 'part';
329 part_options.message = event.message || '';
330 part_options.time = event.time;
331
332 channel = this.panels.getByName(event.channel);
333 if (!channel) return;
334
335 // If this is us, close the panel
336 if (event.nick === this.get('nick')) {
337 channel.close();
338 return;
339 }
340
341 members = channel.get('members');
342 if (!members) return;
343
344 user = members.getByNick(event.nick);
345 if (!user) return;
346
347 members.remove(user, {kiwi: part_options});
348 }
349
350
351
352 function onQuit(event) {
353 var member, members,
354 quit_options = {};
355
356 quit_options.type = 'quit';
357 quit_options.message = event.message || '';
358 quit_options.time = event.time;
359
360 $.each(this.panels.models, function (index, panel) {
361 // Let any query panels know they quit
362 if (panel.isQuery() && panel.get('name').toLowerCase() === event.nick.toLowerCase()) {
363 panel.addMsg(' ', styleText('channel_quit', {
364 nick: event.nick,
365 text: translateText('client_models_channel_quit', [quit_options.message])
366 }), 'action quit', {time: quit_options.time});
367 }
368
369 // Remove the nick from any channels
370 if (panel.isChannel()) {
371 member = panel.get('members').getByNick(event.nick);
372 if (member) {
373 panel.get('members').remove(member, {kiwi: quit_options});
374 }
375 }
376 });
377 }
378
379
380
381 function onKick(event) {
382 var channel, members, user,
383 part_options = {};
384
385 part_options.type = 'kick';
386 part_options.by = event.nick;
387 part_options.message = event.message || '';
388 part_options.current_user_kicked = (event.kicked == this.get('nick'));
389 part_options.current_user_initiated = (event.nick == this.get('nick'));
390 part_options.time = event.time;
391
392 channel = this.panels.getByName(event.channel);
393 if (!channel) return;
394
395 members = channel.get('members');
396 if (!members) return;
397
398 user = members.getByNick(event.kicked);
399 if (!user) return;
400
401
402 members.remove(user, {kiwi: part_options});
403
404 if (part_options.current_user_kicked) {
405 members.reset([]);
406 }
407 }
408
409
410
411 function onMessage(event) {
412 _kiwi.global.events.emit('message:new', {network: this, message: event})
413 .done(_.bind(function() {
414 var panel,
415 is_pm = ((event.target || '').toLowerCase() == this.get('nick').toLowerCase());
416
417 // An ignored user? don't do anything with it
418 if (this.isNickIgnored(event.nick)) {
419 return;
420 }
421
422 if (event.type == 'notice') {
423 if (event.from_server) {
424 panel = this.panels.server;
425
426 } else {
427 panel = this.panels.getByName(event.target) || this.panels.getByName(event.nick);
428
429 // Forward ChanServ messages to its associated channel
430 if (event.nick && event.nick.toLowerCase() == 'chanserv' && event.msg.charAt(0) == '[') {
431 channel_name = /\[([^ \]]+)\]/gi.exec(event.msg);
432 if (channel_name && channel_name[1]) {
433 channel_name = channel_name[1];
434
435 panel = this.panels.getByName(channel_name);
436 }
437 }
438
439 }
440
441 if (!panel) {
442 panel = this.panels.server;
443 }
444
445 } else if (is_pm) {
446 // If a panel isn't found for this PM, create one
447 panel = this.panels.getByName(event.nick);
448 if (!panel) {
449 panel = new _kiwi.model.Query({name: event.nick, network: this});
450 this.panels.add(panel);
451 }
452
453 } else {
454 // If a panel isn't found for this target, reroute to the
455 // server panel
456 panel = this.panels.getByName(event.target);
457 if (!panel) {
458 panel = this.panels.server;
459 }
460 }
461
462 switch (event.type){
463 case 'message':
464 panel.addMsg(event.nick, styleText('privmsg', {text: event.msg}), 'privmsg', {time: event.time});
465 break;
466
467 case 'action':
468 panel.addMsg('', styleText('action', {nick: event.nick, text: event.msg}), 'action', {time: event.time});
469 break;
470
471 case 'notice':
472 panel.addMsg('[' + (event.nick||'') + ']', styleText('notice', {text: event.msg}), 'notice', {time: event.time});
473
474 // Show this notice to the active panel if it didn't have a set target, but only in an active channel or query window
475 active_panel = _kiwi.app.panels().active;
476
477 if (!event.from_server && panel === this.panels.server && active_panel !== this.panels.server) {
478 if (active_panel.get('network') === this && (active_panel.isChannel() || active_panel.isQuery()))
479 active_panel.addMsg('[' + (event.nick||'') + ']', styleText('notice', {text: event.msg}), 'notice', {time: event.time});
480 }
481 break;
482 }
483 }, this));
484 }
485
486
487
488 function onNick(event) {
489 var member;
490
491 $.each(this.panels.models, function (index, panel) {
492 if (panel.get('name') == event.nick)
493 panel.set('name', event.newnick);
494
495 if (!panel.isChannel()) return;
496
497 member = panel.get('members').getByNick(event.nick);
498 if (member) {
499 member.set('nick', event.newnick);
500 panel.addMsg('', styleText('nick_changed', {nick: event.nick, text: translateText('client_models_network_nickname_changed', [event.newnick]), channel: name}), 'action nick', {time: event.time});
501 }
502 });
503 }
504
505
506
507 function onCtcpRequest(event) {
508 // An ignored user? don't do anything with it
509 if (this.isNickIgnored(event.nick)) {
510 return;
511 }
512
513 // Reply to a TIME ctcp
514 if (event.msg.toUpperCase() === 'TIME') {
515 this.gateway.ctcpResponse(event.type, event.nick, (new Date()).toString());
516 }
517 }
518
519
520
521 function onCtcpResponse(event) {
522 // An ignored user? don't do anything with it
523 if (this.isNickIgnored(event.nick)) {
524 return;
525 }
526
527 this.panels.server.addMsg('[' + event.nick + ']', styleText('ctcp', {text: event.msg}), 'ctcp', {time: event.time});
528 }
529
530
531
532 function onTopic(event) {
533 var c;
534 c = this.panels.getByName(event.channel);
535 if (!c) return;
536
537 // Set the channels topic
538 c.set('topic', event.topic);
539
540 // If this is the active channel, update the topic bar too
541 if (c.get('name') === this.panels.active.get('name')) {
542 _kiwi.app.topicbar.setCurrentTopic(event.topic);
543 }
544 }
545
546
547
548 function onTopicSetBy(event) {
549 var c, when;
550 c = this.panels.getByName(event.channel);
551 if (!c) return;
552
553 when = formatDate(new Date(event.when * 1000));
554 c.addMsg('', styleText('channel_topic_setby', {text: translateText('client_models_network_topic', [event.nick, when]), channel: event.channel}), 'topic');
555 }
556
557
558
559 function onChannelInfo(event) {
560 var channel = this.panels.getByName(event.channel);
561 if (!channel) return;
562
563 if (event.url) {
564 channel.set('info_url', event.url);
565 } else if (event.modes) {
566 channel.set('info_modes', event.modes);
567 }
568 }
569
570
571
572 function onUserlist(event) {
573 var that = this,
574 channel = this.panels.getByName(event.channel);
575
576 // If we didn't find a channel for this, may aswell leave
577 if (!channel) return;
578
579 channel.temp_userlist = channel.temp_userlist || [];
580 _.each(event.users, function (item) {
581 var user = new _kiwi.model.Member({
582 nick: item.nick,
583 modes: item.modes,
584 user_prefixes: that.get('user_prefixes')
585 });
586 channel.temp_userlist.push(user);
587 });
588 }
589
590
591
592 function onUserlistEnd(event) {
593 var channel;
594 channel = this.panels.getByName(event.channel);
595
596 // If we didn't find a channel for this, may aswell leave
597 if (!channel) return;
598
599 // Update the members list with the new list
600 channel.get('members').reset(channel.temp_userlist || []);
601
602 // Clear the temporary userlist
603 delete channel.temp_userlist;
604 }
605
606
607
608 function onBanlist(event) {
609 var channel = this.panels.getByName(event.channel);
610 if (!channel)
611 return;
612
613 channel.set('banlist', event.bans || []);
614 }
615
616
617
618 function onMode(event) {
619 var channel, i, prefixes, members, member, find_prefix,
620 request_updated_banlist = false;
621
622 // Build a nicely formatted string to be displayed to a regular human
623 function friendlyModeString (event_modes, alt_target) {
624 var modes = {}, return_string;
625
626 // If no default given, use the main event info
627 if (!event_modes) {
628 event_modes = event.modes;
629 alt_target = event.target;
630 }
631
632 // Reformat the mode object to make it easier to work with
633 _.each(event_modes, function (mode){
634 var param = mode.param || alt_target || '';
635
636 // Make sure we have some modes for this param
637 if (!modes[param]) {
638 modes[param] = {'+':'', '-':''};
639 }
640
641 modes[param][mode.mode[0]] += mode.mode.substr(1);
642 });
643
644 // Put the string together from each mode
645 return_string = [];
646 _.each(modes, function (modeset, param) {
647 var str = '';
648 if (modeset['+']) str += '+' + modeset['+'];
649 if (modeset['-']) str += '-' + modeset['-'];
650 return_string.push(str + ' ' + param);
651 });
652 return_string = return_string.join(', ');
653
654 return return_string;
655 }
656
657
658 channel = this.panels.getByName(event.target);
659 if (channel) {
660 prefixes = this.get('user_prefixes');
661 find_prefix = function (p) {
662 return event.modes[i].mode[1] === p.mode;
663 };
664 for (i = 0; i < event.modes.length; i++) {
665 if (_.any(prefixes, find_prefix)) {
666 if (!members) {
667 members = channel.get('members');
668 }
669 member = members.getByNick(event.modes[i].param);
670 if (!member) {
671 console.log('MODE command recieved for unknown member %s on channel %s', event.modes[i].param, event.target);
672 return;
673 } else {
674 if (event.modes[i].mode[0] === '+') {
675 member.addMode(event.modes[i].mode[1]);
676 } else if (event.modes[i].mode[0] === '-') {
677 member.removeMode(event.modes[i].mode[1]);
678 }
679 members.sort();
680 }
681 } else {
682 // Channel mode being set
683 // TODO: Store this somewhere?
684 //channel.addMsg('', 'CHANNEL === ' + event.nick + ' set mode ' + event.modes[i].mode + ' on ' + event.target, 'action mode');
685 }
686
687 // TODO: Be smart, remove this specific ban from the banlist rather than request a whole banlist
688 if (event.modes[i].mode[1] == 'b')
689 request_updated_banlist = true;
690 }
691
692 channel.addMsg('', styleText('mode', {nick: event.nick, text: translateText('client_models_network_mode', [friendlyModeString()]), channel: event.target}), 'action mode', {time: event.time});
693
694 // TODO: Be smart, remove the specific ban from the banlist rather than request a whole banlist
695 if (request_updated_banlist)
696 this.gateway.raw('MODE ' + channel.get('name') + ' +b');
697
698 } else {
699 // This is probably a mode being set on us.
700 if (event.target.toLowerCase() === this.get("nick").toLowerCase()) {
701 this.panels.server.addMsg('', styleText('selfmode', {nick: event.nick, text: translateText('client_models_network_mode', [friendlyModeString()]), channel: event.target}), 'action mode');
702 } else {
703 console.log('MODE command recieved for unknown target %s: ', event.target, event);
704 }
705 }
706 }
707
708
709
710 function onWhois(event) {
711 var logon_date, idle_time = '', panel;
712
713 if (event.end)
714 return;
715
716 if (typeof event.idle !== 'undefined') {
717 idle_time = secondsToTime(parseInt(event.idle, 10));
718 idle_time = idle_time.h.toString().lpad(2, "0") + ':' + idle_time.m.toString().lpad(2, "0") + ':' + idle_time.s.toString().lpad(2, "0");
719 }
720
721 panel = _kiwi.app.panels().active;
722 if (event.ident) {
723 panel.addMsg(event.nick, styleText('whois_ident', {nick: event.nick, ident: event.ident, host: event.hostname, text: event.msg}), 'whois');
724
725 } else if (event.chans) {
726 panel.addMsg(event.nick, styleText('whois_channels', {nick: event.nick, text: translateText('client_models_network_channels', [event.chans])}), 'whois');
727 } else if (event.irc_server) {
728 panel.addMsg(event.nick, styleText('whois_server', {nick: event.nick, text: translateText('client_models_network_server', [event.irc_server, event.server_info])}), 'whois');
729 } else if (event.msg) {
730 panel.addMsg(event.nick, styleText('whois', {text: event.msg}), 'whois');
731 } else if (event.logon) {
732 logon_date = new Date();
733 logon_date.setTime(event.logon * 1000);
734 logon_date = formatDate(logon_date);
735
736 panel.addMsg(event.nick, styleText('whois_idle_and_signon', {nick: event.nick, text: translateText('client_models_network_idle_and_signon', [idle_time, logon_date])}), 'whois');
737 } else if (event.away_reason) {
738 panel.addMsg(event.nick, styleText('whois_away', {nick: event.nick, text: translateText('client_models_network_away', [event.away_reason])}), 'whois');
739 } else {
740 panel.addMsg(event.nick, styleText('whois_idle', {nick: event.nick, text: translateText('client_models_network_idle', [idle_time])}), 'whois');
741 }
742 }
743
744 function onWhowas(event) {
745 var panel;
746
747 if (event.end)
748 return;
749
750 panel = _kiwi.app.panels().active;
751 if (event.hostname) {
752 panel.addMsg(event.nick, styleText('who', {nick: event.nick, ident: event.ident, host: event.hostname, realname: event.real_name, text: event.msg}), 'whois');
753 } else {
754 panel.addMsg(event.nick, styleText('whois_notfound', {nick: event.nick, text: translateText('client_models_network_nickname_notfound', [])}), 'whois');
755 }
756 }
757
758
759 function onAway(event) {
760 $.each(this.panels.models, function (index, panel) {
761 if (!panel.isChannel()) return;
762
763 member = panel.get('members').getByNick(event.nick);
764 if (member) {
765 member.set('away', !(!event.reason));
766 }
767 });
768 }
769
770
771
772 function onListStart(event) {
773 var chanlist = _kiwi.model.Applet.loadOnce('kiwi_chanlist');
774 chanlist.view.show();
775 }
776
777
778
779 function onIrcError(event) {
780 var panel, tmp;
781
782 if (event.channel !== undefined && !(panel = this.panels.getByName(event.channel))) {
783 panel = this.panels.server;
784 }
785
786 switch (event.error) {
787 case 'banned_from_channel':
788 panel.addMsg(' ', styleText('channel_banned', {nick: event.nick, text: translateText('client_models_network_banned', [event.channel, event.reason]), channel: event.channel}), 'status');
789 _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_banned').fetch(event.channel, event.reason));
790 break;
791 case 'bad_channel_key':
792 panel.addMsg(' ', styleText('channel_badkey', {nick: event.nick, text: translateText('client_models_network_channel_badkey', [event.channel]), channel: event.channel}), 'status');
793 _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_badkey').fetch(event.channel));
794 break;
795 case 'invite_only_channel':
796 panel.addMsg(' ', styleText('channel_inviteonly', {nick: event.nick, text: translateText('client_models_network_channel_inviteonly', [event.nick, event.channel]), channel: event.channel}), 'status');
797 _kiwi.app.message.text(event.channel + ' ' + _kiwi.global.i18n.translate('client_models_network_channel_inviteonly').fetch());
798 break;
799 case 'user_on_channel':
800 panel.addMsg(' ', styleText('channel_alreadyin', {nick: event.nick, text: translateText('client_models_network_channel_alreadyin'), channel: event.channel}));
801 break;
802 case 'channel_is_full':
803 panel.addMsg(' ', styleText('channel_limitreached', {nick: event.nick, text: translateText('client_models_network_channel_limitreached', [event.channel]), channel: event.channel}), 'status');
804 _kiwi.app.message.text(event.channel + ' ' + _kiwi.global.i18n.translate('client_models_network_channel_limitreached').fetch(event.channel));
805 break;
806 case 'chanop_privs_needed':
807 panel.addMsg(' ', styleText('chanop_privs_needed', {text: event.reason, channel: event.channel}), 'status');
808 _kiwi.app.message.text(event.reason + ' (' + event.channel + ')');
809 break;
810 case 'cannot_send_to_channel':
811 panel.addMsg(' ', '== ' + _kiwi.global.i18n.translate('Cannot send message to channel, you are not voiced').fetch(event.channel, event.reason), 'status');
812 break;
813 case 'no_such_nick':
814 tmp = this.panels.getByName(event.nick);
815 if (tmp) {
816 tmp.addMsg(' ', styleText('no_such_nick', {nick: event.nick, text: event.reason, channel: event.channel}), 'status');
817 } else {
818 this.panels.server.addMsg(' ', styleText('no_such_nick', {nick: event.nick, text: event.reason, channel: event.channel}), 'status');
819 }
820 break;
821 case 'nickname_in_use':
822 this.panels.server.addMsg(' ', styleText('nickname_alreadyinuse', {nick: event.nick, text: translateText('client_models_network_nickname_alreadyinuse', [event.nick]), channel: event.channel}), 'status');
823 if (this.panels.server !== this.panels.active) {
824 _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_nickname_alreadyinuse').fetch(event.nick));
825 }
826
827 // Only show the nickchange component if the controlbox is open
828 if (_kiwi.app.controlbox.$el.css('display') !== 'none') {
829 (new _kiwi.view.NickChangeBox()).render();
830 }
831
832 break;
833
834 case 'password_mismatch':
835 this.panels.server.addMsg(' ', styleText('channel_badpassword', {nick: event.nick, text: translateText('client_models_network_badpassword', []), channel: event.channel}), 'status');
836 break;
837 default:
838 // We don't know what data contains, so don't do anything with it.
839 //_kiwi.front.tabviews.server.addMsg(null, ' ', '== ' + data, 'status');
840 }
841 }
842
843
844 function onUnknownCommand(event) {
845 var display_params = _.clone(event.params);
846
847 // A lot of commands have our nick as the first parameter. This is redundant for us
848 if (display_params[0] && display_params[0] == this.get('nick')) {
849 display_params.shift();
850 }
851
852 this.panels.server.addMsg('', styleText('unknown_command', {text: '[' + event.command + '] ' + display_params.join(', ', '')}));
853 }
854
855
856 function onWallops(event) {
857 var active_panel = _kiwi.app.panels().active;
858
859 // Send to server panel
860 this.panels.server.addMsg('[' + (event.nick||'') + ']', styleText('wallops', {text: event.msg}), 'wallops', {time: event.time});
861
862 // Send to active panel if its a channel/query *and* it's related to this network
863 if (active_panel !== this.panels.server && (active_panel.isChannel() || active_panel.isQuery()) && active_panel.get('network') === this)
864 active_panel.addMsg('[' + (event.nick||'') + ']', styleText('wallops', {text: event.msg}), 'wallops', {time: event.time});
865 }
866
867 }
868
869 )();