Handle ROOMS and ROOM ADD protocol commands qmlfrontend
authorunc0rr
Fri, 20 Nov 2015 23:56:13 +0300
branchqmlfrontend
changeset 11418 091149424aa4
parent 11417 4815e406a760
child 11419 8a5cc31483c6
Handle ROOMS and ROOM ADD protocol commands
hedgewars/uFLIPC.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLNetTypes.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/LobbyPage.qml
--- a/hedgewars/uFLIPC.pas	Fri Nov 20 23:05:49 2015 +0300
+++ b/hedgewars/uFLIPC.pas	Fri Nov 20 23:56:13 2015 +0300
@@ -53,7 +53,8 @@
     while (msg.str[0] = #0) and (msg.buf = nil) do
         SDL_CondWait(cond, mut);
 
-    if msg.buf <> nil then
+    if msg.buf <> nil then 
+// FIXME is this copying really needed, the buffer is in another thread already anyway?
     begin
         tmp:= msg.buf;
         msg.buf:= GetMem(msg.len);
--- a/hedgewars/uFLNet.pas	Fri Nov 20 23:05:49 2015 +0300
+++ b/hedgewars/uFLNet.pas	Fri Nov 20 23:56:13 2015 +0300
@@ -33,7 +33,7 @@
 function getShortString: shortstring; forward;
 
 // generated stuff here
-const letters: array[0..211] of char = ('A', 'S', 'K', 'P', 'A', 'S', 'S', 'W',
+const letters: array[0..212] of char = ('A', 'S', 'K', 'P', 'A', 'S', 'S', 'W',
     'O', 'R', 'D', #10, 'B', 'A', 'N', 'L', 'I', 'S', 'T', #10, 'Y', 'E', #10, 'C',
     'H', 'A', 'T', #10, 'L', 'I', 'E', 'N', 'T', '_', 'F', 'L', 'A', 'G', 'S', #10,
     'O', 'N', 'N', 'E', 'C', 'T', 'E', 'D', #10, 'E', 'M', #10, 'R', 'R', 'O', 'R',
@@ -41,22 +41,22 @@
     'N', 'E', 'D', #10, 'I', 'N', 'G', #10, 'K', 'I', 'C', 'K', 'E', 'D', #10, 'L',
     'E', 'F', 'T', #10, 'O', 'B', 'B', 'Y', ':', 'J', 'O', 'I', 'N', 'E', 'D', #10,
     'L', 'E', 'F', 'T', #10, 'N', 'I', 'C', 'K', #10, 'O', 'T', 'I', 'C', 'E', #10,
-    'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'O', 'O', 'M', 'S', #10,
-    'U', 'N', 'D', '_', 'F', 'I', 'N', 'I', 'S', 'H', 'E', 'D', #10, 'U', 'N', '_',
-    'G', 'A', 'M', 'E', #10, 'S', 'E', 'R', 'V', 'E', 'R', '_', 'A', 'U', 'T', 'H',
-    #10, 'M', 'E', 'S', 'S', 'A', 'G', 'E', #10, 'V', 'A', 'R', 'S', #10, 'T', 'E',
-    'A', 'M', '_', 'A', 'C', 'C', 'E', 'P', 'T', 'E', 'D', #10, 'C', 'O', 'L', 'O',
-    'R', #10, 'W', 'A', 'R', 'N', 'I', 'N', 'G', #10, #0, #10);
-const commands: array[0..211] of integer = (12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    -39, 11, 7, 0, 0, 0, 0, 0, -38, 0, 0, -37, 26, 4, 0, 0, -36, 12, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, -35, 0, 0, 0, 0, 0, 0, 0, 0, -34, 8, 2, -33, 0, 0, 0, 0, -32, 7,
-    0, 0, 0, 0, 0, -31, 5, 0, 0, 0, -30, 11, 0, 0, 0, 3, 0, -29, 0, 0, 0, -28, 7, 0,
-    0, 0, 0, 0, -27, 22, 4, 0, 0, -26, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, -25, 0, 0,
-    0, 0, -24, 11, 4, 0, 0, -23, 0, 0, 0, 0, 0, -22, 10, 4, 0, 0, -21, 0, 0, 0, 0,
-    -20, 27, 18, 4, 0, 0, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 0, 0, 0, 0,
-    0, 0, 0, -17, 25, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, -16, 8, 0, 0, 0, 0, 0, 0, -15,
-    0, 0, 0, 0, -14, 20, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0,
-    -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10);
+    'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'O', 'O', 'M', #10, 'S',
+    #10, 'U', 'N', 'D', '_', 'F', 'I', 'N', 'I', 'S', 'H', 'E', 'D', #10, 'U', 'N',
+    '_', 'G', 'A', 'M', 'E', #10, 'S', 'E', 'R', 'V', 'E', 'R', '_', 'A', 'U', 'T',
+    'H', #10, 'M', 'E', 'S', 'S', 'A', 'G', 'E', #10, 'V', 'A', 'R', 'S', #10, 'T',
+    'E', 'A', 'M', '_', 'A', 'C', 'C', 'E', 'P', 'T', 'E', 'D', #10, 'C', 'O', 'L',
+    'O', 'R', #10, 'W', 'A', 'R', 'N', 'I', 'N', 'G', #10, #0, #10);
+const commands: array[0..212] of integer = (12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    -40, 11, 7, 0, 0, 0, 0, 0, -39, 0, 0, -38, 26, 4, 0, 0, -37, 12, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, -36, 0, 0, 0, 0, 0, 0, 0, 0, -35, 8, 2, -34, 0, 0, 0, 0, -33, 7,
+    0, 0, 0, 0, 0, -32, 5, 0, 0, 0, -31, 11, 0, 0, 0, 3, 0, -30, 0, 0, 0, -29, 7, 0,
+    0, 0, 0, 0, -28, 22, 4, 0, 0, -27, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, -26, 0, 0,
+    0, 0, -25, 11, 4, 0, 0, -24, 0, 0, 0, 0, 0, -23, 10, 4, 0, 0, -22, 0, 0, 0, 0,
+    -21, 28, 19, 5, 2, -20, 0, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 0, 0,
+    0, 0, 0, 0, 0, -17, 25, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, -16, 8, 0, 0, 0, 0, 0, 0,
+    -15, 0, 0, 0, 0, -14, 20, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 0, 0,
+    0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10);
 
 procedure handler_;
 begin
@@ -136,21 +136,22 @@
     writeln('[NET] Unknown cmd');
 end;
 
-const handlers: array[0..29] of PHandler = (@handler__UNKNOWN_, @handler_L, @handler_MS, @handler_S,
+const handlers: array[0..30] of PHandler = (@handler__UNKNOWN_, @handler_L, @handler_MS, @handler_S,
     @handler_SL, @handler_L, @handler_S, @handler_, @handler_, @handler_MS,
-    @handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL, @handler_MS,
-    @handler_SMS, @handler_, @handler_S, @handler_MS, @handler_MS, @handler_MS,
-    @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, @handler_SL,
-    @handler_MS, @handler_S);
-const net2cmd: array[0..29] of TCmdType = (cmd_WARNING, cmd_WARNING,
+    @handler_MS, @handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL,
+    @handler_MS, @handler_SMS, @handler_, @handler_S, @handler_MS, @handler_MS,
+    @handler_MS, @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL,
+    @handler_SL, @handler_MS, @handler_S);
+const net2cmd: array[0..30] of TCmdType = (cmd_WARNING, cmd_WARNING,
     cmd_TEAM_COLOR, cmd_TEAM_ACCEPTED, cmd_SERVER_VARS, cmd_SERVER_MESSAGE,
-    cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOMS, cmd_PROTO,
-    cmd_PING, cmd_NOTICE, cmd_NICK, cmd_LOBBY_LEFT, cmd_LOBBY_JOINED, cmd_LEFT,
-    cmd_KICKED, cmd_JOINING, cmd_JOINED, cmd_INFO, cmd_HH_NUM, cmd_ERROR, cmd_EM,
-    cmd_CONNECTED, cmd_CLIENT_FLAGS, cmd_CHAT, cmd_BYE, cmd_BANLIST,
+    cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOMS, cmd_ROOM,
+    cmd_PROTO, cmd_PING, cmd_NOTICE, cmd_NICK, cmd_LOBBY_LEFT, cmd_LOBBY_JOINED,
+    cmd_LEFT, cmd_KICKED, cmd_JOINING, cmd_JOINED, cmd_INFO, cmd_HH_NUM, cmd_ERROR,
+    cmd_EM, cmd_CONNECTED, cmd_CLIENT_FLAGS, cmd_CHAT, cmd_BYE, cmd_BANLIST,
     cmd_ASKPASSWORD);
 
 
+
 // end of generated stuff
 procedure handleTail;
 var cnt: Longint;
--- a/hedgewars/uFLNetProtocol.pas	Fri Nov 20 23:05:49 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Fri Nov 20 23:56:13 2015 +0300
@@ -18,7 +18,7 @@
 procedure handler_BANLIST(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_BANLIST_s(var s: TCmdParamS);
 begin
 end;
@@ -38,7 +38,7 @@
 procedure handler_CLIENT_FLAGS(var p: TCmdParamS);
 begin
 end;
- 
+
 procedure handler_CLIENT_FLAGS_s(var s: TCmdParamS);
 begin
 end;
@@ -53,7 +53,7 @@
 procedure handler_EM(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_EM_s(var s: TCmdParamS);
 begin
 end;
@@ -65,7 +65,7 @@
 procedure handler_HH_NUM(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_HH_NUM_s(var s: TCmdParamS);
 begin
 end;
@@ -73,7 +73,7 @@
 procedure handler_INFO(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_INFO_s(var s: TCmdParamS);
 begin
 end;
@@ -81,7 +81,7 @@
 procedure handler_JOINED(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_JOINED_s(var s: TCmdParamS);
 begin
 end;
@@ -97,7 +97,7 @@
 procedure handler_LEFT(var p: TCmdParamS);
 begin
 end;
- 
+
 procedure handler_LEFT_s(var s: TCmdParamS);
 begin
 end;
@@ -105,7 +105,7 @@
 procedure handler_LOBBY_JOINED(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_LOBBY_JOINED_s(var s: TCmdParamS);
 begin
     sendUI(mtAddLobbyClient, @s.str1[1], length(s.str1));
@@ -127,7 +127,7 @@
 begin
     sendNet('PONG')
 end;
- 
+
 procedure handler_PING_s(var s: TCmdParamS);
 begin
 end;
@@ -136,12 +136,62 @@
 begin
 end;
 
+type TRoomAction = (raUnknown, raAdd, raUpdate, raRemove);
+const raRoomInfoLength: array[TRoomAction] of integer = (1, 9, 10, 1);
+const raRoomAction: array[TRoomAction] of TMessageType = (mtAddRoom, mtAddRoom, mtUpdateRoom, mtRemoveRoom);
+var roomInfo: string;
+    roomLinesCount: integer;
+    roomAction: TRoomAction;
+
+procedure handler_ROOM(var p: TCmdParam);
+begin
+    roomInfo:= '';
+    roomLinesCount:= 0;
+    roomAction:= raUnknown
+end;
+
+procedure handler_ROOM_s(var s: TCmdParamS);
+begin
+    if roomAction = raUnknown then
+    begin
+        if s.str1 = 'ADD' then
+            roomAction:= raAdd
+        else
+            if s.str1 = 'UPD' then
+                roomAction:= raUpdate
+            else
+                if s.str1 = 'DEL' then
+                    roomAction:= raRemove
+    end
+    else begin
+        roomInfo:= roomInfo + s.str1 + #10;
+        inc(roomLinesCount);
+
+        if roomLinesCount = raRoomInfoLength[roomAction] then
+        begin
+            sendUI(raRoomAction[roomAction], @roomInfo[1], length(roomInfo));
+            roomLinesCount:= 0;
+            roomInfo:= ''
+        end;
+    end;
+end;
+
 procedure handler_ROOMS(var p: TCmdParam);
 begin
+    roomInfo:= '';
+    roomLinesCount:= 0
 end;
- 
+
 procedure handler_ROOMS_s(var s: TCmdParamS);
 begin
+    roomInfo:= roomInfo + s.str1 + #10;
+
+    if roomLinesCount = 8 then
+    begin
+        sendUI(mtAddRoom, @roomInfo[1], length(roomInfo));
+        roomLinesCount:= 0;
+        roomInfo:= ''
+    end else inc(roomLinesCount);
 end;
 
 procedure handler_ROUND_FINISHED(var p: TCmdParam);
@@ -171,7 +221,7 @@
 procedure handler_TEAM_COLOR(var p: TCmdParam);
 begin
 end;
- 
+
 procedure handler_TEAM_COLOR_s(var s: TCmdParamS);
 begin
 end;
@@ -192,12 +242,13 @@
     PHandler(@handler_LEFT_s), PHandler(@handler_LOBBY_JOINED),
     PHandler(@handler_LOBBY_JOINED_s), PHandler(@handler_LOBBY_LEFT),
     PHandler(@handler_NICK), PHandler(@handler_NOTICE), PHandler(@handler_PING),
-    PHandler(@handler_PING_s), PHandler(@handler_PROTO), PHandler(@handler_ROOMS),
-    PHandler(@handler_ROOMS_s), PHandler(@handler_ROUND_FINISHED),
-    PHandler(@handler_RUN_GAME), PHandler(@handler_SERVER_AUTH),
-    PHandler(@handler_SERVER_MESSAGE), PHandler(@handler_SERVER_VARS),
-    PHandler(@handler_TEAM_ACCEPTED), PHandler(@handler_TEAM_COLOR),
-    PHandler(@handler_TEAM_COLOR_s), PHandler(@handler_WARNING));
+    PHandler(@handler_PING_s), PHandler(@handler_PROTO), PHandler(@handler_ROOM),
+    PHandler(@handler_ROOM_s), PHandler(@handler_ROOMS), PHandler(@handler_ROOMS_s),
+    PHandler(@handler_ROUND_FINISHED), PHandler(@handler_RUN_GAME),
+    PHandler(@handler_SERVER_AUTH), PHandler(@handler_SERVER_MESSAGE),
+    PHandler(@handler_SERVER_VARS), PHandler(@handler_TEAM_ACCEPTED),
+    PHandler(@handler_TEAM_COLOR), PHandler(@handler_TEAM_COLOR_s),
+    PHandler(@handler_WARNING));
 
 procedure passNetData(p: pointer); cdecl;
 begin
--- a/hedgewars/uFLNetTypes.pas	Fri Nov 20 23:05:49 2015 +0300
+++ b/hedgewars/uFLNetTypes.pas	Fri Nov 20 23:56:13 2015 +0300
@@ -6,9 +6,10 @@
     cmd_ERROR, cmd_HH_NUM, cmd_HH_NUM_s, cmd_INFO, cmd_INFO_s, cmd_JOINED,
     cmd_JOINED_s, cmd_JOINING, cmd_KICKED, cmd_LEFT, cmd_LEFT_s, cmd_LOBBY_JOINED,
     cmd_LOBBY_JOINED_s, cmd_LOBBY_LEFT, cmd_NICK, cmd_NOTICE, cmd_PING, cmd_PING_s,
-    cmd_PROTO, cmd_ROOMS, cmd_ROOMS_s, cmd_ROUND_FINISHED, cmd_RUN_GAME,
-    cmd_SERVER_AUTH, cmd_SERVER_MESSAGE, cmd_SERVER_VARS, cmd_TEAM_ACCEPTED,
-    cmd_TEAM_COLOR, cmd_TEAM_COLOR_s, cmd_WARNING);
+    cmd_PROTO, cmd_ROOM, cmd_ROOM_s, cmd_ROOMS, cmd_ROOMS_s, cmd_ROUND_FINISHED,
+    cmd_RUN_GAME, cmd_SERVER_AUTH, cmd_SERVER_MESSAGE, cmd_SERVER_VARS,
+    cmd_TEAM_ACCEPTED, cmd_TEAM_COLOR, cmd_TEAM_COLOR_s, cmd_WARNING);
+
 
     type TCmdParam = packed record
         cmd: TCmdType;
--- a/hedgewars/uFLTypes.pas	Fri Nov 20 23:05:49 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Fri Nov 20 23:56:13 2015 +0300
@@ -4,7 +4,8 @@
 type
     TMessageType = (mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
                     , mtTeamColor, mtNetData, mtConnected, mtDisconnected, mtAddLobbyClient
-                    , mtRemoveLobbyClient, mtLobbyChatLine);
+                    , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoom, mtUpdateRoom
+                    , mtRemoveRoom);
 
     TIPCMessage = record
                    str: shortstring;
--- a/qmlFrontend/flib.h	Fri Nov 20 23:05:49 2015 +0300
+++ b/qmlFrontend/flib.h	Fri Nov 20 23:56:13 2015 +0300
@@ -20,6 +20,9 @@
     , MSG_ADDLOBBYCLIENT
     , MSG_REMOVELOBBYCLIENT
     , MSG_LOBBYCHATLINE
+    , MSG_ADDROOM
+    , MSG_UPDATEROOM
+    , MSG_REMOVEROOM
 };
 
 typedef union string255_
--- a/qmlFrontend/hwengine.cpp	Fri Nov 20 23:05:49 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Fri Nov 20 23:56:13 2015 +0300
@@ -199,6 +199,17 @@
         emit lobbyChatLine(l[0], l[1]);
         break;
     }
+    case MSG_ADDROOM: {
+        QStringList l = QString::fromUtf8(msg).split('\n');
+        emit roomAdded(0, l[1], l[2].toInt(), l[3].toInt(), l[4], l[5], l[6], l[7], l[8]);
+        break;
+    }
+    case MSG_UPDATEROOM: {
+        break;
+    }
+    case MSG_REMOVEROOM: {
+        break;
+    }
     }
 }
 
--- a/qmlFrontend/hwengine.h	Fri Nov 20 23:05:49 2015 +0300
+++ b/qmlFrontend/hwengine.h	Fri Nov 20 23:56:13 2015 +0300
@@ -55,6 +55,16 @@
     void lobbyClientRemoved(const QString & clientName);
     void lobbyChatLine(const QString & nickname, const QString & line);
 
+    void roomAdded(quint32 flags
+                   , const QString & name
+                   , int players
+                   , int teams
+                   , const QString & host
+                   , const QString & map
+                   , const QString & script
+                   , const QString & scheme
+                   , const QString & weapons);
+
 public slots:
 
 private:
--- a/qmlFrontend/qml/qmlFrontend/LobbyPage.qml	Fri Nov 20 23:05:49 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/LobbyPage.qml	Fri Nov 20 23:56:13 2015 +0300
@@ -1,8 +1,75 @@
 import QtQuick 2.0
+import Hedgewars.Engine 1.0
 
 Rectangle {
+    ListView {
+        id: roomsList
+        x: 20
+        y: 0
+        width: parent.width
+        height: parent.height - x
+        focus: true
+        clip: true
+
+        model: ListModel {
+            id: roomsListModel
+        }
+
+        delegate: Rectangle {
+            id: roomDelegate
+            height: 24
+            width: parent.width
+            color: "transparent"
+
+            Row {
+                spacing: 8;
+                Text {
+                    text: name
+                }
+                Text {
+                    text: players + " / " + teams
+                }
+                Text {
+                    text: host
+                }
+                Text {
+                    text: map
+                }
+                Text {
+                    text: script
+                }
+                Text {
+                    text: scheme
+                }
+                Text {
+                    text: weapons
+                }
+            }
+
+            MouseArea {
+                 z: 1
+                 anchors.fill: parent
+                 onClicked: ;
+            }
+        }
+
+        Connections {
+            target: HWEngine
+            onRoomAdded: roomsListModel.append({
+                               "name" : name
+                               , "players": players
+                               , "teams": teams
+                               , "host": host
+                               , "map": map
+                               , "script": script
+                               , "scheme": scheme
+                               , "weapons": weapons
+                           })
+        }
+    }
 
     Chat {
+        id: lobbyChat;
         x: 0;
         y: 100;
         width: parent.width;