durian for realtime updates
This commit is contained in:
@@ -17,6 +17,7 @@ sqlx = { version = "0.8.0", features = [ "runtime-tokio", "tls-rustls", "sqlite"
|
|||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
moka = { version = "0.12.8", features = ["future"] }
|
moka = { version = "0.12.8", features = ["future"] }
|
||||||
futures-util = "0.3.30"
|
futures-util = "0.3.30"
|
||||||
|
durian = "0.5"
|
||||||
|
|
||||||
realm_auth = { path = "../auth" }
|
realm_auth = { path = "../auth" }
|
||||||
realm_shared = { path = "../shared" }
|
realm_shared = { path = "../shared" }
|
||||||
|
|||||||
6
server/src/events.rs
Normal file
6
server/src/events.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
use durian::bincode_packet;
|
||||||
|
|
||||||
|
#[bincode_packet]
|
||||||
|
pub struct Greet {
|
||||||
|
id: u32
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
pub mod events;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::net::{IpAddr, Ipv6Addr};
|
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
|
use durian::{PacketManager, ServerConfig};
|
||||||
use futures::future::{self};
|
use futures::future::{self};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use sqlx::migrate::MigrateDatabase;
|
use sqlx::migrate::MigrateDatabase;
|
||||||
@@ -13,6 +14,8 @@ use tarpc::{
|
|||||||
use tarpc::server::incoming::Incoming;
|
use tarpc::server::incoming::Incoming;
|
||||||
use tarpc::server::BaseChannel;
|
use tarpc::server::BaseChannel;
|
||||||
use tracing::{info, subscriber, warn};
|
use tracing::{info, subscriber, warn};
|
||||||
|
use realm_server::events;
|
||||||
|
use realm_server::events::{GreetPacketBuilder};
|
||||||
use realm_server::server::RealmChatServer;
|
use realm_server::server::RealmChatServer;
|
||||||
use realm_server::types::RealmChat;
|
use realm_server::types::RealmChat;
|
||||||
|
|
||||||
@@ -52,7 +55,21 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
migrate!().run(&db_pool).await?; // TODO: Do in Docker with Sqlx-cli
|
migrate!().run(&db_pool).await?; // TODO: Do in Docker with Sqlx-cli
|
||||||
info!("Migrations complete!");
|
info!("Migrations complete!");
|
||||||
|
|
||||||
let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), env::var("PORT").expect("PORT must be set").parse::<u16>().unwrap());
|
let port = env::var("PORT").expect("PORT must be set").parse::<u16>().unwrap();
|
||||||
|
let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), port);
|
||||||
|
|
||||||
|
let mut manager = PacketManager::new();
|
||||||
|
manager.init_server(
|
||||||
|
ServerConfig::new(
|
||||||
|
SocketAddr::from((IpAddr::V6(Ipv6Addr::LOCALHOST), port-1)).to_string(),
|
||||||
|
0, None, 2, 256))?;
|
||||||
|
|
||||||
|
let callback = |_| {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
manager.register_receive_packet::<events::Greet>(GreetPacketBuilder).unwrap();
|
||||||
|
|
||||||
|
|
||||||
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
||||||
// to start up a serde-powered json serialization strategy over TCP.
|
// to start up a serde-powered json serialization strategy over TCP.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::net::{SocketAddr};
|
use std::net::{Ipv6Addr, SocketAddr};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use moka::future::Cache;
|
use moka::future::Cache;
|
||||||
@@ -205,6 +205,8 @@ impl RealmChat for RealmChatServer {
|
|||||||
"INSERT INTO user (userid, name, online, admin) VALUES (?,?,?,?)",
|
"INSERT INTO user (userid, name, online, admin) VALUES (?,?,?,?)",
|
||||||
user.userid, user.name, false, false).execute(&self.db_pool).await;
|
user.userid, user.name, false, false).execute(&self.db_pool).await;
|
||||||
|
|
||||||
|
//TODO: tell everyone
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err(MalformedDBResponse),
|
Err(_) => Err(MalformedDBResponse),
|
||||||
@@ -222,6 +224,8 @@ impl RealmChat for RealmChatServer {
|
|||||||
|
|
||||||
let result = query!("DELETE FROM user WHERE userid = ?",user.userid).execute(&self.db_pool).await;
|
let result = query!("DELETE FROM user WHERE userid = ?",user.userid).execute(&self.db_pool).await;
|
||||||
|
|
||||||
|
//TODO: tell everyone
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err(MalformedDBResponse),
|
Err(_) => Err(MalformedDBResponse),
|
||||||
|
|||||||
Reference in New Issue
Block a user