gameServer2/src/protocol/messages.rs
changeset 12142 4d7d41be1993
parent 12141 78925eff02c2
child 12145 a482c7a5f6e3
--- a/gameServer2/src/protocol/messages.rs	Wed Jan 18 22:54:02 2017 +0300
+++ b/gameServer2/src/protocol/messages.rs	Mon Jan 23 23:43:29 2017 +0300
@@ -4,85 +4,80 @@
 use std::convert::From;
 
 #[derive(PartialEq, Debug)]
-pub enum HWProtocolMessage<'a> {
+pub enum HWProtocolMessage {
     // core
     Ping,
     Pong,
-    Quit(Option<&'a str>),
-    Bye(&'a str),
-    LobbyLeft(&'a str),
-    //Cmd(&'a str, Vec<&'a str>),
-    Global(&'a str),
-    Watch(&'a str),
+    Quit(Option<String>),
+    //Cmd(String, Vec<String>),
+    Global(String),
+    Watch(String),
     ToggleServerRegisteredOnly,
     SuperPower,
-    Info(&'a str),
+    Info(String),
     // not entered state
-    Nick(&'a str),
+    Nick(String),
     Proto(u32),
-    Password(&'a str, &'a str),
-    Checker(u32, &'a str, &'a str),
+    Password(String, String),
+    Checker(u32, String, String),
     // lobby
     List,
-    Chat(&'a str),
-    CreateRoom(&'a str, Option<&'a str>),
-    Join(&'a str, Option<&'a str>),
-    Follow(&'a str),
-    Rnd(Vec<&'a str>),
-    Kick(&'a str),
-    Ban(&'a str, &'a str, u32),
-    BanIP(&'a str, &'a str, u32),
-    BanNick(&'a str, &'a str, u32),
+    Chat(String),
+    CreateRoom(String, Option<String>),
+    Join(String, Option<String>),
+    Follow(String),
+    Rnd(Vec<String>),
+    Kick(String),
+    Ban(String, String, u32),
+    BanIP(String, String, u32),
+    BanNick(String, String, u32),
     BanList,
-    Unban(&'a str),
+    Unban(String),
     SetServerVar(ServerVar),
     GetServerVar,
     RestartServer,
     Stats,
     // in room
-    Part(Option<&'a str>),
+    Part(Option<String>),
     Cfg(GameCfg),
     AddTeam(TeamInfo),
-    RemoveTeam(&'a str),
-    SetHedgehogsNumber(&'a str, u8),
-    SetTeamColor(&'a str, u8),
+    RemoveTeam(String),
+    SetHedgehogsNumber(String, u8),
+    SetTeamColor(String, u8),
     ToggleReady,
     StartGame,
-    EngineMessage(&'a str),
+    EngineMessage(String),
     RoundFinished,
     ToggleRestrictJoin,
     ToggleRestrictTeams,
     ToggleRegisteredOnly,
-    RoomName(&'a str),
-    Delegate(&'a str),
-    TeamChat(&'a str),
+    RoomName(String),
+    Delegate(String),
+    TeamChat(String),
     MaxTeams(u8),
     Fix,
     Unfix,
-    Greeting(&'a str),
-    CallVote(Option<(&'a str, Option<&'a str>)>),
-    Vote(&'a str),
-    ForceVote(&'a str),
-    Save(&'a str, &'a str),
-    Delete(&'a str),
-    SaveRoom(&'a str),
-    LoadRoom(&'a str),
-    Connected(u32),
+    Greeting(String),
+    CallVote(Option<(String, Option<String>)>),
+    Vote(String),
+    ForceVote(String),
+    Save(String, String),
+    Delete(String),
+    SaveRoom(String),
+    LoadRoom(String),
     Malformed,
     Empty,
 }
 
-pub fn number<T: From<u8>
-                + std::default::Default
-                + std::ops::MulAssign
-                + std::ops::AddAssign>
-    (digits: Vec<u8>) -> T {
-    let mut value: T = T::default();
-    for digit in digits {
-        value *= T::from(10);
-        value += T::from(digit);
-    }
-    value
+pub enum HWServerMessage<'a> {
+    Ping,
+    Pong,
+    Bye(&'a str),
+    Nick(&'a str),
+    LobbyLeft(&'a str),
+
+    Connected(u32),
+    Unreachable,
 }
 
 fn construct_message(msg: & [&str]) -> String {
@@ -97,25 +92,25 @@
     m
 }
 
-impl<'a> HWProtocolMessage<'a> {
+impl<'a> HWServerMessage<'a> {
     pub fn to_raw_protocol(&self) -> String {
         match self {
-            &HWProtocolMessage::Ping
+            &HWServerMessage::Ping
                 => "PING\n\n".to_string(),
-            &HWProtocolMessage::Pong
+            &HWServerMessage::Pong
                 => "PONG\n\n".to_string(),
-            &HWProtocolMessage::Connected(protocol_version)
+            &HWServerMessage::Connected(protocol_version)
                 => construct_message(&[
                     "CONNECTED",
                     "Hedgewars server http://www.hedgewars.org/",
                     &protocol_version.to_string()
                 ]),
-            &HWProtocolMessage::Bye(msg)
-                => construct_message(&["BYE", msg]),
-            &HWProtocolMessage::Nick(nick)
-            => construct_message(&["NICK", nick]),
-            &HWProtocolMessage::LobbyLeft(msg)
-                => construct_message(&["LOBBY_LEFT", msg]),
+            &HWServerMessage::Bye(msg)
+                => construct_message(&["BYE", &msg]),
+            &HWServerMessage::Nick(nick)
+            => construct_message(&["NICK", &nick]),
+            &HWServerMessage::LobbyLeft(msg)
+                => construct_message(&["LOBBY_LEFT", &msg]),
             _ => construct_message(&["ERROR", "UNIMPLEMENTED"]),
         }
     }