Haruka041 commited on
Commit ·
f0d9c2f
1
Parent(s): fa9f076
fix: reduce disconnects and backup load
Browse files
monopoly-client/src/classes/monopoly-client/MonopolyClient.ts
CHANGED
|
@@ -167,7 +167,7 @@ export class MonopolyClient {
|
|
| 167 |
setInterval(() => {
|
| 168 |
this.sendHeartTime = Date.now();
|
| 169 |
this.sendMsg(SocketMsgType.Heart, "");
|
| 170 |
-
},
|
| 171 |
);
|
| 172 |
}
|
| 173 |
|
|
@@ -377,7 +377,7 @@ export class MonopolyClient {
|
|
| 377 |
() => {
|
| 378 |
this.handleSocketDisconnected("heart-timeout");
|
| 379 |
},
|
| 380 |
-
|
| 381 |
true
|
| 382 |
);
|
| 383 |
|
|
|
|
| 167 |
setInterval(() => {
|
| 168 |
this.sendHeartTime = Date.now();
|
| 169 |
this.sendMsg(SocketMsgType.Heart, "");
|
| 170 |
+
}, 5000)
|
| 171 |
);
|
| 172 |
}
|
| 173 |
|
|
|
|
| 377 |
() => {
|
| 378 |
this.handleSocketDisconnected("heart-timeout");
|
| 379 |
},
|
| 380 |
+
45000,
|
| 381 |
true
|
| 382 |
);
|
| 383 |
|
monopoly-server/src/ws/game-room-manager.ts
CHANGED
|
@@ -14,6 +14,7 @@ type WsClient = WebSocket & {
|
|
| 14 |
__roomId?: string;
|
| 15 |
__userId?: string;
|
| 16 |
__isAlive?: boolean;
|
|
|
|
| 17 |
};
|
| 18 |
|
| 19 |
type RoomUserSession = UserInRoomInfo & {
|
|
@@ -699,10 +700,15 @@ export function attachGameWsGateway(server: import("http").Server) {
|
|
| 699 |
wss.clients.forEach((client) => {
|
| 700 |
const ws = client as WsClient;
|
| 701 |
if (ws.__isAlive === false) {
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
}
|
| 707 |
ws.__isAlive = false;
|
| 708 |
try {
|
|
@@ -736,6 +742,7 @@ export function attachGameWsGateway(server: import("http").Server) {
|
|
| 736 |
wss.on("connection", (rawWs, req) => {
|
| 737 |
const ws = rawWs as WsClient;
|
| 738 |
ws.__isAlive = true;
|
|
|
|
| 739 |
const parsed = new URL(req.url || "", "http://localhost");
|
| 740 |
const queryRoomId = parsed.searchParams.get("roomId") || "";
|
| 741 |
|
|
@@ -745,6 +752,7 @@ export function attachGameWsGateway(server: import("http").Server) {
|
|
| 745 |
|
| 746 |
ws.on("pong", () => {
|
| 747 |
ws.__isAlive = true;
|
|
|
|
| 748 |
});
|
| 749 |
|
| 750 |
ws.on("message", async (payload: RawData) => {
|
|
|
|
| 14 |
__roomId?: string;
|
| 15 |
__userId?: string;
|
| 16 |
__isAlive?: boolean;
|
| 17 |
+
__missedPong?: number;
|
| 18 |
};
|
| 19 |
|
| 20 |
type RoomUserSession = UserInRoomInfo & {
|
|
|
|
| 700 |
wss.clients.forEach((client) => {
|
| 701 |
const ws = client as WsClient;
|
| 702 |
if (ws.__isAlive === false) {
|
| 703 |
+
ws.__missedPong = (ws.__missedPong ?? 0) + 1;
|
| 704 |
+
if (ws.__missedPong >= 2) {
|
| 705 |
+
try {
|
| 706 |
+
ws.terminate();
|
| 707 |
+
} catch {}
|
| 708 |
+
return;
|
| 709 |
+
}
|
| 710 |
+
} else {
|
| 711 |
+
ws.__missedPong = 0;
|
| 712 |
}
|
| 713 |
ws.__isAlive = false;
|
| 714 |
try {
|
|
|
|
| 742 |
wss.on("connection", (rawWs, req) => {
|
| 743 |
const ws = rawWs as WsClient;
|
| 744 |
ws.__isAlive = true;
|
| 745 |
+
ws.__missedPong = 0;
|
| 746 |
const parsed = new URL(req.url || "", "http://localhost");
|
| 747 |
const queryRoomId = parsed.searchParams.get("roomId") || "";
|
| 748 |
|
|
|
|
| 752 |
|
| 753 |
ws.on("pong", () => {
|
| 754 |
ws.__isAlive = true;
|
| 755 |
+
ws.__missedPong = 0;
|
| 756 |
});
|
| 757 |
|
| 758 |
ws.on("message", async (payload: RawData) => {
|
start-space.sh
CHANGED
|
@@ -31,9 +31,9 @@ export MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-$MYSQL_PASSWORD}"
|
|
| 31 |
|
| 32 |
export ENABLE_AUTO_BACKUP="${ENABLE_AUTO_BACKUP:-true}"
|
| 33 |
export BACKUP_KEEP_COUNT="${BACKUP_KEEP_COUNT:-100}"
|
| 34 |
-
export BACKUP_INTERVAL_MIN="${BACKUP_INTERVAL_MIN:-
|
| 35 |
-
export BACKUP_TRIGGER_LINES="${BACKUP_TRIGGER_LINES:-
|
| 36 |
-
export BACKUP_MIN_INTERVAL_SEC="${BACKUP_MIN_INTERVAL_SEC:-
|
| 37 |
export BACKUP_HEARTBEAT_INTERVAL_SEC="${BACKUP_HEARTBEAT_INTERVAL_SEC:-60}"
|
| 38 |
export BACKUP_ARCHIVE_NAME="${BACKUP_ARCHIVE_NAME:-data_backup.zip}"
|
| 39 |
export RESTORE_BACKUP_ON_STARTUP="${RESTORE_BACKUP_ON_STARTUP:-true}"
|
|
@@ -538,7 +538,7 @@ EOF
|
|
| 538 |
rm -f "${output_file}"
|
| 539 |
(
|
| 540 |
cd "${work_dir}"
|
| 541 |
-
zip -q -r -
|
| 542 |
) || return 1
|
| 543 |
|
| 544 |
return 0
|
|
|
|
| 31 |
|
| 32 |
export ENABLE_AUTO_BACKUP="${ENABLE_AUTO_BACKUP:-true}"
|
| 33 |
export BACKUP_KEEP_COUNT="${BACKUP_KEEP_COUNT:-100}"
|
| 34 |
+
export BACKUP_INTERVAL_MIN="${BACKUP_INTERVAL_MIN:-30}"
|
| 35 |
+
export BACKUP_TRIGGER_LINES="${BACKUP_TRIGGER_LINES:-3000}"
|
| 36 |
+
export BACKUP_MIN_INTERVAL_SEC="${BACKUP_MIN_INTERVAL_SEC:-1800}"
|
| 37 |
export BACKUP_HEARTBEAT_INTERVAL_SEC="${BACKUP_HEARTBEAT_INTERVAL_SEC:-60}"
|
| 38 |
export BACKUP_ARCHIVE_NAME="${BACKUP_ARCHIVE_NAME:-data_backup.zip}"
|
| 39 |
export RESTORE_BACKUP_ON_STARTUP="${RESTORE_BACKUP_ON_STARTUP:-true}"
|
|
|
|
| 538 |
rm -f "${output_file}"
|
| 539 |
(
|
| 540 |
cd "${work_dir}"
|
| 541 |
+
zip -q -r -1 "${output_file}" db assets meta.json
|
| 542 |
) || return 1
|
| 543 |
|
| 544 |
return 0
|