parent
74a3540ca5
commit
beaaa09fbe
|
@ -113,6 +113,19 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
anchors.rightMargin: 8
|
||||||
|
spacing: 16
|
||||||
|
Text {
|
||||||
|
text: Backend.translate("Room Password")
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
id: roomPassword
|
||||||
|
maximumLength: 16
|
||||||
|
font.pixelSize: 18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Switch {
|
Switch {
|
||||||
id: freeAssignCheck
|
id: freeAssignCheck
|
||||||
checked: Debugging ? true : false
|
checked: Debugging ? true : false
|
||||||
|
@ -154,6 +167,7 @@ ColumnLayout {
|
||||||
disabledPack: config.disabledPack,
|
disabledPack: config.disabledPack,
|
||||||
generalNum: config.preferredGeneralNum,
|
generalNum: config.preferredGeneralNum,
|
||||||
luckTime: config.preferredLuckTime,
|
luckTime: config.preferredLuckTime,
|
||||||
|
password: roomPassword.text,
|
||||||
disabledGenerals,
|
disabledGenerals,
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
|
|
|
@ -113,6 +113,7 @@ callbacks["UpdateRoomList"] = function(jsonData) {
|
||||||
gameMode: room[2],
|
gameMode: room[2],
|
||||||
playerNum: room[3],
|
playerNum: room[3],
|
||||||
capacity: room[4],
|
capacity: room[4],
|
||||||
|
hasPassword: room[5],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ Item {
|
||||||
id: root
|
id: root
|
||||||
property alias roomModel: roomModel
|
property alias roomModel: roomModel
|
||||||
|
|
||||||
|
property string password
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width / 2 - roomListLayout.width / 2
|
width: parent.width / 2 - roomListLayout.width / 2
|
||||||
height: parent.height * 0.7
|
height: parent.height * 0.7
|
||||||
|
@ -47,7 +49,7 @@ Item {
|
||||||
id: roomDelegate
|
id: roomDelegate
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
height: 22
|
height: 48
|
||||||
width: roomList.width
|
width: roomList.width
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
@ -55,49 +57,40 @@ Item {
|
||||||
spacing: 16
|
spacing: 16
|
||||||
Text {
|
Text {
|
||||||
text: roomId
|
text: roomId
|
||||||
|
color: "grey"
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignLeft
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
text: roomName
|
text: roomName + (hasPassword ? "(🔒)" : "")
|
||||||
|
font.pixelSize: 20
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: gameMode
|
text: Backend.translate(gameMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
color: (playerNum == capacity) ? "red" : "black"
|
color: (playerNum == capacity) ? "red" : "black"
|
||||||
text: playerNum + "/" + capacity
|
text: playerNum + "/" + capacity
|
||||||
|
font.pixelSize: 20
|
||||||
|
font.bold: true
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Button {
|
||||||
text: Backend.translate("Enter")
|
text: (playerNum < capacity) ? Backend.translate("Enter") :
|
||||||
font.pixelSize: 24
|
Backend.translate("Observe")
|
||||||
TapHandler {
|
|
||||||
onTapped: {
|
|
||||||
config.observing = false;
|
|
||||||
mainWindow.busy = true;
|
|
||||||
ClientInstance.notifyServer(
|
|
||||||
"EnterRoom",
|
|
||||||
JSON.stringify([roomId])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
onClicked: {
|
||||||
text: Backend.translate("Observe")
|
if (hasPassword) {
|
||||||
font.pixelSize: 24
|
lobby_dialog.sourceComponent = enterPassword;
|
||||||
TapHandler {
|
lobby_dialog.item.roomId = roomId;
|
||||||
onTapped: {
|
lobby_dialog.item.playerNum = playerNum;
|
||||||
config.observing = true;
|
lobby_dialog.item.capacity = capacity;
|
||||||
mainWindow.busy = true;
|
lobby_drawer.open();
|
||||||
ClientInstance.notifyServer(
|
} else {
|
||||||
"ObserveRoom",
|
enterRoom(roomId, playerNum, capacity, "");
|
||||||
JSON.stringify([roomId])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,6 +226,57 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: enterPassword
|
||||||
|
ColumnLayout {
|
||||||
|
property int roomId
|
||||||
|
property int playerNum
|
||||||
|
property int capacity
|
||||||
|
signal finished()
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.margins: 16
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: Backend.translate("Please input room's password")
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: passwordEdit
|
||||||
|
onTextChanged: root.password = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: "OK"
|
||||||
|
onClicked: {
|
||||||
|
enterRoom(roomId, playerNum, capacity, root.password);
|
||||||
|
parent.finished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
passwordEdit.text = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function enterRoom(roomId, playerNum, capacity, pw) {
|
||||||
|
if (playerNum < capacity) {
|
||||||
|
config.observing = false;
|
||||||
|
mainWindow.busy = true;
|
||||||
|
ClientInstance.notifyServer(
|
||||||
|
"EnterRoom",
|
||||||
|
JSON.stringify([roomId, pw])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
config.observing = true;
|
||||||
|
mainWindow.busy = true;
|
||||||
|
ClientInstance.notifyServer(
|
||||||
|
"ObserveRoom",
|
||||||
|
JSON.stringify([roomId, pw])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
property int lobbyPlayerNum: 0
|
property int lobbyPlayerNum: 0
|
||||||
property int serverPlayerNum: 0
|
property int serverPlayerNum: 0
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,10 @@
|
||||||
<source>server is using version %1, please update</source>
|
<source>server is using version %1, please update</source>
|
||||||
<translation>服务端使用的是版本%1,该更新你的客户端了</translation>
|
<translation>服务端使用的是版本%1,该更新你的客户端了</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>room password error</source>
|
||||||
|
<translation>房间密码错误</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
|
||||||
<context>
|
<context>
|
||||||
|
|
|
@ -32,6 +32,8 @@ Fk:loadTranslationTable{
|
||||||
["Select general num"] = "选将数目",
|
["Select general num"] = "选将数目",
|
||||||
["Operation timeout"] = "操作时长(秒)",
|
["Operation timeout"] = "操作时长(秒)",
|
||||||
["Luck Card Times"] = "手气卡次数",
|
["Luck Card Times"] = "手气卡次数",
|
||||||
|
["Room Password"] = "房间密码",
|
||||||
|
["Please input room's password"] = "请输入房间的密码",
|
||||||
["Game Mode"] = "游戏模式",
|
["Game Mode"] = "游戏模式",
|
||||||
["Enable free assign"] = "自由选将",
|
["Enable free assign"] = "自由选将",
|
||||||
["Enable deputy general"] = "启用副将机制",
|
["Enable deputy general"] = "启用副将机制",
|
||||||
|
|
|
@ -211,7 +211,13 @@ void Router::handlePacket(const QByteArray &rawPacket) {
|
||||||
auto roomId = arr[0].toInt();
|
auto roomId = arr[0].toInt();
|
||||||
auto room = ServerInstance->findRoom(roomId);
|
auto room = ServerInstance->findRoom(roomId);
|
||||||
if (room) {
|
if (room) {
|
||||||
|
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||||
|
auto password = settings["password"].toString();
|
||||||
|
if (password.isEmpty() || arr[1].toString() == password) {
|
||||||
room->addPlayer(sender);
|
room->addPlayer(sender);
|
||||||
|
} else {
|
||||||
|
sender->doNotify("ErrorMsg", "room password error");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender->doNotify("ErrorMsg", "no such room");
|
sender->doNotify("ErrorMsg", "no such room");
|
||||||
}
|
}
|
||||||
|
@ -222,7 +228,13 @@ void Router::handlePacket(const QByteArray &rawPacket) {
|
||||||
auto roomId = arr[0].toInt();
|
auto roomId = arr[0].toInt();
|
||||||
auto room = ServerInstance->findRoom(roomId);
|
auto room = ServerInstance->findRoom(roomId);
|
||||||
if (room) {
|
if (room) {
|
||||||
|
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||||
|
auto password = settings["password"].toString();
|
||||||
|
if (password.isEmpty() || arr[1].toString() == password) {
|
||||||
room->addObserver(sender);
|
room->addObserver(sender);
|
||||||
|
} else {
|
||||||
|
sender->doNotify("ErrorMsg", "room password error");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender->doNotify("ErrorMsg", "no such room");
|
sender->doNotify("ErrorMsg", "no such room");
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,11 +138,15 @@ void Server::updateRoomList() {
|
||||||
QJsonArray arr;
|
QJsonArray arr;
|
||||||
foreach (Room *room, rooms) {
|
foreach (Room *room, rooms) {
|
||||||
QJsonArray obj;
|
QJsonArray obj;
|
||||||
|
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||||
|
auto password = settings["password"].toString();
|
||||||
|
|
||||||
obj << room->getId(); // roomId
|
obj << room->getId(); // roomId
|
||||||
obj << room->getName(); // roomName
|
obj << room->getName(); // roomName
|
||||||
obj << "Role"; // gameMode
|
obj << settings["gameMode"]; // gameMode
|
||||||
obj << room->getPlayers().count(); // playerNum
|
obj << room->getPlayers().count(); // playerNum
|
||||||
obj << room->getCapacity(); // capacity
|
obj << room->getCapacity(); // capacity
|
||||||
|
obj << !password.isEmpty();
|
||||||
arr << obj;
|
arr << obj;
|
||||||
}
|
}
|
||||||
auto jsonData = JsonArray2Bytes(arr);
|
auto jsonData = JsonArray2Bytes(arr);
|
||||||
|
|
Loading…
Reference in New Issue