remove warnings
This commit is contained in:
parent
6232755d47
commit
9f97319c2d
@ -11,7 +11,6 @@ use chrono::prelude::*;
|
|||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
|
|
||||||
use player::{Player, Score};
|
use player::{Player, Score};
|
||||||
use mob::{bot_player, instance_mobs};
|
|
||||||
use game::{Game};
|
use game::{Game};
|
||||||
use item::{Item};
|
use item::{Item};
|
||||||
use vbox;
|
use vbox;
|
||||||
@ -504,6 +503,7 @@ impl Instance {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use mob::{bot_player, instance_mobs};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn instance_pve_test() {
|
fn instance_pve_test() {
|
||||||
|
|||||||
@ -9,8 +9,6 @@ use rand::distributions::{WeightedIndex};
|
|||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use construct::{Colours};
|
|
||||||
|
|
||||||
use item::*;
|
use item::*;
|
||||||
|
|
||||||
pub type VboxIndices = Option<HashMap<ItemType, Vec<String>>>;
|
pub type VboxIndices = Option<HashMap<ItemType, Vec<String>>>;
|
||||||
@ -217,6 +215,7 @@ impl Vbox {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use construct::{Colours};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn combine_test() {
|
fn combine_test() {
|
||||||
|
|||||||
@ -42,7 +42,7 @@ impl Account {
|
|||||||
false => None,
|
false => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Player::new(self.id, Some(self.img), &self.name, constructs))
|
Ok(Player::new(self.id, img, &self.name, constructs))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn anonymous() -> Account {
|
pub fn anonymous() -> Account {
|
||||||
@ -103,7 +103,7 @@ pub fn chat_wheel(_db: &Db, _id: Uuid) -> Result<Vec<String>, Error> {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_name(db: &Db, name: &String) -> Result<Account, Error> {
|
pub fn _select_name(db: &Db, name: &String) -> Result<Account, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT id, name, balance, subscribed, img
|
SELECT id, name, balance, subscribed, img
|
||||||
FROM accounts
|
FROM accounts
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use std::time;
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::{err_msg, format_err};
|
use failure::{format_err};
|
||||||
|
|
||||||
use crossbeam_channel::{Sender, Receiver};
|
use crossbeam_channel::{Sender, Receiver};
|
||||||
|
|
||||||
@ -15,7 +15,6 @@ use names;
|
|||||||
|
|
||||||
use rpc::RpcMessage;
|
use rpc::RpcMessage;
|
||||||
use warden::{GameEvent};
|
use warden::{GameEvent};
|
||||||
use mail::Mail;
|
|
||||||
|
|
||||||
pub type EventsTx = Sender<Event>;
|
pub type EventsTx = Sender<Event>;
|
||||||
type Id = Uuid;
|
type Id = Uuid;
|
||||||
@ -35,7 +34,6 @@ pub struct Events {
|
|||||||
pub tx: Sender<Event>,
|
pub tx: Sender<Event>,
|
||||||
rx: Receiver<Event>,
|
rx: Receiver<Event>,
|
||||||
|
|
||||||
mail: Sender<Mail>,
|
|
||||||
warden: Sender<GameEvent>,
|
warden: Sender<GameEvent>,
|
||||||
clients: HashMap<Id, WsClient>,
|
clients: HashMap<Id, WsClient>,
|
||||||
}
|
}
|
||||||
@ -72,12 +70,11 @@ struct WsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Events {
|
impl Events {
|
||||||
pub fn new(tx: Sender<Event>, rx: Receiver<Event>, warden: Sender<GameEvent>, mail: Sender<Mail>) -> Events {
|
pub fn new(tx: Sender<Event>, rx: Receiver<Event>, warden: Sender<GameEvent>) -> Events {
|
||||||
Events {
|
Events {
|
||||||
tx,
|
tx,
|
||||||
rx,
|
rx,
|
||||||
warden,
|
warden,
|
||||||
mail,
|
|
||||||
clients: HashMap::new(),
|
clients: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,17 +98,6 @@ impl Events {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_client(&mut self, id: Id) -> Result<&mut WsClient, Error> {
|
|
||||||
match self.clients.get_mut(&id) {
|
|
||||||
Some(c) => Ok(c),
|
|
||||||
None => Err(format_err!("connection not found id={:?}", id)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_client(&mut self, id: Id) {
|
|
||||||
self.clients.remove(&id);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn event(&mut self, msg: Event) -> Result<(), Error> {
|
fn event(&mut self, msg: Event) -> Result<(), Error> {
|
||||||
match msg {
|
match msg {
|
||||||
Event::Connect(id, account, tx) => {
|
Event::Connect(id, account, tx) => {
|
||||||
@ -157,7 +143,7 @@ impl Events {
|
|||||||
trace!("unsubscribe id={:?} object={:?}", id, obj);
|
trace!("unsubscribe id={:?} object={:?}", id, obj);
|
||||||
|
|
||||||
match self.clients.get_mut(&id) {
|
match self.clients.get_mut(&id) {
|
||||||
Some(mut client) => {
|
Some(client) => {
|
||||||
client.subs.remove(&obj);
|
client.subs.remove(&obj);
|
||||||
trace!("unsubscribe subscriptions removed={:?}", client.subs.len());
|
trace!("unsubscribe subscriptions removed={:?}", client.subs.len());
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -194,7 +180,9 @@ impl Events {
|
|||||||
|
|
||||||
if !dead.is_empty() {
|
if !dead.is_empty() {
|
||||||
trace!("dead connections={:?}", dead.len());
|
trace!("dead connections={:?}", dead.len());
|
||||||
dead.iter().for_each(|id| self.remove_client(*id));
|
for id in dead.iter() {
|
||||||
|
self.clients.remove(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!("push subscribers={:?}", subs);
|
trace!("push subscribers={:?}", subs);
|
||||||
|
|||||||
@ -111,7 +111,7 @@ pub fn json_response(status: status::Status, response: Json) -> Response {
|
|||||||
return Response::with((content_type, status, json));
|
return Response::with((content_type, status, json));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn json_object(status: status::Status, object: String) -> Response {
|
pub fn _json_object(status: status::Status, object: String) -> Response {
|
||||||
let content_type = "application/json".parse::<Mime>().unwrap();
|
let content_type = "application/json".parse::<Mime>().unwrap();
|
||||||
return Response::with((content_type, status, object));
|
return Response::with((content_type, status, object));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ enum ConstructShapes {
|
|||||||
Line,
|
Line,
|
||||||
V,
|
V,
|
||||||
Tri,
|
Tri,
|
||||||
Plus,
|
// Plus,
|
||||||
Blank,
|
Blank,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +203,7 @@ pub fn shapes_write(id: Uuid) -> Result<Uuid, Error> {
|
|||||||
write!(&mut svg, "<path stroke=\"{fill}\" stroke-width=\"{width}\" d=\"M{x0} {y0}L 0 0 M{x1} {y1}L 0 0 M{x2} {y2}L 0 0 \" transform=\"translate({x_translate}, {y_translate}) rotate({rotation})\" />",
|
write!(&mut svg, "<path stroke=\"{fill}\" stroke-width=\"{width}\" d=\"M{x0} {y0}L 0 0 M{x1} {y1}L 0 0 M{x2} {y2}L 0 0 \" transform=\"translate({x_translate}, {y_translate}) rotate({rotation})\" />",
|
||||||
fill = colour, width = width, x0 = x0, y0 = y0, x1 = x1, y1 = y1, x2 = x2, y2 = y2, rotation = rotation, x_translate = -x_translate, y_translate = -y_translate)?;
|
fill = colour, width = width, x0 = x0, y0 = y0, x1 = x1, y1 = y1, x2 = x2, y2 = y2, rotation = rotation, x_translate = -x_translate, y_translate = -y_translate)?;
|
||||||
},
|
},
|
||||||
ConstructShapes::Plus => {
|
// ConstructShapes::Plus => { },
|
||||||
|
|
||||||
},
|
|
||||||
ConstructShapes::Blank => (),
|
ConstructShapes::Blank => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,11 +122,11 @@ pub fn start() {
|
|||||||
let warden_tick_tx = warden_tx.clone();
|
let warden_tick_tx = warden_tx.clone();
|
||||||
|
|
||||||
let (mail_tx, mail_rx) = unbounded();
|
let (mail_tx, mail_rx) = unbounded();
|
||||||
let http_mail_tx = mail_tx.clone();
|
let _http_mail_tx = mail_tx.clone();
|
||||||
|
|
||||||
// create a clone of the tx so ws handler can tell events
|
// create a clone of the tx so ws handler can tell events
|
||||||
// about connection status
|
// about connection status
|
||||||
let events = events::Events::new(events_tx, events_rx, events_warden_tx, mail_tx);
|
let events = events::Events::new(events_tx, events_rx, events_warden_tx);
|
||||||
let warden = warden::Warden::new(warden_tx, warden_rx, events.tx.clone(), pool.clone());
|
let warden = warden::Warden::new(warden_tx, warden_rx, events.tx.clone(), pool.clone());
|
||||||
|
|
||||||
let pg_pool = pool.clone();
|
let pg_pool = pool.clone();
|
||||||
|
|||||||
@ -261,7 +261,7 @@ pub fn set(tx: &mut Transaction, account: Uuid, email: &String) -> Result<(Uuid,
|
|||||||
return Ok((id, confirm_token));
|
return Ok((id, confirm_token));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listen(rx: Receiver<Mail>) -> SmtpTransport {
|
pub fn listen(_rx: Receiver<Mail>) -> SmtpTransport {
|
||||||
let sender = env::var("MAIL_ADDRESS")
|
let sender = env::var("MAIL_ADDRESS")
|
||||||
.expect("MAIL_ADDRESS must be set");
|
.expect("MAIL_ADDRESS must be set");
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ pub fn listen(rx: Receiver<Mail>) -> SmtpTransport {
|
|||||||
let domain = env::var("MAIL_DOMAIN")
|
let domain = env::var("MAIL_DOMAIN")
|
||||||
.expect("MAIL_DOMAIN must be set");
|
.expect("MAIL_DOMAIN must be set");
|
||||||
|
|
||||||
let mut mailer = SmtpClient::new_simple("smtp.gmail.com").unwrap()
|
let mailer = SmtpClient::new_simple("smtp.gmail.com").unwrap()
|
||||||
.hello_name(ClientId::Domain(domain))
|
.hello_name(ClientId::Domain(domain))
|
||||||
.credentials(Credentials::new(sender, password))
|
.credentials(Credentials::new(sender, password))
|
||||||
.smtp_utf8(true)
|
.smtp_utf8(true)
|
||||||
@ -281,19 +281,6 @@ pub fn listen(rx: Receiver<Mail>) -> SmtpTransport {
|
|||||||
|
|
||||||
info!("mail connected");
|
info!("mail connected");
|
||||||
|
|
||||||
// loop {
|
|
||||||
// match rx.recv() {
|
|
||||||
// Ok(m) => match send_mail(&mut mailer, m) {
|
|
||||||
// Ok(r) => info!("{:?}", r),
|
|
||||||
// Err(e) => warn!("{:?}", e),
|
|
||||||
// },
|
|
||||||
// Err(e) => {
|
|
||||||
// error!("{:?}", e);
|
|
||||||
// panic!("mail thread cannot continue");
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Explicitly close the SMTP transaction as we enabled connection reuse
|
// Explicitly close the SMTP transaction as we enabled connection reuse
|
||||||
// mailer.close();
|
// mailer.close();
|
||||||
return mailer;
|
return mailer;
|
||||||
|
|||||||
@ -86,7 +86,7 @@ impl Mtx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
|
pub fn _delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
|
||||||
let query = "
|
let query = "
|
||||||
DELETE
|
DELETE
|
||||||
FROM mtx
|
FROM mtx
|
||||||
|
|||||||
@ -143,7 +143,7 @@ pub fn listen(pool: PgPool, events: Sender<Event>) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn construct_delete(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<(), Error> {
|
pub fn _construct_delete(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<(), Error> {
|
||||||
let query = "
|
let query = "
|
||||||
DELETE
|
DELETE
|
||||||
FROM constructs
|
FROM constructs
|
||||||
@ -163,7 +163,7 @@ pub fn construct_delete(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Res
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn construct_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Construct, Error> {
|
pub fn _construct_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Construct, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT data
|
SELECT data
|
||||||
FROM constructs
|
FROM constructs
|
||||||
@ -290,7 +290,7 @@ pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> {
|
|||||||
return Ok(game);
|
return Ok(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select(db: &Db, id: Uuid) -> Result<Game, Error> {
|
pub fn _game_select(db: &Db, id: Uuid) -> Result<Game, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM games
|
FROM games
|
||||||
@ -312,7 +312,7 @@ pub fn select(db: &Db, id: Uuid) -> Result<Game, Error> {
|
|||||||
return Ok(game);
|
return Ok(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list(db: &Db, number: u32) -> Result<Vec<Game>, Error> {
|
pub fn _game_list(db: &Db, number: u32) -> Result<Vec<Game>, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT data
|
SELECT data
|
||||||
FROM games
|
FROM games
|
||||||
@ -815,7 +815,7 @@ pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uu
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bot_instance() -> Instance {
|
pub fn _bot_instance() -> Instance {
|
||||||
let mut instance = Instance::new();
|
let mut instance = Instance::new();
|
||||||
|
|
||||||
let bot_player = bot_player();
|
let bot_player = bot_player();
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
use std::time::{Duration};
|
use std::time::{Duration};
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crossbeam_channel::{tick, Sender, Receiver};
|
use crossbeam_channel::{tick, Sender, Receiver};
|
||||||
|
|
||||||
// Db Commons
|
// Db Commons
|
||||||
@ -24,13 +22,12 @@ use pg::{
|
|||||||
pvp,
|
pvp,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Id = usize;
|
|
||||||
type Pair = (PvpRequest, PvpRequest);
|
type Pair = (PvpRequest, PvpRequest);
|
||||||
|
|
||||||
pub enum GameEvent {
|
pub enum GameEvent {
|
||||||
Upkeep,
|
Upkeep,
|
||||||
|
|
||||||
Finish(Uuid),
|
// Finish(Uuid),
|
||||||
|
|
||||||
Match(Pair),
|
Match(Pair),
|
||||||
}
|
}
|
||||||
@ -76,10 +73,10 @@ impl Warden {
|
|||||||
match msg {
|
match msg {
|
||||||
GameEvent::Upkeep => self.on_upkeep(),
|
GameEvent::Upkeep => self.on_upkeep(),
|
||||||
GameEvent::Match(pair) => self.on_match(pair),
|
GameEvent::Match(pair) => self.on_match(pair),
|
||||||
GameEvent::Finish(id) => {
|
// GameEvent::Finish(id) => {
|
||||||
info!("game finished id={:?}", id);
|
// info!("game finished id={:?}", id);
|
||||||
Ok(())
|
// Ok(())
|
||||||
},
|
// },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +128,7 @@ impl Warden {
|
|||||||
fn fetch_games(mut tx: Transaction) -> Result<Transaction, Error> {
|
fn fetch_games(mut tx: Transaction) -> Result<Transaction, Error> {
|
||||||
let games = games_need_upkeep(&mut tx)?;
|
let games = games_need_upkeep(&mut tx)?;
|
||||||
|
|
||||||
for mut game in games {
|
for game in games {
|
||||||
let game = game.upkeep();
|
let game = game.upkeep();
|
||||||
match game_update(&mut tx, &game) {
|
match game_update(&mut tx, &game) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
@ -146,7 +143,7 @@ fn fetch_games(mut tx: Transaction) -> Result<Transaction, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_instances(mut tx: Transaction) -> Result<Transaction, Error> {
|
fn fetch_instances(mut tx: Transaction) -> Result<Transaction, Error> {
|
||||||
for mut instance in instances_need_upkeep(&mut tx)? {
|
for instance in instances_need_upkeep(&mut tx)? {
|
||||||
let (instance, new_game) = instance.upkeep();
|
let (instance, new_game) = instance.upkeep();
|
||||||
|
|
||||||
if let Some(game) = new_game {
|
if let Some(game) = new_game {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user