Start on messages parser
authorunc0rr
Thu, 05 Jan 2017 19:07:01 +0300
changeset 12130 6273f89ab13d
parent 12129 07972a8c2433
child 12131 a4d22f197bd2
Start on messages parser
gameServer2/Cargo.toml
gameServer2/build.rs
gameServer2/src/protocol.rs
gameServer2/src/protocol/hwprotocol.lalrpop
gameServer2/src/protocol/messages.rs
gameServer2/src/protocol/mod.rs
gameServer2/src/server/coretypes.rs
gameServer2/src/server/mod.rs
--- a/gameServer2/Cargo.toml	Tue Jan 03 00:19:47 2017 +0300
+++ b/gameServer2/Cargo.toml	Thu Jan 05 19:07:01 2017 +0300
@@ -1,11 +1,15 @@
 [package]
-
 name = "hedgewars-server"
 version = "0.0.1"
 authors = [ "Andrey Korotaev <a.korotaev@hedgewars.org>" ]
+build = "build.rs"
 
 [dependencies]
 rand = "0.3"
 mio = "0.6"
 slab = "0.3"
 netbuf = "0.3.8"
+lalrpop-util = "0.12.4"
+
+[build-dependencies]
+lalrpop = "0.12.4"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/build.rs	Thu Jan 05 19:07:01 2017 +0300
@@ -0,0 +1,5 @@
+extern crate lalrpop;
+
+fn main() {
+    lalrpop::process_root().unwrap();
+}
--- a/gameServer2/src/protocol.rs	Tue Jan 03 00:19:47 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-use netbuf;
-use std::io::Read;
-use std::io::Result;
-
-
-pub struct FrameDecoder {
-    buf: netbuf::Buf,
-}
-
-impl FrameDecoder {
-    pub fn new() -> FrameDecoder {
-        FrameDecoder {
-            buf: netbuf::Buf::new()
-        }
-    }
-
-    pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
-        self.buf.read_from(stream)
-    }
-
-    pub fn extract_messages(&mut self) -> &[u8] {
-        &self.buf[..]
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/protocol/hwprotocol.lalrpop	Thu Jan 05 19:07:01 2017 +0300
@@ -0,0 +1,17 @@
+use std::str;
+
+use super::messages::HWProtocolMessage::*;
+use super::messages::HWProtocolMessage;
+
+grammar;
+
+pub ProtocolMessage: HWProtocolMessage<'input> = {
+    "NICK" <s:Str> => Nick(s),
+};
+
+Str: &'input str = {
+    <s:r"[^\n]\n"> => s,
+};
+
+
+//Num32: i32 = <s:r"[0-9]+"> => i32::from_str(s).unwrap();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/protocol/messages.rs	Thu Jan 05 19:07:01 2017 +0300
@@ -0,0 +1,65 @@
+use server::coretypes::{ServerVar, GameCfg, TeamInfo, HedgehogInfo};
+
+
+pub enum HWProtocolMessage<'a> {
+    // core
+    Ping,
+    Pong,
+    Quit(Option<&'a str>),
+    //Cmd(&'a str, Vec<&'a str>),
+    Global(&'a str),
+    Watch(&'a str),
+    ToggleServerRegisteredOnly,
+    SuperPower,
+    Info(&'a str),
+    // not entered state
+    Nick(&'a str),
+    Proto(u32),
+    Password(&'a str, &'a str),
+    Checker(&'a str),
+    // 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),
+    BanList,
+    Unban(&'a str),
+    SetServerVar(ServerVar),
+    GetServerVar,
+    RestartServer,
+    Stats,
+    // in room
+    Part(Option<&'a str>),
+    Cfg(GameCfg),
+    AddTeam(TeamInfo),
+    RemoveTeam(&'a str),
+    SetHedgehogsNumber(&'a str, u8),
+    SetTeamColor(&'a str, u8),
+    ToggleReady,
+    StartGame,
+    EngineMessage,
+    RoundFinished,
+    ToggleRestrictJoin,
+    ToggleRestrictTeams,
+    ToggleRegisteredOnly,
+    RoomName(&'a str),
+    Delegate(&'a str),
+    TeamChat(&'a str),
+    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, &'a str),
+    SaveRoom(&'a str),
+    LoadRoom(&'a str),
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/protocol/mod.rs	Thu Jan 05 19:07:01 2017 +0300
@@ -0,0 +1,26 @@
+use netbuf;
+use std::io::Read;
+use std::io::Result;
+
+mod messages;
+mod hwprotocol;
+
+pub struct FrameDecoder {
+    buf: netbuf::Buf,
+}
+
+impl FrameDecoder {
+    pub fn new() -> FrameDecoder {
+        FrameDecoder {
+            buf: netbuf::Buf::new()
+        }
+    }
+
+    pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
+        self.buf.read_from(stream)
+    }
+
+    pub fn extract_messages(&mut self) -> &[u8] {
+        &self.buf[..]
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/server/coretypes.rs	Thu Jan 05 19:07:01 2017 +0300
@@ -0,0 +1,26 @@
+pub enum ServerVar {
+    MOTDNew(String),
+    MOTDOld(String),
+    LatestProto(u32),
+}
+
+pub enum GameCfg {
+
+}
+
+pub struct TeamInfo {
+    name: String,
+    color: u8,
+    grave: String,
+    fort: String,
+    voice_pack: String,
+    flag: String,
+    difficulty: u8,
+    hedgehogs_number: u8,
+    hedgehogs: [HedgehogInfo; 8],
+}
+
+pub struct HedgehogInfo {
+    name: String,
+    hat: String,
+}
--- a/gameServer2/src/server/mod.rs	Tue Jan 03 00:19:47 2017 +0300
+++ b/gameServer2/src/server/mod.rs	Thu Jan 05 19:07:01 2017 +0300
@@ -1,2 +1,3 @@
 pub mod server;
 pub mod client;
+pub mod coretypes;