mirror of
https://codeberg.org/steam-vent/chat.git
synced 2026-11-30 12:40:52 +01:00
apply fixes
This commit is contained in:
parent
5710d6858e
commit
ff9a62d860
5 changed files with 1001 additions and 693 deletions
1689
Cargo.lock
generated
1689
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
17
Cargo.toml
17
Cargo.toml
|
|
@ -1,19 +1,20 @@
|
||||||
[package]
|
[package]
|
||||||
name = "steam-vent-chat"
|
name = "aurelia-steam-vent-chat"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "Steam chat client library"
|
description = "Steam chat client library (Aurelia fork of steam-vent-chat, ported to steam-vent 0.5)"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://codeberg.org/steam-vent/chat"
|
repository = "https://codeberg.org/Drackrath/aurelia-steam-vent-chat"
|
||||||
rust-version = "1.85.0"
|
rust-version = "1.85.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
steam-vent = "0.4.0"
|
steam-vent = "0.5"
|
||||||
steamid-ng = "2.0.0"
|
steam-vent-proto = "=0.5.2"
|
||||||
tokio-stream = "0.1.17"
|
steamid-ng = { version = "3", features = ["serde"] }
|
||||||
|
tokio-stream = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
|
||||||
tracing-subscriber = "0.3.20"
|
tracing-subscriber = "0.3.20"
|
||||||
clap = { version = "4.5.47", features = ["derive"] }
|
clap = { version = "4.5.47", features = ["derive"] }
|
||||||
|
|
|
||||||
15
README.md
15
README.md
|
|
@ -1,4 +1,4 @@
|
||||||
# steam-vent-chat
|
# aurelia-steam-vent-chat
|
||||||
|
|
||||||
Steam chat client library.
|
Steam chat client library.
|
||||||
|
|
||||||
|
|
@ -6,6 +6,19 @@ A high-level companion library for
|
||||||
[steam-vent](https://codeberg.org/steam-vent/steam-vent) for sending and
|
[steam-vent](https://codeberg.org/steam-vent/steam-vent) for sending and
|
||||||
receiving steam chat messages.
|
receiving steam chat messages.
|
||||||
|
|
||||||
|
This is the [Aurelia](https://github.com/Drackrath/Aurelia) fork of
|
||||||
|
[steam-vent-chat](https://codeberg.org/steam-vent/chat). It differs from
|
||||||
|
upstream in these ways:
|
||||||
|
|
||||||
|
- Ported to steam-vent 0.5 and steamid-ng 3. Protos now come from
|
||||||
|
`steam-vent-proto`, because steam-vent no longer re-exports them.
|
||||||
|
- `ChatClient::listen` borrows the client instead of returning a `'static`
|
||||||
|
stream.
|
||||||
|
- Notifications with an invalid friend Steam ID are dropped, because steamid-ng
|
||||||
|
3 has no default `SteamID` to fall back to.
|
||||||
|
- Incoming messages are delivered. Upstream checks `local_echo()` on both arms,
|
||||||
|
so it drops every message from a friend.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use steam_vent::auth::{
|
||||||
FileGuardDataStore, SharedSecretAuthConfirmationHandler,
|
FileGuardDataStore, SharedSecretAuthConfirmationHandler,
|
||||||
};
|
};
|
||||||
use steam_vent::{Connection, ServerList};
|
use steam_vent::{Connection, ServerList};
|
||||||
use steam_vent_chat::{ChatClient, ChatEvent};
|
use aurelia_steam_vent_chat::{ChatClient, ChatEvent};
|
||||||
use steamid_ng::SteamID;
|
use steamid_ng::SteamID;
|
||||||
use tokio::spawn;
|
use tokio::spawn;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
|
|
@ -56,7 +56,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let chat = ChatClient::new(connection);
|
// listen() borrows; spawn needs 'static.
|
||||||
|
let chat: &'static ChatClient = Box::leak(Box::new(ChatClient::new(connection)));
|
||||||
|
|
||||||
let mut events = chat.listen();
|
let mut events = chat.listen();
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
|
|
|
||||||
18
src/lib.rs
18
src/lib.rs
|
|
@ -1,4 +1,6 @@
|
||||||
use steam_vent::proto::steammessages_friendmessages_steamclient::{CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request};
|
use steam_vent_proto::steammessages_friendmessages_steamclient::{
|
||||||
|
CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request,
|
||||||
|
};
|
||||||
use steam_vent::{Connection, ConnectionTrait, NetworkError};
|
use steam_vent::{Connection, ConnectionTrait, NetworkError};
|
||||||
use steamid_ng::SteamID;
|
use steamid_ng::SteamID;
|
||||||
use tokio_stream::{Stream, StreamExt};
|
use tokio_stream::{Stream, StreamExt};
|
||||||
|
|
@ -15,7 +17,7 @@ impl ChatClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listen for incoming events
|
/// Listen for incoming events
|
||||||
pub fn listen(&self) -> impl Stream<Item = Result<ChatEvent, NetworkError>> + 'static {
|
pub fn listen(&self) -> impl Stream<Item = Result<ChatEvent, NetworkError>> + '_ {
|
||||||
self.connection
|
self.connection
|
||||||
.on_notification::<CFriendMessages_IncomingMessage_Notification>()
|
.on_notification::<CFriendMessages_IncomingMessage_Notification>()
|
||||||
.filter_map(|notification| {
|
.filter_map(|notification| {
|
||||||
|
|
@ -59,17 +61,23 @@ impl TryFrom<CFriendMessages_IncomingMessage_Notification> for ChatEvent {
|
||||||
fn try_from(
|
fn try_from(
|
||||||
notification: CFriendMessages_IncomingMessage_Notification,
|
notification: CFriendMessages_IncomingMessage_Notification,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let source = SteamID::try_from(notification.steamid_friend()).unwrap_or_default();
|
// steamid-ng 3.x dropped `Default` for `SteamID`, so an unparseable id can
|
||||||
|
// no longer fall back to a zero id — drop the event instead.
|
||||||
|
let source = SteamID::try_from(notification.steamid_friend()).map_err(|_| ())?;
|
||||||
let message_type =
|
let message_type =
|
||||||
MessageType::try_from(notification.chat_entry_type()).unwrap_or_default();
|
MessageType::try_from(notification.chat_entry_type()).unwrap_or_default();
|
||||||
Ok(match message_type {
|
Ok(match message_type {
|
||||||
MessageType::Chat if notification.local_echo() => ChatEvent::Message(MessageEvent {
|
// A message from the friend (not a local echo of our own send). The
|
||||||
|
// upstream code guarded both arms on `local_echo()`, which made the
|
||||||
|
// echo arm unreachable and silently dropped every genuine incoming
|
||||||
|
// message; the real distinction is whether `local_echo` is set.
|
||||||
|
MessageType::Chat if !notification.local_echo() => ChatEvent::Message(MessageEvent {
|
||||||
source,
|
source,
|
||||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||||
message: notification.message.unwrap_or_default(),
|
message: notification.message.unwrap_or_default(),
|
||||||
message_no_bbcode: notification.message_no_bbcode,
|
message_no_bbcode: notification.message_no_bbcode,
|
||||||
}),
|
}),
|
||||||
MessageType::Chat if notification.local_echo() => ChatEvent::EchoMessage(MessageEvent {
|
MessageType::Chat => ChatEvent::EchoMessage(MessageEvent {
|
||||||
source,
|
source,
|
||||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||||
message: notification.message.unwrap_or_default(),
|
message: notification.message.unwrap_or_default(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue