hit hwplay://server:port and automatically join an unofficial server (on osx right now)
authorkoda
Sun, 10 Mar 2013 15:44:03 +0100
changeset 8716 e09633d10f16
parent 8715 70a586fc76fd
child 8717 6e1ccd678e8a
child 8718 1c0614f5f3bd
hit hwplay://server:port and automatically join an unofficial server (on osx right now)
QTfrontend/HWApplication.cpp
QTfrontend/hwform.cpp
QTfrontend/hwform.h
share/Info.plist.in
--- a/QTfrontend/HWApplication.cpp	Sun Mar 10 11:29:00 2013 +0100
+++ b/QTfrontend/HWApplication.cpp	Sun Mar 10 15:44:03 2013 +0100
@@ -50,23 +50,28 @@
 bool HWApplication::event(QEvent *event)
 {
     QFileOpenEvent *openEvent;
-    QString scheme, path;
+    QString scheme, path, address;
 
     if (event->type() == QEvent::FileOpen) {
         openEvent = (QFileOpenEvent *)event;
         scheme = openEvent->url().scheme();
         path = openEvent->url().path();
+        address = openEvent->url().host();
 
         QFile file(path);
         if (scheme == "file" && file.exists()) {
             form->PlayDemoQuick(openEvent->file());
             return true;
+        } else if (scheme == "hwplay") {
+            int port = openEvent->url().port(NETGAME_DEFAULT_PORT);
+            form->NetConnectQuick(address, (quint16) port);
+            return true;
         } else {
             const QString errmsg = tr("Not yet implemented").arg(path);
             MessageDialog::ShowErrorMessage(errmsg, form);
             return false;
         }
-     }
+    }
 
     return QApplication::event(event);
 }
--- a/QTfrontend/hwform.cpp	Sun Mar 10 11:29:00 2013 +0100
+++ b/QTfrontend/hwform.cpp	Sun Mar 10 15:44:03 2013 +0100
@@ -1000,8 +1000,14 @@
     game->PlayDemo(demofilename, false);
 }
 
+void HWForm::NetConnectQuick(const QString & host, quint16 port)
+{
+    NetConnectServer(host, port);
+}
+
 void HWForm::NetConnectServer(const QString & host, quint16 port)
 {
+    qDebug("connecting to %s:%d", qPrintable(host), port);
     _NetConnect(host, port, ui.pageOptions->editNetNick->text().trimmed());
 }
 
--- a/QTfrontend/hwform.h	Sun Mar 10 11:29:00 2013 +0100
+++ b/QTfrontend/hwform.h	Sun Mar 10 15:44:03 2013 +0100
@@ -62,12 +62,14 @@
         Ui_HWForm ui;
         static GameUIConfig * config;
         void updateXfire();
-        void PlayDemoQuick(const QString & demofilename);
         void exit();
         void setButtonDescription(QString desc);
         void backDescription();
         void GoToVideos();
 
+        void NetConnectQuick(const QString & host, quint16 port);
+        void PlayDemoQuick(const QString & demofilename);
+
     private slots:
         void GoToSaves();
         void GoToDemos();
--- a/share/Info.plist.in	Sun Mar 10 11:29:00 2013 +0100
+++ b/share/Info.plist.in	Sun Mar 10 15:44:03 2013 +0100
@@ -156,7 +156,6 @@
             <string>Viewer</string>
         </dict>
     </array>
-    <!--
     <key>CFBundleURLTypes</key>
     <array>
         <dict>
@@ -164,12 +163,14 @@
             <string>Hedgewars URIs</string>
             <key>CFBundleURLSchemes</key>
             <array>
+            <!--
                 <string>hwd</string>
                 <string>hws</string>
                 <string>hwdlc</string>
+            -->
+                <string>hwplay</string>
             </array>
         </dict>
     </array>
-    -->
 </dict>
 </plist>