Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit f385977

Browse files
committed
Feat: only clear current route on attack_failue.
1 parent 57da499 commit f385977

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

main.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ async function createWindow() {
312312

313313
ipcMain.on('change-server-config', async (_, val) => {
314314
let port = val.port, name = val.name
315+
if (!(port > 0 && port < 65535)) {
316+
dialog.showErrorBox('Server creation failed', 'The port number must be between 0 and 65535')
317+
mainWindow.webContents.send('server-error', err)
318+
return;
319+
}
315320
global.serverConfig.port = port
316321
if (name && name.length) {
317322
global.serverConfig.name = xss(name)
@@ -339,21 +344,6 @@ async function createWindow() {
339344

340345
let player;
341346

342-
socket.on('reconnect', async (playerId) => {
343-
try {
344-
if (global.gameStarted) { // Allow to reconnect
345-
let playerIndex = await getPlayerIndex(playerId)
346-
if (playerIndex !== -1) {
347-
player = global.players[playerIndex]
348-
global.players[playerIndex].socket_id = socket.id
349-
io.local.emit('room_message', player.trans(), 're-joined the lobby.')
350-
}
351-
}
352-
} catch (e) {
353-
socket.emit('error', 'An unknown error occurred: ' + e.message, e.stack)
354-
}
355-
})
356-
357347
socket.on('set_username', async (username) => {
358348
if (global.gameStarted) {
359349
socket.emit('reject_join', 'Game is already started')

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "gennia",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Yet another portable generals.io server & client",
55
"main": "main.js",
66
"scripts": {
77
"start": "electron --trace-warnings .",
8-
"build": "electron-builder"
8+
"build": "electron-builder --win --ia32"
99
},
1010
"repository": "https://github.com/GenniaApp/Gennia",
1111
"keywords": [
@@ -14,7 +14,7 @@
1414
"socket-io",
1515
"game"
1616
],
17-
"author": "the Gennia Authors",
17+
"author": "Gennia Developing Team",
1818
"license": "CC0-1.0",
1919
"devDependencies": {
2020
"electron": "^21.2.1",
@@ -23,7 +23,7 @@
2323
"build": {
2424
"appId": "com.reqwey.gennia",
2525
"productName": "Gennia",
26-
"copyright": "© 2022 the Gennia Authors",
26+
"copyright": "© 2022 Gennia Developing Team",
2727
"win": {
2828
"icon": "assets/img/favicon.png"
2929
}

renderer.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ let Queue = (function () {
3232
items.push(item);
3333
}
3434

35+
clearFromMap(route) {
36+
$(`#td${route.from.x}-${route.from.y}`).removeClass(`queue_${dirName(route)}`)
37+
}
38+
3539
pop() {
36-
let item = items.shift()
40+
let item = items.shift();
3741
if (this.lastItem) {
38-
$(`#td${this.lastItem.from.x}-${this.lastItem.from.y}`).removeClass(`queue_${dirName(this.lastItem)}`)
42+
this.clearFromMap(this.lastItem);
3943
}
4044
this.lastItem = item;
4145
return item;
@@ -44,7 +48,7 @@ let Queue = (function () {
4448
pop_back() {
4549
let item = items.pop()
4650
if (item) {
47-
$(`#td${item.from.x}-${item.from.y}`).removeClass(`queue_${dirName(item)}`)
51+
this.clearFromMap(item);
4852
return item;
4953
}
5054
}
@@ -67,11 +71,15 @@ let Queue = (function () {
6771

6872
clear() {
6973
items.forEach(item => {
70-
$(`#td${item.from.x}-${item.from.y}`).removeClass(`queue_${dirName(item)}`)
74+
this.clearFromMap(item)
7175
})
7276
items.length = 0
77+
this.clearLastItem()
78+
}
79+
80+
clearLastItem() {
7381
if (this.lastItem)
74-
$(`#td${this.lastItem.from.x}-${this.lastItem.from.y}`).removeClass(`queue_${dirName(this.lastItem)}`)
82+
this.clearFromMap(this.lastItem)
7583
}
7684

7785
print() { // Print on map
@@ -584,7 +592,7 @@ function gameJoin(username) {
584592
</table>
585593
</div>
586594
</div>`)
587-
window.turn = 1
595+
window.gameTurn = 1
588596
window.queue = new Queue()
589597
// let appContainer = document.getElementById('reqAppContainer')
590598
$(document).bind('keydown', (event) => {
@@ -667,8 +675,17 @@ function gameJoin(username) {
667675
})
668676
})
669677

670-
socket.on('attack_failure', () => {
671-
window.queue.clear()
678+
socket.on('attack_failure', (from, to) => {
679+
window.queue.clearLastItem()
680+
while (!window.queue.isEmpty()) {
681+
let point = window.queue.front().from
682+
if (point.x === to.x && point.y === to.y) {
683+
window.queue.pop()
684+
to = point
685+
} else {
686+
break;
687+
}
688+
}
672689
})
673690

674691
socket.on('captured', (player1, player2) => {
@@ -693,8 +710,8 @@ function gameJoin(username) {
693710
window.queue.clear()
694711
}
695712
gameMap = JSON.parse(gameMap);
696-
if (turn % 2 === 0) ++window.turn
697-
$('.reqtitle').html(`<h3> Turn ${window.turn} - Gennia</h3>`)
713+
if (turn % 2 === 0) ++window.gameTurn
714+
$('.reqtitle').html(`<h3> Turn ${window.gameTurn} - Gennia</h3>`)
698715
for (var i = 0; i < width; ++i) {
699716
for (var j = 0; j < height; ++j) {
700717
var $cell = $(`#td${i}-${j}`);

0 commit comments

Comments
 (0)