author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 06 Aug 2018 21:41:06 +0200 | |
branch | 0.9.24 |
changeset 13620 | 3561a457c11c |
parent 13124 | 1e39b8749072 |
child 13421 | cdf69667593b |
permissions | -rw-r--r-- |
12135 | 1 |
use server::coretypes::{ServerVar, GameCfg, TeamInfo, HedgehogInfo}; |
12136 | 2 |
use std; |
3 |
use std::ops; |
|
4 |
use std::convert::From; |
|
12135 | 5 |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
6 |
#[derive(PartialEq, Eq, Clone, Debug)] |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
7 |
pub enum HWProtocolMessage { |
12135 | 8 |
// core |
9 |
Ping, |
|
10 |
Pong, |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
11 |
Quit(Option<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
12 |
//Cmd(String, Vec<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
13 |
Global(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
14 |
Watch(String), |
12135 | 15 |
ToggleServerRegisteredOnly, |
16 |
SuperPower, |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
17 |
Info(String), |
12135 | 18 |
// not entered state |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
19 |
Nick(String), |
12135 | 20 |
Proto(u32), |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
21 |
Password(String, String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
22 |
Checker(u32, String, String), |
12135 | 23 |
// lobby |
24 |
List, |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
25 |
Chat(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
26 |
CreateRoom(String, Option<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
27 |
Join(String, Option<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
28 |
Follow(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
29 |
Rnd(Vec<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
30 |
Kick(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
31 |
Ban(String, String, u32), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
32 |
BanIP(String, String, u32), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
33 |
BanNick(String, String, u32), |
12135 | 34 |
BanList, |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
35 |
Unban(String), |
12135 | 36 |
SetServerVar(ServerVar), |
37 |
GetServerVar, |
|
38 |
RestartServer, |
|
39 |
Stats, |
|
40 |
// in room |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
41 |
Part(Option<String>), |
12135 | 42 |
Cfg(GameCfg), |
43 |
AddTeam(TeamInfo), |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
44 |
RemoveTeam(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
45 |
SetHedgehogsNumber(String, u8), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
46 |
SetTeamColor(String, u8), |
12135 | 47 |
ToggleReady, |
48 |
StartGame, |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
49 |
EngineMessage(String), |
12135 | 50 |
RoundFinished, |
51 |
ToggleRestrictJoin, |
|
52 |
ToggleRestrictTeams, |
|
53 |
ToggleRegisteredOnly, |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
54 |
RoomName(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
55 |
Delegate(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
56 |
TeamChat(String), |
12135 | 57 |
MaxTeams(u8), |
58 |
Fix, |
|
59 |
Unfix, |
|
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
60 |
Greeting(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
61 |
CallVote(Option<(String, Option<String>)>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
62 |
Vote(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
63 |
ForceVote(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
64 |
Save(String, String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
65 |
Delete(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
66 |
SaveRoom(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
67 |
LoadRoom(String), |
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
68 |
Malformed, |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
69 |
Empty, |
12135 | 70 |
} |
12136 | 71 |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
72 |
pub enum HWServerMessage { |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
73 |
Ping, |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
74 |
Pong, |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
75 |
Bye(String), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
76 |
Nick(String), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
77 |
LobbyLeft(String), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
78 |
LobbyJoined(Vec<String>), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
79 |
ChatMsg(String, String), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
80 |
ClientFlags(String, Vec<String>), |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
81 |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
82 |
Warning(String), |
12147
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
83 |
Connected(u32), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12146
diff
changeset
|
84 |
Unreachable, |
12136 | 85 |
} |
12141 | 86 |
|
87 |
fn construct_message(msg: & [&str]) -> String { |
|
88 |
let mut m = String::with_capacity(64); |
|
89 |
||
90 |
for s in msg { |
|
91 |
m.push_str(s); |
|
92 |
m.push('\n'); |
|
93 |
} |
|
94 |
m.push('\n'); |
|
95 |
||
96 |
m |
|
97 |
} |
|
98 |
||
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
99 |
impl<'a> HWProtocolMessage { |
12141 | 100 |
pub fn to_raw_protocol(&self) -> String { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
101 |
use self::HWProtocolMessage::*; |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
102 |
match *self { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
103 |
Ping => "PING\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
104 |
Pong => "PONG\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
105 |
Quit(None) => format!("QUIT\n\n"), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
106 |
Quit(Some(ref msg)) => format!("QUIT\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
107 |
Global(ref msg) => format!("CMD\nGLOBAL\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
108 |
Watch(ref name) => format!("CMD\nWATCH\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
109 |
ToggleServerRegisteredOnly => "CMD\nREGISTERED_ONLY\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
110 |
SuperPower => "CMD\nSUPER_POWER\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
111 |
Info(ref info) => format!("CMD\nINFO\n{}\n\n", info), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
112 |
Nick(ref nick) => format!("NICK\n{}\n\n", nick), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
113 |
Proto(version) => format!("PROTO\n{}\n\n", version), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
114 |
Password(ref p, ref s) => format!("PASSWORD\n{}\n{}\n\n", p, s), //? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
115 |
Checker(i, ref n, ref p) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
116 |
format!("CHECKER\n{}\n{}\n{}\n\n", i, n, p), //?, |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
117 |
List => "LIST\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
118 |
Chat(ref msg) => format!("CHAT\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
119 |
CreateRoom(ref name, None) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
120 |
format!("CREATE_ROOM\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
121 |
CreateRoom(ref name, Some(ref password)) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
122 |
format!("CREATE_ROOM\n{}\n{}\n\n", name, password), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
123 |
Join(ref name, None) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
124 |
format!("JOIN\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
125 |
Join(ref name, Some(ref arg)) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
126 |
format!("JOIN\n{}\n{}\n\n", name, arg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
127 |
Follow(ref name) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
128 |
format!("FOLLOW\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
129 |
//Rnd(Vec<String>), ??? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
130 |
Kick(ref name) => format!("KICK\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
131 |
Ban(ref name, ref reason, time) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
132 |
format!("BAN\n{}\n{}\n{}\n\n", name, reason, time), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
133 |
BanIP(ref ip, ref reason, time) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
134 |
format!("BAN_IP\n{}\n{}\n{}\n\n", ip, reason, time), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
135 |
BanNick(ref nick, ref reason, time) => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
136 |
format!("BAN_NICK\n{}\n{}\n{}\n\n", nick, reason, time), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
137 |
BanList => "BANLIST\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
138 |
Unban(ref name) => format!("UNBAN\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
139 |
//SetServerVar(ServerVar), ??? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
140 |
GetServerVar => "GET_SERVER_VAR\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
141 |
RestartServer => "CMD\nRESTART_SERVER\nYES\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
142 |
Stats => "CMD\nSTATS\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
143 |
Part(None) => "CMD\nPART\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
144 |
Part(Some(ref msg)) => format!("CMD\nPART\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
145 |
//Cfg(GameCfg) ?? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
146 |
//AddTeam(TeamInfo) ??, |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
147 |
RemoveTeam(ref name) => format!("REMOVE_TEAM\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
148 |
//SetHedgehogsNumber(String, u8), ?? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
149 |
//SetTeamColor(String, u8), ?? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
150 |
ToggleReady => "TOGGLE_READY\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
151 |
StartGame => "START_GAME\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
152 |
EngineMessage(ref msg) => format!("EM\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
153 |
RoundFinished => "ROUNDFINISHED\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
154 |
ToggleRestrictJoin => "TOGGLE_RESTRICT_JOINS\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
155 |
ToggleRestrictTeams => "TOGGLE_RESTRICT_TEAMS\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
156 |
ToggleRegisteredOnly => "TOGGLE_REGISTERED_ONLY\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
157 |
RoomName(ref name) => format!("ROOM_NAME\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
158 |
Delegate(ref name) => format!("CMD\nDELEGATE\n{}\n\n", name), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
159 |
TeamChat(ref msg) => format!("TEAMCHAT\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
160 |
MaxTeams(count) => format!("CMD\nMAXTEAMS\n{}\n\n", count) , |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
161 |
Fix => "CMD\nFIX\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
162 |
Unfix => "CMD\nUNFIX\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
163 |
Greeting(ref msg) => format!("CMD\nGREETING\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
164 |
//CallVote(Option<(String, Option<String>)>) =>, ?? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
165 |
Vote(ref msg) => format!("CMD\nVOTE\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
166 |
ForceVote(ref msg) => format!("CMD\nFORCE\n{}\n\n", msg), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
167 |
//Save(String, String), ?? |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
168 |
Delete(ref room) => format!("CMD\nDELETE\n{}\n\n", room), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
169 |
SaveRoom(ref room) => format!("CMD\nSAVEROOM\n{}\n\n", room), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
170 |
LoadRoom(ref room) => format!("CMD\nLOADROOM\n{}\n\n", room), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
171 |
Malformed => "A\nQUICK\nBROWN\nHOG\nJUMPS\nOVER\nTHE\nLAZY\nDOG\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
172 |
Empty => "\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
173 |
_ => panic!("Protocol message not yet implemented") |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
174 |
} |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
175 |
} |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
176 |
} |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
177 |
|
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
178 |
impl HWServerMessage { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
179 |
pub fn to_raw_protocol(&self) -> String { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
180 |
use self::HWServerMessage::*; |
12141 | 181 |
match self { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
182 |
&Ping => "PING\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
183 |
&Pong => "PONG\n\n".to_string(), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
184 |
&Connected(protocol_version) |
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
185 |
=> construct_message(&[ |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
186 |
"CONNECTED", |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
187 |
"Hedgewars server http://www.hedgewars.org/", |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
188 |
&protocol_version.to_string() |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12141
diff
changeset
|
189 |
]), |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
190 |
&Bye(ref msg) => construct_message(&["BYE", &msg]), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
191 |
&Nick(ref nick) => construct_message(&["NICK", &nick]), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
192 |
&LobbyLeft(ref nick) |
12152 | 193 |
=> construct_message(&["LOBBY_LEFT", &nick]), |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
194 |
&LobbyJoined(ref nicks) |
12150 | 195 |
=> { |
196 |
let mut v = vec!["LOBBY:JOINED"]; |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
197 |
v.extend(nicks.iter().map(|n| { &n[..] })); |
12150 | 198 |
construct_message(&v) |
199 |
}, |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
200 |
&ClientFlags(ref flags, ref nicks) |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
201 |
=> { |
12152 | 202 |
let mut v = vec!["CLIENT_FLAGS"]; |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
203 |
v.push(&flags[..]); |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
204 |
v.extend(nicks.iter().map(|n| { &n[..] })); |
12152 | 205 |
construct_message(&v) |
206 |
}, |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
207 |
&ChatMsg(ref nick, ref msg) |
12152 | 208 |
=> construct_message(&["CHAT", &nick, &msg]), |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12152
diff
changeset
|
209 |
&Warning(ref msg) |
12152 | 210 |
=> construct_message(&["WARNING", &msg]), |
12146 | 211 |
_ => construct_message(&["ERROR", "UNIMPLEMENTED"]), |
12141 | 212 |
} |
213 |
} |
|
214 |
} |