Ajout de vérifications des informations données
This commit is contained in:
parent
b707b857a9
commit
4c0c392819
13
src/main.rs
13
src/main.rs
|
@ -1,6 +1,5 @@
|
|||
//! Un simple serveur http pour enregistrer des scores du jeu Ponguito.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
|
||||
use axum::extract::{Path, Query};
|
||||
|
@ -138,6 +137,18 @@ async fn register_score(
|
|||
LeftmostXForwardedFor(ip): LeftmostXForwardedFor,
|
||||
Path((name, score)): Path<(String, u32)>,
|
||||
) -> impl IntoResponse {
|
||||
// Vérification des informations
|
||||
let name = name.trim().to_lowercase();
|
||||
if name.is_empty() || score == 0 {
|
||||
return StatusCode::BAD_REQUEST;
|
||||
}
|
||||
|
||||
// Vérification du nom du joueur
|
||||
let authorized_characters = "abcdefghijklmnopqrstuvwxyz0123456789_-";
|
||||
if name.chars().any(|c| !authorized_characters.contains(c)) {
|
||||
return StatusCode::BAD_REQUEST;
|
||||
}
|
||||
|
||||
// Création du fichier de logs des scores si il n'existe pas
|
||||
let mut file = OpenOptions::new()
|
||||
.create(true)
|
||||
|
|
Loading…
Reference in a new issue