--- a/hedgewars/SDLh.pas Wed Nov 18 22:18:39 2015 +0300
+++ b/hedgewars/SDLh.pas Thu Nov 19 23:04:53 2015 +0300
@@ -1119,6 +1119,7 @@
(or have fun debugging nil arguments) *)
function SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
+procedure SDL_DetachThread(thread: PSDL_Thread); cdecl; external SDLLibName;
function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
--- a/hedgewars/uFLNet.pas Wed Nov 18 22:18:39 2015 +0300
+++ b/hedgewars/uFLNet.pas Thu Nov 19 23:04:53 2015 +0300
@@ -6,6 +6,7 @@
procedure initModule;
procedure freeModule;
procedure sendNet(s: shortstring);
+procedure sendNetLn(s: shortstring);
implementation
uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
@@ -81,7 +82,6 @@
f: boolean;
begin
sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
- writeln('handler_MS');
cmd.cmd:= Succ(state.cmd);
repeat
@@ -99,8 +99,12 @@
end;
procedure handler_SL;
+var cmd: TCmdParamSL;
begin
- writeln('handler_SL');
+ cmd.cmd:= state.cmd;
+ cmd.str1:= getShortString;
+ cmd.str2:= getShortString; // FIXME should be long string
+ sendUI(mtNetData, @cmd, sizeof(cmd));
handleTail()
end;
@@ -195,11 +199,6 @@
getNextChar:= state.buf[state.bufpos];
end;
-function netWriter(sock: PTCPSocket): LongInt; cdecl; export;
-begin
- netWriter:= 0;
-end;
-
function netReader(data: pointer): LongInt; cdecl; export;
var c: char;
ipaddr: TIPAddress;
@@ -209,8 +208,6 @@
if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
sock:= SDLNet_TCP_Open(ipaddr);
- SDL_CreateThread(@netWriter, 'netWriter', sock);
-
repeat
c:= getNextChar;
//writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l]);
@@ -238,6 +235,7 @@
end
until state.netState = netDisconnected;
+ SDLNet_TCP_Close(sock);
sock:= nil;
writeln('[NET] netReader: disconnected');
@@ -249,6 +247,12 @@
ipcToNet(s + endCmd);
end;
+procedure sendNetLn(s: shortstring);
+begin
+ writeln('[NET] Send: ', s);
+ ipcToNet(s + #10);
+end;
+
function getShortString: shortstring;
var s: shortstring;
c: char;
@@ -286,6 +290,7 @@
state.netState:= netConnecting;
netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil);
+ SDL_DetachThread(netReaderThread)
end;
procedure initModule;
--- a/hedgewars/uFLNetProtocol.pas Wed Nov 18 22:18:39 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas Thu Nov 19 23:04:53 2015 +0300
@@ -23,10 +23,14 @@
procedure handler_BYE(var p: TCmdParamSL);
begin
+ sendUI(mtDisconnected, @p.str2[1], length(p.str2));
end;
procedure handler_CHAT(var p: TCmdParamSL);
+var s: string;
begin
+ s:= p.str1 + #10 + p.str2;
+ sendUI(mtLobbyChatLine, @s[1], length(s));
end;
procedure handler_CLIENT_FLAGS(var p: TCmdParamS);
@@ -39,7 +43,9 @@
procedure handler_CONNECTED(var p: TCmdParami);
begin
- writeln('Connected!!!!! ', p.param1)
+ sendUI(mtConnected, nil, 0);
+ sendNet('PROTO' + #10 + '51');
+ sendNet('NICK' + #10 + 'qmlfrontend');
end;
procedure handler_EM(var p: TCmdParam);
@@ -100,6 +106,7 @@
procedure handler_LOBBY_JOINED_s(var s: TCmdParamS);
begin
+ sendUI(mtAddLobbyClient, @s.str1[1], length(s.str1));
end;
procedure handler_LOBBY_LEFT(var p: TCmdParamSL);
--- a/hedgewars/uFLTypes.pas Wed Nov 18 22:18:39 2015 +0300
+++ b/hedgewars/uFLTypes.pas Thu Nov 19 23:04:53 2015 +0300
@@ -3,7 +3,8 @@
type
TMessageType = (mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
- , mtTeamColor, mtNetData);
+ , mtTeamColor, mtNetData, mtConnected, mtDisconnected, mtAddLobbyClient
+ , mtRemoveLobbyClient, mtLobbyChatLine);
TIPCMessage = record
str: shortstring;
--- a/qmlFrontend/flib.h Wed Nov 18 22:18:39 2015 +0300
+++ b/qmlFrontend/flib.h Thu Nov 19 23:04:53 2015 +0300
@@ -15,6 +15,11 @@
, MSG_REMOVETEAM
, MSG_TEAMCOLOR
, MSG_NETDATA
+ , MSG_CONNECTED
+ , MSG_DISCONNECTED
+ , MSG_ADDLOBBYCLIENT
+ , MSG_REMOVELOBBYCLIENT
+ , MSG_LOBBYCHATLINE
};
typedef union string255_
--- a/qmlFrontend/hwengine.cpp Wed Nov 18 22:18:39 2015 +0300
+++ b/qmlFrontend/hwengine.cpp Thu Nov 19 23:04:53 2015 +0300
@@ -135,7 +135,7 @@
HWEngine * obj = (HWEngine *)context;
QByteArray b = QByteArray(msg, len);
- qDebug() << "FLIPC in" << b.size() << b;
+ //qDebug() << "FLIPC in" << b.size() << b;
QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
}
@@ -156,15 +156,15 @@
break;
}
case MSG_REMOVEPLAYINGTEAM: {
- emit playingTeamRemoved(msg);
+ emit playingTeamRemoved(QString::fromUtf8(msg));
break;
}
case MSG_ADDTEAM: {
- emit localTeamAdded(msg, 0);
+ emit localTeamAdded(QString::fromUtf8(msg), 0);
break;
}
case MSG_REMOVETEAM: {
- emit localTeamRemoved(msg);
+ emit localTeamRemoved(QString::fromUtf8(msg));
break;
}
case MSG_TEAMCOLOR: {
@@ -174,6 +174,28 @@
}
case MSG_NETDATA: {
flibPassNetData(msg.constData());
+ break;
+ }
+ case MSG_CONNECTED: {
+ emit netConnected();
+ break;
+ }
+ case MSG_DISCONNECTED: {
+ emit netDisconnected(QString::fromUtf8(msg));
+ break;
+ }
+ case MSG_ADDLOBBYCLIENT: {
+ emit lobbyClientAdded(QString::fromUtf8(msg));
+ break;
+ }
+ case MSG_REMOVELOBBYCLIENT: {
+ emit lobbyClientRemoved(QString::fromUtf8(msg));
+ break;
+ }
+ case MSG_LOBBYCHATLINE: {
+ QStringList l = QString::fromUtf8(msg).split('\n');
+ emit lobbyChatLine(l[0], l[1]);
+ break;
}
}
}
--- a/qmlFrontend/hwengine.h Wed Nov 18 22:18:39 2015 +0300
+++ b/qmlFrontend/hwengine.h Thu Nov 19 23:04:53 2015 +0300
@@ -46,6 +46,13 @@
void teamColorChanged(const QString & teamName, const QString & colorValue);
+ void netConnected();
+ void netDisconnected(const QString & message);
+
+ void lobbyClientAdded(const QString & clientName);
+ void lobbyClientRemoved(const QString & clientName);
+ void lobbyChatLine(const QString & nickname, const QString & line);
+
public slots:
private:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlFrontend/qml/qmlFrontend/Chat.qml Thu Nov 19 23:04:53 2015 +0300
@@ -0,0 +1,117 @@
+import QtQuick 2.0
+import Hedgewars.Engine 1.0
+
+Rectangle {
+ id: chat
+ color: "#15193a"
+ radius: 8
+ border.width: 4
+ opacity: 1
+ border.color: "#ea761d"
+
+ ListView {
+ id: chatLines
+ x: 0
+ y: 0
+ width: parent.width - clientsList.width
+ height: parent.height
+ focus: true
+ clip: true
+ highlightFollowsCurrentItem: true
+
+ model: ListModel {
+ id: chatLinesModel
+ }
+
+ delegate: Rectangle {
+ id: chatLinesDelegate
+ height: 24
+ width: parent.width
+ color: "transparent"
+
+ Row {
+ spacing: 8;
+ Text {
+ color: "#ffffa0"
+ text: nick
+
+ MouseArea {
+ z: 1
+ anchors.fill: parent
+ onClicked: ;
+ }
+ }
+ Text {
+ color: "#ffffff"
+ text: name
+
+ MouseArea {
+ z: 1
+ anchors.fill: parent
+ onClicked: ;
+ }
+ }
+ }
+
+ }
+
+ Connections {
+ target: HWEngine
+ onLobbyChatLine: {
+ chatLinesModel.append({"nick" : nickname, "name": line})
+ if(chatLinesModel.count > 200)
+ chatLinesModel.remove(0)
+ chatLines.currentIndex = chatLinesModel.count - 1
+ }
+ }
+ }
+
+ ListView {
+ id: clientsList
+ x: parent.width - width
+ width: 100
+ height: parent.height
+ focus: true
+ clip: true
+
+ model: ListModel {
+ id: chatClientsModel
+ }
+
+ delegate: Rectangle {
+ id: chatClientDelegate
+ height: 24
+ width: parent.width
+ color: "transparent"
+
+ Row {
+ Text {
+ color: "#ffffff"
+ text: name
+
+ MouseArea {
+ z: 1
+ anchors.fill: parent
+ onClicked: ;
+ }
+ }
+ }
+
+ }
+
+ Connections {
+ target: HWEngine
+ onLobbyClientAdded: {
+ chatClientsModel.append({"isAdmin": false, "name": clientName})
+ }
+ onLobbyClientRemoved: {
+ var i = chatClientsModel.count - 1;
+ while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
+
+ if(i >= 0) chatClientsModel.remove(i, 1);
+ }
+ }
+ }
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlFrontend/qml/qmlFrontend/LobbyPage.qml Thu Nov 19 23:04:53 2015 +0300
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+
+Rectangle {
+
+ Chat {
+ x: 0;
+ y: 100;
+ width: parent.width;
+ height: parent.height - y;
+ }
+}
+
+
--- a/qmlFrontend/qml/qmlFrontend/main.qml Wed Nov 18 22:18:39 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/main.qml Thu Nov 19 23:04:53 2015 +0300
@@ -1,4 +1,5 @@
import QtQuick 2.0
+import Hedgewars.Engine 1.0
Rectangle {
id: pages
@@ -10,6 +11,7 @@
, "LocalGame"
, "GameConfig"
, "Connect"
+ , "LobbyPage"
];
property string currentPage : "First";
@@ -33,4 +35,10 @@
}
}
}
+
+ Connections {
+ target: HWEngine
+ onNetConnected: currentPage = "LobbyPage";
+ onNetDisconnected: currentPage = "First";
+ }
}
--- a/qmlFrontend/qmlFrontend.qrc Wed Nov 18 22:18:39 2015 +0300
+++ b/qmlFrontend/qmlFrontend.qrc Thu Nov 19 23:04:53 2015 +0300
@@ -7,5 +7,7 @@
<file>qml/qmlFrontend/LocalGame.qml</file>
<file>qml/qmlFrontend/main.qml</file>
<file>qml/qmlFrontend/Connect.qml</file>
+ <file>qml/qmlFrontend/LobbyPage.qml</file>
+ <file>qml/qmlFrontend/Chat.qml</file>
</qresource>
</RCC>