testing
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
let client = mongodb::sync::Client::with_uri_str("mongodb://admin:admin@localhost/").unwrap();
|
let client = mongodb::sync::Client::with_uri_str("mongodb://admin:admin@localhost/").unwrap();
|
||||||
let database = Arc::new(database::Database::new(&client));
|
let database = Arc::new(database::Database::new(&client));
|
||||||
|
|
||||||
let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
|
let listener = TcpListener::bind("0.0.0.0:8080").unwrap();
|
||||||
|
|
||||||
for stream in listener.incoming() {
|
for stream in listener.incoming() {
|
||||||
println!("New connection");
|
println!("New connection");
|
||||||
|
|||||||
+29
-5
@@ -8,15 +8,37 @@ use crate::{
|
|||||||
use super::Session;
|
use super::Session;
|
||||||
|
|
||||||
pub fn player(session: &Session, uuid: String) -> Result {
|
pub fn player(session: &Session, uuid: String) -> Result {
|
||||||
let player = session
|
// First, try to find the existing player
|
||||||
|
match session
|
||||||
.database
|
.database
|
||||||
.players
|
.players
|
||||||
.find(doc! {
|
.find(doc! { "uuid": uuid.clone() })
|
||||||
"uuid": uuid.clone(),
|
|
||||||
})
|
|
||||||
.run()?
|
.run()?
|
||||||
.deserialize_current()?;
|
.deserialize_current()
|
||||||
|
{
|
||||||
|
// Player exists, return their data
|
||||||
|
Ok(player) => Ok(Response::Player {
|
||||||
|
cloak: player.cloak,
|
||||||
|
uuid,
|
||||||
|
cloaks: player.cloaks,
|
||||||
|
hats: player.hats,
|
||||||
|
hat: player.hat,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Player doesn't exist, create a new player
|
||||||
|
Err(_) => {
|
||||||
|
let player = Player {
|
||||||
|
uuid: uuid.clone(),
|
||||||
|
cloaks: Vec::new(),
|
||||||
|
cloak: "".to_string(),
|
||||||
|
hats: Vec::new(),
|
||||||
|
hat: String::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Insert the new player
|
||||||
|
session.database.players.insert_one(player.clone()).run()?;
|
||||||
|
|
||||||
|
// Return the newly created player's data
|
||||||
Ok(Response::Player {
|
Ok(Response::Player {
|
||||||
cloak: player.cloak,
|
cloak: player.cloak,
|
||||||
uuid,
|
uuid,
|
||||||
@@ -24,6 +46,8 @@ pub fn player(session: &Session, uuid: String) -> Result {
|
|||||||
hats: player.hats,
|
hats: player.hats,
|
||||||
hat: player.hat,
|
hat: player.hat,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(session: &Session) -> Result {
|
pub fn create(session: &Session) -> Result {
|
||||||
|
|||||||
Reference in New Issue
Block a user