ACCOUNT CREATION AND LOGIN
This commit is contained in:
@@ -9,6 +9,7 @@ impl From<ClientMsg> for ClientMsgInst {
|
||||
ClientMsg::CreateAccount(v) => Self::CreateAccountV0(v),
|
||||
ClientMsg::RequestMsgs => Self::RequestMsgsV0,
|
||||
ClientMsg::SendMsg(v) => Self::SendMsgV0(v),
|
||||
ClientMsg::Login(v) => Self::LoginV0(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +20,7 @@ impl From<ClientMsgInst> for ClientMsg {
|
||||
ClientMsgInst::CreateAccountV0(v) => Self::CreateAccount(v),
|
||||
ClientMsgInst::RequestMsgsV0 => Self::RequestMsgs,
|
||||
ClientMsgInst::SendMsgV0(v) => Self::SendMsg(v),
|
||||
ClientMsgInst::LoginV0(v) => Self::Login(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,10 +28,11 @@ impl From<ClientMsgInst> for ClientMsg {
|
||||
impl From<ServerMsg> for ServerMsgInst {
|
||||
fn from(value: ServerMsg) -> Self {
|
||||
match value {
|
||||
ServerMsg::CreateAccount(v) => Self::CreateAccountV0(v),
|
||||
ServerMsg::CreateAccountResp(v) => Self::CreateAccountRespV0(v),
|
||||
ServerMsg::LoadMsg(v) => Self::LoadMsgV0(v),
|
||||
ServerMsg::LoadMsgs(v) => Self::LoadMsgsV0(v),
|
||||
ServerMsg::ServerError(v) => Self::ServerErrorV0(v),
|
||||
ServerMsg::LoginResp(v) => Self::LoginRespV0(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,10 +40,11 @@ impl From<ServerMsg> for ServerMsgInst {
|
||||
impl From<ServerMsgInst> for ServerMsg {
|
||||
fn from(value: ServerMsgInst) -> Self {
|
||||
match value {
|
||||
ServerMsgInst::CreateAccountV0(v) => Self::CreateAccount(v),
|
||||
ServerMsgInst::CreateAccountRespV0(v) => Self::CreateAccountResp(v),
|
||||
ServerMsgInst::LoadMsgV0(v) => Self::LoadMsg(v),
|
||||
ServerMsgInst::LoadMsgsV0(v) => Self::LoadMsgs(v),
|
||||
ServerMsgInst::ServerErrorV0(v) => Self::ServerError(v),
|
||||
ServerMsgInst::LoginRespV0(v) => Self::LoginResp(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,19 @@ use rand::TryRng;
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum ClientMsgInst {
|
||||
CreateAccountV0(CreateAccountV0) = 0,
|
||||
RequestMsgsV0 = 1,
|
||||
SendMsgV0(SendMsgV0) = 2,
|
||||
LoginV0(LoginV0) = 1,
|
||||
RequestMsgsV0 = 2,
|
||||
SendMsgV0(SendMsgV0) = 3,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum ServerMsgInst {
|
||||
CreateAccountV0(CreateAccountRespV0) = 0,
|
||||
LoadMsgV0(LoadMsgV0) = 1,
|
||||
LoadMsgsV0(Vec<LoadMsgV0>) = 2,
|
||||
ServerErrorV0(ServerErrorV0) = 3,
|
||||
CreateAccountRespV0(CreateAccountRespV0) = 0,
|
||||
LoginRespV0(LoginRespV0) = 1,
|
||||
LoadMsgV0(LoadMsgV0) = 2,
|
||||
LoadMsgsV0(Vec<LoadMsgV0>) = 3,
|
||||
ServerErrorV0(ServerErrorV0) = 4,
|
||||
}
|
||||
|
||||
pub type UserIdV0 = u64;
|
||||
@@ -24,7 +26,12 @@ pub struct CreateAccountV0 {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub token: String,
|
||||
pub login_key: LoginKeyV0,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct LoginV0 {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
@@ -34,6 +41,13 @@ pub enum CreateAccountRespV0 {
|
||||
InvalidToken,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum LoginRespV0 {
|
||||
Ok { id: UserIdV0 },
|
||||
UnknownUsername,
|
||||
InvalidPassword,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct LoginKeyV0(Vec<u8>);
|
||||
impl LoginKeyV0 {
|
||||
@@ -47,6 +61,10 @@ impl LoginKeyV0 {
|
||||
.expect("failed to generate random key");
|
||||
Self(key.to_vec())
|
||||
}
|
||||
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl From<Vec<u8>> for LoginKeyV0 {
|
||||
fn from(value: Vec<u8>) -> Self {
|
||||
|
||||
@@ -3,13 +3,15 @@ use super::data::*;
|
||||
#[derive(Debug)]
|
||||
pub enum ClientMsg {
|
||||
CreateAccount(CreateAccount),
|
||||
Login(Login),
|
||||
RequestMsgs,
|
||||
SendMsg(SendMsg),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ServerMsg {
|
||||
CreateAccount(CreateAccountResp),
|
||||
CreateAccountResp(CreateAccountResp),
|
||||
LoginResp(LoginResp),
|
||||
LoadMsg(LoadMsg),
|
||||
LoadMsgs(Vec<LoadMsg>),
|
||||
ServerError(ServerError),
|
||||
@@ -21,6 +23,8 @@ 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;
|
||||
|
||||
impl From<CreateAccount> for ClientMsg {
|
||||
@@ -29,6 +33,12 @@ impl From<CreateAccount> for ClientMsg {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Login> for ClientMsg {
|
||||
fn from(value: Login) -> Self {
|
||||
Self::Login(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ServerError> for ServerMsg {
|
||||
fn from(value: ServerError) -> Self {
|
||||
Self::ServerError(value)
|
||||
@@ -43,6 +53,12 @@ impl From<LoadMsg> for ServerMsg {
|
||||
|
||||
impl From<CreateAccountResp> for ServerMsg {
|
||||
fn from(value: CreateAccountResp) -> Self {
|
||||
Self::CreateAccount(value)
|
||||
Self::CreateAccountResp(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LoginResp> for ServerMsg {
|
||||
fn from(value: LoginResp) -> Self {
|
||||
Self::LoginResp(value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user