rust/hedgewars-server/src/protocol/parser.rs
author alfadur
Mon, 07 Oct 2019 23:53:47 +0300
changeset 15444 c03b2e263488
parent 15124 824472aa4d97
child 15801 f57a3d48072b
permissions -rw-r--r--
add smth
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13431
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     1
/** The parsers for the chat and multiplayer protocol. The main parser is `message`.
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     2
 * # Protocol
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     3
 * All messages consist of `\n`-separated strings. The end of a message is
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     4
 * indicated by a double newline - `\n\n`.
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     5
 *
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     6
 * For example, a nullary command like PING will be actually sent as `PING\n\n`.
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     7
 * A unary command, such as `START_GAME nick` will be actually sent as `START_GAME\nnick\n\n`.
6a818f9192f4 Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13423
diff changeset
     8
 */
15114
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
     9
use nom::{
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    10
    branch::alt,
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    11
    bytes::complete::{tag, tag_no_case, take_until, take_while},
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    12
    character::complete::{newline, not_line_ending},
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
    13
    combinator::{map, peek},
15114
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    14
    error::{ErrorKind, ParseError},
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    15
    multi::separated_list,
15124
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
    16
    sequence::{delimited, pair, preceded, terminated, tuple},
15114
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    17
    Err, IResult,
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    18
};
a7841105493e upgrade to nom5 beta2
alfadur
parents: 15112
diff changeset
    19
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    20
use std::{
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    21
    num::ParseIntError,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    22
    ops::Range,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    23
    str,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    24
    str::{FromStr, Utf8Error},
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    25
};
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents:
diff changeset
    26
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    27
use super::messages::{HwProtocolMessage, HwProtocolMessage::*};
15074
c5a6e8566425 shuffle server files
alfadur
parents: 14795
diff changeset
    28
use crate::core::types::{
14783
b3adc030104b implement server vars
alfadur
parents: 14777
diff changeset
    29
    GameCfg, HedgehogInfo, ServerVar, TeamInfo, VoteType, MAX_HEDGEHOGS_PER_TEAM,
b3adc030104b implement server vars
alfadur
parents: 14777
diff changeset
    30
};
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    31
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    32
#[derive(Debug, PartialEq)]
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    33
pub struct HwProtocolError {}
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    34
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    35
impl HwProtocolError {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    36
    fn new() -> Self {
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    37
        HwProtocolError {}
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    38
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    39
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    40
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    41
impl<I> ParseError<I> for HwProtocolError {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    42
    fn from_error_kind(input: I, kind: ErrorKind) -> Self {
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    43
        HwProtocolError::new()
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    44
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    45
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    46
    fn append(input: I, kind: ErrorKind, other: Self) -> Self {
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    47
        HwProtocolError::new()
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    48
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    49
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    50
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    51
impl From<Utf8Error> for HwProtocolError {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    52
    fn from(_: Utf8Error) -> Self {
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    53
        HwProtocolError::new()
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    54
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    55
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    56
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    57
impl From<ParseIntError> for HwProtocolError {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    58
    fn from(_: ParseIntError) -> Self {
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    59
        HwProtocolError::new()
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    60
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    61
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    62
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    63
pub type HwResult<'a, O> = IResult<&'a [u8], O, HwProtocolError>;
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    64
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    65
fn end_of_message(input: &[u8]) -> HwResult<&[u8]> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    66
    tag("\n\n")(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    67
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    68
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    69
fn convert_utf8(input: &[u8]) -> HwResult<&str> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    70
    match str::from_utf8(input) {
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    71
        Ok(str) => Ok((b"", str)),
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    72
        Err(utf_err) => Result::Err(Err::Failure(utf_err.into())),
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    73
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    74
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    75
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    76
fn convert_from_str<T>(str: &str) -> HwResult<T>
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    77
where
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    78
    T: FromStr<Err = ParseIntError>,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    79
{
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    80
    match T::from_str(str) {
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    81
        Ok(x) => Ok((b"", x)),
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    82
        Err(format_err) => Result::Err(Err::Failure(format_err.into())),
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    83
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    84
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    85
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    86
fn str_line(input: &[u8]) -> HwResult<&str> {
15116
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
    87
    let (i, text) = not_line_ending(input.clone())?;
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
    88
    if i != input {
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
    89
        Ok((i, convert_utf8(text)?.1))
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
    90
    } else {
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
    91
        Err(Err::Error(HwProtocolError::new()))
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
    92
    }
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    93
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    94
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    95
fn a_line(input: &[u8]) -> HwResult<String> {
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
    96
    map(str_line, String::from)(input)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    97
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
    98
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
    99
fn cmd_arg(input: &[u8]) -> HwResult<String> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   100
    let delimiters = b" \n";
15116
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   101
    let (i, str) = take_while(move |c| !delimiters.contains(&c))(input.clone())?;
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   102
    if i != input {
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   103
        Ok((i, convert_utf8(str)?.1.to_string()))
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   104
    } else {
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   105
        Err(Err::Error(HwProtocolError::new()))
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   106
    }
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   107
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   108
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   109
fn u8_line(input: &[u8]) -> HwResult<u8> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   110
    let (i, str) = str_line(input)?;
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   111
    Ok((i, convert_from_str(str)?.1))
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   112
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   113
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   114
fn u16_line(input: &[u8]) -> HwResult<u16> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   115
    let (i, str) = str_line(input)?;
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   116
    Ok((i, convert_from_str(str)?.1))
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   117
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   118
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   119
fn u32_line(input: &[u8]) -> HwResult<u32> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   120
    let (i, str) = str_line(input)?;
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   121
    Ok((i, convert_from_str(str)?.1))
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   122
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   123
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   124
fn yes_no_line(input: &[u8]) -> HwResult<bool> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   125
    alt((
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   126
        map(tag_no_case(b"YES"), |_| true),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   127
        map(tag_no_case(b"NO"), |_| false),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   128
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   129
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   130
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   131
fn opt_arg<'a>(input: &'a [u8]) -> HwResult<'a, Option<String>> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   132
    alt((
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   133
        map(peek(end_of_message), |_| None),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   134
        map(preceded(tag("\n"), a_line), Some),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   135
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   136
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   137
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   138
fn spaces(input: &[u8]) -> HwResult<&[u8]> {
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   139
    preceded(tag(" "), take_while(|c| c == b' '))(input)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   140
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   141
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   142
fn opt_space_arg<'a>(input: &'a [u8]) -> HwResult<'a, Option<String>> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   143
    alt((
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   144
        map(peek(end_of_message), |_| None),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   145
        map(preceded(spaces, a_line), Some),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   146
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   147
}
12134
109e6765b1fc Optional parameters parsing function
unc0rr
parents: 12133
diff changeset
   148
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   149
fn hedgehog_array(input: &[u8]) -> HwResult<[HedgehogInfo; 8]> {
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   150
    fn hedgehog_line(input: &[u8]) -> HwResult<HedgehogInfo> {
15124
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   151
        map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   152
            tuple((terminated(a_line, newline), a_line)),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   153
            |(name, hat)| HedgehogInfo { name, hat },
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   154
        )(input)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   155
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   156
15124
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   157
    let (i, (h1, h2, h3, h4, h5, h6, h7, h8)) = tuple((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   158
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   159
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   160
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   161
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   162
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   163
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   164
        terminated(hedgehog_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   165
        hedgehog_line,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   166
    ))(input)?;
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   167
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   168
    Ok((i, [h1, h2, h3, h4, h5, h6, h7, h8]))
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   169
}
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents:
diff changeset
   170
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   171
fn voting(input: &[u8]) -> HwResult<VoteType> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   172
    alt((
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   173
        map(tag_no_case("PAUSE"), |_| VoteType::Pause),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   174
        map(tag_no_case("NEWSEED"), |_| VoteType::NewSeed),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   175
        map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   176
            preceded(pair(tag_no_case("KICK"), spaces), a_line),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   177
            VoteType::Kick,
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   178
        ),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   179
        map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   180
            preceded(pair(tag_no_case("HEDGEHOGS"), spaces), u8_line),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   181
            VoteType::HedgehogsPerTeam,
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   182
        ),
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   183
        map(preceded(tag_no_case("MAP"), opt_space_arg), VoteType::Map),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   184
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   185
}
12135
23ee939ba66a Add more messages to the parser
unc0rr
parents: 12134
diff changeset
   186
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   187
fn no_arg_message(input: &[u8]) -> HwResult<HwProtocolMessage> {
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   188
    fn message<'a>(
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   189
        name: &'a str,
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   190
        msg: HwProtocolMessage,
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   191
    ) -> impl Fn(&'a [u8]) -> HwResult<'a, HwProtocolMessage> {
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   192
        move |i| map(tag(name), |_| msg.clone())(i)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   193
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   194
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   195
    alt((
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   196
        message("PING", Ping),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   197
        message("PONG", Pong),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   198
        message("LIST", List),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   199
        message("BANLIST", BanList),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   200
        message("GET_SERVER_VAR", GetServerVar),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   201
        message("TOGGLE_READY", ToggleReady),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   202
        message("START_GAME", StartGame),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   203
        message("TOGGLE_RESTRICT_JOINS", ToggleRestrictJoin),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   204
        message("TOGGLE_RESTRICT_TEAMS", ToggleRestrictTeams),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   205
        message("TOGGLE_REGISTERED_ONLY", ToggleRegisteredOnly),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   206
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   207
}
12135
23ee939ba66a Add more messages to the parser
unc0rr
parents: 12134
diff changeset
   208
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   209
fn single_arg_message(input: &[u8]) -> HwResult<HwProtocolMessage> {
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   210
    fn message<'a, T, F, G>(
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   211
        name: &'a str,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   212
        parser: F,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   213
        constructor: G,
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   214
    ) -> impl Fn(&'a [u8]) -> HwResult<'a, HwProtocolMessage>
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   215
    where
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   216
        F: Fn(&[u8]) -> HwResult<T>,
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   217
        G: Fn(T) -> HwProtocolMessage,
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   218
    {
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   219
        map(preceded(tag(name), parser), constructor)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   220
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   221
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   222
    alt((
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   223
        message("NICK\n", a_line, Nick),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   224
        message("INFO\n", a_line, Info),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   225
        message("CHAT\n", a_line, Chat),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   226
        message("PART", opt_arg, Part),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   227
        message("FOLLOW\n", a_line, Follow),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   228
        message("KICK\n", a_line, Kick),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   229
        message("UNBAN\n", a_line, Unban),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   230
        message("EM\n", a_line, EngineMessage),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   231
        message("TEAMCHAT\n", a_line, TeamChat),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   232
        message("ROOM_NAME\n", a_line, RoomName),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   233
        message("REMOVE_TEAM\n", a_line, RemoveTeam),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   234
        message("ROUNDFINISHED", opt_arg, |_| RoundFinished),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   235
        message("PROTO\n", u16_line, Proto),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   236
        message("QUIT", opt_arg, Quit),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   237
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   238
}
12135
23ee939ba66a Add more messages to the parser
unc0rr
parents: 12134
diff changeset
   239
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   240
fn cmd_message<'a>(input: &'a [u8]) -> HwResult<'a, HwProtocolMessage> {
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   241
    fn cmd_no_arg<'a>(
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   242
        name: &'a str,
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   243
        msg: HwProtocolMessage,
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   244
    ) -> impl Fn(&'a [u8]) -> HwResult<'a, HwProtocolMessage> {
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   245
        move |i| map(tag_no_case(name), |_| msg.clone())(i)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   246
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   247
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   248
    fn cmd_single_arg<'a, T, F, G>(
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   249
        name: &'a str,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   250
        parser: F,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   251
        constructor: G,
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   252
    ) -> impl Fn(&'a [u8]) -> HwResult<'a, HwProtocolMessage>
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   253
    where
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   254
        F: Fn(&'a [u8]) -> HwResult<'a, T>,
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   255
        G: Fn(T) -> HwProtocolMessage,
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   256
    {
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   257
        map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   258
            preceded(pair(tag_no_case(name), spaces), parser),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   259
            constructor,
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   260
        )
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   261
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   262
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   263
    fn cmd_no_arg_message(input: &[u8]) -> HwResult<HwProtocolMessage> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   264
        alt((
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   265
            cmd_no_arg("STATS", Stats),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   266
            cmd_no_arg("FIX", Fix),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   267
            cmd_no_arg("UNFIX", Unfix),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   268
            cmd_no_arg("REGISTERED_ONLY", ToggleServerRegisteredOnly),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   269
            cmd_no_arg("SUPER_POWER", SuperPower),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   270
        ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   271
    }
12135
23ee939ba66a Add more messages to the parser
unc0rr
parents: 12134
diff changeset
   272
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   273
    fn cmd_single_arg_message(input: &[u8]) -> HwResult<HwProtocolMessage> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   274
        alt((
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   275
            cmd_single_arg("RESTART_SERVER", |i| tag("YES")(i), |_| RestartServer),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   276
            cmd_single_arg("DELEGATE", a_line, Delegate),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   277
            cmd_single_arg("DELETE", a_line, Delete),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   278
            cmd_single_arg("SAVEROOM", a_line, SaveRoom),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   279
            cmd_single_arg("LOADROOM", a_line, LoadRoom),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   280
            cmd_single_arg("GLOBAL", a_line, Global),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   281
            cmd_single_arg("WATCH", u32_line, Watch),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   282
            cmd_single_arg("VOTE", yes_no_line, Vote),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   283
            cmd_single_arg("FORCE", yes_no_line, ForceVote),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   284
            cmd_single_arg("INFO", a_line, Info),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   285
            cmd_single_arg("MAXTEAMS", u8_line, MaxTeams),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   286
            cmd_single_arg("CALLVOTE", voting, |v| CallVote(Some(v))),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   287
        ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   288
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   289
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   290
    preceded(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   291
        tag("CMD\n"),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   292
        alt((
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   293
            cmd_no_arg_message,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   294
            cmd_single_arg_message,
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   295
            map(tag_no_case("CALLVOTE"), |_| CallVote(None)),
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   296
            map(preceded(tag_no_case("GREETING"), opt_space_arg), Greeting),
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   297
            map(preceded(tag_no_case("PART"), opt_space_arg), Part),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   298
            map(preceded(tag_no_case("QUIT"), opt_space_arg), Quit),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   299
            map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   300
                preceded(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   301
                    tag_no_case("SAVE"),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   302
                    pair(preceded(spaces, cmd_arg), preceded(spaces, cmd_arg)),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   303
                ),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   304
                |(n, l)| Save(n, l),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   305
            ),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   306
            map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   307
                preceded(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   308
                    tag_no_case("RND"),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   309
                    alt((
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   310
                        map(peek(end_of_message), |_| vec![]),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   311
                        preceded(spaces, separated_list(spaces, cmd_arg)),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   312
                    )),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   313
                ),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   314
                Rnd,
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   315
            ),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   316
        )),
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   317
    )(input)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   318
}
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   319
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   320
fn config_message<'a>(input: &'a [u8]) -> HwResult<'a, HwProtocolMessage> {
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   321
    fn cfg_single_arg<'a, T, F, G>(
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   322
        name: &'a str,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   323
        parser: F,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   324
        constructor: G,
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   325
    ) -> impl Fn(&'a [u8]) -> HwResult<'a, GameCfg>
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   326
    where
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   327
        F: Fn(&[u8]) -> HwResult<T>,
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   328
        G: Fn(T) -> GameCfg,
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   329
    {
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   330
        map(preceded(pair(tag(name), newline), parser), constructor)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   331
    }
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   332
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   333
    let (i, cfg) = preceded(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   334
        tag("CFG\n"),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   335
        alt((
15119
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   336
            cfg_single_arg("THEME", a_line, GameCfg::Theme),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   337
            cfg_single_arg("SCRIPT", a_line, GameCfg::Script),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   338
            cfg_single_arg("MAP", a_line, GameCfg::MapType),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   339
            cfg_single_arg("MAPGEN", u32_line, GameCfg::MapGenerator),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   340
            cfg_single_arg("MAZE_SIZE", u32_line, GameCfg::MazeSize),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   341
            cfg_single_arg("TEMPLATE", u32_line, GameCfg::Template),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   342
            cfg_single_arg("FEATURE_SIZE", u32_line, GameCfg::FeatureSize),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   343
            cfg_single_arg("SEED", a_line, GameCfg::Seed),
901751d3cd80 make custom combinators high order
alfadur
parents: 15118
diff changeset
   344
            cfg_single_arg("DRAWNMAP", a_line, GameCfg::DrawnMap),
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   345
            preceded(pair(tag("AMMO"), newline), |i| {
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   346
                let (i, name) = a_line(i)?;
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   347
                let (i, value) = opt_arg(i)?;
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   348
                Ok((i, GameCfg::Ammo(name, value)))
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   349
            }),
15124
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   350
            preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   351
                pair(tag("SCHEME"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   352
                map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   353
                    pair(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   354
                        a_line,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   355
                        alt((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   356
                            map(peek(end_of_message), |_| None),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   357
                            map(preceded(newline, separated_list(newline, a_line)), Some),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   358
                        )),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   359
                    ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   360
                    |(name, values)| GameCfg::Scheme(name, values.unwrap_or_default()),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   361
                ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   362
            ),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   363
        )),
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   364
    )(input)?;
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   365
    Ok((i, Cfg(cfg)))
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   366
}
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents:
diff changeset
   367
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   368
fn server_var_message(input: &[u8]) -> HwResult<HwProtocolMessage> {
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   369
    map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   370
        preceded(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   371
            tag("SET_SERVER_VAR\n"),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   372
            alt((
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   373
                map(preceded(tag("MOTD_NEW\n"), a_line), ServerVar::MOTDNew),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   374
                map(preceded(tag("MOTD_OLD\n"), a_line), ServerVar::MOTDOld),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   375
                map(
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   376
                    preceded(tag("LATEST_PROTO\n"), u16_line),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   377
                    ServerVar::LatestProto,
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   378
                ),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   379
            )),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   380
        ),
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   381
        SetServerVar,
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   382
    )(input)
14783
b3adc030104b implement server vars
alfadur
parents: 14777
diff changeset
   383
}
b3adc030104b implement server vars
alfadur
parents: 14777
diff changeset
   384
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   385
fn complex_message(input: &[u8]) -> HwResult<HwProtocolMessage> {
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   386
    alt((
15124
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   387
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   388
            pair(tag("PASSWORD"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   389
            map(pair(terminated(a_line, newline), a_line), |(pass, salt)| {
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   390
                Password(pass, salt)
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   391
            }),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   392
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   393
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   394
            pair(tag("CHECKER"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   395
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   396
                tuple((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   397
                    terminated(u16_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   398
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   399
                    a_line,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   400
                )),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   401
                |(protocol, name, pass)| Checker(protocol, name, pass),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   402
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   403
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   404
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   405
            pair(tag("CREATE_ROOM"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   406
            map(pair(a_line, opt_arg), |(name, pass)| CreateRoom(name, pass)),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   407
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   408
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   409
            pair(tag("JOIN_ROOM"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   410
            map(pair(a_line, opt_arg), |(name, pass)| JoinRoom(name, pass)),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   411
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   412
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   413
            pair(tag("ADD_TEAM"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   414
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   415
                tuple((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   416
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   417
                    terminated(u8_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   418
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   419
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   420
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   421
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   422
                    terminated(u8_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   423
                    hedgehog_array,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   424
                )),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   425
                |(name, color, grave, fort, voice_pack, flag, difficulty, hedgehogs)| {
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   426
                    AddTeam(Box::new(TeamInfo {
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   427
                        owner: String::new(),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   428
                        name,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   429
                        color,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   430
                        grave,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   431
                        fort,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   432
                        voice_pack,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   433
                        flag,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   434
                        difficulty,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   435
                        hedgehogs,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   436
                        hedgehogs_number: 0,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   437
                    }))
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   438
                },
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   439
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   440
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   441
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   442
            pair(tag("HH_NUM"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   443
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   444
                pair(terminated(a_line, newline), u8_line),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   445
                |(name, count)| SetHedgehogsNumber(name, count),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   446
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   447
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   448
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   449
            pair(tag("TEAM_COLOR"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   450
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   451
                pair(terminated(a_line, newline), u8_line),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   452
                |(name, color)| SetTeamColor(name, color),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   453
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   454
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   455
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   456
            pair(tag("BAN"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   457
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   458
                tuple((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   459
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   460
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   461
                    u32_line,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   462
                )),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   463
                |(name, reason, time)| Ban(name, reason, time),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   464
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   465
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   466
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   467
            pair(tag("BAN_IP"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   468
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   469
                tuple((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   470
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   471
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   472
                    u32_line,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   473
                )),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   474
                |(ip, reason, time)| BanIp(ip, reason, time),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   475
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   476
        ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   477
        preceded(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   478
            pair(tag("BAN_NICK"), newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   479
            map(
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   480
                tuple((
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   481
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   482
                    terminated(a_line, newline),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   483
                    u32_line,
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   484
                )),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   485
                |(nick, reason, time)| BanNick(nick, reason, time),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   486
            ),
824472aa4d97 use tuple parsers
alfadur
parents: 15122
diff changeset
   487
        ),
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   488
    ))(input)
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   489
}
13422
5fb27f94fc3b Implement game config messages
alfadur
parents: 13419
diff changeset
   490
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   491
pub fn malformed_message(input: &[u8]) -> HwResult<()> {
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   492
    map(terminated(take_until(&b"\n\n"[..]), end_of_message), |_| ())(input)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   493
}
12137
193dfdcb0620 - Use logging facilities instead of plain println!
unc0rr
parents: 12136
diff changeset
   494
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   495
pub fn message(input: &[u8]) -> HwResult<HwProtocolMessage> {
15122
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   496
    delimited(
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   497
        take_while(|c| c == b'\n'),
15122
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   498
        alt((
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   499
            no_arg_message,
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   500
            single_arg_message,
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   501
            cmd_message,
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   502
            config_message,
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   503
            server_var_message,
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   504
            complex_message,
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   505
        )),
4f31954a0b81 simplify root parser
alfadur
parents: 15119
diff changeset
   506
        end_of_message,
15118
0e59abde6766 parser cleanup
alfadur
parents: 15116
diff changeset
   507
    )(input)
14775
09d46ab83361 port server parser to nom 5
alfadur
parents: 14457
diff changeset
   508
}
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents:
diff changeset
   509
13796
59ea2403f62d move everything test related into test cfg
alfadur
parents: 13795
diff changeset
   510
#[cfg(test)]
14777
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   511
mod test {
15112
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   512
    use super::message;
15116
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   513
    use crate::{
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   514
        core::types::GameCfg,
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   515
        protocol::{messages::HwProtocolMessage::*, parser::HwProtocolError, test::gen_proto_msg},
15112
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   516
    };
14777
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   517
    use proptest::{proptest, proptest_helper};
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   518
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   519
    #[cfg(test)]
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   520
    proptest! {
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   521
        #[test]
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   522
        fn is_parser_composition_idempotent(ref msg in gen_proto_msg()) {
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   523
            println!("!! Msg: {:?}, Bytes: {:?} !!", msg, msg.to_raw_protocol().as_bytes());
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   524
            assert_eq!(message(msg.to_raw_protocol().as_bytes()), Ok((&b""[..], msg.clone())))
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   525
        }
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   526
    }
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   527
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12142
diff changeset
   528
    #[test]
14777
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   529
    fn parse_test() {
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   530
        assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping)));
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   531
        assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   532
        assert_eq!(
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   533
            message(b"NICK\nit's me\n\n"),
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   534
            Ok((&b""[..], Nick("it's me".to_string())))
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   535
        );
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   536
        assert_eq!(message(b"PROTO\n51\n\n"), Ok((&b""[..], Proto(51))));
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   537
        assert_eq!(
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   538
            message(b"QUIT\nbye-bye\n\n"),
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   539
            Ok((&b""[..], Quit(Some("bye-bye".to_string()))))
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   540
        );
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   541
        assert_eq!(message(b"QUIT\n\n"), Ok((&b""[..], Quit(None))));
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   542
        assert_eq!(
14795
add191d825f4 add parser error handling
alfadur
parents: 14785
diff changeset
   543
            message(b"CMD\nwatch 49471\n\n"),
add191d825f4 add parser error handling
alfadur
parents: 14785
diff changeset
   544
            Ok((&b""[..], Watch(49471)))
14777
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   545
        );
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   546
        assert_eq!(
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   547
            message(b"BAN\nme\nbad\n77\n\n"),
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   548
            Ok((&b""[..], Ban("me".to_string(), "bad".to_string(), 77)))
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   549
        );
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   550
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   551
        assert_eq!(message(b"CMD\nPART\n\n"), Ok((&b""[..], Part(None))));
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   552
        assert_eq!(
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   553
            message(b"CMD\nPART _msg_\n\n"),
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   554
            Ok((&b""[..], Part(Some("_msg_".to_string()))))
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   555
        );
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   556
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   557
        assert_eq!(message(b"CMD\nRND\n\n"), Ok((&b""[..], Rnd(vec![]))));
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   558
        assert_eq!(
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   559
            message(b"CMD\nRND A B\n\n"),
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   560
            Ok((&b""[..], Rnd(vec![String::from("A"), String::from("B")])))
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   561
        );
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   562
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   563
        assert_eq!(
15116
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   564
            message(b"CFG\nSCHEME\na\nA\n\n"),
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   565
            Ok((
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   566
                &b""[..],
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   567
                Cfg(GameCfg::Scheme("a".to_string(), vec!["A".to_string()]))
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   568
            ))
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   569
        );
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   570
cce6e707172f fix lists parsing
alfadur
parents: 15114
diff changeset
   571
        assert_eq!(
14795
add191d825f4 add parser error handling
alfadur
parents: 14785
diff changeset
   572
            message(b"QUIT\n1\n2\n\n"),
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   573
            Err(nom::Err::Error(HwProtocolError::new()))
14777
8015a6e4ca3c move parser tests into test module
alfadur
parents: 14775
diff changeset
   574
        );
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12142
diff changeset
   575
    }
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12142
diff changeset
   576
}