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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
callbacks["NetworkDelayTest"] = function(jsonData) {
|
2022-12-18 12:52:52 +08:00
|
|
|
// jsonData: RSA pub key
|
|
|
|
let cipherText
|
|
|
|
if (config.savedPassword[config.serverAddr] !== undefined
|
|
|
|
&& config.savedPassword[config.serverAddr].shorten_password === config.password) {
|
|
|
|
cipherText = config.savedPassword[config.serverAddr].password;
|
|
|
|
if (Debugging)
|
|
|
|
console.log("use remembered password", config.password);
|
|
|
|
} else {
|
|
|
|
cipherText = Backend.pubEncrypt(jsonData, config.password);
|
|
|
|
}
|
|
|
|
config.cipherText = cipherText;
|
|
|
|
let md5sum = Backend.calcFileMD5();
|
2022-04-30 15:27:56 +08:00
|
|
|
ClientInstance.notifyServer("Setup", JSON.stringify([
|
2022-12-18 12:52:52 +08:00
|
|
|
config.screenName, cipherText, md5sum
|
2022-04-30 15:27:56 +08:00
|
|
|
]));
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
callbacks["ErrorMsg"] = function(jsonData) {
|
2022-04-30 15:27:56 +08:00
|
|
|
console.log("ERROR: " + jsonData);
|
2023-01-29 18:11:41 +08:00
|
|
|
toast.show(qsTr(jsonData), 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;
|
|
|
|
Pacman.loadSummary(sheduled_download, true);
|
|
|
|
sheduled_download = "";
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
2023-02-21 13:44:24 +08:00
|
|
|
callbacks["UpdatePackage"] = (jsonData) => sheduled_download = jsonData;
|
|
|
|
|
2023-02-15 19:54:35 +08:00
|
|
|
callbacks["UpdateBusyText"] = function(jsonData) {
|
|
|
|
mainWindow.busyText = jsonData;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["DownloadComplete"] = function() {
|
|
|
|
mainWindow.busy = false;
|
|
|
|
mainStack.currentItem.downloadComplete(); // should be pacman page
|
|
|
|
}
|
|
|
|
|
2022-03-27 14:49:41 +08:00
|
|
|
callbacks["BackToStart"] = function(jsonData) {
|
2022-04-30 15:27:56 +08:00
|
|
|
while (mainStack.depth > 1) {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
2022-03-27 14:49:41 +08:00
|
|
|
}
|
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
callbacks["EnterLobby"] = function(jsonData) {
|
2022-04-30 15:27:56 +08:00
|
|
|
// depth == 1 means the lobby page is not present in mainStack
|
2022-05-01 18:37:13 +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;
|
|
|
|
config.savedPassword[config.serverAddr] = {
|
|
|
|
username: config.screenName,
|
|
|
|
password: config.cipherText,
|
|
|
|
shorten_password: config.cipherText.slice(0, 8)
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
mainStack.push(lobby);
|
|
|
|
} else {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
|
|
|
mainWindow.busy = false;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["EnterRoom"] = function(jsonData) {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int capacity, int timeout
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
config.roomCapacity = data[0];
|
2022-09-15 11:17:13 +08:00
|
|
|
config.roomTimeout = data[1] - 1;
|
2023-02-15 19:54:35 +08:00
|
|
|
let roomSettings = data[2];
|
|
|
|
config.enableFreeAssign = roomSettings.enableFreeAssign;
|
2022-04-30 15:27:56 +08:00
|
|
|
mainStack.push(room);
|
|
|
|
mainWindow.busy = false;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["UpdateRoomList"] = function(jsonData) {
|
2022-04-30 15:27:56 +08:00
|
|
|
let current = mainStack.currentItem; // should be lobby
|
|
|
|
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],
|
2022-03-23 19:40:28 +08:00
|
|
|
});
|
2022-04-30 15:27:56 +08:00
|
|
|
});
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-12-18 12:52:52 +08:00
|
|
|
|
|
|
|
callbacks["Chat"] = function(jsonData) {
|
|
|
|
// jsonData: { string userName, string general, string time, string msg }
|
|
|
|
let current = mainStack.currentItem; // lobby(TODO) or room
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let pid = data.type;
|
|
|
|
let userName = data.userName;
|
|
|
|
let general = Backend.translate(data.general);
|
|
|
|
let time = data.time;
|
|
|
|
let msg = data.msg;
|
|
|
|
if (general === "")
|
|
|
|
current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`);
|
|
|
|
else
|
|
|
|
current.addToChat(pid, data, `[${time}] ${userName}(${general}): ${msg}`);
|
|
|
|
}
|