testing
This commit is contained in:
+13
-10
@@ -8,25 +8,28 @@ use crate::{
|
|||||||
use super::Session;
|
use super::Session;
|
||||||
|
|
||||||
pub fn player(session: &Session, uuid: String) -> Result {
|
pub fn player(session: &Session, uuid: String) -> Result {
|
||||||
// First, try to find the existing player
|
// Try to find the player with the given UUID
|
||||||
match session
|
let mut cursor = session
|
||||||
.database
|
.database
|
||||||
.players
|
.players
|
||||||
.find(doc! { "uuid": uuid.clone() })
|
.find(doc! { "uuid": uuid.clone() })
|
||||||
.run()?
|
.run()?;
|
||||||
.deserialize_current()
|
|
||||||
{
|
// Check if there's a document in the cursor
|
||||||
// Player exists, return their data
|
match cursor.next() {
|
||||||
Ok(player) => Ok(Response::Player {
|
Some(Ok(player)) => {
|
||||||
|
// Player exists, deserialize and return their data
|
||||||
|
Ok(Response::Player {
|
||||||
cloak: player.cloak,
|
cloak: player.cloak,
|
||||||
uuid,
|
uuid,
|
||||||
cloaks: player.cloaks,
|
cloaks: player.cloaks,
|
||||||
hats: player.hats,
|
hats: player.hats,
|
||||||
hat: player.hat,
|
hat: player.hat,
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Player doesn't exist, create a new player
|
// No document found or deserialization error
|
||||||
Err(_) => {
|
_ => {
|
||||||
let player = Player {
|
let player = Player {
|
||||||
uuid: uuid.clone(),
|
uuid: uuid.clone(),
|
||||||
cloaks: Vec::new(),
|
cloaks: Vec::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user