--- a/gameServer2/src/main.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/main.rs Wed Dec 06 23:46:17 2017 +0100
@@ -39,19 +39,19 @@
if event.kind().is_readable() {
match event.token() {
utils::SERVER => server.accept(&poll).unwrap(),
- tok => server.client_readable(&poll, tok).unwrap(),
+ Token(tok) => server.client_readable(&poll, tok).unwrap(),
}
}
if event.kind().is_writable() {
match event.token() {
utils::SERVER => unreachable!(),
- tok => server.client_writable(&poll, tok).unwrap(),
+ Token(tok) => server.client_writable(&poll, tok).unwrap(),
}
}
if event.kind().is_hup() || event.kind().is_error() {
match event.token() {
utils::SERVER => unreachable!(),
- tok => server.client_error(&poll, tok).unwrap(),
+ Token(tok) => server.client_error(&poll, tok).unwrap(),
}
}
}
--- a/gameServer2/src/server/actions.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/actions.rs Wed Dec 06 23:46:17 2017 +0100
@@ -22,12 +22,12 @@
use self::Action::*;
-pub fn run_action(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, action: Action) {
+pub fn run_action(server: &mut HWServer, token: usize, poll: &mio::Poll, action: Action) {
match action {
SendMe(msg) =>
server.send(token, &msg),
SendAllButMe(msg) => {
- for c in server.clients.iter_mut() {
+ for (i, c) in server.clients.iter_mut() {
if c.id != token {
c.send_string(&msg)
}
@@ -57,7 +57,7 @@
let joined_msg;
{
let mut lobby_nicks: Vec<&str> = Vec::new();
- for c in server.clients.iter() {
+ for (_, c) in server.clients.iter() {
if c.room_id.is_some() {
lobby_nicks.push(&c.nick);
}
@@ -71,7 +71,7 @@
]);
},
AddRoom(name, password) => {
- let room_id = server.rooms.insert(HWRoom::new()).ok().expect("Cannot add room");
+ let room_id = server.rooms.insert(HWRoom::new());
{
let r = &mut server.rooms[room_id];
let c = &mut server.clients[token];
--- a/gameServer2/src/server/client.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/client.rs Wed Dec 06 23:46:17 2017 +0100
@@ -1,4 +1,4 @@
-use mio::tcp::*;
+use mio::net::TcpStream;
use mio::*;
use std::io::Write;
use std::io;
@@ -15,8 +15,8 @@
decoder: ProtocolDecoder,
buf_out: netbuf::Buf,
- pub id: Token,
- pub room_id: Option<Token>,
+ pub id: usize,
+ pub room_id: Option<usize>,
pub nick: String,
pub protocol_number: u32,
pub is_master: bool,
@@ -31,7 +31,7 @@
decoder: ProtocolDecoder::new(),
buf_out: netbuf::Buf::new(),
room_id: None,
- id: Token(0),
+ id: 0,
nick: String::new(),
protocol_number: 0,
--- a/gameServer2/src/server/handlers/inroom.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/handlers/inroom.rs Wed Dec 06 23:46:17 2017 +0100
@@ -6,7 +6,7 @@
use protocol::messages::HWProtocolMessage;
use protocol::messages::HWServerMessage::*;
-pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
+pub fn handle(server: &mut HWServer, token: usize, poll: &mio::Poll, message: HWProtocolMessage) {
match message {
_ => warn!("Unimplemented!"),
}
--- a/gameServer2/src/server/handlers/lobby.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/handlers/lobby.rs Wed Dec 06 23:46:17 2017 +0100
@@ -6,14 +6,14 @@
use protocol::messages::HWProtocolMessage;
use protocol::messages::HWServerMessage::*;
-pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
+pub fn handle(server: &mut HWServer, token: usize, poll: &mio::Poll, message: HWProtocolMessage) {
match message {
HWProtocolMessage::Chat(msg) => {
let chat_msg = ChatMsg(&server.clients[token].nick, &msg).to_raw_protocol();
server.react(token, poll, vec![SendAllButMe(chat_msg)]);
},
HWProtocolMessage::CreateRoom(name, password) => {
- let room_exists = server.rooms.iter().find(|&r| r.name == name).is_some();
+ let room_exists = server.rooms.iter().find(|&(_, r)| r.name == name).is_some();
if room_exists {
server.react(token, poll, vec![Warn("Room exists".to_string())]);
} else {
--- a/gameServer2/src/server/handlers/loggingin.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/handlers/loggingin.rs Wed Dec 06 23:46:17 2017 +0100
@@ -6,7 +6,7 @@
use protocol::messages::HWProtocolMessage;
use protocol::messages::HWServerMessage::*;
-pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
+pub fn handle(server: &mut HWServer, token: usize, poll: &mio::Poll, message: HWProtocolMessage) {
match message {
HWProtocolMessage::Nick(nick) =>
if server.clients[token].room_id == None {
--- a/gameServer2/src/server/handlers/mod.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/handlers/mod.rs Wed Dec 06 23:46:17 2017 +0100
@@ -12,7 +12,7 @@
mod lobby;
mod inroom;
-pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
+pub fn handle(server: &mut HWServer, token: usize, poll: &mio::Poll, message: HWProtocolMessage) {
match message {
HWProtocolMessage::Ping =>
server.react(token, poll, vec![SendMe(Pong.to_raw_protocol())]),
--- a/gameServer2/src/server/server.rs Tue Dec 05 11:36:29 2017 -0500
+++ b/gameServer2/src/server/server.rs Wed Dec 06 23:46:17 2017 +0100
@@ -1,5 +1,5 @@
use slab;
-use mio::tcp::*;
+use mio::net::*;
use mio::*;
use std::io;
@@ -7,19 +7,19 @@
use super::client::HWClient;
use super::actions;
-type Slab<T> = slab::Slab<T, Token>;
+type Slab<T> = slab::Slab<T>;
pub struct HWServer {
listener: TcpListener,
pub clients: Slab<HWClient>,
pub rooms: Slab<HWRoom>,
- pub lobby_id: Token,
+ pub lobby_id: usize,
}
impl HWServer {
pub fn new(listener: TcpListener, clients_limit: usize, rooms_limit: usize) -> HWServer {
let mut rooms = Slab::with_capacity(rooms_limit);
- let token = rooms.insert(HWRoom::new()).ok().expect("Cannot create lobby");
+ let token = rooms.insert(HWRoom::new());
HWServer {
listener: listener,
clients: Slab::with_capacity(clients_limit),
@@ -38,17 +38,16 @@
info!("Connected: {}", addr);
let client = HWClient::new(sock);
- let token = self.clients.insert(client)
- .ok().expect("could not add connection to slab");
+ let token = self.clients.insert(client);
self.clients[token].id = token;
- self.clients[token].register(poll, token);
+ self.clients[token].register(poll, Token(token));
Ok(())
}
pub fn client_readable(&mut self, poll: &Poll,
- token: Token) -> io::Result<()> {
+ token: usize) -> io::Result<()> {
let actions;
{
actions = self.clients[token].readable(poll);
@@ -60,14 +59,14 @@
}
pub fn client_writable(&mut self, poll: &Poll,
- token: Token) -> io::Result<()> {
+ token: usize) -> io::Result<()> {
self.clients[token].writable(poll)?;
Ok(())
}
pub fn client_error(&mut self, poll: &Poll,
- token: Token) -> io::Result<()> {
+ token: usize) -> io::Result<()> {
let actions;
{
actions = self.clients[token].error(poll);
@@ -78,11 +77,11 @@
Ok(())
}
- pub fn send(&mut self, token: Token, msg: &String) {
+ pub fn send(&mut self, token: usize, msg: &String) {
self.clients[token].send_string(msg);
}
- pub fn react(&mut self, token: Token, poll: &Poll, actions: Vec<actions::Action>) {
+ pub fn react(&mut self, token: usize, poll: &Poll, actions: Vec<actions::Action>) {
for action in actions {
actions::run_action(self, token, poll, action);
}
@@ -91,7 +90,7 @@
pub struct HWRoom {
- pub id: Token,
+ pub id: usize,
pub name: String,
pub password: Option<String>,
pub protocol_number: u32,
@@ -101,7 +100,7 @@
impl HWRoom {
pub fn new() -> HWRoom {
HWRoom {
- id: Token(0),
+ id: 0,
name: String::new(),
password: None,
protocol_number: 0,