gameServer2/src/protocol/messages.rs
changeset 13483 d79795acaa73
parent 13449 914f9b970f4d
child 13486 8697b235f236
equal deleted inserted replaced
13482:f748a72432f2 13483:d79795acaa73
     1 use server::coretypes::{ServerVar, GameCfg, TeamInfo, HedgehogInfo};
     1 use server::coretypes::{
       
     2     ServerVar, GameCfg, TeamInfo,
       
     3     HedgehogInfo, VoteType
       
     4 };
     2 use std::{ops, convert::From, iter::once};
     5 use std::{ops, convert::From, iter::once};
     3 
     6 
     4 #[derive(PartialEq, Eq, Clone, Debug)]
     7 #[derive(PartialEq, Eq, Clone, Debug)]
     5 pub enum HWProtocolMessage {
     8 pub enum HWProtocolMessage {
     6     // core
     9     // core
    54     TeamChat(String),
    57     TeamChat(String),
    55     MaxTeams(u8),
    58     MaxTeams(u8),
    56     Fix,
    59     Fix,
    57     Unfix,
    60     Unfix,
    58     Greeting(String),
    61     Greeting(String),
    59     CallVote(Option<(String, Option<String>)>),
    62     CallVote(Option<VoteType>),
    60     Vote(String),
    63     Vote(bool),
    61     ForceVote(String),
    64     ForceVote(bool),
    62     Save(String, String),
    65     Save(String, String),
    63     Delete(String),
    66     Delete(String),
    64     SaveRoom(String),
    67     SaveRoom(String),
    65     LoadRoom(String),
    68     LoadRoom(String),
    66     Malformed,
    69     Malformed,
    88     TeamRemove(String),
    91     TeamRemove(String),
    89     TeamAccepted(String),
    92     TeamAccepted(String),
    90     TeamColor(String, u8),
    93     TeamColor(String, u8),
    91     HedgehogsNumber(String, u8),
    94     HedgehogsNumber(String, u8),
    92     ConfigEntry(String, Vec<String>),
    95     ConfigEntry(String, Vec<String>),
       
    96     Kicked,
    93     RunGame,
    97     RunGame,
    94     ForwardEngineMessage(Vec<String>),
    98     ForwardEngineMessage(Vec<String>),
    95     RoundFinished,
    99     RoundFinished,
    96 
   100 
    97     ServerMessage(String),
   101     ServerMessage(String),
    98     Warning(String),
   102     Warning(String),
    99     Error(String),
   103     Error(String),
   100     Connected(u32),
   104     Connected(u32),
   101     Unreachable,
   105     Unreachable,
       
   106 }
       
   107 
       
   108 pub fn server_chat(msg: &str) -> HWServerMessage  {
       
   109     HWServerMessage::ChatMsg{ nick: "[server]".to_string(), msg: msg.to_string() }
   102 }
   110 }
   103 
   111 
   104 impl GameCfg {
   112 impl GameCfg {
   105     pub fn to_protocol(&self) -> (String, Vec<String>) {
   113     pub fn to_protocol(&self) -> (String, Vec<String>) {
   106         use server::coretypes::GameCfg::*;
   114         use server::coretypes::GameCfg::*;
   278             TeamAccepted(name) => msg!["TEAM_ACCEPTED", name],
   286             TeamAccepted(name) => msg!["TEAM_ACCEPTED", name],
   279             TeamColor(name, color) => msg!["TEAM_COLOR", name, color],
   287             TeamColor(name, color) => msg!["TEAM_COLOR", name, color],
   280             HedgehogsNumber(name, number) => msg!["HH_NUM", name, number],
   288             HedgehogsNumber(name, number) => msg!["HH_NUM", name, number],
   281             ConfigEntry(name, values) =>
   289             ConfigEntry(name, values) =>
   282                 construct_message(&["CFG", name], &values),
   290                 construct_message(&["CFG", name], &values),
       
   291             Kicked => msg!["KICKED"],
   283             RunGame => msg!["RUN_GAME"],
   292             RunGame => msg!["RUN_GAME"],
   284             ForwardEngineMessage(em) =>
   293             ForwardEngineMessage(em) =>
   285                 construct_message(&["EM"], &em),
   294                 construct_message(&["EM"], &em),
   286             RoundFinished => msg!["ROUND_FINISHED"],
   295             RoundFinished => msg!["ROUND_FINISHED"],
   287             ChatMsg {nick, msg} => msg!["CHAT", nick, msg],
   296             ChatMsg {nick, msg} => msg!["CHAT", nick, msg],