Merge branch 'development' of https://github.com/prawnsalad/KiwiIRC into development
[KiwiIRC.git] / client / assets / dev / model_application.js
index 5a8e413127f5f74d4fa562e5d9c78f0b80bc4abb..9dcdb1c07425e18e8a6766cb730da406161197ed 100644 (file)
@@ -140,8 +140,10 @@ kiwi.model.Application = function () {
                 server: 'irc.kiwiirc.com',\r
                 port: 6667,\r
                 ssl: false,\r
-                channel: window.location.hash || '#kiwiirc'\r
+                channel: window.location.hash || '#kiwiirc',\r
+                channel_key: ''\r
             };\r
+            var uricheck;\r
 \r
             // Process the URL part by part, extracting as we go\r
             parts = window.location.pathname.toString().replace(this.get('base_path'), '').split('/');\r
@@ -150,22 +152,56 @@ kiwi.model.Application = function () {
                 parts.shift();\r
 \r
                 if (parts.length > 0 && parts[0]) {\r
-                    // Extract the port+ssl if we find one\r
-                    if (parts[0].search(/:/) > 0) {\r
-                        defaults.port = parts[0].substring(parts[0].search(/:/) + 1);\r
-                        defaults.server = parts[0].substring(0, parts[0].search(/:/));\r
-                        if (defaults.port[0] === '+') {\r
-                            defaults.port = parseInt(defaults.port.substring(1), 10);\r
-                            defaults.ssl = true;\r
+                    // Check to see if we're dealing with an irc: uri, or whether we need to extract the server/channel info from the HTTP URL path.\r
+                    uricheck = parts[0].substr(0, 7).toLowerCase();\r
+                    if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) {\r
+                        parts[0] = decodeURIComponent(parts[0]);\r
+                        // irc[s]://<host>[:<port>]/[<channel>[?<password>]]\r
+                        uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]);\r
+                        /*\r
+                            uricheck[1] = ssl (optional)\r
+                            uricheck[2] = host\r
+                            uricheck[3] = port (optional)\r
+                            uricheck[4] = channel (optional)\r
+                            uricheck[5] = channel key (optional, channel must also be set)\r
+                        */\r
+                        if (uricheck) {\r
+                            if (typeof uricheck[1] !== 'undefined') {\r
+                                defaults.ssl = true;\r
+                                if (defaults.port === 6667) {\r
+                                    defaults.port = 6697;\r
+                                }\r
+                            }\r
+                            defaults.server = uricheck[2];\r
+                            if (typeof uricheck[3] !== 'undefined') {\r
+                                defaults.port = uricheck[3];\r
+                            }\r
+                            if (typeof uricheck[4] !== 'undefined') {\r
+                                defaults.channel = '#' + uricheck[4];\r
+                                if (typeof uricheck[5] !== 'undefined') {\r
+                                    defaults.channel_key = uricheck[5];\r
+                                }\r
+                            }\r
+                        }\r
+                        parts = [];\r
+                    } else {\r
+                        // Extract the port+ssl if we find one\r
+                        if (parts[0].search(/:/) > 0) {\r
+                            defaults.port = parts[0].substring(parts[0].search(/:/) + 1);\r
+                            defaults.server = parts[0].substring(0, parts[0].search(/:/));\r
+                            if (defaults.port[0] === '+') {\r
+                                defaults.port = parseInt(defaults.port.substring(1), 10);\r
+                                defaults.ssl = true;\r
+                            } else {\r
+                                defaults.ssl = false;\r
+                            }\r
+\r
                         } else {\r
-                            defaults.ssl = false;\r
+                            defaults.server = parts[0];\r
                         }\r
 \r
-                    } else {\r
-                        defaults.server = parts[0];\r
+                        parts.shift();\r
                     }\r
-\r
-                    parts.shift();\r
                 }\r
 \r
                 if (parts.length > 0 && parts[0]) {\r
@@ -192,7 +228,7 @@ kiwi.model.Application = function () {
                 that.view.barsShow();\r
                 \r
                 if (auto_connect_details.channel) {\r
-                    that.controlbox.processInput('/JOIN ' + auto_connect_details.channel);\r
+                    that.controlbox.processInput('/JOIN ' + auto_connect_details.channel + ' ' + auto_connect_details.channel_key);\r
                 }\r
             });\r
 \r