mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
Suppression pénalités d'envoi de position
This commit is contained in:
@@ -32,10 +32,11 @@ export function initAdminSocketHandler() {
|
||||
//Admin namespace
|
||||
io.of("admin").on("connection", (socket) => {
|
||||
//Flag to check if the user is logged in, defined for each socket
|
||||
console.log("Connection of an admin");
|
||||
let loggedIn = false;
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log("user disconnected");
|
||||
console.log("Disconnection of an admin");
|
||||
//Remove the socket from the logged in sockets array
|
||||
loggedInSockets = loggedInSockets.filter(s => s !== socket.id);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { secureAdminBroadcast } from "./admin_socket.js";
|
||||
import { isInCircle } from "./map_utils.js";
|
||||
import { playersBroadcast, sendUpdatedTeamInformations } from "./team_socket.js";
|
||||
|
||||
import timeoutHandler from "./timeoutHandler.js";
|
||||
import penaltyController from "./penalty_controller.js";
|
||||
import zoneManager from "./zone_manager.js";
|
||||
|
||||
@@ -70,6 +71,7 @@ export default {
|
||||
if (newState != GameState.PLAYING) {
|
||||
zoneManager.reset();
|
||||
penaltyController.stop();
|
||||
timeoutHandler.endAllSendPositionTimeout();
|
||||
}
|
||||
//Game reset
|
||||
if (newState == GameState.SETUP) {
|
||||
@@ -253,7 +255,8 @@ export default {
|
||||
initLastSentLocations() {
|
||||
for (let team of this.teams) {
|
||||
team.lastSentLocation = team.currentLocation;
|
||||
team.locationSendDeadline = Number(new Date()) + penaltyController.settings.allowedTimeBetweenPositionUpdate * 60 * 1000;
|
||||
team.locationSendDeadline = Date.now() + penaltyController.settings.allowedTimeBetweenPositionUpdate * 60 * 1000;
|
||||
timeoutHandler.setSendPositionTimeout(team.id, team.locationSendDeadline);
|
||||
this.getTeam(team.chasing).enemyLocation = team.lastSentLocation;
|
||||
sendUpdatedTeamInformations(team.id);
|
||||
}
|
||||
@@ -277,11 +280,13 @@ export default {
|
||||
return false;
|
||||
}
|
||||
writeSeePosition(Date.now(), teamId, team.chasing);
|
||||
team.locationSendDeadline = Number(new Date()) + penaltyController.settings.allowedTimeBetweenPositionUpdate * 60 * 1000;
|
||||
team.locationSendDeadline = Date.now() + penaltyController.settings.allowedTimeBetweenPositionUpdate * 60 * 1000;
|
||||
timeoutHandler.setSendPositionTimeout(team.id, team.locationSendDeadline);
|
||||
team.lastSentLocation = team.currentLocation;
|
||||
if (this.getTeam(team.chasing) != null) {
|
||||
team.enemyLocation = this.getTeam(team.chasing).lastSentLocation;
|
||||
}
|
||||
sendUpdatedTeamInformations(team.id);
|
||||
return team;
|
||||
},
|
||||
|
||||
@@ -297,6 +302,7 @@ export default {
|
||||
//remove the team from the list
|
||||
this.teams = this.teams.filter(t => t.id !== teamId);
|
||||
this.updateTeamChasing();
|
||||
timeoutHandler.endSendPositionTimeout(team.id);
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -325,6 +331,7 @@ export default {
|
||||
*/
|
||||
capture(teamId) {
|
||||
this.getTeam(teamId).captured = true
|
||||
timeoutHandler.endSendPositionTimeout(teamId);
|
||||
this.updateTeamChasing();
|
||||
},
|
||||
|
||||
@@ -355,6 +362,7 @@ export default {
|
||||
finishGame() {
|
||||
this.setState(GameState.FINISHED);
|
||||
zoneManager.reset();
|
||||
timeoutHandler.endAllSendPositionTimeout()
|
||||
playersBroadcast("game_state", this.state);
|
||||
},
|
||||
}
|
||||
@@ -32,7 +32,7 @@ export default {
|
||||
//Watch periodically if all teams need are following the rules
|
||||
this.checkIntervalId = setInterval(() => {
|
||||
if (game.state == GameState.PLAYING) {
|
||||
this.watchPositionUpdate();
|
||||
//this.watchPositionUpdate();
|
||||
this.watchZone();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
@@ -62,28 +62,28 @@ export function sendUpdatedTeamInformations(teamId) {
|
||||
})
|
||||
})
|
||||
}
|
||||
export function initTeamSocket() {
|
||||
|
||||
export function initTeamSocket() {
|
||||
io.of("player").on("connection", (socket) => {
|
||||
console.log("Connection of a player");
|
||||
let teamId = null;
|
||||
console.log("a user connected");
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log("user disconnected");
|
||||
console.log("Disconnection of a player");
|
||||
logoutPlayer(socket.id)
|
||||
});
|
||||
|
||||
socket.on("login", (loginTeamId, callback) => {
|
||||
if (game.getTeam(loginTeamId) === undefined) {
|
||||
let team = game.getTeam(loginTeamId);
|
||||
if (team === undefined) {
|
||||
socket.emit("login_response", false);
|
||||
if (typeof callback === "function") {
|
||||
callback({ isLoggedIn: false, message: "Login denied" });
|
||||
}
|
||||
} else {
|
||||
logoutPlayer(socket.id)
|
||||
teamId = loginTeamId;
|
||||
let team = game.getTeam(loginTeamId);
|
||||
team.sockets.push(socket.id);
|
||||
teamId = loginTeamId;
|
||||
sendUpdatedTeamInformations(loginTeamId);
|
||||
socket.emit("login_response", true);
|
||||
socket.emit("game_state", game.state)
|
||||
@@ -132,18 +132,17 @@ export function initTeamSocket() {
|
||||
}
|
||||
game.updateTeamChasing();
|
||||
teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation, locationSendDeadline: team.locationSendDeadline, lastSentLocation: team.lastSentLocation });
|
||||
teamBroadcast(teamId, "success", "Position udpated")
|
||||
secureAdminBroadcast("teams", game.teams)
|
||||
});
|
||||
|
||||
socket.on("capture", (captureCode, callback) => {
|
||||
let capturedTeam = game.getTeam(teamId)?.chasing
|
||||
let capturedTeam = game.getTeam(teamId)?.chasing;
|
||||
if (capturedTeam !== undefined && game.requestCapture(teamId, captureCode)) {
|
||||
sendUpdatedTeamInformations(teamId);
|
||||
sendUpdatedTeamInformations(capturedTeam);
|
||||
secureAdminBroadcast("teams", game.teams);
|
||||
if (typeof callback === "function") {
|
||||
callback({ hasCaptured : true, message: "Capture succesful" });
|
||||
callback({ hasCaptured : true, message: "Capture successful" });
|
||||
}
|
||||
} else {
|
||||
socket.emit("error", "Incorrect code");
|
||||
|
||||
30
traque-back/timeoutHandler.js
Normal file
30
traque-back/timeoutHandler.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import game from "./game.js";
|
||||
|
||||
export default {
|
||||
teams: [],
|
||||
|
||||
setSendPositionTimeout(teamID, deadline) {
|
||||
const foundTeam = this.teams.find(t => t.teamID === teamID);
|
||||
if (!foundTeam) {
|
||||
this.teams.push({teamID: teamID, timeoutID: setTimeout(() => game.sendLocation(teamID), deadline - Date.now())});
|
||||
} else {
|
||||
clearTimeout(foundTeam.timeoutID);
|
||||
foundTeam.timeoutID = setTimeout(() => game.sendLocation(teamID), deadline - Date.now());
|
||||
}
|
||||
},
|
||||
|
||||
endSendPositionTimeout(teamID) {
|
||||
const foundTeam = this.teams.find(t => t.teamID === teamID);
|
||||
if (foundTeam) {
|
||||
clearTimeout(foundTeam.timeoutID);
|
||||
this.teams = this.teams.filter(t => t.teamID !== teamID);
|
||||
}
|
||||
},
|
||||
|
||||
endAllSendPositionTimeout() {
|
||||
for (const team of this.teams) {
|
||||
clearTimeout(team.timeoutID);
|
||||
}
|
||||
this.teams = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user