mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-04-10 16:30:18 +02:00
Server heavy refactoring 4 (not functionnal)
This commit is contained in:
23
server/traque-back/eslint.config.mjs
Normal file
23
server/traque-back/eslint.config.mjs
Normal 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",
|
||||
},
|
||||
},
|
||||
];
|
||||
906
server/traque-back/package-lock.json
generated
906
server/traque-back/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ export const PLAYER_HANDLER_EVENTS = {
|
||||
LOCATION: "location",
|
||||
SCAN: "scan",
|
||||
CAPTURE: "capture",
|
||||
DEVICE: "device",
|
||||
};
|
||||
|
||||
export const ADMIN_HANDLER_EVENTS = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -6,6 +6,7 @@ export class DefaultTeam {
|
||||
|
||||
// --------------- LIFE CYCLE --------------- //
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
init(_settings) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export class FinishedTeam {
|
||||
|
||||
// --------------- LIFE CYCLE --------------- //
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
init(_settings) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user