rust/hedgewars-checker/src/main.rs
author unc0rr
Wed, 24 Oct 2018 00:08:23 +0200
changeset 13953 e98e2fc556a7
parent 13952 d12ca66054aa
child 13955 a857cd1cc3f0
permissions -rw-r--r--
Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     1
#[macro_use]
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     2
extern crate log;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     3
extern crate argparse;
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
     4
extern crate base64;
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     5
extern crate dirs;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     6
extern crate ini;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     7
extern crate netbuf;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
     8
extern crate stderrlog;
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
     9
extern crate tempfile;
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    10
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    11
use argparse::{ArgumentParser, Store};
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    12
use ini::Ini;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    13
use netbuf::Buf;
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    14
use std::io::Write;
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    15
use std::net::TcpStream;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    16
use std::process::Command;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    17
use std::str::FromStr;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    18
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    19
type CheckError = Box<std::error::Error>;
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    20
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    21
fn extract_packet(buf: &mut Buf) -> Option<netbuf::Buf> {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    22
    let packet_end = (&buf[..]).windows(2).position(|window| window == b"\n\n")?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    23
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    24
    let mut tail = buf.split_off(packet_end);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    25
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    26
    std::mem::swap(&mut tail, buf);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    27
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    28
    buf.consume(2);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    29
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    30
    Some(tail)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    31
}
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    32
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    33
fn check(executable: &str, data_prefix: &str, buffer: &[u8]) -> Result<Vec<Vec<u8>>, CheckError> {
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    34
    let mut replay = tempfile::NamedTempFile::new()?;
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    35
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    36
    for line in buffer.split(|b| *b == '\n' as u8) {
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    37
        replay.write(&base64::decode(line)?);
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    38
    }
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    39
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    40
    let temp_file_path = replay.path();
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    41
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    42
    let mut home_dir = dirs::home_dir().unwrap();
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    43
    home_dir.push(".hedgewars");
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    44
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    45
    let output = Command::new(executable)
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    46
        .arg("--user-prefix")
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    47
        .arg(&home_dir)
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    48
        .arg("--prefix")
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    49
        .arg(data_prefix)
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    50
        .arg("--nomusic")
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    51
        .arg("--nosound")
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    52
        .arg("--stats-only")
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    53
        .arg(temp_file_path)
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    54
        .output()?;
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    55
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    56
    let mut result = Vec::new();
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    57
    for line in output.stdout.split(|b| *b == '\n' as u8) {
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    58
        result.push(line.to_vec());
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    59
    }
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    60
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    61
    Ok(result)
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    62
}
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    63
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    64
fn connect_and_run(
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    65
    username: &str,
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    66
    password: &str,
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    67
    protocol_number: u32,
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    68
    executable: &str,
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    69
    data_prefix: &str,
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    70
) -> Result<(), CheckError> {
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    71
    info!("Connecting...");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    72
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    73
    let mut stream = TcpStream::connect("hedgewars.org:46631")?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    74
    stream.set_nonblocking(false)?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    75
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    76
    let mut buf = Buf::new();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    77
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    78
    loop {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    79
        buf.read_from(&mut stream)?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    80
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    81
        while let Some(msg) = extract_packet(&mut buf) {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    82
            if msg[..].starts_with(b"CONNECTED") {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    83
                info!("Connected");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    84
                let p = format!(
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    85
                    "CHECKER\n{}\n{}\n{}\n\n",
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    86
                    protocol_number, username, password
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    87
                );
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    88
                stream.write(p.as_bytes())?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    89
            } else if msg[..].starts_with(b"PING") {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    90
                stream.write(b"PONG\n\n")?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    91
            } else if msg[..].starts_with(b"LOGONPASSED") {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    92
                info!("Logged in");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
    93
                stream.write(b"READY\n\n")?;
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    94
            } else if msg[..].starts_with(b"REPLAY") {
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    95
                info!("Got a replay");
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    96
                let result = check(executable, data_prefix, &msg[7..])?;
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    97
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    98
                debug!(
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
    99
                    "Check result: [{}]",
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   100
                    String::from_utf8_lossy(&result.join(&(',' as u8)))
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   101
                );
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   102
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   103
                stream.write(&result.join(&('\n' as u8)))?;
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   104
                stream.write(b"\n\n")?;
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   105
            } else if msg[..].starts_with(b"BYE") {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   106
                warn!("Received BYE: {}", String::from_utf8_lossy(&msg[..]));
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   107
                return Ok(());
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   108
            } else if msg[..].starts_with(b"ERROR") {
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   109
                warn!("Received ERROR: {}", String::from_utf8_lossy(&msg[..]));
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   110
                return Ok(());
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   111
            } else {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   112
                warn!(
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   113
                    "Unknown protocol command: {}",
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   114
                    String::from_utf8_lossy(&msg[..])
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   115
                )
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   116
            }
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   117
        }
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   118
    }
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   119
}
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   120
13953
e98e2fc556a7 Create replay file, run engine, result from it and send it to the server. Not implemented: filtering of engine output.
unc0rr
parents: 13952
diff changeset
   121
fn get_protocol_number(executable: &str) -> std::io::Result<u32> {
13952
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   122
    let output = Command::new(executable).arg("--protocol").output()?;
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   123
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   124
    Ok(u32::from_str(&String::from_utf8(output.stdout).unwrap().as_str()).unwrap_or(55))
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   125
}
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   126
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   127
fn main() {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   128
    stderrlog::new()
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   129
        .verbosity(3)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   130
        .timestamp(stderrlog::Timestamp::Second)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   131
        .module(module_path!())
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   132
        .init()
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   133
        .unwrap();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   134
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   135
    let mut frontend_settings = dirs::home_dir().unwrap();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   136
    frontend_settings.push(".hedgewars/settings.ini");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   137
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   138
    let i = Ini::load_from_file(frontend_settings.to_str().unwrap()).unwrap();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   139
    let username = i.get_from(Some("net"), "nick").unwrap();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   140
    let password = i.get_from(Some("net"), "passwordhash").unwrap();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   141
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   142
    let mut exe = "/usr/local/bin/hwengine".to_string();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   143
    let mut prefix = "/usr/local/share/hedgewars/Data".to_string();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   144
    {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   145
        let mut ap = ArgumentParser::new();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   146
        ap.set_description("Game replay checker for hedgewars.");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   147
        ap.refer(&mut exe)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   148
            .add_option(&["--exe"], Store, "Path to hwengine executable");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   149
        ap.refer(&mut prefix)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   150
            .add_option(&["--prefix"], Store, "Path main Data dir");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   151
        ap.parse_args_or_exit();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   152
    }
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   153
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   154
    info!("Executable: {}", exe);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   155
    info!("Data dir: {}", prefix);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   156
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   157
    let protocol_number = get_protocol_number(&exe.as_str()).unwrap_or_default();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   158
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   159
    info!("Using protocol number {}", protocol_number);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   160
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   161
    connect_and_run(&username, &password, protocol_number, &exe, &prefix);
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   162
}
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   163
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   164
#[cfg(test)]
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   165
#[test]
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   166
fn test() {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   167
    let mut buf = Buf::new();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   168
    buf.extend(b"Hell");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   169
    if let Some(_) = extract_packet(&mut buf) {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   170
        assert!(false)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   171
    }
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   172
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   173
    buf.extend(b"o\n\nWorld");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   174
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   175
    let packet2 = extract_packet(&mut buf).unwrap();
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   176
    assert_eq!(&buf[..], b"World");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   177
    assert_eq!(&packet2[..], b"Hello");
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   178
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   179
    if let Some(_) = extract_packet(&mut buf) {
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   180
        assert!(false)
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   181
    }
d12ca66054aa Start checker implementation in rust
unc0rr
parents:
diff changeset
   182
}