Merge branch 'winston' of https://github.com/M2Ys4U/KiwiIRC into winston
[KiwiIRC.git] / client / src / models / application.js
1 (function () {
2
3 _kiwi.model.Application = Backbone.Model.extend({
4 /** _kiwi.view.Application */
5 view: null,
6
7 /** _kiwi.view.StatusMessage */
8 message: null,
9
10 /* Address for the kiwi server */
11 kiwi_server: null,
12
13 initialize: function (options) {
14 if (options.container) {
15 this.set('container', options.container);
16 }
17
18 // The base url to the kiwi server
19 this.set('base_path', options.base_path ? options.base_path : '/kiwi');
20
21 // Path for the settings.json file
22 this.set('settings_path', options.settings_path ?
23 options.settings_path :
24 this.get('base_path') + '/assets/settings.json'
25 );
26
27 // Any options sent down from the server
28 this.server_settings = options.server_settings || {};
29 this.translations = options.translations || {};
30 this.themes = options.themes || [];
31
32 // Best guess at where the kiwi server is if not already specified
33 this.kiwi_server = options.kiwi_server || this.detectKiwiServer();
34
35 // The applet to initially load
36 this.startup_applet_name = options.startup || 'kiwi_startup';
37
38 // Set any default settings before anything else is applied
39 if (this.server_settings && this.server_settings.client && this.server_settings.client.settings) {
40 this.applyDefaultClientSettings(this.server_settings.client.settings);
41 }
42 },
43
44
45 start: function () {
46 // Set the gateway up
47 _kiwi.gateway = new _kiwi.model.Gateway();
48 this.bindGatewayCommands(_kiwi.gateway);
49
50 this.initializeClient();
51 this.initializeGlobals();
52
53 this.view.barsHide(true);
54
55 this.showStartup();
56 },
57
58
59 detectKiwiServer: function () {
60 // If running from file, default to localhost:7777 by default
61 if (window.location.protocol === 'file:') {
62 return 'http://localhost:7778';
63 } else {
64 // Assume the kiwi server is on the same server
65 return window.location.protocol + '//' + window.location.host;
66 }
67 },
68
69
70 showStartup: function() {
71 this.startup_applet = _kiwi.model.Applet.load(this.startup_applet_name, {no_tab: true});
72 this.startup_applet.tab = this.view.$('.console');
73 this.startup_applet.view.show();
74 },
75
76
77 initializeClient: function () {
78 this.view = new _kiwi.view.Application({model: this, el: this.get('container')});
79
80 // Takes instances of model_network
81 this.connections = new _kiwi.model.NetworkPanelList();
82
83 // Applets panel list
84 this.applet_panels = new _kiwi.model.PanelList();
85 this.applet_panels.view.$el.addClass('panellist applets');
86 this.view.$el.find('.tabs').append(this.applet_panels.view.$el);
87
88 /**
89 * Set the UI components up
90 */
91 this.controlbox = new _kiwi.view.ControlBox({el: $('#kiwi .controlbox')[0]});
92 this.bindControllboxCommands(this.controlbox);
93
94 this.topicbar = new _kiwi.view.TopicBar({el: this.view.$el.find('.topic')[0]});
95
96 new _kiwi.view.AppToolbar({el: _kiwi.app.view.$el.find('.toolbar .app_tools')[0]});
97 new _kiwi.view.ChannelTools({el: _kiwi.app.view.$el.find('.channel_tools')[0]});
98
99 this.message = new _kiwi.view.StatusMessage({el: this.view.$el.find('.status_message')[0]});
100
101 this.resize_handle = new _kiwi.view.ResizeHandler({el: this.view.$el.find('.memberlists_resize_handle')[0]});
102
103 // Rejigg the UI sizes
104 this.view.doLayout();
105 },
106
107
108 initializeGlobals: function () {
109 _kiwi.global.connections = this.connections;
110
111 _kiwi.global.panels = this.panels;
112 _kiwi.global.panels.applets = this.applet_panels;
113
114 _kiwi.global.components.Applet = _kiwi.model.Applet;
115 _kiwi.global.components.Panel =_kiwi.model.Panel;
116 },
117
118
119 applyDefaultClientSettings: function (settings) {
120 _.each(settings, function (value, setting) {
121 if (typeof _kiwi.global.settings.get(setting) === 'undefined') {
122 _kiwi.global.settings.set(setting, value);
123 }
124 });
125 },
126
127
128 panels: (function() {
129 var active_panel;
130
131 var fn = function(panel_type) {
132 var panels;
133
134 // Default panel type
135 panel_type = panel_type || 'connections';
136
137 switch (panel_type) {
138 case 'connections':
139 panels = this.connections.panels();
140 break;
141 case 'applets':
142 panels = this.applet_panels.models;
143 break;
144 }
145
146 // Active panels / server
147 panels.active = active_panel;
148 panels.server = this.connections.active_connection ?
149 this.connections.active_connection.panels.server :
150 null;
151
152 return panels;
153 };
154
155 _.extend(fn, Backbone.Events);
156
157 // Keep track of the active panel. Channel/query/server or applet
158 fn.bind('active', function (new_active_panel) {
159 active_panel = new_active_panel;
160 });
161
162 return fn;
163 })(),
164
165
166 bindGatewayCommands: function (gw) {
167 var that = this;
168
169 gw.on('onconnect', function (event) {
170 that.view.barsShow();
171 });
172
173
174 /**
175 * Handle the reconnections to the kiwi server
176 */
177 (function () {
178 // 0 = non-reconnecting state. 1 = reconnecting state.
179 var gw_stat = 0;
180
181 // If the current or upcoming disconnect was planned
182 var unplanned_disconnect = false;
183
184 gw.on('disconnect', function (event) {
185 unplanned_disconnect = !gw.disconnect_requested;
186
187 if (unplanned_disconnect) {
188 var msg = _kiwi.global.i18n.translate('client_models_application_reconnecting').fetch() + '...';
189 that.message.text(msg, {timeout: 10000});
190 }
191
192 that.view.$el.removeClass('connected');
193
194 // Mention the disconnection on every channel
195 _kiwi.app.connections.forEach(function(connection) {
196 connection.panels.server.addMsg('', msg, 'action quit');
197
198 connection.panels.forEach(function(panel) {
199 if (!panel.isChannel())
200 return;
201
202 panel.addMsg('', msg, 'action quit');
203 });
204 });
205
206 gw_stat = 1;
207 });
208
209
210 gw.on('reconnecting', function (event) {
211 var msg = _kiwi.global.i18n.translate('client_models_application_reconnect_in_x_seconds').fetch(event.delay/1000) + '...';
212
213 // Only need to mention the repeating re-connection messages on server panels
214 _kiwi.app.connections.forEach(function(connection) {
215 connection.panels.server.addMsg('', msg, 'action quit');
216 });
217 });
218
219
220 gw.on('onconnect', function (event) {
221 that.view.$el.addClass('connected');
222 if (gw_stat !== 1) return;
223
224 if (unplanned_disconnect) {
225 var msg = _kiwi.global.i18n.translate('client_models_application_reconnect_successfully').fetch() + ':)';
226 that.message.text(msg, {timeout: 5000});
227 }
228
229 // Mention the re-connection on every channel
230 _kiwi.app.connections.forEach(function(connection) {
231 connection.panels.server.addMsg('', msg, 'action join');
232
233 connection.panels.forEach(function(panel) {
234 if (!panel.isChannel())
235 return;
236
237 panel.addMsg('', msg, 'action join');
238 });
239 });
240
241 gw_stat = 0;
242 });
243 })();
244
245
246 gw.on('kiwi:reconfig', function () {
247 $.getJSON(that.get('settings_path'), function (data) {
248 that.server_settings = data.server_settings || {};
249 that.translations = data.translations || {};
250 });
251 });
252
253
254 gw.on('kiwi:jumpserver', function (data) {
255 var serv;
256 // No server set? Then nowhere to jump to.
257 if (typeof data.kiwi_server === 'undefined')
258 return;
259
260 serv = data.kiwi_server;
261
262 // Strip any trailing slash from the end
263 if (serv[serv.length-1] === '/')
264 serv = serv.substring(0, serv.length-1);
265
266 // Force the jumpserver now?
267 if (data.force) {
268 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
269 var jump_server_interval = Math.random() * (360 - 300) + 300;
270
271 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
272 var msg = _kiwi.global.i18n.translate('client_models_application_jumpserver_prepare').fetch();
273 that.message.text(msg, {timeout: 10000});
274
275 setTimeout(function forcedReconnect() {
276 var msg = _kiwi.global.i18n.translate('client_models_application_jumpserver_reconnect').fetch();
277 that.message.text(msg, {timeout: 8000});
278
279 setTimeout(function forcedReconnectPartTwo() {
280 _kiwi.app.kiwi_server = serv;
281
282 _kiwi.gateway.reconnect(function() {
283 // Reconnect all the IRC connections
284 that.connections.forEach(function(con){ con.reconnect(); });
285 });
286 }, 5000);
287
288 }, jump_server_interval * 1000);
289 }
290 });
291 },
292
293
294
295 /**
296 * Bind to certain commands that may be typed into the control box
297 */
298 bindControllboxCommands: function (controlbox) {
299 var that = this;
300
301 // Default aliases
302 $.extend(controlbox.preprocessor.aliases, {
303 // General aliases
304 '/p': '/part $1+',
305 '/me': '/action $1+',
306 '/j': '/join $1+',
307 '/q': '/query $1+',
308 '/w': '/whois $1+',
309 '/raw': '/quote $1+',
310
311 // Op related aliases
312 '/op': '/quote mode $channel +o $1+',
313 '/deop': '/quote mode $channel -o $1+',
314 '/hop': '/quote mode $channel +h $1+',
315 '/dehop': '/quote mode $channel -h $1+',
316 '/voice': '/quote mode $channel +v $1+',
317 '/devoice': '/quote mode $channel -v $1+',
318 '/k': '/kick $channel $1+',
319 '/ban': '/quote mode $channel +b $1+',
320 '/unban': '/quote mode $channel -b $1+',
321
322 // Misc aliases
323 '/slap': '/me slaps $1 around a bit with a large trout'
324 });
325
326 // Functions to bind to controlbox events
327 var fn_to_bind = {
328 'unknown_command': unknownCommand,
329 'command': allCommands,
330 'command:msg': msgCommand,
331 'command:action': actionCommand,
332 'command:join': joinCommand,
333 'command:part': partCommand,
334 'command:nick': nickCommand,
335 'command:query': queryCommand,
336 'command:invite': inviteCommand,
337 'command:topic': topicCommand,
338 'command:notice': noticeCommand,
339 'command:quote': quoteCommand,
340 'command:kick': kickCommand,
341 'command:clear': clearCommand,
342 'command:ctcp': ctcpCommand,
343 'command:server': serverCommand,
344 'command:whois': whoisCommand,
345 'command:whowas': whowasCommand,
346 'command:encoding': encodingCommand,
347 'command:channel': channelCommand,
348 'command:applet': appletCommand,
349 'command:settings': settingsCommand,
350 'command:script': scriptCommand
351 };
352
353 fn_to_bind['command:css'] = function (ev) {
354 var queryString = '?reload=' + new Date().getTime();
355 $('link[rel="stylesheet"]').each(function () {
356 this.href = this.href.replace(/\?.*|$/, queryString);
357 });
358 };
359
360 fn_to_bind['command:js'] = function (ev) {
361 if (!ev.params[0]) return;
362 $script(ev.params[0] + '?' + (new Date().getTime()));
363 };
364
365
366 fn_to_bind['command:set'] = function (ev) {
367 if (!ev.params[0]) return;
368
369 var setting = ev.params[0],
370 value;
371
372 // Do we have a second param to set a value?
373 if (ev.params[1]) {
374 ev.params.shift();
375
376 value = ev.params.join(' ');
377
378 // If we're setting a true boolean value..
379 if (value === 'true')
380 value = true;
381
382 // If we're setting a false boolean value..
383 if (value === 'false')
384 value = false;
385
386 // If we're setting a number..
387 if (parseInt(value, 10).toString() === value)
388 value = parseInt(value, 10);
389
390 _kiwi.global.settings.set(setting, value);
391 }
392
393 // Read the value to the user
394 _kiwi.app.panels().active.addMsg('', setting + ' = ' + _kiwi.global.settings.get(setting).toString());
395 };
396
397
398 fn_to_bind['command:save'] = function (ev) {
399 _kiwi.global.settings.save();
400 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_settings_saved').fetch());
401 };
402
403
404 fn_to_bind['command:alias'] = function (ev) {
405 var name, rule;
406
407 // No parameters passed so list them
408 if (!ev.params[1]) {
409 $.each(controlbox.preprocessor.aliases, function (name, rule) {
410 _kiwi.app.panels().server.addMsg(' ', name + ' => ' + rule);
411 });
412 return;
413 }
414
415 // Deleting an alias?
416 if (ev.params[0] === 'del' || ev.params[0] === 'delete') {
417 name = ev.params[1];
418 if (name[0] !== '/') name = '/' + name;
419 delete controlbox.preprocessor.aliases[name];
420 return;
421 }
422
423 // Add the alias
424 name = ev.params[0];
425 ev.params.shift();
426 rule = ev.params.join(' ');
427
428 // Make sure the name starts with a slash
429 if (name[0] !== '/') name = '/' + name;
430
431 // Now actually add the alias
432 controlbox.preprocessor.aliases[name] = rule;
433 };
434
435
436 fn_to_bind['command:ignore'] = function (ev) {
437 var list = this.connections.active_connection.get('ignore_list');
438
439 // No parameters passed so list them
440 if (!ev.params[0]) {
441 if (list.length > 0) {
442 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_title').fetch() + ':');
443 $.each(list, function (idx, ignored_pattern) {
444 _kiwi.app.panels().active.addMsg(' ', ignored_pattern);
445 });
446 } else {
447 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_none').fetch());
448 }
449 return;
450 }
451
452 // We have a parameter, so add it
453 list.push(ev.params[0]);
454 this.connections.active_connection.set('ignore_list', list);
455 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_nick').fetch(ev.params[0]));
456 };
457
458
459 fn_to_bind['command:unignore'] = function (ev) {
460 var list = this.connections.active_connection.get('ignore_list');
461
462 if (!ev.params[0]) {
463 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_stop_notice').fetch());
464 return;
465 }
466
467 list = _.reject(list, function(pattern) {
468 return pattern === ev.params[0];
469 });
470
471 this.connections.active_connection.set('ignore_list', list);
472
473 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_stopped').fetch(ev.params[0]));
474 };
475
476
477 _.each(fn_to_bind, function(fn, event_name) {
478 controlbox.on(event_name, _.bind(fn, that));
479 });
480 },
481
482
483 isChannelName: function (channel_name) {
484 var channel_prefix = _kiwi.gateway.get('channel_prefix');
485
486 if (!channel_name || !channel_name.length) return false;
487 return (channel_prefix.indexOf(channel_name[0]) > -1);
488 }
489 });
490
491
492
493
494 // A fallback action. Send a raw command to the server
495 function unknownCommand (ev) {
496 var raw_cmd = ev.command + ' ' + ev.params.join(' ');
497 console.log('RAW: ' + raw_cmd);
498 this.connections.active_connection.gateway.raw(raw_cmd);
499 }
500
501 function allCommands (ev) {}
502
503 function joinCommand (ev) {
504 var panels, channel_names;
505
506 channel_names = ev.params.join(' ').split(',');
507 panels = this.connections.active_connection.createAndJoinChannels(channel_names);
508
509 // Show the last channel if we have one
510 if (panels.length)
511 panels[panels.length - 1].view.show();
512 }
513
514 function queryCommand (ev) {
515 var destination, message, panel;
516
517 destination = ev.params[0];
518 ev.params.shift();
519
520 message = ev.params.join(' ');
521
522 // Check if we have the panel already. If not, create it
523 panel = this.connections.active_connection.panels.getByName(destination);
524 if (!panel) {
525 panel = new _kiwi.model.Query({name: destination});
526 this.connections.active_connection.panels.add(panel);
527 }
528
529 if (panel) panel.view.show();
530
531 if (message) {
532 this.connections.active_connection.gateway.msg(panel.get('name'), message);
533 panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message);
534 }
535
536 }
537
538 function msgCommand (ev) {
539 var message,
540 destination = ev.params[0],
541 panel = this.connections.active_connection.panels.getByName(destination) || this.panels().server;
542
543 ev.params.shift();
544 message = formatToIrcMsg(ev.params.join(' '));
545
546 panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message);
547 this.connections.active_connection.gateway.msg(destination, message);
548 }
549
550 function actionCommand (ev) {
551 if (_kiwi.app.panels().active.isServer()) {
552 return;
553 }
554
555 var panel = _kiwi.app.panels().active;
556 panel.addMsg('', '* ' + _kiwi.app.connections.active_connection.get('nick') + ' ' + ev.params.join(' '), 'action');
557 this.connections.active_connection.gateway.action(panel.get('name'), ev.params.join(' '));
558 }
559
560 function partCommand (ev) {
561 var that = this;
562
563 if (ev.params.length === 0) {
564 this.connections.active_connection.gateway.part(_kiwi.app.panels().active.get('name'));
565 } else {
566 _.each(ev.params, function (channel) {
567 that.connections.active_connection.gateway.part(channel);
568 });
569 }
570 }
571
572 function nickCommand (ev) {
573 this.connections.active_connection.gateway.changeNick(ev.params[0]);
574 }
575
576 function topicCommand (ev) {
577 var channel_name;
578
579 if (ev.params.length === 0) return;
580
581 if (this.isChannelName(ev.params[0])) {
582 channel_name = ev.params[0];
583 ev.params.shift();
584 } else {
585 channel_name = _kiwi.app.panels().active.get('name');
586 }
587
588 this.connections.active_connection.gateway.topic(channel_name, ev.params.join(' '));
589 }
590
591 function noticeCommand (ev) {
592 var destination;
593
594 // Make sure we have a destination and some sort of message
595 if (ev.params.length <= 1) return;
596
597 destination = ev.params[0];
598 ev.params.shift();
599
600 this.connections.active_connection.gateway.notice(destination, ev.params.join(' '));
601 }
602
603 function quoteCommand (ev) {
604 var raw = ev.params.join(' ');
605 this.connections.active_connection.gateway.raw(raw);
606 }
607
608 function kickCommand (ev) {
609 var nick, panel = _kiwi.app.panels().active;
610
611 if (!panel.isChannel()) return;
612
613 // Make sure we have a nick
614 if (ev.params.length === 0) return;
615
616 nick = ev.params[0];
617 ev.params.shift();
618
619 this.connections.active_connection.gateway.kick(panel.get('name'), nick, ev.params.join(' '));
620 }
621
622 function clearCommand (ev) {
623 // Can't clear a server or applet panel
624 if (_kiwi.app.panels().active.isServer() || _kiwi.app.panels().active.isApplet()) {
625 return;
626 }
627
628 if (_kiwi.app.panels().active.clearMessages) {
629 _kiwi.app.panels().active.clearMessages();
630 }
631 }
632
633 function ctcpCommand(ev) {
634 var target, type;
635
636 // Make sure we have a target and a ctcp type (eg. version, time)
637 if (ev.params.length < 2) return;
638
639 target = ev.params[0];
640 ev.params.shift();
641
642 type = ev.params[0];
643 ev.params.shift();
644
645 this.connections.active_connection.gateway.ctcp(true, type, target, ev.params.join(' '));
646 }
647
648 function settingsCommand (ev) {
649 var settings = _kiwi.model.Applet.loadOnce('kiwi_settings');
650 settings.view.show();
651 }
652
653 function scriptCommand (ev) {
654 var editor = _kiwi.model.Applet.loadOnce('kiwi_script_editor');
655 editor.view.show();
656 }
657
658 function appletCommand (ev) {
659 if (!ev.params[0]) return;
660
661 var panel = new _kiwi.model.Applet();
662
663 if (ev.params[1]) {
664 // Url and name given
665 panel.load(ev.params[0], ev.params[1]);
666 } else {
667 // Load a pre-loaded applet
668 if (_kiwi.applets[ev.params[0]]) {
669 panel.load(new _kiwi.applets[ev.params[0]]());
670 } else {
671 _kiwi.app.panels().server.addMsg('', _kiwi.global.i18n.translate('client_models_application_applet_notfound').fetch(ev.params[0]));
672 return;
673 }
674 }
675
676 _kiwi.app.connections.active_connection.panels.add(panel);
677 panel.view.show();
678 }
679
680
681
682 function inviteCommand (ev) {
683 var nick, channel;
684
685 // A nick must be specified
686 if (!ev.params[0])
687 return;
688
689 // Can only invite into channels
690 if (!_kiwi.app.panels().active.isChannel())
691 return;
692
693 nick = ev.params[0];
694 channel = _kiwi.app.panels().active.get('name');
695
696 _kiwi.app.connections.active_connection.gateway.raw('INVITE ' + nick + ' ' + channel);
697
698 _kiwi.app.panels().active.addMsg('', '== ' + nick + ' has been invited to ' + channel, 'action');
699 }
700
701
702 function whoisCommand (ev) {
703 var nick;
704
705 if (ev.params[0]) {
706 nick = ev.params[0];
707 } else if (_kiwi.app.panels().active.isQuery()) {
708 nick = _kiwi.app.panels().active.get('name');
709 }
710
711 if (nick)
712 _kiwi.app.connections.active_connection.gateway.raw('WHOIS ' + nick + ' ' + nick);
713 }
714
715
716 function whowasCommand (ev) {
717 var nick;
718
719 if (ev.params[0]) {
720 nick = ev.params[0];
721 } else if (_kiwi.app.panels().active.isQuery()) {
722 nick = _kiwi.app.panels().active.get('name');
723 }
724
725 if (nick)
726 _kiwi.app.connections.active_connection.gateway.raw('WHOWAS ' + nick);
727 }
728
729 function encodingCommand (ev) {
730 if (ev.params[0]) {
731 _kiwi.gateway.setEncoding(null, ev.params[0], function (success) {
732 if (success) {
733 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_changed').fetch(ev.params[0]));
734 } else {
735 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_invalid').fetch(ev.params[0]));
736 }
737 });
738 } else {
739 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_notspecified').fetch());
740 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_usage').fetch());
741 }
742 }
743
744 function channelCommand (ev) {
745 var active_panel = _kiwi.app.panels().active;
746
747 if (!active_panel.isChannel())
748 return;
749
750 new _kiwi.model.ChannelInfo({channel: _kiwi.app.panels().active});
751 }
752
753 function serverCommand (ev) {
754 var server, port, ssl, password, nick,
755 tmp;
756
757 // If no server address given, show the new connection dialog
758 if (!ev.params[0]) {
759 tmp = new _kiwi.view.MenuBox(_kiwi.global.i18n.translate('client_models_application_connection_create').fetch());
760 tmp.addItem('new_connection', new _kiwi.model.NewConnection().view.$el);
761 tmp.show();
762
763 // Center screen the dialog
764 tmp.$el.offset({
765 top: (this.view.$el.height() / 2) - (tmp.$el.height() / 2),
766 left: (this.view.$el.width() / 2) - (tmp.$el.width() / 2)
767 });
768
769 return;
770 }
771
772 // Port given in 'host:port' format and no specific port given after a space
773 if (ev.params[0].indexOf(':') > 0) {
774 tmp = ev.params[0].split(':');
775 server = tmp[0];
776 port = tmp[1];
777
778 password = ev.params[1] || undefined;
779
780 } else {
781 // Server + port given as 'host port'
782 server = ev.params[0];
783 port = ev.params[1] || 6667;
784
785 password = ev.params[2] || undefined;
786 }
787
788 // + in the port means SSL
789 if (port.toString()[0] === '+') {
790 ssl = true;
791 port = parseInt(port.substring(1), 10);
792 } else {
793 ssl = false;
794 }
795
796 // Default port if one wasn't found
797 port = port || 6667;
798
799 // Use the same nick as we currently have
800 nick = _kiwi.app.connections.active_connection.get('nick');
801
802 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_connection_connecting').fetch(server, port.toString()));
803
804 _kiwi.gateway.newConnection({
805 nick: nick,
806 host: server,
807 port: port,
808 ssl: ssl,
809 password: password
810 }, function(err, new_connection) {
811 if (err)
812 _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_connection_error').fetch(server, port.toString(), err.toString()));
813 });
814 }
815
816 })();