author | unc0rr |
Fri, 27 Jan 2017 23:03:31 +0300 | |
changeset 12146 | 8d8fb85bc09c |
parent 12145 | a482c7a5f6e3 |
child 12147 | 03ccb89820f3 |
permissions | -rw-r--r-- |
12130 | 1 |
use server::coretypes::{ServerVar, GameCfg, TeamInfo, HedgehogInfo}; |
12131 | 2 |
use std; |
3 |
use std::ops; |
|
4 |
use std::convert::From; |
|
12130 | 5 |
|
12131 | 6 |
#[derive(PartialEq, Debug)] |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
7 |
pub enum HWProtocolMessage { |
12130 | 8 |
// core |
9 |
Ping, |
|
10 |
Pong, |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
11 |
Quit(Option<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
12 |
//Cmd(String, Vec<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
13 |
Global(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
14 |
Watch(String), |
12130 | 15 |
ToggleServerRegisteredOnly, |
16 |
SuperPower, |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
17 |
Info(String), |
12130 | 18 |
// not entered state |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
19 |
Nick(String), |
12130 | 20 |
Proto(u32), |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
21 |
Password(String, String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
22 |
Checker(u32, String, String), |
12130 | 23 |
// lobby |
24 |
List, |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
25 |
Chat(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
26 |
CreateRoom(String, Option<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
27 |
Join(String, Option<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
28 |
Follow(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
29 |
Rnd(Vec<String>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
30 |
Kick(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
31 |
Ban(String, String, u32), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
32 |
BanIP(String, String, u32), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
33 |
BanNick(String, String, u32), |
12130 | 34 |
BanList, |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
35 |
Unban(String), |
12130 | 36 |
SetServerVar(ServerVar), |
37 |
GetServerVar, |
|
38 |
RestartServer, |
|
39 |
Stats, |
|
40 |
// in room |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
41 |
Part(Option<String>), |
12130 | 42 |
Cfg(GameCfg), |
43 |
AddTeam(TeamInfo), |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
44 |
RemoveTeam(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
45 |
SetHedgehogsNumber(String, u8), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
46 |
SetTeamColor(String, u8), |
12130 | 47 |
ToggleReady, |
48 |
StartGame, |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
49 |
EngineMessage(String), |
12130 | 50 |
RoundFinished, |
51 |
ToggleRestrictJoin, |
|
52 |
ToggleRestrictTeams, |
|
53 |
ToggleRegisteredOnly, |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
54 |
RoomName(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
55 |
Delegate(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
56 |
TeamChat(String), |
12130 | 57 |
MaxTeams(u8), |
58 |
Fix, |
|
59 |
Unfix, |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
60 |
Greeting(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
61 |
CallVote(Option<(String, Option<String>)>), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
62 |
Vote(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
63 |
ForceVote(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
64 |
Save(String, String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
65 |
Delete(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
66 |
SaveRoom(String), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
67 |
LoadRoom(String), |
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
68 |
Malformed, |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
69 |
Empty, |
12130 | 70 |
} |
12131 | 71 |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
72 |
pub enum HWServerMessage<'a> { |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
73 |
Ping, |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
74 |
Pong, |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
75 |
Bye(&'a str), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
76 |
Nick(&'a str), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
77 |
LobbyLeft(&'a str), |
12145 | 78 |
LobbyJoined(&'a [&'a str]), |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
79 |
|
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
80 |
Connected(u32), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
81 |
Unreachable, |
12131 | 82 |
} |
12136 | 83 |
|
84 |
fn construct_message(msg: & [&str]) -> String { |
|
85 |
let mut m = String::with_capacity(64); |
|
86 |
||
87 |
for s in msg { |
|
88 |
m.push_str(s); |
|
89 |
m.push('\n'); |
|
90 |
} |
|
91 |
m.push('\n'); |
|
92 |
||
93 |
m |
|
94 |
} |
|
95 |
||
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
96 |
impl<'a> HWServerMessage<'a> { |
12136 | 97 |
pub fn to_raw_protocol(&self) -> String { |
98 |
match self { |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
99 |
&HWServerMessage::Ping |
12136 | 100 |
=> "PING\n\n".to_string(), |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
101 |
&HWServerMessage::Pong |
12136 | 102 |
=> "PONG\n\n".to_string(), |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
103 |
&HWServerMessage::Connected(protocol_version) |
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
104 |
=> construct_message(&[ |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
105 |
"CONNECTED", |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
106 |
"Hedgewars server http://www.hedgewars.org/", |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
107 |
&protocol_version.to_string() |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
108 |
]), |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
109 |
&HWServerMessage::Bye(msg) |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
110 |
=> construct_message(&["BYE", &msg]), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
111 |
&HWServerMessage::Nick(nick) |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
112 |
=> construct_message(&["NICK", &nick]), |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
113 |
&HWServerMessage::LobbyLeft(msg) |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
114 |
=> construct_message(&["LOBBY_LEFT", &msg]), |
12145 | 115 |
&HWServerMessage::LobbyJoined(msg) |
116 |
=> { |
|
117 |
let mut v = vec!["LOBBY:JOINED"]; |
|
118 |
v.extend_from_slice(msg); |
|
119 |
construct_message(&v) |
|
120 |
}, |
|
12141 | 121 |
_ => construct_message(&["ERROR", "UNIMPLEMENTED"]), |
12136 | 122 |
} |
123 |
} |
|
124 |
} |