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,
};
use futures::{SinkExt as _, StreamExt};
use serde::Deserialize;
use snafu::prelude::*;
use tokio::sync::broadcast;
use vapore_proto::{
@ -31,7 +30,7 @@ use crate::{
const CHANNEL_CAPACITY: usize = 16;
#[derive(Clone)]
struct SessionInner {
struct CMSessionInner {
/// Steam ID of current user. When set to None we are not logged in
steam_id: Option<u64>,
/// Realm we're connecting to. AIUI this corresponds to account universe.
@ -56,24 +55,28 @@ struct SessionInner {
subscribe_senders: HashMap<EMsg, broadcast::Sender<CMRawProtoBufMessage>>,
}
impl SessionInner {
pub fn alloc_jobid(&mut self) -> u64 {
impl CMSessionInner {
/// 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()
}
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() {
waker.wake()
}
}
}
struct Context {
struct CMContext {
socket: WebSocketStream<ConnectStream>,
session: Arc<Mutex<SessionInner>>,
session: Arc<Mutex<CMSessionInner>>,
}
impl Context {
impl CMContext {
fn handle_receive(
self: Pin<&mut Self>,
message: tungstenite::Result<tungstenite::Message>,
@ -174,7 +177,7 @@ impl Context {
}
}
impl Future for Context {
impl Future for CMContext {
type Output = Result<(), ClientError>;
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)]
pub struct CMSession {
inner: Arc<Mutex<SessionInner>>,
inner: Arc<Mutex<CMSessionInner>>,
}
impl CMSession {
@ -204,7 +211,7 @@ impl CMSession {
url: server.to_string(),
})?;
let inner = SessionInner {
let inner = CMSessionInner {
steam_id: None,
realm: 1,
client_session_id: 0,
@ -217,7 +224,7 @@ impl CMSession {
let inner_wrapped = Arc::new(Mutex::new(inner));
let context = Context {
let context = CMContext {
socket,
session: inner_wrapped.clone(),
};