get_game_url is added
This commit is contained in:
parent
fbb13adaa9
commit
2066a469dc
|
@ -19,7 +19,7 @@ nats = { version = "0" }
|
||||||
prost = { version = "0" }
|
prost = { version = "0" }
|
||||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.81-snapshot" }
|
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.83-snapshot" }
|
||||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.67-snapshot" }
|
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.69-snapshot" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
||||||
futures::try_join!(self.list_games(),).map(|_| ())
|
futures::try_join!(self.list_games(), self.get_game_url(),).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_client_in_header(
|
fn get_client_in_header(
|
||||||
|
@ -62,6 +62,57 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_member_session_with_renewal(
|
||||||
|
&self,
|
||||||
|
client: &bpr::models::core::network::Client,
|
||||||
|
) -> Result<Option<bpr::models::member_session::MemberSession>, bcr::error::rpc::Error> {
|
||||||
|
let ss_get_member_session_req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest {
|
||||||
|
client: Some(client.clone()),
|
||||||
|
request: Some(bpr::ss::member_session::get_member_session_with_renewal_request::Request {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_get_member_session_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL,
|
||||||
|
ss_get_member_session_req.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let ss_get_member_session_res =
|
||||||
|
bpr::ss::member_session::GetMemberSessionWithRenewalResponse::decode(
|
||||||
|
ss_get_member_session_res_msg.data.as_slice(),
|
||||||
|
)
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if let Some(e) = ss_get_member_session_res.error {
|
||||||
|
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(r) = ss_get_member_session_res.result {
|
||||||
|
return Ok(r.member_session);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
async fn list_games(&self) -> Result<(), Box<dyn std::error::Error>> {
|
async fn list_games(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let s = self
|
let s = self
|
||||||
.connection_broker
|
.connection_broker
|
||||||
|
@ -170,4 +221,118 @@ impl Service {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_game_url(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::frontend::api::game::SUBJECT_GET_GAME_URL,
|
||||||
|
self.queue_broker.as_str(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
while let Some(message) = s.next().await {
|
||||||
|
if let Err(e) = async {
|
||||||
|
let client = self.get_client_in_header(&message)?;
|
||||||
|
let member_session = match self.get_member_session_with_renewal(&client).await? {
|
||||||
|
Some(ms) => ms,
|
||||||
|
None => {
|
||||||
|
return Err(bcr::error::rpc::Error::InvalidRequest(
|
||||||
|
bcr::error::rpc::InvalidRequest {
|
||||||
|
message: "Unauthorized".to_string(),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let req = bpr::c2se::api::game::GetGameUrlRequest::decode(message.data.as_slice())
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
||||||
|
message: format!("invalid request: {}", e),
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let ss_get_game_url_req = bpr::ss::api::game::GetGameUrlRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(bpr::ss::api::game::get_game_url_request::Request {
|
||||||
|
vendor_key: req.vendor_key,
|
||||||
|
game_key: req.game_key,
|
||||||
|
member_id: member_session.member_id,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_get_game_url_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::api::game::SUBJECT_GET_GAME_URL,
|
||||||
|
ss_get_game_url_req.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let ss_get_game_url_res =
|
||||||
|
bpr::ss::api::game::GetGameUrlResponse::decode(ss_get_game_url_res_msg.data.as_slice())
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if let Some(e) = ss_get_game_url_res.error {
|
||||||
|
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(r) = ss_get_game_url_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::api::game::GetGameUrlResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(bpr::c2se::api::game::get_game_url_response::Result {
|
||||||
|
user_id: r.user_id,
|
||||||
|
balance: r.balance,
|
||||||
|
url: r.url,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok::<(), bcr::error::rpc::Error>(())
|
||||||
|
}
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::api::game::GetGameUrlResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user