gameServer2/src/protocol/messages.rs
author unc0rr
Wed, 11 Jan 2017 17:39:21 +0300
changeset 12134 109e6765b1fc
parent 12133 81df2e1f9ae9
child 12135 23ee939ba66a
permissions -rw-r--r--
Optional parameters parsing function
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
     1
use server::coretypes::{ServerVar, GameCfg, TeamInfo, HedgehogInfo};
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
     2
use std;
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
     3
use std::ops;
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
     4
use std::convert::From;
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
     5
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
     6
#[derive(PartialEq, Debug)]
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
     7
pub enum HWProtocolMessage<'a> {
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
     8
    // core
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
     9
    Ping,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    10
    Pong,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    11
    Quit(Option<&'a str>),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    12
    //Cmd(&'a str, Vec<&'a str>),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    13
    Global(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    14
    Watch(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    15
    ToggleServerRegisteredOnly,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    16
    SuperPower,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    17
    Info(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    18
    // not entered state
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    19
    Nick(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    20
    Proto(u32),
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    21
    Password(&'a str, &'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    22
    Checker(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    23
    // lobby
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    24
    List,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    25
    Chat(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    26
    CreateRoom(&'a str, Option<&'a str>),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    27
    Join(&'a str, Option<&'a str>),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    28
    Follow(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    29
    Rnd(Vec<&'a str>),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    30
    Kick(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    31
    Ban(&'a str, &'a str, u32),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    32
    BanIP(&'a str, &'a str, u32),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    33
    BanNick(&'a str, &'a str, u32),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    34
    BanList,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    35
    Unban(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    36
    SetServerVar(ServerVar),
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    37
    GetServerVar,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    38
    RestartServer,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    39
    Stats,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    40
    // in room
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    41
    Part(Option<&'a str>),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    42
    Cfg(GameCfg),
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    43
    AddTeam(TeamInfo),
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    44
    RemoveTeam(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    45
    SetHedgehogsNumber(&'a str, u8),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    46
    SetTeamColor(&'a str, u8),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    47
    ToggleReady,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    48
    StartGame,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    49
    EngineMessage(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    50
    RoundFinished,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    51
    ToggleRestrictJoin,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    52
    ToggleRestrictTeams,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    53
    ToggleRegisteredOnly,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    54
    RoomName(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    55
    Delegate(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    56
    TeamChat(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    57
    MaxTeams(u8),
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    58
    Fix,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    59
    Unfix,
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    60
    Greeting(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    61
    CallVote(Option<(&'a str, Option<&'a str>)>),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    62
    Vote(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    63
    ForceVote(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    64
    Save(&'a str, &'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    65
    Delete(&'a str, &'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    66
    SaveRoom(&'a str),
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12131
diff changeset
    67
    LoadRoom(&'a str),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    68
}
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    69
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    70
pub fn number<T: From<u8>
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    71
                + std::default::Default
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    72
                + std::ops::MulAssign
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    73
                + std::ops::AddAssign>
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    74
    (digits: Vec<u8>) -> T {
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    75
    let mut value: T = T::default();
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    76
    for digit in digits {
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    77
        value *= T::from(10);
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    78
        value += T::from(digit);
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    79
    }
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    80
    value
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    81
}