forked from lavina/lavina
split proto irc defs into its own crate
This commit is contained in:
parent
87d73af811
commit
17bb275412
|
@ -763,6 +763,7 @@ dependencies = [
|
|||
"nom",
|
||||
"nonempty",
|
||||
"prometheus",
|
||||
"proto-irc",
|
||||
"quick-xml",
|
||||
"regex",
|
||||
"reqwest",
|
||||
|
@ -1151,6 +1152,18 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proto-irc"
|
||||
version = "0.0.1-dev"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_matches",
|
||||
"futures-util",
|
||||
"nom",
|
||||
"nonempty",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.30.0"
|
||||
|
|
32
Cargo.toml
32
Cargo.toml
|
@ -1,33 +1,51 @@
|
|||
[workspace]
|
||||
members = [
|
||||
".",
|
||||
"crates/proto-irc"
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.0.1-dev"
|
||||
|
||||
[workspace.dependencies]
|
||||
nom = "7.1.3"
|
||||
assert_matches = "1.5.0"
|
||||
tokio = { version = "1.24.1", features = ["full"] } # async runtime
|
||||
futures-util = "0.3.25"
|
||||
anyhow = "1.0.68" # error utils
|
||||
nonempty = "0.8.1"
|
||||
|
||||
[package]
|
||||
name = "lavina"
|
||||
version = "0.0.1-dev"
|
||||
version.workspace = true
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.68" # error utils
|
||||
anyhow.workspace = true
|
||||
figment = { version = "0.10.8", features = ["env", "toml"] } # configuration files
|
||||
hyper = { version = "1.0.0-rc.3,<1.0.0-rc.4", features = ["server", "http1"] } # http server
|
||||
http-body-util = "0.1.0-rc.3"
|
||||
serde = { version = "1.0.152", features = ["rc", "serde_derive"] }
|
||||
serde_json = "1.0.93"
|
||||
tokio = { version = "1.24.1", features = ["full"] } # async runtime
|
||||
tokio.workspace = true
|
||||
tracing = "0.1.37" # logging & tracing api
|
||||
tracing-subscriber = "0.3.16"
|
||||
futures-util = "0.3.25"
|
||||
futures-util.workspace = true
|
||||
prometheus = { version = "0.13.3", default-features = false }
|
||||
regex = "1.7.1"
|
||||
lazy_static = "1.4.0"
|
||||
nom = "7.1.3"
|
||||
nonempty = "0.8.1"
|
||||
nom.workspace = true
|
||||
nonempty.workspace = true
|
||||
tokio-rustls = "0.24.1"
|
||||
rustls-pemfile = "1.0.2"
|
||||
quick-xml = { version = "0.30.0", features = ["async-tokio"] }
|
||||
derive_more = "0.99.17"
|
||||
uuid = { version = "1.3.0", features = ["v4"] }
|
||||
sqlx = { version = "0.7.0-alpha.2", features = ["sqlite", "migrate"] }
|
||||
proto-irc = { path = "crates/proto-irc" }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.5.0"
|
||||
assert_matches.workspace = true
|
||||
regex = "1.7.1"
|
||||
reqwest = { version = "0.11", default-features = false }
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "proto-irc"
|
||||
edition = "2021"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
nom.workspace = true
|
||||
nonempty.workspace = true
|
||||
tokio.workspace = true
|
||||
futures-util.workspace = true
|
||||
anyhow.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches.workspace = true
|
|
@ -1,10 +1,13 @@
|
|||
//! Client-to-Server IRC protocol.
|
||||
pub mod client;
|
||||
mod prelude;
|
||||
pub mod server;
|
||||
#[cfg(test)]
|
||||
mod testkit;
|
||||
pub mod user;
|
||||
|
||||
use std::io::Result;
|
||||
use crate::prelude::Str;
|
||||
use std::io::Result;
|
||||
|
||||
use nom::{
|
||||
branch::alt,
|
||||
|
@ -101,7 +104,7 @@ mod test {
|
|||
use assert_matches::*;
|
||||
|
||||
use super::*;
|
||||
use crate::util::testkit::*;
|
||||
use crate::testkit::*;
|
||||
|
||||
#[test]
|
||||
fn test_chan_global() {
|
|
@ -0,0 +1,3 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
pub type Str = Arc<str>;
|
|
@ -3,7 +3,7 @@ use tokio::io::AsyncWrite;
|
|||
use tokio::io::AsyncWriteExt;
|
||||
|
||||
use super::*;
|
||||
use crate::protos::irc::user::PrefixedNick;
|
||||
use crate::user::PrefixedNick;
|
||||
|
||||
/// Server-to-client message.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -287,7 +287,9 @@ impl ServerMessageBody {
|
|||
chan.write_async(writer).await?;
|
||||
writer.write_all(b" :").await?;
|
||||
for member in members {
|
||||
writer.write_all(member.prefix.to_string().as_bytes()).await?;
|
||||
writer
|
||||
.write_all(member.prefix.to_string().as_bytes())
|
||||
.await?;
|
||||
writer.write_all(member.nick.as_bytes()).await?;
|
||||
writer.write_all(b" ").await?;
|
||||
}
|
||||
|
@ -387,7 +389,7 @@ mod test {
|
|||
use assert_matches::*;
|
||||
|
||||
use super::*;
|
||||
use crate::util::testkit::*;
|
||||
use crate::testkit::*;
|
||||
|
||||
#[test]
|
||||
fn test_server_message_notice() {
|
|
@ -0,0 +1,16 @@
|
|||
use std::future::Future;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use futures_util::task::noop_waker_ref;
|
||||
use tokio::pin;
|
||||
|
||||
pub fn sync_future<T>(future: impl Future<Output = T>) -> anyhow::Result<T> {
|
||||
let waker = noop_waker_ref();
|
||||
let mut context = Context::from_waker(waker);
|
||||
pin!(future);
|
||||
if let Poll::Ready(a) = future.poll(&mut context) {
|
||||
Ok(a)
|
||||
} else {
|
||||
Err(anyhow::Error::msg("Future has suspended"))
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
use super::*;
|
||||
use std::fmt;
|
||||
use crate::core::player::PlayerId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Prefix {
|
||||
|
@ -23,10 +22,9 @@ pub struct PrefixedNick {
|
|||
|
||||
impl PrefixedNick {
|
||||
pub fn from_str(nick: Str) -> PrefixedNick {
|
||||
PrefixedNick { prefix: Prefix::Empty, nick }
|
||||
PrefixedNick {
|
||||
prefix: Prefix::Empty,
|
||||
nick,
|
||||
}
|
||||
|
||||
pub fn from_player_id(id: PlayerId) -> PrefixedNick {
|
||||
PrefixedNick { prefix: Prefix::Empty, nick: id.into_inner() }
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ use futures_util::future::join_all;
|
|||
use nonempty::nonempty;
|
||||
use nonempty::NonEmpty;
|
||||
use prometheus::{IntCounter, IntGauge, Registry as MetricsRegistry};
|
||||
|
||||
use serde::Deserialize;
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWrite, AsyncWriteExt, BufReader, BufWriter};
|
||||
use tokio::net::tcp::{ReadHalf, WriteHalf};
|
||||
|
@ -15,10 +16,10 @@ use crate::core::player::*;
|
|||
use crate::core::repo::Storage;
|
||||
use crate::core::room::{RoomId, RoomInfo, RoomRegistry};
|
||||
use crate::prelude::*;
|
||||
use crate::protos::irc::client::{client_message, ClientMessage};
|
||||
use crate::protos::irc::server::{AwayStatus, ServerMessage, ServerMessageBody};
|
||||
use crate::protos::irc::{Chan, Recipient};
|
||||
use crate::protos::irc::user::PrefixedNick;
|
||||
use proto_irc::client::{client_message, ClientMessage};
|
||||
use proto_irc::server::{AwayStatus, ServerMessage, ServerMessageBody};
|
||||
use proto_irc::{Chan, Recipient};
|
||||
use proto_irc::user::{Prefix, PrefixedNick};
|
||||
use crate::util::Terminator;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -669,7 +670,7 @@ async fn produce_on_join_cmd_messages(
|
|||
}
|
||||
.write_async(writer)
|
||||
.await?;
|
||||
let prefixed_members: Vec<PrefixedNick> = room_info.members.iter().map(|member| PrefixedNick::from_player_id(member.clone())).collect();
|
||||
let prefixed_members: Vec<PrefixedNick> = room_info.members.iter().map(|member| PrefixedNick::from_str(member.clone().into_inner())).collect();
|
||||
let non_empty_members: NonEmpty<PrefixedNick> = NonEmpty::from_vec(prefixed_members).unwrap_or(nonempty![PrefixedNick::from_str(user.nickname.clone())]);
|
||||
|
||||
ServerMessage {
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
//! Definitions of wire protocols to be used in implementations of projections.
|
||||
pub mod irc;
|
||||
pub mod xmpp;
|
||||
|
|
Loading…
Reference in New Issue