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