stuff
This commit is contained in:
@@ -10,6 +10,7 @@ impl From<ClientMsg> for ClientMsgInst {
|
||||
ClientMsg::RequestMsgs => Self::RequestMsgsV0,
|
||||
ClientMsg::SendMsg(v) => Self::SendMsgV0(v),
|
||||
ClientMsg::Login(v) => Self::LoginV0(v),
|
||||
ClientMsg::RequestUsers(v) => Self::RequestUsersV0(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +22,7 @@ impl From<ClientMsgInst> for ClientMsg {
|
||||
ClientMsgInst::RequestMsgsV0 => Self::RequestMsgs,
|
||||
ClientMsgInst::SendMsgV0(v) => Self::SendMsg(v),
|
||||
ClientMsgInst::LoginV0(v) => Self::Login(v),
|
||||
ClientMsgInst::RequestUsersV0(v) => Self::RequestUsers(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +35,7 @@ impl From<ServerMsg> for ServerMsgInst {
|
||||
ServerMsg::LoadMsgs(v) => Self::LoadMsgsV0(v),
|
||||
ServerMsg::ServerError(v) => Self::ServerErrorV0(v),
|
||||
ServerMsg::LoginResp(v) => Self::LoginRespV0(v),
|
||||
ServerMsg::RequestUsersResp(v) => Self::RequestUsersRespV0(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,6 +48,7 @@ impl From<ServerMsgInst> for ServerMsg {
|
||||
ServerMsgInst::LoadMsgsV0(v) => Self::LoadMsgs(v),
|
||||
ServerMsgInst::ServerErrorV0(v) => Self::ServerError(v),
|
||||
ServerMsgInst::LoginRespV0(v) => Self::LoginResp(v),
|
||||
ServerMsgInst::RequestUsersRespV0(v) => Self::RequestUsersResp(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ pub enum ClientMsgInst {
|
||||
LoginV0(LoginV0) = 1,
|
||||
RequestMsgsV0 = 2,
|
||||
SendMsgV0(SendMsgV0) = 3,
|
||||
RequestUsersV0(RequestUsersV0) = 4,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
@@ -17,6 +18,7 @@ pub enum ServerMsgInst {
|
||||
LoadMsgV0(LoadMsgV0) = 2,
|
||||
LoadMsgsV0(Vec<LoadMsgV0>) = 3,
|
||||
ServerErrorV0(ServerErrorV0) = 4,
|
||||
RequestUsersRespV0(RequestUsersRespV0) = 5,
|
||||
}
|
||||
|
||||
pub type UserIdV0 = u64;
|
||||
@@ -48,6 +50,20 @@ pub enum LoginRespV0 {
|
||||
InvalidPassword,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct RequestUsersV0;
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct RequestUsersRespV0 {
|
||||
pub users: Vec<ServerUserV0>,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct ServerUserV0 {
|
||||
pub id: UserIdV0,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct LoginKeyV0(Vec<u8>);
|
||||
impl LoginKeyV0 {
|
||||
@@ -86,4 +102,5 @@ pub struct LoadMsgV0 {
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum ServerErrorV0 {
|
||||
NotLoggedIn,
|
||||
NoPermission,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod conversion;
|
||||
mod data;
|
||||
pub mod data;
|
||||
mod msg;
|
||||
mod no_cert;
|
||||
mod request;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::data::*;
|
||||
use super::data;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ClientMsg {
|
||||
@@ -6,6 +6,7 @@ pub enum ClientMsg {
|
||||
Login(Login),
|
||||
RequestMsgs,
|
||||
SendMsg(SendMsg),
|
||||
RequestUsers(RequestUsers),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -15,17 +16,23 @@ pub enum ServerMsg {
|
||||
LoadMsg(LoadMsg),
|
||||
LoadMsgs(Vec<LoadMsg>),
|
||||
ServerError(ServerError),
|
||||
RequestUsersResp(RequestUsersResp),
|
||||
}
|
||||
|
||||
pub type LoginKey = LoginKeyV0;
|
||||
pub type SendMsg = SendMsgV0;
|
||||
pub type LoadMsg = LoadMsgV0;
|
||||
pub type ServerError = ServerErrorV0;
|
||||
pub type CreateAccount = CreateAccountV0;
|
||||
pub type CreateAccountResp = CreateAccountRespV0;
|
||||
pub type Login = LoginV0;
|
||||
pub type LoginResp = LoginRespV0;
|
||||
pub type UserId = UserIdV0;
|
||||
// TODO: a ton of this should really just be macros :sob:
|
||||
|
||||
pub use data::CreateAccountRespV0 as CreateAccountResp;
|
||||
pub use data::CreateAccountV0 as CreateAccount;
|
||||
pub use data::LoadMsgV0 as LoadMsg;
|
||||
pub use data::LoginKeyV0 as LoginKey;
|
||||
pub use data::LoginRespV0 as LoginResp;
|
||||
pub use data::LoginV0 as Login;
|
||||
pub use data::RequestUsersRespV0 as RequestUsersResp;
|
||||
pub use data::RequestUsersV0 as RequestUsers;
|
||||
pub use data::SendMsgV0 as SendMsg;
|
||||
pub use data::ServerErrorV0 as ServerError;
|
||||
pub use data::ServerUserV0 as ServerUser;
|
||||
pub use data::UserIdV0 as UserId;
|
||||
|
||||
impl From<CreateAccount> for ClientMsg {
|
||||
fn from(value: CreateAccount) -> Self {
|
||||
@@ -39,6 +46,12 @@ impl From<Login> for ClientMsg {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RequestUsers> for ClientMsg {
|
||||
fn from(value: RequestUsers) -> Self {
|
||||
Self::RequestUsers(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ServerError> for ServerMsg {
|
||||
fn from(value: ServerError) -> Self {
|
||||
Self::ServerError(value)
|
||||
@@ -62,3 +75,9 @@ impl From<LoginResp> for ServerMsg {
|
||||
Self::LoginResp(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RequestUsersResp> for ServerMsg {
|
||||
fn from(value: RequestUsersResp) -> Self {
|
||||
Self::RequestUsersResp(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::*;
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use crate::net::{ClientMsgInst, ServerMsgInst};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct RequestId(NonZeroU32);
|
||||
|
||||
@@ -30,3 +29,44 @@ pub struct ServerRespMsg {
|
||||
pub id: Option<RequestId>,
|
||||
pub msg: ServerMsgInst,
|
||||
}
|
||||
|
||||
pub trait RequestMsg: Into<ClientMsg> {
|
||||
type Result;
|
||||
fn result(msg: ServerMsg) -> Option<Self::Result>;
|
||||
}
|
||||
|
||||
impl RequestMsg for CreateAccount {
|
||||
type Result = CreateAccountResp;
|
||||
|
||||
fn result(msg: ServerMsg) -> Option<Self::Result> {
|
||||
if let ServerMsg::CreateAccountResp(res) = msg {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RequestMsg for Login {
|
||||
type Result = LoginResp;
|
||||
|
||||
fn result(msg: ServerMsg) -> Option<Self::Result> {
|
||||
if let ServerMsg::LoginResp(res) = msg {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RequestMsg for RequestUsers {
|
||||
type Result = RequestUsersResp;
|
||||
|
||||
fn result(msg: ServerMsg) -> Option<Self::Result> {
|
||||
if let ServerMsg::RequestUsersResp(res) = msg {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user