mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-04-11 00:30:19 +02:00
Server heavy refactoring 3 (not functionnal)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { DEFAULT_ZONES_SETTINGS } from "@/config/zone.js";
|
||||
import { DefaultState, PlacementState, PlayingState, FinishedState } from '@/core/states/game/index.js';
|
||||
import { DEFAULT_ZONES_SETTINGS } from "#config/zone.js";
|
||||
import { DefaultState, PlacementState, PlayingState, FinishedState } from '#core/states/game/index.js';
|
||||
|
||||
export const STATE_SETTINGS = {
|
||||
ENTRY_STATE_CLASS: DefaultState,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as turf from '@turf/turf';
|
||||
import { ZoneWithDuration } from '@/core/models/zone.js';
|
||||
import { TURF_BUFFER_SIZE, TURF_CIRCLE_STEPS, TURF_DISTANCE_UNIT, ZONE_TYPES } from '@/config/zone.js';
|
||||
import { ZoneWithDuration } from '#core/models/zone.js';
|
||||
import { TURF_BUFFER_SIZE, TURF_CIRCLE_STEPS, TURF_DISTANCE_UNIT, ZONE_TYPES } from '#config/zone.js';
|
||||
|
||||
export const settingsToZoneList = (settings) => {
|
||||
if (!settings) return [];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as turf from '@turf/turf';
|
||||
import { Zone } from '@/core/models/zone.js';
|
||||
import { TURF_CIRCLE_STEPS, TURF_DISTANCE_UNIT } from '@/config/zone.js';
|
||||
import { Zone } from '#core/models/zone.js';
|
||||
import { TURF_CIRCLE_STEPS, TURF_DISTANCE_UNIT } from '#config/zone.js';
|
||||
|
||||
export const settingsToZone = (settings) => {
|
||||
if (!settings) return null;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { ZoneManager } from "@/core/managers/zone_manager.js";
|
||||
import { TeamManager } from '@/core/managers/team_manager.js';
|
||||
import { GAME_MANAGER_EVENTS } from "@/config/events.js";
|
||||
import { ZoneManager } from "#core/managers/zone_manager.js";
|
||||
import { TeamManager } from '#core/managers/team_manager.js';
|
||||
import { GAME_MANAGER_EVENTS } from "#config/events.js";
|
||||
|
||||
|
||||
export class GameManager extends EventEmitter {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Team } from "@/core/models/team.js";
|
||||
import { Team } from "#core/models/team.js";
|
||||
|
||||
export class TeamManager {
|
||||
constructor() {
|
||||
@@ -36,7 +36,7 @@ export class TeamManager {
|
||||
const team = new Team(id, teamName);
|
||||
if (!this.has(id)) this.order.push(id);
|
||||
this._map.set(id, team);
|
||||
return id;
|
||||
return team;
|
||||
}
|
||||
|
||||
delete(id) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Scheduler } from "@/util/scheduler.js";
|
||||
import { settingsToZoneList } from "@/core/factories/game_zone_factory.js";
|
||||
import { Scheduler } from "#util/scheduler.js";
|
||||
import { settingsToZoneList } from "#core/factories/game_zone_factory.js";
|
||||
|
||||
export class ZoneManager {
|
||||
constructor() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CAPTURE_CODE_LENGTH, TEAM_ID_LENGTH } from "@/config/game.js";
|
||||
import { randint } from "@/util/random.js";
|
||||
import { CAPTURE_CODE_LENGTH, TEAM_ID_LENGTH } from "#config/game.js";
|
||||
import { randint } from "#util/random.js";
|
||||
|
||||
export class Team {
|
||||
constructor(id, teamName) {
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { DefaultTeam } from "@/core/states/teams/default_team.js";
|
||||
import { DefaultTeam } from "#core/states/teams/default_team.js";
|
||||
|
||||
export class DefaultState {
|
||||
static name = "default";
|
||||
|
||||
get name () {
|
||||
return this.constructor.name;
|
||||
}
|
||||
|
||||
constructor(teams, zoneManager) {
|
||||
this.teams = teams;
|
||||
this.zoneManager = zoneManager;
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return "default";
|
||||
}
|
||||
|
||||
|
||||
// --------------- LIFE CYCLE --------------- //
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { FinishedTeam } from "@/core/states/teams/finished_team.js";
|
||||
import { FinishedTeam } from "#core/states/teams/finished_team.js";
|
||||
|
||||
export class FinishedState {
|
||||
static name = "finished";
|
||||
|
||||
get name () {
|
||||
return this.constructor.name;
|
||||
}
|
||||
|
||||
constructor(teams, zoneManager) {
|
||||
this.teams = teams;
|
||||
this.zoneManager = zoneManager;
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return "finished";
|
||||
}
|
||||
|
||||
|
||||
// --------------- LIFE CYCLE --------------- //
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { DefaultState } from '@/core/states/game/default_state.js';
|
||||
export { PlacementState } from '@/core/states/game/placement_state.js';
|
||||
export { PlayingState } from '@/core/states/game/playing_state.js';
|
||||
export { FinishedState } from '@/core/states/game/finished_state.js';
|
||||
export { DefaultState } from '#core/states/game/default_state.js';
|
||||
export { PlacementState } from '#core/states/game/placement_state.js';
|
||||
export { PlayingState } from '#core/states/game/playing_state.js';
|
||||
export { FinishedState } from '#core/states/game/finished_state.js';
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { PlacementTeam } from "@/core/states/teams/placement_team.js";
|
||||
import { PlacementTeam } from "#core/states/teams/placement_team.js";
|
||||
|
||||
export class PlacementState {
|
||||
static name = "placement";
|
||||
|
||||
get name () {
|
||||
return this.constructor.name;
|
||||
}
|
||||
|
||||
constructor(teams, zoneManager) {
|
||||
this.teams = teams;
|
||||
this.zoneManager = zoneManager;
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return "placement";
|
||||
}
|
||||
|
||||
|
||||
// --------------- LIFE CYCLE --------------- //
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { PlayingTeam } from "@/core/states/teams/playing_team.js";
|
||||
import { PlayingTeam } from "#core/states/teams/playing_team.js";
|
||||
|
||||
export class PlayingState {
|
||||
static name = "playing";
|
||||
|
||||
get name () {
|
||||
return this.constructor.name;
|
||||
}
|
||||
|
||||
constructor(teams, zoneManager) {
|
||||
this.teams = teams;
|
||||
this.zoneManager = zoneManager;
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return "playing";
|
||||
}
|
||||
|
||||
|
||||
// --------------- LIFE CYCLE --------------- //
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { settingsToZone } from "@/core/factories/placement_zone_factory.js";
|
||||
import { settingsToZone } from "#core/factories/placement_zone_factory.js";
|
||||
|
||||
export class PlacementTeam {
|
||||
constructor(team) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Team } from "@/core/models/team.js";
|
||||
import { ScheduledTask } from "@/util/scheduler.js";
|
||||
import { RESTART_TIMERS } from "@/config/game.js";
|
||||
import { Team } from "#core/models/team.js";
|
||||
import { ScheduledTask } from "#util/scheduler.js";
|
||||
import { RESTART_TIMERS } from "#config/game.js";
|
||||
|
||||
export class PlayingTeam {
|
||||
constructor(team, zoneManager) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createHash } from "crypto";
|
||||
import { ADMIN_PASSWORD_HASH } from "@/config/server.js";
|
||||
import { ADMIN_HANDLER_EVENTS } from "@/config/events.js";
|
||||
import { ADMIN_PASSWORD_HASH } from "#config/server.js";
|
||||
import { ADMIN_HANDLER_EVENTS } from "#config/events.js";
|
||||
|
||||
export class AdminHandler {
|
||||
constructor(gameManager) {
|
||||
@@ -29,7 +29,7 @@ class AdminConnection {
|
||||
if (this._isLoggedIn) return;
|
||||
|
||||
const hash = createHash('sha256').update(password).digest('hex');
|
||||
if (hash !== ADMIN_PASSWORD_HASH) return false;
|
||||
if (false && hash !== ADMIN_PASSWORD_HASH) return false; // TODO : temporaire
|
||||
|
||||
this._isLoggedIn = true;
|
||||
this._gameManager.onAdminLogin(this._socket.id);
|
||||
@@ -49,9 +49,8 @@ class AdminConnection {
|
||||
this._logout()
|
||||
});
|
||||
|
||||
this._socket.on(ADMIN_HANDLER_EVENTS.LOGIN, (password, callback) => {
|
||||
this._socket.on(ADMIN_HANDLER_EVENTS.LOGIN, (password) => {
|
||||
this._login(password);
|
||||
callback(this._isLoggedIn);
|
||||
});
|
||||
|
||||
this._socket.on(ADMIN_HANDLER_EVENTS.LOGOUT, () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PLAYER_HANDLER_EVENTS } from "@/config/events.js";
|
||||
import { PLAYER_HANDLER_EVENTS } from "#config/events.js";
|
||||
|
||||
export class PlayerHandler {
|
||||
constructor(gameManager) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DefaultState, PlacementState, PlayingState, FinishedState } from "@/core/states/game/index.js";
|
||||
import { DefaultState, PlacementState, PlayingState, FinishedState } from "#core/states/game/index.js";
|
||||
|
||||
const TEAM_STATE_MAP = {
|
||||
[DefaultState.name]: (_team, _gameState) => ({}),
|
||||
@@ -55,9 +55,8 @@ export class AdminMapper {
|
||||
}
|
||||
|
||||
return {
|
||||
stateName: stateName,
|
||||
teams: teamsDto,
|
||||
teamsOrder: this.gameManager.teams.order,
|
||||
gameState: stateName,
|
||||
teams: this.gameManager.teams.order.map(teamId => teamsDto[teamId]),
|
||||
zones: zonesDto,
|
||||
settings: this.gameManager.settings
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DefaultState, PlacementState, PlayingState, FinishedState } from "@/core/states/game/index.js";
|
||||
import { DefaultState, PlacementState, PlayingState, FinishedState } from "#core/states/game/index.js";
|
||||
|
||||
const TEAM_STATE_MAP = {
|
||||
[DefaultState.name]: (_team, _gameState) => ({}),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AdminMapper } from "@/externals/mappers/admin_mapper.js";
|
||||
import { StateTracker } from "@/util/state_tracker.js";
|
||||
import { GAME_MANAGER_EVENTS, ADMIN_SYNCHRONIZER_EVENTS } from "@/config/events.js";
|
||||
import { AdminMapper } from "#externals/mappers/admin_mapper.js";
|
||||
import { StateTracker } from "#util/state_tracker.js";
|
||||
import { GAME_MANAGER_EVENTS, ADMIN_SYNCHRONIZER_EVENTS } from "#config/events.js";
|
||||
|
||||
export class AdminSynchronizer {
|
||||
constructor(gameManager) {
|
||||
@@ -11,11 +11,16 @@ export class AdminSynchronizer {
|
||||
init(io) {
|
||||
this.gameManager.on(GAME_MANAGER_EVENTS.INIT_ADMIN, (socketId) => {
|
||||
const { dto } = this.gameStateTracker.getSyncDto();
|
||||
console.log("INIT ADMIN");
|
||||
console.log(dto);
|
||||
io.to(socketId).emit(ADMIN_SYNCHRONIZER_EVENTS.UPDATE_FULL, dto);
|
||||
});
|
||||
|
||||
this.gameManager.on(GAME_MANAGER_EVENTS.UPDATE_GAME, () => {
|
||||
const { dto, hasChanged } = this.gameStateTracker.getSyncDto();
|
||||
console.log("UPDATE ADMIN");
|
||||
console.log(hasChanged);
|
||||
console.log(dto);
|
||||
if (hasChanged) io.emit(ADMIN_SYNCHRONIZER_EVENTS.UPDATE_FULL, dto);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GAME_MANAGER_EVENTS, PLAYER_SYNCHRONIZER_EVENTS } from "@/config/events.js";
|
||||
import { PlayerMapper } from "@/externals/mappers/player_mapper.js";
|
||||
import { StateTracker } from "@/util/state_tracker.js";
|
||||
import { GAME_MANAGER_EVENTS, PLAYER_SYNCHRONIZER_EVENTS } from "#config/events.js";
|
||||
import { PlayerMapper } from "#externals/mappers/player_mapper.js";
|
||||
import { StateTracker } from "#util/state_tracker.js";
|
||||
|
||||
export class PlayerSynchronizer {
|
||||
constructor(gameManager) {
|
||||
|
||||
@@ -2,16 +2,16 @@ import { createServer } from "http";
|
||||
import express from "express";
|
||||
import { Server } from "socket.io";
|
||||
// Core
|
||||
import { GameManager } from "@/core/managers/game_manager.js";
|
||||
import { GameManager } from "#core/managers/game_manager.js";
|
||||
// Externals
|
||||
import { PhotoService } from "@/externals/api/photo.js";
|
||||
import { PlayerSynchronizer } from "@/externals/synchronizers/player_synchronizer.js";
|
||||
import { PlayerHandler } from "@/externals/handlers/playerHandler.js";
|
||||
import { AdminSynchronizer } from "@/externals/synchronizers/admin_synchronizer.js";
|
||||
import { AdminHandler } from "@/externals/handlers/adminHandler.js";
|
||||
import { PhotoService } from "#externals/api/photo.js";
|
||||
import { PlayerSynchronizer } from "#externals/synchronizers/player_synchronizer.js";
|
||||
import { PlayerHandler } from "#externals/handlers/playerHandler.js";
|
||||
import { AdminSynchronizer } from "#externals/synchronizers/admin_synchronizer.js";
|
||||
import { AdminHandler } from "#externals/handlers/adminHandler.js";
|
||||
// Config
|
||||
import { PORT, HOST } from "@/config/server.js";
|
||||
import { DEFAULT_GAME_SETTINGS, STATE_SETTINGS } from "@/config/game.js";
|
||||
import { PORT, HOST } from "#config/server.js";
|
||||
import { DEFAULT_GAME_SETTINGS, STATE_SETTINGS } from "#config/game.js";
|
||||
|
||||
|
||||
// Configuration
|
||||
@@ -21,7 +21,6 @@ const io = new Server(httpServer, {
|
||||
cors: { origin: "*", methods: ["GET", "POST"] }
|
||||
});
|
||||
|
||||
|
||||
// Initialization
|
||||
const gameManager = new GameManager(STATE_SETTINGS, DEFAULT_GAME_SETTINGS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user