lib: Rename things in preperation for a proper session

This commit is contained in:
Artemis Tosini 2024-09-05 04:00:26 +00:00
parent 23bba30baa
commit 5e7d4c6d98
Signed by: artemist
GPG key ID: ADFFE553DCBB831E

View file

@ -13,7 +13,6 @@ use async_tungstenite::{
tungstenite, WebSocketStream, tungstenite, WebSocketStream,
}; };
use futures::{SinkExt as _, StreamExt}; use futures::{SinkExt as _, StreamExt};
use serde::Deserialize;
use snafu::prelude::*; use snafu::prelude::*;
use tokio::sync::broadcast; use tokio::sync::broadcast;
use vapore_proto::{ use vapore_proto::{
@ -31,7 +30,7 @@ use crate::{
const CHANNEL_CAPACITY: usize = 16; const CHANNEL_CAPACITY: usize = 16;
#[derive(Clone)] #[derive(Clone)]
struct SessionInner { struct CMSessionInner {
/// Steam ID of current user. When set to None we are not logged in /// Steam ID of current user. When set to None we are not logged in
steam_id: Option<u64>, steam_id: Option<u64>,
/// Realm we're connecting to. AIUI this corresponds to account universe. /// Realm we're connecting to. AIUI this corresponds to account universe.
@ -56,24 +55,28 @@ struct SessionInner {
subscribe_senders: HashMap<EMsg, broadcast::Sender<CMRawProtoBufMessage>>, subscribe_senders: HashMap<EMsg, broadcast::Sender<CMRawProtoBufMessage>>,
} }
impl SessionInner { impl CMSessionInner {
pub fn alloc_jobid(&mut self) -> u64 { /// Create a new job ID.
/// Officially there's some complicated format for this,
/// but we're using random for now
fn alloc_jobid(&mut self) -> u64 {
rand::random() rand::random()
} }
pub fn wake_sender(&mut self) { /// Wake the send thread, use after adding messages to the send queue
fn wake_sender(&mut self) {
if let Some(waker) = self.send_waker.take() { if let Some(waker) = self.send_waker.take() {
waker.wake() waker.wake()
} }
} }
} }
struct Context { struct CMContext {
socket: WebSocketStream<ConnectStream>, socket: WebSocketStream<ConnectStream>,
session: Arc<Mutex<SessionInner>>, session: Arc<Mutex<CMSessionInner>>,
} }
impl Context { impl CMContext {
fn handle_receive( fn handle_receive(
self: Pin<&mut Self>, self: Pin<&mut Self>,
message: tungstenite::Result<tungstenite::Message>, message: tungstenite::Result<tungstenite::Message>,
@ -174,7 +177,7 @@ impl Context {
} }
} }
impl Future for Context { impl Future for CMContext {
type Output = Result<(), ClientError>; type Output = Result<(), ClientError>;
fn poll( fn poll(
@ -191,9 +194,13 @@ impl Future for Context {
} }
} }
/// A low-level connection to a Valve Connection Manager server.
/// You can use it to send requests, call RPC functions,
/// and subscribe to message types, but it will not keep a record
/// of data recieved.
#[derive(Clone)] #[derive(Clone)]
pub struct CMSession { pub struct CMSession {
inner: Arc<Mutex<SessionInner>>, inner: Arc<Mutex<CMSessionInner>>,
} }
impl CMSession { impl CMSession {
@ -204,7 +211,7 @@ impl CMSession {
url: server.to_string(), url: server.to_string(),
})?; })?;
let inner = SessionInner { let inner = CMSessionInner {
steam_id: None, steam_id: None,
realm: 1, realm: 1,
client_session_id: 0, client_session_id: 0,
@ -217,7 +224,7 @@ impl CMSession {
let inner_wrapped = Arc::new(Mutex::new(inner)); let inner_wrapped = Arc::new(Mutex::new(inner));
let context = Context { let context = CMContext {
socket, socket,
session: inner_wrapped.clone(), session: inner_wrapped.clone(),
}; };