testing buy
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
pub const CLOAKS: &[&str] = &["mercedes_flow", "glitch"];
|
||||
|
||||
pub const HATS: &[&str] = &["horns_black", "horns_white", "halo", "halo_black"];
|
||||
@@ -11,6 +11,7 @@ pub mod encryption;
|
||||
pub mod methods;
|
||||
pub mod parser;
|
||||
pub mod response;
|
||||
pub mod cosmetics;
|
||||
|
||||
fn main() -> Result<(), response::Error> {
|
||||
let rsa = Rsa::generate(2048)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
use mongodb::bson::doc;
|
||||
|
||||
use crate::{methods::Session, response::Result};
|
||||
|
||||
pub fn buy_cloak(session: &Session, cloak: String) -> Result {
|
||||
let filter = doc! {
|
||||
"uuid": session.local_player.id.clone(),
|
||||
"points": { "$gte": 100 }
|
||||
};
|
||||
|
||||
if let Some(doc) = session.database.players.find_one(filter).run()? {
|
||||
println!("Found matching document: {:?}", doc);
|
||||
Ok(crate::response::Response::Success)
|
||||
} else {
|
||||
Err(crate::response::Error::TransactionError(
|
||||
"Not enough coins".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod buy;
|
||||
pub mod player;
|
||||
mod set_cloak;
|
||||
mod set_hat;
|
||||
@@ -126,6 +127,8 @@ impl Session {
|
||||
Ok(Response::Players(players))
|
||||
}
|
||||
|
||||
"buy_cloak" => buy::buy_cloak(self, params.parse_param("cloak")?),
|
||||
|
||||
_ => Err(crate::response::Error::InvalidMethod(method.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -74,6 +74,7 @@ pub enum Error {
|
||||
AuthenticationError(String),
|
||||
ValidationError(String),
|
||||
EncryptionError(String),
|
||||
TransactionError(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
@@ -81,7 +82,9 @@ impl std::fmt::Display for Error {
|
||||
match self {
|
||||
Error::InvalidRequest(msg) => write!(f, "Invalid request: {}", msg),
|
||||
Error::InvalidMethod(method) => write!(f, "Invalid method: {}", method),
|
||||
Error::InvalidParameter { param, reason } => write!(f, "Invalid parameter '{}': {}", param, reason),
|
||||
Error::InvalidParameter { param, reason } => {
|
||||
write!(f, "Invalid parameter '{}': {}", param, reason)
|
||||
}
|
||||
Error::ParameterNotFound(param) => write!(f, "Required parameter not found: {}", param),
|
||||
Error::InvalidSession(details) => write!(f, "Invalid session: {}", details),
|
||||
Error::InvalidHandshake(details) => write!(f, "Handshake failed: {}", details),
|
||||
|
||||
Reference in New Issue
Block a user