From 67f62c659a6b032e34e290067bbe0303df726214 Mon Sep 17 00:00:00 2001 From: ntr Date: Fri, 12 Oct 2018 12:34:47 +1100 Subject: [PATCH] threads per ws maybe? --- client/src/components/battle.jsx | 4 ++-- client/src/components/cryp.list.jsx | 4 ++-- server/WORKLOG.md | 1 + server/src/battle.rs | 4 ++-- server/src/combat.rs | 3 ++- server/src/cryp.rs | 6 +++--- server/src/net.rs | 10 +++++++++- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/client/src/components/battle.jsx b/client/src/components/battle.jsx index c13d8418..0eaad396 100644 --- a/client/src/components/battle.jsx +++ b/client/src/components/battle.jsx @@ -4,8 +4,8 @@ function CrypPanel({ battle }) { if (!battle) return
...
; return (
- {JSON.stringify(battle.a)} - {JSON.stringify(battle.b)} +
{JSON.stringify(battle.a)}
+
{JSON.stringify(battle.b)}
diff --git a/client/src/components/cryp.list.jsx b/client/src/components/cryp.list.jsx index a3b57604..ce7091b2 100644 --- a/client/src/components/cryp.list.jsx +++ b/client/src/components/cryp.list.jsx @@ -1,6 +1,6 @@ const preact = require('preact'); -function CrypPanel({ cryps, sendCombatPve }) { +function CrypList({ cryps, sendCombatPve }) { if (!cryps) return
not ready
; const crypPanels = cryps.map(cryp => ( @@ -39,4 +39,4 @@ function CrypPanel({ cryps, sendCombatPve }) { ); } -module.exports = CrypPanel; +module.exports = CrypList; diff --git a/server/WORKLOG.md b/server/WORKLOG.md index f74e3b48..b75a3e70 100755 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -3,6 +3,7 @@ * auto login * ws reconnect ✔️ * Levelling + * KO cooldowns * Global rolls * Logins ✔️ * Cryp Ownership ✔ diff --git a/server/src/battle.rs b/server/src/battle.rs index 0eb05dca..4026984f 100755 --- a/server/src/battle.rs +++ b/server/src/battle.rs @@ -40,8 +40,8 @@ impl Battle { let mut a_turn = self.a.turn(); let mut b_turn = self.b.turn(); - self.a.assign_dmg(&self.b, &a_turn, &b_turn); - self.b.assign_dmg(&self.a, &b_turn, &a_turn); + self.a.assign_dmg(&self.b, &mut a_turn, &b_turn); + self.b.assign_dmg(&self.a, &mut b_turn, &a_turn); self.log.append(&mut a_turn.log); self.log.append(&mut b_turn.log); diff --git a/server/src/combat.rs b/server/src/combat.rs index f3ecea60..c4ff9404 100755 --- a/server/src/combat.rs +++ b/server/src/combat.rs @@ -116,7 +116,8 @@ pub fn pve(params: CombatPveParams, db: &Db, account: &Account) -> Result &mut Cryp { + pub fn assign_dmg(&mut self, opp: &Cryp, plr_t: &mut Turn, opp_t: &Turn) -> &mut Cryp { let final_dmg = opp_t.dmg.result.saturating_sub(plr_t.def.result); let blocked = opp_t.dmg.result.saturating_sub(final_dmg); self.hp.reduce(final_dmg); - println!("{:?} deals {:?} dmg to {:?} ({:?} blocked / {:?} hp remaining)" + plr_t.log.push(format!("{:?} deals {:?} dmg to {:?} ({:?} blocked / {:?} hp remaining)" ,opp.name ,final_dmg ,self.name ,blocked - ,self.hp.value); + ,self.hp.value)); self } diff --git a/server/src/net.rs b/server/src/net.rs index 956dfbf2..358597ab 100755 --- a/server/src/net.rs +++ b/server/src/net.rs @@ -2,6 +2,7 @@ use ws::{listen, Handler, Sender, Result, Message, Handshake, CloseCode, Error}; use serde_cbor::{to_vec}; use std::env; +use std::thread::spawn; use r2d2::{Pool}; use r2d2::{PooledConnection}; @@ -78,5 +79,12 @@ pub fn start() { let pool = db_connection(database_url); - listen("127.0.0.1:40000", |out| { Server { out, rpc: Rpc {}, db: pool.clone() } }).unwrap(); + listen("127.0.0.1:40000", |out| { + let db = pool.clone(); + let handler = spawn(move || { + Server { out, rpc: Rpc {}, db } + }); + let result = handler.join().unwrap(); + return result; + }).unwrap(); }