Files
Rocketmc/src/auth/minecraft/socket.rs
Geometrically 039d26feeb Add launcher analytics (#661)
* Add more analytics

* finish hydra move

* Finish websocket flow

* add minecraft account flow

* Finish playtime vals + payout automation
2023-08-02 14:43:04 -07:00

41 lines
1.0 KiB
Rust

use crate::database::models::flow_item::Flow;
use crate::queue::socket::ActiveSockets;
use actix_web::web::Payload;
use actix_web::{get, web, HttpRequest, HttpResponse};
use actix_ws::{Closed, Session};
use chrono::Duration;
use tokio::sync::RwLock;
#[get("ws")]
pub async fn route(
req: HttpRequest,
body: Payload,
db: web::Data<RwLock<ActiveSockets>>,
redis: web::Data<deadpool_redis::Pool>,
) -> Result<HttpResponse, actix_web::Error> {
let (res, session, _msg_stream) = actix_ws::handle(&req, body)?;
let _ = sock(session, db, redis).await;
Ok(res)
}
async fn sock(
mut ws_stream: Session,
db: web::Data<RwLock<ActiveSockets>>,
redis: web::Data<deadpool_redis::Pool>,
) -> Result<(), Closed> {
if let Ok(state) = Flow::MinecraftAuth
.insert(Duration::minutes(30), &redis)
.await
{
ws_stream
.text(serde_json::json!({ "login_code": state }).to_string())
.await?;
let db = db.write().await;
db.auth_sockets.insert(state, ws_stream);
}
Ok(())
}