Protocol
This commit is contained in:
@@ -4,12 +4,41 @@ use super::*;
|
||||
|
||||
impl super::Client {
|
||||
pub async fn initialize(mut socket: WebSocket) -> anyhow::Result<Self> {
|
||||
if let Some(ServerMessage::Initialize()) = Client::read_socket(&mut socket).await? {}
|
||||
let Some(ServerMethod::Initialize {
|
||||
public_key,
|
||||
timestamp,
|
||||
signature,
|
||||
}) = Client::read_socket(&mut socket).await?
|
||||
else {
|
||||
Client::send_socket(
|
||||
&mut socket,
|
||||
ClientMethod::Error {
|
||||
error: Cow::Borrowed(
|
||||
"Failed to initialize, unexpected method, expected: initialize",
|
||||
),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
return Err(anyhow::anyhow!(
|
||||
"Failed to initialize: Client sent the wrong method"
|
||||
));
|
||||
};
|
||||
|
||||
Client::send_socket(
|
||||
&mut socket,
|
||||
ClientMethod::Initialized {
|
||||
public_key,
|
||||
timestamp,
|
||||
signature,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Self {
|
||||
socket,
|
||||
meta: super::ClientMeta {},
|
||||
pub_key: String::new(),
|
||||
public_key: String::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user