aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/clientloginreject.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2020-09-26 12:01:27 +0200
committerMax Audron <audron@cocaine.farm>2020-09-26 12:03:01 +0200
commit3bdae21716d10032f70a0a889070766bbbe4d141 (patch)
tree78a1ddf98601fbbc03a9375626dfa7923ab85521 /src/message/handshake/clientloginreject.rs
parentadd parsing of signalproxy messages (diff)
split handshake.rs
Diffstat (limited to 'src/message/handshake/clientloginreject.rs')
-rw-r--r--src/message/handshake/clientloginreject.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/message/handshake/clientloginreject.rs b/src/message/handshake/clientloginreject.rs
new file mode 100644
index 0000000..e8380d6
--- /dev/null
+++ b/src/message/handshake/clientloginreject.rs
@@ -0,0 +1,46 @@
+use crate::error::ProtocolError;
+use crate::primitive::{Variant, VariantMap};
+use crate::{HandshakeDeserialize, HandshakeSerialize};
+
+use failure::Error;
+
+/// ClientLoginReject is received after the client failed to login
+/// It contains an error message as String
+#[derive(Debug)]
+pub struct ClientLoginReject {
+ error: String,
+}
+
+impl HandshakeSerialize for ClientLoginReject {
+ fn serialize(&self) -> Result<Vec<u8>, Error> {
+ let mut values: VariantMap = VariantMap::with_capacity(1);
+ values.insert(
+ "MsgType".to_string(),
+ Variant::String("ClientLoginReject".to_string()),
+ );
+ values.insert(
+ "ErrorString".to_string(),
+ Variant::String(self.error.clone()),
+ );
+ return HandshakeSerialize::serialize(&values);
+ }
+}
+
+impl HandshakeDeserialize for ClientLoginReject {
+ fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
+
+ let msgtype = match_variant!(&values["MsgType"], Variant::StringUTF8);
+
+ if msgtype == "ClientLogin" {
+ return Ok((
+ len,
+ Self {
+ error: match_variant!(values["ErrorString"], Variant::String),
+ },
+ ));
+ } else {
+ bail!(ProtocolError::WrongMsgType);
+ }
+ }
+}