gameServer2/src/protocol/messages.rs
author unc0rr
Fri, 06 Jan 2017 01:00:21 +0300
changeset 12131 a4d22f197bd2
parent 12130 6273f89ab13d
child 12133 81df2e1f9ae9
permissions -rw-r--r--
Still trying to make parser work
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)]
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
     7
pub enum HWProtocolMessage {
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,
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    11
    Quit(Option<String>),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    12
    //Cmd(String, Vec<String>),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    13
    Global(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    14
    Watch(String),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    15
    ToggleServerRegisteredOnly,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    16
    SuperPower,
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    17
    Info(String),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    18
    // not entered state
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    19
    Nick(String),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    20
    Proto(u32),
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    21
    Password(String, String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    22
    Checker(String),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    23
    // lobby
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    24
    List,
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    25
    Chat(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    26
    CreateRoom(String, Option<String>),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    27
    Join(String, Option<String>),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    28
    Follow(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    29
    Rnd(Vec<String>),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    30
    Kick(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    31
    Ban(String, String, u32),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    32
    BanIP(String, String, u32),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    33
    BanNick(String, String, u32),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    34
    BanList,
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    35
    Unban(String),
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
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    41
    Part(Option<String>),
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),
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    44
    RemoveTeam(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    45
    SetHedgehogsNumber(String, u8),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    46
    SetTeamColor(String, u8),
12130
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    47
    ToggleReady,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    48
    StartGame,
6273f89ab13d Start on messages parser
unc0rr
parents:
diff changeset
    49
    EngineMessage,
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,
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    54
    RoomName(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    55
    Delegate(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    56
    TeamChat(String),
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,
12131
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    60
    Greeting(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    61
    CallVote(Option<(String, Option<String>)>),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    62
    Vote(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    63
    ForceVote(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    64
    Save(String, String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    65
    Delete(String, String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    66
    SaveRoom(String),
a4d22f197bd2 Still trying to make parser work
unc0rr
parents: 12130
diff changeset
    67
    LoadRoom(String),
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
}