Start network support: only setting up a connection for now qmlfrontend
authorunc0rr
Thu, 16 Apr 2015 23:31:13 +0300
branchqmlfrontend
changeset 10896 5a74923120d5
parent 10894 6157d057f04e
child 10898 f373838129c2
Start network support: only setting up a connection for now
hedgewars/CMakeLists.txt
hedgewars/hwLibrary.pas
hedgewars/uFLNet.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/Connect.qml
qmlFrontend/qml/qmlFrontend/First.qml
qmlFrontend/qml/qmlFrontend/main.qml
qmlFrontend/qmlFrontend.qrc
--- a/hedgewars/CMakeLists.txt	Tue Apr 14 11:18:14 2015 +0300
+++ b/hedgewars/CMakeLists.txt	Thu Apr 16 23:31:13 2015 +0300
@@ -108,6 +108,7 @@
     uFLData.pas
     uFLGameConfig.pas
     uFLIPC.pas
+    uFLNet.pas
     uFLScripts.pas
     uFLSchemes.pas
     uFLTeams.pas
--- a/hedgewars/hwLibrary.pas	Tue Apr 14 11:18:14 2015 +0300
+++ b/hedgewars/hwLibrary.pas	Thu Apr 16 23:31:13 2015 +0300
@@ -47,6 +47,7 @@
     , uFLScripts
     , uFLSchemes
     , uFLAmmo
+    , uFLNet
     ;
 
 {$INCLUDE "config.inc"}
@@ -109,10 +110,12 @@
 begin
     initIPC;
     uPhysFSLayer.initModule(localPrefix, userPrefix);
+    uFLNet.initModule;
 end;
 
 procedure flibFree; cdecl;
 begin
+    uFLNet.freeModule;
     uPhysFSLayer.freemodule;
     freeIPC;
 end;
@@ -154,6 +157,7 @@
     registerGUIMessagesCallback,
     flibInit,
     flibFree,
+    //game config
     resetGameConfig,
     setSeed,
     getSeed,
@@ -171,6 +175,8 @@
     tryAddTeam,
     tryRemoveTeam,
     changeTeamColor,
+    // network
+    connectOfficialServer,
 
     // dunno what these are
     RunEngine,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uFLNet.pas	Thu Apr 16 23:31:13 2015 +0300
@@ -0,0 +1,37 @@
+unit uFLNet;
+interface
+
+procedure connectOfficialServer;
+
+procedure initModule;
+procedure freeModule;
+
+implementation
+uses SDLh;
+
+var sock: PTCPSocket;
+    fds: PSDLNet_SocketSet;
+
+procedure connectOfficialServer;
+var ipaddr: TIPAddress;
+begin
+    if sock <> nil then 
+        exit;
+
+    if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
+        sock:= SDLNet_TCP_Open(ipaddr)
+end;
+
+procedure initModule;
+begin
+    sock:= nil;
+
+    SDLNet_Init;
+    fds:= SDLNet_AllocSocketSet(1);
+end;
+
+procedure freeModule;
+begin
+end;
+
+end.
--- a/qmlFrontend/flib.h	Tue Apr 14 11:18:14 2015 +0300
+++ b/qmlFrontend/flib.h	Thu Apr 16 23:31:13 2015 +0300
@@ -55,6 +55,8 @@
 typedef void tryRemoveTeam_t(const char * teamName);
 typedef void changeTeamColor_t(const char * teamName, int32_t dir);
 
+typedef void connectOfficialServer_t();
+
 #ifdef __cplusplus
 }
 #endif
--- a/qmlFrontend/hwengine.cpp	Tue Apr 14 11:18:14 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Thu Apr 16 23:31:13 2015 +0300
@@ -33,6 +33,8 @@
     tryAddTeam_t * flibTryAddTeam;
     tryRemoveTeam_t * flibTryRemoveTeam;
     changeTeamColor_t * flibChangeTeamColor;
+
+    connectOfficialServer_t * flibConnectOfficialServer;
 }
 
 Q_DECLARE_METATYPE(MessageType);
@@ -77,6 +79,8 @@
     flibTryRemoveTeam = (tryRemoveTeam_t*) hwlib.resolve("tryRemoveTeam");
     flibChangeTeamColor = (changeTeamColor_t*) hwlib.resolve("changeTeamColor");
 
+    flibConnectOfficialServer = (connectOfficialServer_t*) hwlib.resolve("connectOfficialServer");
+
     flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
     flibRegisterGUIMessagesCallback(this, &guiMessagesCallback);
 
@@ -237,6 +241,11 @@
     flibChangeTeamColor(teamName.toUtf8().constData(), dir);
 }
 
+void HWEngine::connect(const QString &host, quint16 port)
+{
+    flibConnectOfficialServer();
+}
+
 void HWEngine::setTheme(const QString &theme)
 {
     flibSetTheme(theme.toUtf8().constData());
--- a/qmlFrontend/hwengine.h	Tue Apr 14 11:18:14 2015 +0300
+++ b/qmlFrontend/hwengine.h	Thu Apr 16 23:31:13 2015 +0300
@@ -34,6 +34,8 @@
     Q_INVOKABLE void tryRemoveTeam(const QString & teamName);
     Q_INVOKABLE void changeTeamColor(const QString & teamName, int dir);
 
+    Q_INVOKABLE void connect(const QString & host, quint16 port);
+
 signals:
     void previewImageChanged();
     void localTeamAdded(const QString & teamName, int aiLevel);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlFrontend/qml/qmlFrontend/Connect.qml	Thu Apr 16 23:31:13 2015 +0300
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+import Hedgewars.Engine 1.0
+
+Rectangle {
+    HWButton {
+        id: btnNetConnect
+        x: 80
+        y: 80
+        width: 256
+        height: 128
+
+        onClicked: HWEngine.connect("netserver.hedgewars.org", 46631);
+    }
+}
--- a/qmlFrontend/qml/qmlFrontend/First.qml	Tue Apr 14 11:18:14 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/First.qml	Thu Apr 16 23:31:13 2015 +0300
@@ -17,6 +17,8 @@
         y: 80
         width: 166
         height: 166
+
+        onClicked: pages.currentPage = "Connect"
     }
 
     HWButton {
--- a/qmlFrontend/qml/qmlFrontend/main.qml	Tue Apr 14 11:18:14 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/main.qml	Thu Apr 16 23:31:13 2015 +0300
@@ -9,6 +9,7 @@
         "First"
         , "LocalGame"
         , "GameConfig"
+        , "Connect"
     ];
 
     property string  currentPage : "First";
--- a/qmlFrontend/qmlFrontend.qrc	Tue Apr 14 11:18:14 2015 +0300
+++ b/qmlFrontend/qmlFrontend.qrc	Thu Apr 16 23:31:13 2015 +0300
@@ -6,5 +6,6 @@
         <file>qml/qmlFrontend/HWComboBox.qml</file>
         <file>qml/qmlFrontend/LocalGame.qml</file>
         <file>qml/qmlFrontend/main.qml</file>
+        <file>qml/qmlFrontend/Connect.qml</file>
     </qresource>
 </RCC>