2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-05-01 10:37:13 +00:00
|
|
|
var generalsOverviewPage, cardsOverviewPage;
|
|
|
|
var clientPageCreated = false;
|
|
|
|
function createClientPages() {
|
|
|
|
if (!clientPageCreated) {
|
|
|
|
clientPageCreated = true;
|
|
|
|
|
|
|
|
generalsOverviewPage = generalsOverview.createObject(mainWindow);
|
|
|
|
cardsOverviewPage = cardsOverview.createObject(mainWindow);
|
|
|
|
|
|
|
|
mainWindow.generalsOverviewPage = generalsOverviewPage;
|
|
|
|
mainWindow.cardsOverviewPage = cardsOverviewPage;
|
2023-02-26 08:51:29 +00:00
|
|
|
}
|
2022-05-01 10:37:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 13:23:42 +00:00
|
|
|
var callbacks = {};
|
2023-02-21 05:44:24 +00:00
|
|
|
let sheduled_download = "";
|
2022-03-24 13:23:42 +00:00
|
|
|
|
2023-06-30 20:12:19 +00:00
|
|
|
callbacks["ServerDetected"] = (j) => {
|
|
|
|
const serverDialog = mainStack.currentItem.serverDialog;
|
|
|
|
if (!serverDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const item = serverDialog.item;
|
|
|
|
if (item) {
|
|
|
|
toast.show(qsTr("Detected Server %1").arg(j.slice(7)), 10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["GetServerDetail"] = (j) => {
|
2023-07-01 15:14:30 +00:00
|
|
|
const [ver, icon, desc, capacity, count, addr] = JSON.parse(j);
|
2023-06-30 20:12:19 +00:00
|
|
|
const serverDialog = mainStack.currentItem.serverDialog;
|
|
|
|
if (!serverDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const item = serverDialog.item;
|
|
|
|
if (item) {
|
|
|
|
item.updateServerDetail(addr, [ver, icon, desc, capacity, count]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["NetworkDelayTest"] = (jsonData) => {
|
2022-12-18 04:52:52 +00:00
|
|
|
// jsonData: RSA pub key
|
2023-04-15 04:06:39 +00:00
|
|
|
let cipherText;
|
|
|
|
let aeskey;
|
2022-12-18 04:52:52 +00:00
|
|
|
if (config.savedPassword[config.serverAddr] !== undefined
|
|
|
|
&& config.savedPassword[config.serverAddr].shorten_password === config.password) {
|
|
|
|
cipherText = config.savedPassword[config.serverAddr].password;
|
2023-04-15 04:06:39 +00:00
|
|
|
aeskey = config.savedPassword[config.serverAddr].key;
|
2023-04-15 04:40:07 +00:00
|
|
|
config.aeskey = aeskey ?? "";
|
2023-04-15 04:06:39 +00:00
|
|
|
Backend.setAESKey(aeskey);
|
2022-12-18 04:52:52 +00:00
|
|
|
if (Debugging)
|
|
|
|
console.log("use remembered password", config.password);
|
|
|
|
} else {
|
|
|
|
cipherText = Backend.pubEncrypt(jsonData, config.password);
|
2023-04-15 04:06:39 +00:00
|
|
|
config.aeskey = Backend.getAESKey();
|
2022-12-18 04:52:52 +00:00
|
|
|
}
|
|
|
|
config.cipherText = cipherText;
|
2023-03-14 12:50:36 +00:00
|
|
|
Backend.replyDelayTest(config.screenName, cipherText);
|
2022-03-24 13:23:42 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["ErrorMsg"] = (jsonData) => {
|
2023-05-18 23:45:36 +00:00
|
|
|
let log;
|
|
|
|
try {
|
2023-06-08 17:16:23 +00:00
|
|
|
const a = JSON.parse(jsonData);
|
2023-05-18 23:45:36 +00:00
|
|
|
log = qsTr(a[0]).arg(a[1]);
|
|
|
|
} catch (e) {
|
|
|
|
log = qsTr(jsonData);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("ERROR: " + log);
|
|
|
|
toast.show(log, 5000);
|
2022-04-30 07:27:56 +00:00
|
|
|
mainWindow.busy = false;
|
2023-02-21 05:44:24 +00:00
|
|
|
if (sheduled_download !== "") {
|
|
|
|
mainWindow.busy = true;
|
|
|
|
Pacman.loadSummary(sheduled_download, true);
|
|
|
|
sheduled_download = "";
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
callbacks["UpdatePackage"] = (jsonData) => sheduled_download = jsonData;
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["UpdateBusyText"] = (jsonData) => {
|
2023-02-15 11:54:35 +00:00
|
|
|
mainWindow.busyText = jsonData;
|
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["DownloadComplete"] = () => {
|
2023-02-15 11:54:35 +00:00
|
|
|
mainWindow.busy = false;
|
|
|
|
mainStack.currentItem.downloadComplete(); // should be pacman page
|
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["BackToStart"] = (jsonData) => {
|
2022-04-30 07:27:56 +00:00
|
|
|
while (mainStack.depth > 1) {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
2022-03-27 06:49:41 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["EnterLobby"] = (jsonData) => {
|
2022-04-30 07:27:56 +00:00
|
|
|
// depth == 1 means the lobby page is not present in mainStack
|
2022-05-01 10:37:13 +00:00
|
|
|
createClientPages();
|
2022-04-30 07:27:56 +00:00
|
|
|
if (mainStack.depth === 1) {
|
2022-12-18 04:52:52 +00:00
|
|
|
// we enter the lobby successfully, so save password now.
|
|
|
|
config.lastLoginServer = config.serverAddr;
|
|
|
|
config.savedPassword[config.serverAddr] = {
|
|
|
|
username: config.screenName,
|
|
|
|
password: config.cipherText,
|
2023-04-15 04:06:39 +00:00
|
|
|
key: config.aeskey,
|
2022-12-18 04:52:52 +00:00
|
|
|
shorten_password: config.cipherText.slice(0, 8)
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
mainStack.push(lobby);
|
|
|
|
} else {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
|
|
|
mainWindow.busy = false;
|
2023-06-10 15:55:39 +00:00
|
|
|
config.saveConf();
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["EnterRoom"] = (jsonData) => {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: int capacity, int timeout
|
2023-06-08 17:16:23 +00:00
|
|
|
const data = JSON.parse(jsonData);
|
2022-04-30 07:27:56 +00:00
|
|
|
config.roomCapacity = data[0];
|
2022-09-15 03:17:13 +00:00
|
|
|
config.roomTimeout = data[1] - 1;
|
2023-06-08 17:16:23 +00:00
|
|
|
const roomSettings = data[2];
|
2023-02-15 11:54:35 +00:00
|
|
|
config.enableFreeAssign = roomSettings.enableFreeAssign;
|
2022-04-30 07:27:56 +00:00
|
|
|
mainStack.push(room);
|
|
|
|
mainWindow.busy = false;
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["UpdateRoomList"] = (jsonData) => {
|
|
|
|
const current = mainStack.currentItem; // should be lobby
|
2023-06-09 09:23:02 +00:00
|
|
|
if (mainStack.depth === 2) {
|
2023-06-08 17:16:23 +00:00
|
|
|
current.roomModel.clear();
|
|
|
|
JSON.parse(jsonData).forEach(function (room) {
|
|
|
|
current.roomModel.append({
|
|
|
|
roomId: room[0],
|
|
|
|
roomName: room[1],
|
|
|
|
gameMode: room[2],
|
|
|
|
playerNum: room[3],
|
|
|
|
capacity: room[4],
|
|
|
|
hasPassword: room[5] ? true : false,
|
|
|
|
});
|
2022-03-23 11:40:28 +00:00
|
|
|
});
|
2023-06-08 17:16:23 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-12-18 04:52:52 +00:00
|
|
|
|
2023-04-05 07:13:58 +00:00
|
|
|
callbacks["UpdatePlayerNum"] = (j) => {
|
2023-06-08 17:16:23 +00:00
|
|
|
const current = mainStack.currentItem; // should be lobby
|
2023-06-09 09:23:02 +00:00
|
|
|
if (mainStack.depth === 2) {
|
2023-06-08 17:16:23 +00:00
|
|
|
const data = JSON.parse(j);
|
|
|
|
const l = data[0];
|
|
|
|
const s = data[1];
|
|
|
|
current.lobbyPlayerNum = l;
|
|
|
|
current.serverPlayerNum = s;
|
|
|
|
}
|
2023-04-05 07:13:58 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["Chat"] = (jsonData) => {
|
2022-12-18 04:52:52 +00:00
|
|
|
// jsonData: { string userName, string general, string time, string msg }
|
2023-06-08 17:16:23 +00:00
|
|
|
const current = mainStack.currentItem; // lobby or room
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const pid = data.sender;
|
|
|
|
const userName = data.userName;
|
|
|
|
const general = Backend.translate(data.general);
|
|
|
|
const time = data.time;
|
|
|
|
const msg = data.msg;
|
2023-04-10 13:34:23 +00:00
|
|
|
|
2023-06-29 12:42:07 +00:00
|
|
|
if (config.blockedUsers.indexOf(userName) !== -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
if (general === "")
|
|
|
|
current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`);
|
|
|
|
else
|
|
|
|
current.addToChat(pid, data, `[${time}] ${userName}(${general}): ${msg}`);
|
|
|
|
}
|
2023-04-18 15:26:15 +00:00
|
|
|
|
2023-06-08 17:16:23 +00:00
|
|
|
callbacks["ServerMessage"] = (jsonData) => {
|
|
|
|
const current = mainStack.currentItem; // lobby or room
|
2023-04-18 15:26:15 +00:00
|
|
|
current.sendDanmaku('<font color="gold"><b>[Server] </b></font>' + jsonData);
|
|
|
|
}
|
2023-05-18 23:45:36 +00:00
|
|
|
|
|
|
|
callbacks["ShowToast"] = (j) => toast.show(j);
|
|
|
|
callbacks["InstallKey"] = (j) => Backend.installAESKey();
|