mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
Logs de la partie
This commit is contained in:
@@ -15,6 +15,8 @@ COPY . .
|
|||||||
|
|
||||||
RUN if [ ! -d uploads ]; then mkdir uploads; fi
|
RUN if [ ! -d uploads ]; then mkdir uploads; fi
|
||||||
|
|
||||||
|
RUN if [ ! -d trajectories ]; then mkdir trajectories; fi
|
||||||
|
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
|
||||||
# Start the application
|
# Start the application
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import penaltyController from "./penalty_controller.js";
|
|||||||
import zoneManager from "./zone_manager.js";
|
import zoneManager from "./zone_manager.js";
|
||||||
|
|
||||||
import { getDistanceFromLatLon } from "./map_utils.js";
|
import { getDistanceFromLatLon } from "./map_utils.js";
|
||||||
|
import { writePosition, writeCapture, writeSeePosition } from "./trajectory.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The possible states of the game
|
* The possible states of the game
|
||||||
@@ -237,6 +238,7 @@ export default {
|
|||||||
if (location == null) {
|
if (location == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
writePosition(Date.now(), teamId, location[0], location[1]);
|
||||||
team.currentLocation = location;
|
team.currentLocation = location;
|
||||||
//Update the team ready status if they are in their starting area
|
//Update the team ready status if they are in their starting area
|
||||||
if (this.state == GameState.PLACEMENT && team.startingArea && team.startingArea && location) {
|
if (this.state == GameState.PLACEMENT && team.startingArea && team.startingArea && location) {
|
||||||
@@ -274,7 +276,7 @@ export default {
|
|||||||
if (team.currentLocation == null) {
|
if (team.currentLocation == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
writeSeePosition(Date.now(), teamId, team.chasing);
|
||||||
team.locationSendDeadline = Number(new Date()) + penaltyController.settings.allowedTimeBetweenPositionUpdate * 60 * 1000;
|
team.locationSendDeadline = Number(new Date()) + penaltyController.settings.allowedTimeBetweenPositionUpdate * 60 * 1000;
|
||||||
team.lastSentLocation = team.currentLocation;
|
team.lastSentLocation = team.currentLocation;
|
||||||
if (this.getTeam(team.chasing) != null) {
|
if (this.getTeam(team.chasing) != null) {
|
||||||
@@ -309,6 +311,7 @@ export default {
|
|||||||
requestCapture(teamId, captureCode) {
|
requestCapture(teamId, captureCode) {
|
||||||
let enemyTeam = this.getTeam(this.getTeam(teamId).chasing)
|
let enemyTeam = this.getTeam(this.getTeam(teamId).chasing)
|
||||||
if (enemyTeam && enemyTeam.captureCode == captureCode) {
|
if (enemyTeam && enemyTeam.captureCode == captureCode) {
|
||||||
|
writeCapture(Date.now(), teamId, enemyTeam.id);
|
||||||
this.capture(enemyTeam.id);
|
this.capture(enemyTeam.id);
|
||||||
this.updateTeamChasing();
|
this.updateTeamChasing();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { readFileSync } from "fs";
|
|||||||
import { initAdminSocketHandler } from "./admin_socket.js";
|
import { initAdminSocketHandler } from "./admin_socket.js";
|
||||||
import { initTeamSocket } from "./team_socket.js";
|
import { initTeamSocket } from "./team_socket.js";
|
||||||
import { initPhotoUpload } from "./photo.js";
|
import { initPhotoUpload } from "./photo.js";
|
||||||
|
import { initTrajectories } from "./trajectory.js";
|
||||||
//extract admin password from .env file
|
//extract admin password from .env file
|
||||||
config();
|
config();
|
||||||
const HOST = process.env.HOST;
|
const HOST = process.env.HOST;
|
||||||
@@ -33,3 +34,4 @@ export const io = new Server(httpServer, {
|
|||||||
initAdminSocketHandler();
|
initAdminSocketHandler();
|
||||||
initTeamSocket();
|
initTeamSocket();
|
||||||
initPhotoUpload();
|
initPhotoUpload();
|
||||||
|
initTrajectories();
|
||||||
|
|||||||
65
traque-back/trajectory.js
Normal file
65
traque-back/trajectory.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
const UPLOAD_DIR = "trajectories";
|
||||||
|
const EXTENSION = "txt";
|
||||||
|
|
||||||
|
// Useful functions
|
||||||
|
|
||||||
|
function teamIDToPath(teamID) {
|
||||||
|
return path.join(UPLOAD_DIR, teamID + "." + EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dataToLine(...data) {
|
||||||
|
return data.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
const errorFile = (err) => {
|
||||||
|
if (err) console.error("Error appending to file:", err);
|
||||||
|
};
|
||||||
|
|
||||||
|
function addLineToFile(teamID, line) {
|
||||||
|
// Insert the line in the file of teamID depending on the date (lines are sorted by date)
|
||||||
|
if (!fs.existsSync(teamIDToPath(teamID))) {
|
||||||
|
fs.writeFile(teamIDToPath(teamID), line + '\n', errorFile);
|
||||||
|
} else {
|
||||||
|
fs.readFile(teamIDToPath(teamID), 'utf8', (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
errorFile(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let lines = data.trim().split('\n');
|
||||||
|
const newDate = parseInt(line.split(',')[0], 10);
|
||||||
|
let insertIndex = lines.length;
|
||||||
|
for (let i = lines.length - 1; i >= 0; i--) {
|
||||||
|
const date = parseInt(lines[i].split(',')[0], 10);
|
||||||
|
if (date <= newDate) {
|
||||||
|
insertIndex = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.splice(insertIndex, 0, line);
|
||||||
|
fs.writeFile(teamIDToPath(teamID), lines.join('\n') + '\n', errorFile);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export functions
|
||||||
|
|
||||||
|
export async function initTrajectories() {
|
||||||
|
const files = fs.readdirSync(UPLOAD_DIR);
|
||||||
|
for (const file of files) fs.unlinkSync(path.join(UPLOAD_DIR, file));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writePosition(date, teamID, lon, lat) {
|
||||||
|
addLineToFile(teamID, dataToLine(date, "position", lon, lat));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeCapture(date, teamID, capturedTeamID) {
|
||||||
|
addLineToFile(teamID, dataToLine(date, "capture", capturedTeamID));
|
||||||
|
addLineToFile(capturedTeamID, dataToLine(date, "captured", teamID));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeSeePosition(date, teamID, seenTeamID) {
|
||||||
|
addLineToFile(teamID, dataToLine(date, "see"));
|
||||||
|
addLineToFile(seenTeamID, dataToLine(date, "seen"));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user