svt
This commit is contained in:
+2
-2
@@ -50,7 +50,7 @@ mod payments;
|
||||
mod pg;
|
||||
mod player;
|
||||
mod events;
|
||||
mod rpc;
|
||||
pub mod rpc;
|
||||
mod skill;
|
||||
mod spec;
|
||||
mod util;
|
||||
@@ -70,7 +70,7 @@ struct JsonLog {
|
||||
msg: String,
|
||||
}
|
||||
|
||||
fn setup_logger() -> Result<(), fern::InitError> {
|
||||
pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
let colors_line = ColoredLevelConfig::new()
|
||||
.error(Color::Red)
|
||||
.warn(Color::Yellow)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
extern crate mnml;
|
||||
|
||||
use mnml::start;
|
||||
|
||||
fn main() {
|
||||
start()
|
||||
}
|
||||
+40
-33
@@ -14,7 +14,7 @@ use cookie::Cookie;
|
||||
use stripe::{Client as StripeClient, Subscription};
|
||||
|
||||
use crossbeam_channel::{unbounded, Sender as CbSender};
|
||||
use ws::{listen, CloseCode, Message, Handler, Request, Response};
|
||||
use ws::{Builder, listen, CloseCode, Message, Handler, Request, Response, Settings, Sender as WsSender};
|
||||
|
||||
use account::{Account};
|
||||
use account;
|
||||
@@ -66,7 +66,7 @@ pub enum RpcMessage {
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
enum RpcRequest {
|
||||
pub enum RpcRequest {
|
||||
Ping {},
|
||||
ItemInfo {},
|
||||
DevResolve { a: Uuid, b: Uuid, skill: Skill },
|
||||
@@ -359,39 +359,46 @@ impl Handler for Connection {
|
||||
|
||||
pub fn start(pool: PgPool, events_tx: CbSender<Event>, stripe: StripeClient) {
|
||||
let mut rng = thread_rng();
|
||||
listen("127.0.0.1:40055", move |out| {
|
||||
Builder::new()
|
||||
.with_settings(Settings {
|
||||
max_connections: 10_000,
|
||||
..Settings::default()
|
||||
})
|
||||
.build(move |out: WsSender| {
|
||||
// we give the tx half to the connection object
|
||||
// which in turn passes a clone to the events system
|
||||
// the rx half goes into a thread where it waits for messages
|
||||
// that need to be delivered to the client
|
||||
// both the ws message handler and the events thread must use
|
||||
// this channel to send messages
|
||||
let (tx, rx) = unbounded::<RpcMessage>();
|
||||
|
||||
// we give the tx half to the connection object
|
||||
// which in turn passes a clone to the events system
|
||||
// the rx half goes into a thread where it waits for messages
|
||||
// that need to be delivered to the client
|
||||
// both the ws message handler and the events thread must use
|
||||
// this channel to send messages
|
||||
let (tx, rx) = unbounded::<RpcMessage>();
|
||||
spawn(move || {
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok(n) => {
|
||||
let response = to_vec(&n).unwrap();
|
||||
out.send(Message::Binary(response)).unwrap();
|
||||
}
|
||||
// we done
|
||||
Err(_e) => {
|
||||
break;
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
spawn(move || {
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok(n) => {
|
||||
let response = to_vec(&n).unwrap();
|
||||
out.send(Message::Binary(response)).unwrap();
|
||||
}
|
||||
// we done
|
||||
Err(_e) => {
|
||||
break;
|
||||
},
|
||||
};
|
||||
Connection {
|
||||
id: rng.gen::<usize>(),
|
||||
account: None,
|
||||
ws: tx,
|
||||
pool: pool.clone(),
|
||||
stripe: stripe.clone(),
|
||||
events: events_tx.clone(),
|
||||
}
|
||||
});
|
||||
|
||||
Connection {
|
||||
id: rng.gen::<usize>(),
|
||||
account: None,
|
||||
ws: tx,
|
||||
pool: pool.clone(),
|
||||
stripe: stripe.clone(),
|
||||
events: events_tx.clone(),
|
||||
}
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap()
|
||||
.listen("127.0.0.1:40055")
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user