Server heavy refactoring 4 (not functionnal)

This commit is contained in:
Sebastien Riviere
2026-03-12 23:17:21 +01:00
parent e1b6c0e0c5
commit 1389dce132
95 changed files with 5320 additions and 27986 deletions

View File

@@ -0,0 +1,23 @@
import js from "@eslint/js";
import globals from "globals";
export default [
{
ignores: ["node_modules/*", "dist/*", "logs/*"],
},
js.configs.recommended,
{
files: ["**/*.{js,mjs}"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.node,
},
},
rules: {
"semi": ["error", "always"],
"no-unused-vars": "warn",
},
},
];

File diff suppressed because it is too large Load Diff

View File

@@ -19,5 +19,10 @@
"multer": "^1.4.5-lts.1",
"random-location": "^1.1.3",
"socket.io": "^4.7.5"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"eslint": "^10.0.3",
"globals": "^17.4.0"
}
}

View File

@@ -4,7 +4,6 @@ export const PLAYER_HANDLER_EVENTS = {
LOCATION: "location",
SCAN: "scan",
CAPTURE: "capture",
DEVICE: "device",
};
export const ADMIN_HANDLER_EVENTS = {

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-unused-vars */
import { DEFAULT_ZONES_SETTINGS } from "#config/zone.js";
import { DefaultState, PlacementState, PlayingState, FinishedState } from '#core/states/game/index.js';
@@ -36,7 +37,7 @@ export const DEFAULT_GAME_SETTINGS = {
placementZones: {},
scanDelay: 10 * 60 * 1000, // ms
outOfZoneDelay: 5 * 60 * 1000 // ms
}
};
export const TEAM_ID_LENGTH = 6;
export const CAPTURE_CODE_LENGTH = 4;

View File

@@ -32,7 +32,7 @@ export class TeamManager {
add(teamName) {
if (!Team.isTeamNameValid(teamName)) return null;
let id; do { id = Team.getNewTeamId() } while (this.has(id));
let id; do { id = Team.getNewTeamId(); } while (this.has(id));
const team = new Team(id, teamName);
if (!this.has(id)) this.order.push(id);
this._map.set(id, team);

View File

@@ -9,15 +9,15 @@ export class Team {
this.state = null;
}
static isTeamNameValid = (teamName) => {
static isTeamNameValid(teamName) {
return typeof teamName === 'string' && teamName.length > 0;
}
static getNewTeamId = () => {
static getNewTeamId() {
return randint(10 ** TEAM_ID_LENGTH).toString().padStart(TEAM_ID_LENGTH, '0');
}
static getNewCaptureCode = () => {
static getNewCaptureCode() {
return randint(10 ** CAPTURE_CODE_LENGTH).toString().padStart(CAPTURE_CODE_LENGTH, '0');
}

View File

@@ -23,6 +23,7 @@ export class DefaultState {
this.teams.forEach(team => this.initTeam(team, settings));
}
// eslint-disable-next-line no-unused-vars
clearTeam(_team) {}
exit() {

View File

@@ -23,6 +23,7 @@ export class FinishedState {
this.teams.forEach(team => this.initTeam(team, settings));
}
// eslint-disable-next-line no-unused-vars
clearTeam(_team) {}
exit() {

View File

@@ -23,6 +23,7 @@ export class PlacementState {
this.teams.forEach(team => this.initTeam(team, settings));
}
// eslint-disable-next-line no-unused-vars
clearTeam(_team) {}
exit() {

View File

@@ -6,6 +6,7 @@ export class DefaultTeam {
// --------------- LIFE CYCLE --------------- //
// eslint-disable-next-line no-unused-vars
init(_settings) {
return this;
}

View File

@@ -6,6 +6,7 @@ export class FinishedTeam {
// --------------- LIFE CYCLE --------------- //
// eslint-disable-next-line no-unused-vars
init(_settings) {
return this;
}

View File

@@ -29,7 +29,7 @@ class AdminConnection {
if (this._isLoggedIn) return;
const hash = createHash('sha256').update(password).digest('hex');
if (false && hash !== ADMIN_PASSWORD_HASH) return false; // TODO : temporaire
if (hash !== ADMIN_PASSWORD_HASH) return false;
this._isLoggedIn = true;
this._gameManager.onAdminLogin(this._socket.id);
@@ -46,7 +46,7 @@ class AdminConnection {
this._socket.on("disconnect", () => {
console.log("Disconnection of an admin");
this._logout()
this._logout();
});
this._socket.on(ADMIN_HANDLER_EVENTS.LOGIN, (password) => {
@@ -54,17 +54,17 @@ class AdminConnection {
});
this._socket.on(ADMIN_HANDLER_EVENTS.LOGOUT, () => {
this._logout()
this._logout();
});
// Actions
const protectedActions = {
[ADMIN_HANDLER_EVENTS.ADD_TEAM]: (id) => this._gameManager.addTeam(id),
[ADMIN_HANDLER_EVENTS.REMOVE_TEAM]: (id) => this._gameManager.removeTeam(id),
[ADMIN_HANDLER_EVENTS.REORDER_TEAM]: (id) => this._gameManager.reorderTeam(id),
[ADMIN_HANDLER_EVENTS.ELIMINATE_TEAM]: (id) => this._gameManager.eliminate(id),
[ADMIN_HANDLER_EVENTS.REVIVE_TEAM]: (id) => this._gameManager.revive(id),
[ADMIN_HANDLER_EVENTS.ADD_TEAM]: (teamName) => this._gameManager.addTeam(teamName),
[ADMIN_HANDLER_EVENTS.REMOVE_TEAM]: (teamId) => this._gameManager.removeTeam(teamId),
[ADMIN_HANDLER_EVENTS.REORDER_TEAM]: (newTeamsOrder) => this._gameManager.reorderTeam(newTeamsOrder),
[ADMIN_HANDLER_EVENTS.ELIMINATE_TEAM]: (teamId) => this._gameManager.eliminate(teamId),
[ADMIN_HANDLER_EVENTS.REVIVE_TEAM]: (teamId) => this._gameManager.revive(teamId),
[ADMIN_HANDLER_EVENTS.STATE]: (state) => this._gameManager.setState(state),
[ADMIN_HANDLER_EVENTS.SETTINGS]: (settings) => this._gameManager.setSettings(settings),
};

View File

@@ -47,7 +47,7 @@ class PlayerConnection {
this._socket.on("disconnect", () => {
console.log("Disconnection of a player");
this._logout()
this._logout();
});
this._socket.on(PLAYER_HANDLER_EVENTS.LOGIN, (loginTeamId, callback) => {
@@ -56,7 +56,7 @@ class PlayerConnection {
});
this._socket.on(PLAYER_HANDLER_EVENTS.LOGOUT, () => {
this._logout()
this._logout();
});
// Actions

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-unused-vars */
import { DefaultState, PlacementState, PlayingState, FinishedState } from "#core/states/game/index.js";
const TEAM_STATE_MAP = {
@@ -43,7 +44,7 @@ export class AdminMapper {
id: team.id,
name: team.name,
location: team.location,
state: TEAM_STATE_MAP[stateName](team, this.gameManager.state)
stateData: TEAM_STATE_MAP[stateName](team, this.gameManager.state)
};
});
@@ -52,14 +53,14 @@ export class AdminMapper {
currentZone: this.gameManager.zoneManager.currentZonePolygon,
nextZone: this.gameManager.zoneManager.nextZonePolygon,
zoneTransitionDate: this.gameManager.zoneManager.dateOfZoneTransition
}
};
return {
gameState: stateName,
teams: this.gameManager.teams.order.map(teamId => teamsDto[teamId]),
zones: zonesDto,
settings: this.gameManager.settings
}
};
}
hash(dto) {

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-unused-vars */
import { DefaultState, PlacementState, PlayingState, FinishedState } from "#core/states/game/index.js";
const TEAM_STATE_MAP = {
@@ -43,8 +44,8 @@ export class PlayerMapper {
return {
id: this.team.id,
name: this.team.name,
stateName: this.gameState.name,
state: TEAM_STATE_MAP[this.gameState.name](this.team, this.gameState)
gameState: this.gameState.name,
stateData: TEAM_STATE_MAP[this.gameState.name](this.team, this.gameState)
};
}

View File

@@ -18,7 +18,7 @@ export class PlayerSynchronizer {
this.gameManager.teams.forEach((team, teamId) => {
const { dto, hasChanged } = this._getSyncDtoOfTeam(team);
if (hasChanged) io.to(teamId).emit(PLAYER_SYNCHRONIZER_EVENTS.UPDATE_FULL, dto);
})
});
});
this.gameManager.on(GAME_MANAGER_EVENTS.DELETE_TEAM, (teamId) => {