formatage

This commit is contained in:
Mathieu Oriol
2024-09-09 17:01:26 +02:00
parent d6cf0e8d60
commit f0285e2873
5 changed files with 21 additions and 21 deletions

View File

@@ -20,9 +20,9 @@ const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
* @param {String} data The data to send
*/
export function secureAdminBroadcast(event, data) {
loggedInSockets.forEach(s => {
io.of("admin").to(s).emit(event, data);
});
loggedInSockets.forEach(s => {
io.of("admin").to(s).emit(event, data);
});
}
//Array of logged in sockets
@@ -73,10 +73,10 @@ export function initAdminSocketHandler() {
socket.emit("error", "Not logged in");
return;
}
if(!game.changeSettings(settings)) {
if (!game.changeSettings(settings)) {
socket.emit("error", "Invalid settings");
}
secureAdminBroadcast("game_settings",game.settings);
secureAdminBroadcast("game_settings", game.settings);
playersBroadcast("game_settings", game.settings);
})
@@ -99,10 +99,10 @@ export function initAdminSocketHandler() {
socket.emit("error", "Not logged in");
return;
}
if(!penaltyController.updateSettings(settings)) {
if (!penaltyController.updateSettings(settings)) {
socket.emit("error", "Invalid settings");
socket.emit("penalty_settings", penaltyController.settings)
}else {
} else {
secureAdminBroadcast("penalty_settings", penaltyController.settings)
}

View File

@@ -20,11 +20,11 @@ export const GameState = {
export default {
//List of teams, as objects. To see the fields see the addTeam methods
teams : [],
teams: [],
//Current state of the game
state : GameState.SETUP,
state: GameState.SETUP,
//Settings of the game
settings : {
settings: {
loserEndGameMessage: "",
winnerEndGameMessage: "",
capturedMessage: "",
@@ -37,7 +37,7 @@ export default {
* @returns true if the settings are applied
*/
changeSettings(newSettings) {
this.settings = {...this.settings, ...newSettings};
this.settings = { ...this.settings, ...newSettings };
return true;
},
@@ -232,7 +232,7 @@ export default {
}
//The location sent by the team will be null if the browser call API dooes not succeed
//See issue #19
if(location == null) {
if (location == null) {
return false;
}
team.currentLocation = location;
@@ -264,7 +264,7 @@ export default {
if (team == undefined) {
return false;
}
if(team.currentLocation == null) {
if (team.currentLocation == null) {
return false;
}

View File

@@ -4,7 +4,7 @@ This module manages the verification of the game rules and the penalties.
import { isInCircle } from "./map_utils.js";
import { sendUpdatedTeamInformations, teamBroadcast } from "./team_socket.js";
import { secureAdminBroadcast } from "./admin_socket.js";
import game, {GameState} from "./game.js";
import game, { GameState } from "./game.js";
import zone from "./zone_manager.js";
export default {

View File

@@ -4,7 +4,7 @@ It receives messages, checks permissions, manages authentication and performs ac
This module also exposes functions to send messages via socket to all teams
*/
import { secureAdminBroadcast } from "./admin_socket.js";
import { io} from "./index.js";
import { io } from "./index.js";
import game from "./game.js";
import zone from "./zone_manager.js";
@@ -43,7 +43,7 @@ function logoutPlayer(id) {
export function sendUpdatedTeamInformations(teamId) {
let team = game.getTeam(teamId)
if(!team) {
if (!team) {
return false;
}
team.sockets.forEach(socketId => {
@@ -106,7 +106,7 @@ export function initTeamSocket() {
return;
}
let team = game.getTeam(teamId)
if(team == undefined) {
if (team == undefined) {
logoutPlayer(socket.id);
return;
}
@@ -125,8 +125,8 @@ export function initTeamSocket() {
return;
}
game.updateTeamChasing();
teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation,locationSendDeadline: team.locationSendDeadline });
teamBroadcast(teamId,"success", "Position udpated")
teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation, locationSendDeadline: team.locationSendDeadline });
teamBroadcast(teamId, "success", "Position udpated")
secureAdminBroadcast("teams", game.teams)
});

View File

@@ -200,8 +200,8 @@ export default {
onNextZoneUpdate(newZone) {
playersBroadcast("new_zone", newZone)
secureAdminBroadcast("new_zone", newZone)
},
},
//a call to onZoneUpdate will be made every updateIntervalSeconds when the zone is changing
onZoneUpdate(zone) {
playersBroadcast("zone", zone)