1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![allow(missing_docs)]
use crate::cmds::do_cmd;
use crate::cmds::proxy_commands::*;
use crate::cmdset;
use crate::comms::Client;
use crate::prelude::{CmdSet, Command, LinesCodecResult};
use crate::send;
use serde::{Deserialize, Serialize};
use std::marker::Send;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum ConnStates {
AwaitingName,
AwaitingPassword,
AwaitingNewName,
AwaitingNewPassword,
ConfirmNewPassword,
MainMenu,
Playing,
Quit,
}
impl ConnStates {
pub async fn execute(
self,
mut client: &mut Client,
response: String,
) -> LinesCodecResult<Self> {
match self {
ConnStates::AwaitingName => {
let mut cmdset = cmdset![CmdProxyNew, CmdProxyAccount];
let cmd: Option<&mut (dyn Command + Send)> = cmdset.get(response);
let errmsg = format!("Error attempting to executing cmd: {:?}", cmd);
do_cmd(
&mut client,
cmd,
"Login with existing account name using `account [name] or enter `new`",
)
.await
.expect(&errmsg);
Ok(ConnStates::AwaitingName)
}
_ => Ok(ConnStates::Quit),
}
}
}