2023-04-09 13:35:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-08-01 21:01:01 +08:00
|
|
|
/*
|
2022-05-01 18:37:13 +08: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 16:51:29 +08:00
|
|
|
}
|
2022-05-01 18:37:13 +08:00
|
|
|
}
|
2023-08-01 21:01:01 +08:00
|
|
|
*/
|
2022-05-01 18:37:13 +08:00
|
|
|
|
2022-03-24 21:23:42 +08:00
|
|
|
var callbacks = {};
|
2023-02-21 13:44:24 +08:00
|
|
|
let sheduled_download = "";
|
2022-03-24 21:23:42 +08:00
|
|
|
|
2023-07-01 04:12:19 +08:00
|
|
|
callbacks["ServerDetected"] = (j) => {
|
|
|
|
const serverDialog = mainStack.currentItem.serverDialog;
|
|
|
|
if (!serverDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const item = serverDialog.item;
|
|
|
|
if (item) {
|
2024-07-03 01:31:22 +08:00
|
|
|
// toast.show(qsTr("Detected Server %1").arg(j.slice(7)), 10000);
|
|
|
|
item.addLANServer(j.slice(7))
|
2023-07-01 04:12:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["GetServerDetail"] = (j) => {
|
2023-07-01 23:14:30 +08:00
|
|
|
const [ver, icon, desc, capacity, count, addr] = JSON.parse(j);
|
2023-07-01 04:12:19 +08:00
|
|
|
const serverDialog = mainStack.currentItem.serverDialog;
|
|
|
|
if (!serverDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const item = serverDialog.item;
|
|
|
|
if (item) {
|
2024-07-03 01:31:22 +08:00
|
|
|
let [_addr, port] = addr.split(',');
|
|
|
|
port = parseInt(port);
|
|
|
|
item.updateServerDetail(_addr, port, [ver, icon, desc, capacity, count]);
|
2023-07-01 04:12:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["NetworkDelayTest"] = (jsonData) => {
|
2022-12-18 12:52:52 +08:00
|
|
|
// jsonData: RSA pub key
|
2023-04-15 12:06:39 +08:00
|
|
|
let cipherText;
|
|
|
|
let aeskey;
|
2024-07-03 01:31:22 +08:00
|
|
|
// const savedPw = config.savedPassword[config.serverAddr];
|
|
|
|
// if (savedPw?.shorten_password === config.password) {
|
|
|
|
// cipherText = config.savedPassword[config.serverAddr].password;
|
|
|
|
// aeskey = config.savedPassword[config.serverAddr].key;
|
|
|
|
// config.aeskey = aeskey ?? "";
|
|
|
|
// Backend.setAESKey(aeskey);
|
|
|
|
// if (Debugging)
|
|
|
|
// console.log("use remembered password", config.password);
|
|
|
|
// } else {
|
|
|
|
cipherText = Backend.pubEncrypt(jsonData, config.password);
|
|
|
|
config.aeskey = Backend.getAESKey();
|
|
|
|
// }
|
2022-12-18 12:52:52 +08:00
|
|
|
config.cipherText = cipherText;
|
2023-03-14 20:50:36 +08:00
|
|
|
Backend.replyDelayTest(config.screenName, cipherText);
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["ErrorMsg"] = (jsonData) => {
|
2023-05-19 07:45:36 +08:00
|
|
|
let log;
|
|
|
|
try {
|
2023-06-09 01:16:23 +08:00
|
|
|
const a = JSON.parse(jsonData);
|
2023-05-19 07:45:36 +08:00
|
|
|
log = qsTr(a[0]).arg(a[1]);
|
|
|
|
} catch (e) {
|
|
|
|
log = qsTr(jsonData);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("ERROR: " + log);
|
|
|
|
toast.show(log, 5000);
|
2022-04-30 15:27:56 +08:00
|
|
|
mainWindow.busy = false;
|
2023-02-21 13:44:24 +08:00
|
|
|
if (sheduled_download !== "") {
|
|
|
|
mainWindow.busy = true;
|
2024-04-19 22:38:00 +08:00
|
|
|
Pacman.loadSummary(JSON.stringify(sheduled_download), true);
|
2023-02-21 13:44:24 +08:00
|
|
|
sheduled_download = "";
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
2024-06-10 14:58:31 +08:00
|
|
|
callbacks["ErrorDlg"] = (jsonData) => {
|
|
|
|
let log;
|
|
|
|
try {
|
|
|
|
const a = JSON.parse(jsonData);
|
|
|
|
log = qsTr(a[0]).arg(a[1]);
|
|
|
|
} catch (e) {
|
|
|
|
log = qsTr(jsonData);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("ERROR: " + log);
|
|
|
|
Backend.showDialog("warning", log, jsonData);
|
|
|
|
mainWindow.busy = false;
|
|
|
|
if (sheduled_download !== "") {
|
|
|
|
mainWindow.busy = true;
|
|
|
|
Pacman.loadSummary(JSON.stringify(sheduled_download), true);
|
|
|
|
sheduled_download = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 13:44:24 +08:00
|
|
|
callbacks["UpdatePackage"] = (jsonData) => sheduled_download = jsonData;
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["UpdateBusyText"] = (jsonData) => {
|
2023-02-15 19:54:35 +08:00
|
|
|
mainWindow.busyText = jsonData;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["DownloadComplete"] = () => {
|
2023-02-15 19:54:35 +08:00
|
|
|
mainWindow.busy = false;
|
|
|
|
mainStack.currentItem.downloadComplete(); // should be pacman page
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["BackToStart"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
while (mainStack.depth > 1) {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
2022-03-27 14:49:41 +08:00
|
|
|
}
|
|
|
|
|
2024-04-19 20:53:19 +08:00
|
|
|
callbacks["SetServerSettings"] = (data) => {
|
2023-08-27 20:21:37 +08:00
|
|
|
const [ motd, hiddenPacks, enableBots ] = data;
|
2023-08-03 15:24:17 +08:00
|
|
|
config.serverMotd = motd;
|
|
|
|
config.serverHiddenPacks = hiddenPacks;
|
2023-08-27 20:21:37 +08:00
|
|
|
config.serverEnableBot = enableBots;
|
2023-08-03 15:24:17 +08:00
|
|
|
};
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["EnterLobby"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// depth == 1 means the lobby page is not present in mainStack
|
2023-08-01 21:01:01 +08:00
|
|
|
// createClientPages();
|
2022-04-30 15:27:56 +08:00
|
|
|
if (mainStack.depth === 1) {
|
2022-12-18 12:52:52 +08:00
|
|
|
// we enter the lobby successfully, so save password now.
|
|
|
|
config.lastLoginServer = config.serverAddr;
|
2024-07-03 01:31:22 +08:00
|
|
|
// config.savedPassword[config.serverAddr] = {
|
|
|
|
// username: config.screenName,
|
|
|
|
// password: config.cipherText,
|
|
|
|
// key: config.aeskey,
|
|
|
|
// shorten_password: config.cipherText.slice(0, 8)
|
|
|
|
// }
|
2022-04-30 15:27:56 +08:00
|
|
|
mainStack.push(lobby);
|
|
|
|
} else {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
|
|
|
mainWindow.busy = false;
|
2023-07-02 22:43:56 +08:00
|
|
|
ClientInstance.notifyServer("RefreshRoomList", "");
|
2023-06-10 23:55:39 +08:00
|
|
|
config.saveConf();
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
2024-04-19 20:53:19 +08:00
|
|
|
callbacks["EnterRoom"] = (data) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int capacity, int timeout
|
|
|
|
config.roomCapacity = data[0];
|
2022-09-15 11:17:13 +08:00
|
|
|
config.roomTimeout = data[1] - 1;
|
2023-06-09 01:16:23 +08:00
|
|
|
const roomSettings = data[2];
|
2023-02-15 19:54:35 +08:00
|
|
|
config.enableFreeAssign = roomSettings.enableFreeAssign;
|
2023-09-06 22:16:09 +08:00
|
|
|
config.heg = roomSettings.gameMode.includes('heg_mode');
|
2022-04-30 15:27:56 +08:00
|
|
|
mainStack.push(room);
|
|
|
|
mainWindow.busy = false;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
2024-04-19 20:53:19 +08:00
|
|
|
callbacks["UpdateRoomList"] = (data) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const current = mainStack.currentItem; // should be lobby
|
2023-06-09 17:23:02 +08:00
|
|
|
if (mainStack.depth === 2) {
|
2023-06-09 01:16:23 +08:00
|
|
|
current.roomModel.clear();
|
2024-04-19 20:53:19 +08:00
|
|
|
data.forEach(room => {
|
2024-04-07 00:35:57 +08:00
|
|
|
const [roomId, roomName, gameMode, playerNum, capacity, hasPassword,
|
|
|
|
outdated] = room;
|
2023-06-09 01:16:23 +08:00
|
|
|
current.roomModel.append({
|
2024-04-07 00:35:57 +08:00
|
|
|
roomId, roomName, gameMode, playerNum, capacity,
|
|
|
|
hasPassword, outdated,
|
2023-06-09 01:16:23 +08:00
|
|
|
});
|
2022-03-23 19:40:28 +08:00
|
|
|
});
|
2023-06-09 01:16:23 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-12-18 12:52:52 +08:00
|
|
|
|
2024-04-19 20:53:19 +08:00
|
|
|
callbacks["UpdatePlayerNum"] = (data) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const current = mainStack.currentItem; // should be lobby
|
2023-06-09 17:23:02 +08:00
|
|
|
if (mainStack.depth === 2) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const l = data[0];
|
|
|
|
const s = data[1];
|
|
|
|
current.lobbyPlayerNum = l;
|
|
|
|
current.serverPlayerNum = s;
|
|
|
|
}
|
2023-04-05 15:13:58 +08:00
|
|
|
}
|
|
|
|
|
2024-04-19 20:53:19 +08:00
|
|
|
callbacks["Chat"] = (data) => {
|
2022-12-18 12:52:52 +08:00
|
|
|
// jsonData: { string userName, string general, string time, string msg }
|
2023-06-09 01:16:23 +08:00
|
|
|
const current = mainStack.currentItem; // lobby or room
|
|
|
|
const pid = data.sender;
|
|
|
|
const userName = data.userName;
|
2024-01-25 03:23:29 +08:00
|
|
|
const general = luatr(data.general);
|
2023-06-09 01:16:23 +08:00
|
|
|
const time = data.time;
|
|
|
|
const msg = data.msg;
|
2023-04-10 21:34:23 +08:00
|
|
|
|
2023-06-29 20:42:07 +08:00
|
|
|
if (config.blockedUsers.indexOf(userName) !== -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
let text;
|
2022-12-18 12:52:52 +08:00
|
|
|
if (general === "")
|
2024-01-25 03:23:29 +08:00
|
|
|
text = `<font color="#3598E8">[${time}] ${userName}:</font> ${msg}`;
|
2022-12-18 12:52:52 +08:00
|
|
|
else
|
2024-01-25 03:23:29 +08:00
|
|
|
text = `<font color="#3598E8">[${time}] ${userName}` +
|
|
|
|
`(${general}):</font> ${msg}`;
|
|
|
|
current.addToChat(pid, data, text);
|
2022-12-18 12:52:52 +08:00
|
|
|
}
|
2023-04-18 23:26:15 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["ServerMessage"] = (jsonData) => {
|
|
|
|
const current = mainStack.currentItem; // lobby or room
|
2023-10-27 22:53:25 +08:00
|
|
|
current.sendDanmaku('<font color="grey"><b>[Server] </b></font>' + jsonData);
|
2023-04-18 23:26:15 +08:00
|
|
|
}
|
2023-05-19 07:45:36 +08:00
|
|
|
|
|
|
|
callbacks["ShowToast"] = (j) => toast.show(j);
|
|
|
|
callbacks["InstallKey"] = (j) => Backend.installAESKey();
|
2023-12-28 12:11:24 +08:00
|
|
|
|
|
|
|
callbacks["AddTotalGameTime"] = (jsonData) => {
|
|
|
|
config.totalTime++;
|
|
|
|
}
|