# HG changeset patch # User unc0rr # Date 1429216273 -10800 # Node ID 5a74923120d519d34d49987bdeb644a264eb350d # Parent 6157d057f04ea805e8097581d31ab4832a0103ff Start network support: only setting up a connection for now diff -r 6157d057f04e -r 5a74923120d5 hedgewars/CMakeLists.txt --- 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 diff -r 6157d057f04e -r 5a74923120d5 hedgewars/hwLibrary.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, diff -r 6157d057f04e -r 5a74923120d5 hedgewars/uFLNet.pas --- /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. diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/flib.h --- 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 diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/hwengine.cpp --- 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()); diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/hwengine.h --- 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); diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/qml/qmlFrontend/Connect.qml --- /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); + } +} diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/qml/qmlFrontend/First.qml --- 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 { diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/qml/qmlFrontend/main.qml --- 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"; diff -r 6157d057f04e -r 5a74923120d5 qmlFrontend/qmlFrontend.qrc --- 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 @@ qml/qmlFrontend/HWComboBox.qml qml/qmlFrontend/LocalGame.qml qml/qmlFrontend/main.qml + qml/qmlFrontend/Connect.qml