From d1c226b934e5076148cbe4bbf58e5b14c155e38d Mon Sep 17 00:00:00 2001 From: Ivan Skorokhodov Date: Sun, 25 Dec 2016 17:41:14 +0300 Subject: [PATCH 1/2] feat(gamblers/xsporta): make real bet in check_offer --- src/gamblers/xsporta.rs | 84 +++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 46 deletions(-) diff --git a/src/gamblers/xsporta.rs b/src/gamblers/xsporta.rs index 8fa74f1..a993e54 100644 --- a/src/gamblers/xsporta.rs +++ b/src/gamblers/xsporta.rs @@ -25,6 +25,36 @@ impl XBet { session: Session::new("1xsporta.space") } } + + fn try_place_bet(&self, offer: &Offer, outcome: &Outcome, stake: Currency) -> Result { + let stake: f64 = stake.into(); + let hash = self.session.get_cookie("uhash").unwrap(); + let user_id = self.session.get_cookie("ua").unwrap(); + + let result = match offer.outcomes.iter().position(|o| o == outcome).unwrap() { + 0 => 1, + 1 => 3, + 2 => 2, + _ => return Err(Error::from("Outcome not found in offer")) + }; + + let path = "/en/dataLineLive/put_bets_common.php"; + let request_data = PlaceBetRequest { + Events: vec![ + PlaceBetRequestEvent { + GameId: offer.oid as u32, + Coef: outcome.1, + Kind: 3, + Type: result + } + ], + Summ: stake.to_string(), + UserId: user_id, + hash: hash + }; + + self.session.request(&path).post(request_data) + } } impl Gambler for XBet { @@ -101,33 +131,7 @@ impl Gambler for XBet { } fn place_bet(&self, offer: Offer, outcome: Outcome, stake: Currency) -> Result<()> { - let stake: f64 = stake.into(); - let hash = self.session.get_cookie("uhash").unwrap(); - let user_id = self.session.get_cookie("ua").unwrap(); - - let result = match offer.outcomes.iter().position(|o| o == &outcome).unwrap() { - 0 => 1, - 1 => 3, - 2 => 2, - _ => return Err(Error::from("Outcome not found in offer")) - }; - - let path = "/en/dataLineLive/put_bets_common.php"; - let request_data = PlaceBetRequest { - Events: vec![ - PlaceBetRequestEvent { - GameId: offer.oid as u32, - Coef: outcome.1, - Kind: 3, - Type: result - } - ], - Summ: stake.to_string(), - UserId: user_id, - hash: hash - }; - - let response: PlaceBetResponse = try!(self.session.request(&path).post(request_data)); + let response = try!(self.try_place_bet(&offer, &outcome, stake)); if !response.Success { return Err(From::from(response.Error)); @@ -136,20 +140,15 @@ impl Gambler for XBet { Ok(()) } - fn check_offer(&self, offer: &Offer, _: &Outcome, _: Currency) -> Result { - let path = format!("/LineFeed/GetGame?id={}&count=50&cnt=10&lng=en", offer.oid); - let message = try!(self.session.request(&path).get::()); + fn check_offer(&self, offer: &Offer, outcome: &Outcome, stake: Currency) -> Result { + let response = try!(self.try_place_bet(offer, outcome, Currency(1))); - if !message.Success || message.Value.is_none() { - if message.Error.contains("not found") { - return Ok(false); - } else { - return Err(Error::from(message.Error)); - } - } + if response.Error.contains("The minimum stake is") { + let min_stake = try!(response.Error.as_str() + .trim_left_matches("The minimum stake is ") + .parse::()); - if let Some(recent) = grab_offer(message.Value.unwrap()) { - Ok(&recent == offer) + Ok(stake >= Currency::from(min_stake)) } else { Ok(false) } @@ -163,13 +162,6 @@ struct Get1x2Response { Value: Vec } -#[derive(Deserialize)] -struct GetGameResponse { - Error: String, - Success: bool, - Value: Option -} - #[derive(Deserialize)] struct Info { Id: u32, From f3381bff6c1e2758b82aa79a6e7ed8dc27e29f3f Mon Sep 17 00:00:00 2001 From: Ivan Skorokhodov Date: Sun, 25 Dec 2016 17:59:13 +0300 Subject: [PATCH 2/2] feat(gamblers): log response when check_offer is failed --- src/gamblers/cybbet.rs | 8 +++++++- src/gamblers/vitalbet.rs | 3 ++- src/gamblers/xsporta.rs | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gamblers/cybbet.rs b/src/gamblers/cybbet.rs index 4c528e2..70fb69c 100644 --- a/src/gamblers/cybbet.rs +++ b/src/gamblers/cybbet.rs @@ -186,7 +186,13 @@ impl Gambler for CybBet { fn check_offer(&self, offer: &Offer, outcome: &Outcome, stake: Currency) -> Result { let response = try!(self.try_place_bet("/games/checkbet", &offer, &outcome, stake)); - Ok(response == r#"{"errorExpress":[],"errorSingle":[],"warning":""}"#) + let ok = response == r#"{"errorExpress":[],"errorSingle":[],"warning":""}"#; + + if !ok { + warn!("Unexpected response in check_offer: {:?}", response); + } + + Ok(ok) } } diff --git a/src/gamblers/vitalbet.rs b/src/gamblers/vitalbet.rs index 8dcc7c9..771e7a2 100644 --- a/src/gamblers/vitalbet.rs +++ b/src/gamblers/vitalbet.rs @@ -211,7 +211,7 @@ impl Gambler for VitalBet { let response = try!(self.try_place_bet(event, outcome, Currency(1))); match response.ErrorMessage { - Some(m) => { + Some(ref m) => { if m.contains("Minimum allowed stake") { let min_stake = try!(m.as_str() .trim_left_matches("Bet not accepted. Reason: Minimum allowed stake is '$") @@ -220,6 +220,7 @@ impl Gambler for VitalBet { Ok(stake >= Currency::from(min_stake)) } else { + warn!("Unexpected response in check_offer: {:?}", response); Ok(false) } }, diff --git a/src/gamblers/xsporta.rs b/src/gamblers/xsporta.rs index a993e54..c1b225f 100644 --- a/src/gamblers/xsporta.rs +++ b/src/gamblers/xsporta.rs @@ -150,6 +150,7 @@ impl Gambler for XBet { Ok(stake >= Currency::from(min_stake)) } else { + warn!("Unexpected response in check_offer: {:?}", response); Ok(false) } } @@ -196,7 +197,7 @@ struct PlaceBetRequestEvent { Type: u32 } -#[derive(Deserialize)] +#[derive(Debug, Deserialize)] struct PlaceBetResponse { Error: String, Success: bool