yggdrasil/src/util/structs/BlockedServer.rs

35 lines
1.3 KiB
Rust

/*
* Yggdrasil: Minecraft authentication server
* Copyright (C) 2023 0xf8.dev@proton.me
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use serde::{Deserialize, Serialize};
use crate::*;
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct BlockedServer {
pub id: i64,
pub pattern: String,
pub sha1: String,
pub reason: Option<String>,
}
impl BlockedServer {
pub async fn from_id(db: &Database, id: i64) -> Option<Self> {
let record = sqlx::query_as!(BlockedServer, "SELECT * FROM blocked_servers WHERE id = $1", id)
.fetch_one(&db.pool)
.await;
match record {
Ok(r) => Some(r),
Err(_) => None,
}
}
}