Fix build errors.
This commit is contained in:
parent
9c0c400546
commit
614616193c
@ -12,7 +12,6 @@ hyper-tungstenite = "0.14.0"
|
|||||||
rustls = "0.23.5"
|
rustls = "0.23.5"
|
||||||
rustls-pemfile = "2.1.2"
|
rustls-pemfile = "2.1.2"
|
||||||
webpki-roots = "0.26"
|
webpki-roots = "0.26"
|
||||||
opaque-ke = "2.0.0"
|
|
||||||
hyper = { version = "1.4.1", features = ["full"] }
|
hyper = { version = "1.4.1", features = ["full"] }
|
||||||
hyper-util = { version = "0.1.7", features = ["tokio"] }
|
hyper-util = { version = "0.1.7", features = ["tokio"] }
|
||||||
http-body-util = "0.1.2"
|
http-body-util = "0.1.2"
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use bus::Bus;
|
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod util;
|
mod util;
|
||||||
mod app;
|
mod app;
|
||||||
@ -24,19 +22,11 @@ use system::{
|
|||||||
};
|
};
|
||||||
use protocol::QRPacket;
|
use protocol::QRPacket;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct HttpServiceArgs {
|
struct HttpServiceArgs {
|
||||||
tx:Sender<QRPacket>,
|
tx:Sender<QRPacket>,
|
||||||
cache:WebCache,
|
cache:WebCache,
|
||||||
}
|
}
|
||||||
impl HttpServiceArgs {
|
|
||||||
pub async fn clone(&mut self) -> Self
|
|
||||||
{
|
|
||||||
Self {
|
|
||||||
tx:self.tx.clone(),
|
|
||||||
cache:self.cache.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn service_http(mut request:hyper::Request<hyper::body::Incoming>, args:HttpServiceArgs) -> Result<hyper::Response<http_body_util::Full<Bytes>>, std::convert::Infallible>
|
async fn service_http(mut request:hyper::Request<hyper::body::Incoming>, args:HttpServiceArgs) -> Result<hyper::Response<http_body_util::Full<Bytes>>, std::convert::Infallible>
|
||||||
// Serve cached files and upgrade websocket connections.
|
// Serve cached files and upgrade websocket connections.
|
||||||
@ -120,7 +110,7 @@ async fn service_http(mut request:hyper::Request<hyper::body::Incoming>, args:Ht
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_http<S>(stream:S, addr:SocketAddr, mut args:HttpServiceArgs) -> Result<(),()>
|
async fn handle_http<S>(stream:S, addr:SocketAddr, args:HttpServiceArgs) -> Result<(),()>
|
||||||
where S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static
|
where S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static
|
||||||
// Hand off socket connection to Hyper server.
|
// Hand off socket connection to Hyper server.
|
||||||
//
|
//
|
||||||
@ -132,10 +122,9 @@ where S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static
|
|||||||
|
|
||||||
let io = TokioIo::new(stream);
|
let io = TokioIo::new(stream);
|
||||||
|
|
||||||
let args = args.clone().await;
|
|
||||||
let conn = http1::Builder::new()
|
let conn = http1::Builder::new()
|
||||||
.serve_connection(io, service_fn(move |req| {
|
.serve_connection(io, service_fn(move |req| {
|
||||||
service_http(req, args)
|
service_http(req, args.clone())
|
||||||
}));
|
}));
|
||||||
|
|
||||||
conn.with_upgrades().await.ok();
|
conn.with_upgrades().await.ok();
|
||||||
@ -207,123 +196,111 @@ async fn main()
|
|||||||
}
|
}
|
||||||
js_asset_data += "}};";
|
js_asset_data += "}};";
|
||||||
|
|
||||||
match b_main.connect().await {
|
/*
|
||||||
Ok(mut bus) => {
|
** Cache source files.
|
||||||
|
*/
|
||||||
|
let cache = WebCache::new();
|
||||||
|
cache.cache("text/html", "/.html", &[
|
||||||
|
WebCache::file("www/.html"),
|
||||||
|
]).ok();
|
||||||
|
cache.cache_whitespace_minimize("/.html").ok();
|
||||||
|
cache.cache("text/css", "/.css", &[
|
||||||
|
WebCache::file("www/css/main.css"),
|
||||||
|
WebCache::file("www/css/ui.css"),
|
||||||
|
WebCache::file("www/css/form.css"),
|
||||||
|
WebCache::file("www/css/game.css"),
|
||||||
|
WebCache::file("www/css/text.css"),
|
||||||
|
WebCache::file("www/css/profile.css"),
|
||||||
|
WebCache::file("www/css/util.css"),
|
||||||
|
]).ok();
|
||||||
|
cache.cache("text/javascript", "/.js", &[
|
||||||
|
WebCache::file("www/js/const.js"),
|
||||||
|
WebCache::file("www/js/language.js"),
|
||||||
|
WebCache::file("www/js/util.js"),
|
||||||
|
WebCache::file("www/js/badge.js"),
|
||||||
|
WebCache::file("www/js/game_asset.js"),
|
||||||
|
WebCache::string(&js_asset_data),
|
||||||
|
WebCache::file("www/js/game.js"),
|
||||||
|
WebCache::file("www/js/interface.js"),
|
||||||
|
WebCache::file("www/js/ui.js"),
|
||||||
|
WebCache::file("www/js/scene.js"),
|
||||||
|
WebCache::file("www/js/system.js"),
|
||||||
|
WebCache::file("www/js/main.js"),
|
||||||
|
]).ok();
|
||||||
|
cache.cache("image/png", "/favicon.png", &[
|
||||||
|
WebCache::file("www/asset/favicon.png"),
|
||||||
|
]).ok();
|
||||||
|
cache.cache("image/png", "/favicon_notify.png", &[
|
||||||
|
WebCache::file("www/asset/favicon_notify.png"),
|
||||||
|
]).ok();
|
||||||
|
|
||||||
/*
|
let about_path = std::path::Path::new("www/pages/about");
|
||||||
** Cache source files.
|
for doc in [
|
||||||
*/
|
"main",
|
||||||
let cache = WebCache::new();
|
] {
|
||||||
cache.cache("text/html", "/.html", &[
|
if cache.cache("text/html", &format!("/about/{}.html", doc), &[
|
||||||
WebCache::file("www/.html"),
|
WebCache::markdown(about_path.join(format!("{}.md", doc)))
|
||||||
]).ok();
|
]).is_err() {
|
||||||
cache.cache_whitespace_minimize("/.html").ok();
|
println!("error: failed to load: {}", doc);
|
||||||
cache.cache("text/css", "/.css", &[
|
}
|
||||||
WebCache::file("www/css/main.css"),
|
}
|
||||||
WebCache::file("www/css/ui.css"),
|
|
||||||
WebCache::file("www/css/form.css"),
|
|
||||||
WebCache::file("www/css/game.css"),
|
|
||||||
WebCache::file("www/css/text.css"),
|
|
||||||
WebCache::file("www/css/profile.css"),
|
|
||||||
WebCache::file("www/css/util.css"),
|
|
||||||
]).ok();
|
|
||||||
cache.cache("text/javascript", "/.js", &[
|
|
||||||
WebCache::file("www/js/const.js"),
|
|
||||||
WebCache::file("www/js/language.js"),
|
|
||||||
WebCache::file("www/js/util.js"),
|
|
||||||
WebCache::file("www/js/badge.js"),
|
|
||||||
WebCache::file("www/js/game_asset.js"),
|
|
||||||
WebCache::string(&js_asset_data),
|
|
||||||
WebCache::file("www/js/game.js"),
|
|
||||||
WebCache::file("www/js/interface.js"),
|
|
||||||
WebCache::file("www/js/ui.js"),
|
|
||||||
WebCache::file("www/js/scene.js"),
|
|
||||||
WebCache::file("www/js/system.js"),
|
|
||||||
WebCache::file("www/js/main.js"),
|
|
||||||
]).ok();
|
|
||||||
cache.cache("image/png", "/favicon.png", &[
|
|
||||||
WebCache::file("www/asset/favicon.png"),
|
|
||||||
]).ok();
|
|
||||||
cache.cache("image/png", "/favicon_notify.png", &[
|
|
||||||
WebCache::file("www/asset/favicon_notify.png"),
|
|
||||||
]).ok();
|
|
||||||
|
|
||||||
let about_path = std::path::Path::new("www/pages/about");
|
let guide_path = std::path::Path::new("www/pages/guide");
|
||||||
for doc in [
|
for doc in [
|
||||||
"main",
|
"game",
|
||||||
] {
|
"pieces",
|
||||||
if cache.cache("text/html", &format!("/about/{}.html", doc), &[
|
"interface",
|
||||||
WebCache::markdown(about_path.join(format!("{}.md", doc)))
|
] {
|
||||||
]).is_err() {
|
if cache.cache("text/html", &format!("/guide/{}.html", doc), &[
|
||||||
println!("error: failed to load: {}", doc);
|
WebCache::markdown(guide_path.join(format!("{}.md", doc))),
|
||||||
}
|
]).is_err() {
|
||||||
}
|
println!("error: failed to load: {}", doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let guide_path = std::path::Path::new("www/pages/guide");
|
/*
|
||||||
for doc in [
|
** Initialize network services.
|
||||||
"game",
|
*/
|
||||||
"pieces",
|
let mut tcp_server = TcpServer::new();
|
||||||
"interface",
|
match tcp_server.bind("127.0.0.1:38611").await {
|
||||||
] {
|
Ok(_) => {
|
||||||
if cache.cache("text/html", &format!("/guide/{}.html", doc), &[
|
let c = cache.clone();
|
||||||
WebCache::markdown(guide_path.join(format!("{}.md", doc))),
|
let data_tx = data_tx.clone();
|
||||||
]).is_err() {
|
tokio::spawn(async move {
|
||||||
println!("error: failed to load: {}", doc);
|
while tcp_server.accept(handle_tcp, HttpServiceArgs {
|
||||||
}
|
tx:data_tx.clone(),
|
||||||
}
|
cache:c.clone(),
|
||||||
|
}).await.is_ok() { }
|
||||||
|
});
|
||||||
/*
|
|
||||||
** Initialize network services.
|
|
||||||
*/
|
|
||||||
let mut tcp_server = TcpServer::new();
|
|
||||||
match tcp_server.bind("127.0.0.1:38611").await {
|
|
||||||
Ok(_) => {
|
|
||||||
let mut b = bus.connect().await.unwrap();
|
|
||||||
let c = cache.clone();
|
|
||||||
let data_tx = data_tx.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
while tcp_server.accept(handle_tcp, HttpServiceArgs {
|
|
||||||
tx:data_tx,
|
|
||||||
cache:c.clone(),
|
|
||||||
}).await.is_ok() { }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
println!("error: failed to bind TCP port 38611.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut tls_server = TlsServer::new();
|
|
||||||
for domain in [
|
|
||||||
"omen.kirisame.com",
|
|
||||||
"dzura.com",
|
|
||||||
] {
|
|
||||||
if tls_server.add_cert(domain, &format!("cert/{}/fullchain.pem", domain), &format!("cert/{}/privkey.pem", domain)).await.is_err() {
|
|
||||||
println!("error: failed to load TLS certificates for {}.", domain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match tls_server.bind("0.0.0.0:38612").await {
|
|
||||||
Ok(_) => {
|
|
||||||
let (tx, rx) = tokio::sync::mpsc::channel::<>(24);
|
|
||||||
let mut b = bus.connect().await.unwrap();
|
|
||||||
let c = cache.clone();
|
|
||||||
|
|
||||||
let data_tx = data_tx.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
while tls_server.accept(handle_tls, HttpServiceArgs {
|
|
||||||
tx:data_tx,
|
|
||||||
cache:c.clone(),
|
|
||||||
}).await.is_ok() { }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
println!("error: failed to bind TLS port 38612.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("error: failed to initialize HTTPS service.");
|
println!("error: failed to bind TCP port 38611.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut tls_server = TlsServer::new();
|
||||||
|
for domain in [
|
||||||
|
"omen.kirisame.com",
|
||||||
|
"dzura.com",
|
||||||
|
] {
|
||||||
|
if tls_server.add_cert(domain, &format!("cert/{}/fullchain.pem", domain), &format!("cert/{}/privkey.pem", domain)).await.is_err() {
|
||||||
|
println!("error: failed to load TLS certificates for {}.", domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match tls_server.bind("0.0.0.0:38612").await {
|
||||||
|
Ok(_) => {
|
||||||
|
let c = cache.clone();
|
||||||
|
let data_tx = data_tx.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
while tls_server.accept(handle_tls, HttpServiceArgs {
|
||||||
|
tx:data_tx.clone(),
|
||||||
|
cache:c.clone(),
|
||||||
|
}).await.is_ok() { }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("error: failed to bind TLS port 38612.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ pub async fn thread_system(mut app:App, mut rx:Receiver<QRPacket>)
|
|||||||
|
|
||||||
let mut send_user_status = Vec::<u32>::new();
|
let mut send_user_status = Vec::<u32>::new();
|
||||||
|
|
||||||
while let Some(packet) = rx.recv().await {
|
while let Some(qr) = rx.recv().await {
|
||||||
let qr = packet.data;
|
|
||||||
|
|
||||||
let mut user_id = None;
|
let mut user_id = None;
|
||||||
let mut context = Context::None;
|
let mut context = Context::None;
|
||||||
@ -44,7 +43,7 @@ pub async fn thread_system(mut app:App, mut rx:Receiver<QRPacket>)
|
|||||||
stream,
|
stream,
|
||||||
} => {
|
} => {
|
||||||
let id = app.connections.add(Connection {
|
let id = app.connections.add(Connection {
|
||||||
stream: request.stream,
|
stream,
|
||||||
auth: None,
|
auth: None,
|
||||||
|
|
||||||
context:Context::None,
|
context:Context::None,
|
||||||
@ -1053,10 +1052,8 @@ pub async fn thread_system(mut app:App, mut rx:Receiver<QRPacket>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_game_state(app:&App, session:&Session) -> protocol::PacketGameStateResponse
|
fn generate_game_state(app:&App, session:&Session) -> PacketGameStateResponse
|
||||||
{
|
{
|
||||||
use protocol::PacketGameStateResponse;
|
|
||||||
|
|
||||||
let mut response = PacketGameStateResponse::new();
|
let mut response = PacketGameStateResponse::new();
|
||||||
|
|
||||||
response.token = session.token;
|
response.token = session.token;
|
||||||
|
@ -11,7 +11,7 @@ use crate::{
|
|||||||
HttpServiceArgs,
|
HttpServiceArgs,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, mut args:HttpServiceArgs) -> Result<(),()>
|
pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, args:HttpServiceArgs) -> Result<(),()>
|
||||||
// Handle websocket connection.
|
// Handle websocket connection.
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, mut args:HttpServi
|
|||||||
let conn_id :u32;
|
let conn_id :u32;
|
||||||
|
|
||||||
let (sink, mut stream) = ws.split();
|
let (sink, mut stream) = ws.split();
|
||||||
let (tx, rx) = mpsc::channel::<QRPacket>(1);
|
let (tx, mut rx) = mpsc::channel::<QRPacket>(1);
|
||||||
|
|
||||||
// Perform connection handshake with data system.
|
// Perform connection handshake with data system.
|
||||||
// - Provide system with connection/bus pairing.
|
// - Provide system with connection/bus pairing.
|
||||||
@ -30,11 +30,10 @@ pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, mut args:HttpServi
|
|||||||
args.tx.send(QRPacket::new(0, QRPacketData::QConn {
|
args.tx.send(QRPacket::new(0, QRPacketData::QConn {
|
||||||
tx:tx.clone(),
|
tx:tx.clone(),
|
||||||
stream:Arc::new(RwLock::new(sink)),
|
stream:Arc::new(RwLock::new(sink)),
|
||||||
})).await?;
|
})).await.map_err(|_| ())?;
|
||||||
|
|
||||||
if let Some(resp) = rx.blocking_recv() {
|
if let Some(qr) = rx.recv().await {
|
||||||
let qr = &resp.data;
|
match &qr.data {
|
||||||
match qr.data {
|
|
||||||
QRPacketData::RConn => { conn_id = qr.id; }
|
QRPacketData::RConn => { conn_id = qr.id; }
|
||||||
_ => { return Err(()); }
|
_ => { return Err(()); }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user