good structure
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
mod player;
|
||||
mod set_cloak;
|
||||
|
||||
use std::{
|
||||
@@ -66,6 +67,8 @@ impl Session {
|
||||
|
||||
"set_cloak" => set_cloak::set_cloak(self, params.parse_param("cloak")?),
|
||||
|
||||
"player" => player::player(self, params.parse_param("uuid")?),
|
||||
|
||||
_ => Err(crate::response::Error::InvalidRequest),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
use mongodb::bson::doc;
|
||||
|
||||
use crate::response::{Response, Result};
|
||||
|
||||
use super::Session;
|
||||
|
||||
pub fn player(session: &Session, uuid: String) -> Result {
|
||||
let player = session
|
||||
.database
|
||||
.players
|
||||
.find(doc! {
|
||||
"uuid": uuid.clone(),
|
||||
})
|
||||
.run()?
|
||||
.deserialize_current()
|
||||
.unwrap();
|
||||
|
||||
Ok(Response::Player {
|
||||
cloak: player.cloak,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
use mongodb::bson::doc;
|
||||
|
||||
use crate::response::{Response, Result};
|
||||
|
||||
use super::Session;
|
||||
|
||||
pub fn set_cloak(session: &Session, cloak: String) -> Result {
|
||||
session.database.players.update_one(
|
||||
doc! {
|
||||
"uuid": session.player.id.clone(),
|
||||
},
|
||||
doc! {
|
||||
"$set": {
|
||||
"cloak": cloak,
|
||||
},
|
||||
},
|
||||
).run()?;
|
||||
|
||||
Ok(Response::Success)
|
||||
}
|
||||
Reference in New Issue
Block a user