forked from lavina/lavina
1
0
Fork 0

irc: remove hardcoded text from welcome messages

- use server name in welcome message
- use app version of crate in app_version field

Reviewed-on: lavina/lavina#35
Co-authored-by: homycdev <abdulkhamid98@gmail.com>
Co-committed-by: homycdev <abdulkhamid98@gmail.com>
This commit is contained in:
homycdev 2024-03-15 00:54:55 +00:00 committed by Nikita Vilunov
parent c6fb74a848
commit 4b1958b5ae
2 changed files with 52 additions and 21 deletions

View File

@ -30,6 +30,8 @@ mod cap;
use crate::cap::Capabilities;
pub const APP_VERSION: &str = concat!("lavina", "_", env!("CARGO_PKG_VERSION"));
#[derive(Deserialize, Debug, Clone)]
pub struct ServerConfig {
pub listen_on: SocketAddr,
@ -391,13 +393,14 @@ async fn handle_registered_socket<'a>(
let player_id = PlayerId::from(user.nickname.clone())?;
let mut connection = players.connect_to_player(player_id.clone()).await;
let text: Str = format!("Welcome to {} Server", &config.server_name).into();
ServerMessage {
tags: vec![],
sender: Some(config.server_name.clone()),
body: ServerMessageBody::N001Welcome {
client: user.nickname.clone(),
text: "Welcome to Kek Server".into(),
text: text.clone(),
},
}
.write_async(writer)
@ -407,7 +410,7 @@ async fn handle_registered_socket<'a>(
sender: Some(config.server_name.clone()),
body: ServerMessageBody::N002YourHost {
client: user.nickname.clone(),
text: "Welcome to Kek Server".into(),
text: text.clone(),
},
}
.write_async(writer)
@ -417,7 +420,7 @@ async fn handle_registered_socket<'a>(
sender: Some(config.server_name.clone()),
body: ServerMessageBody::N003Created {
client: user.nickname.clone(),
text: "Welcome to Kek Server".into(),
text: text.clone(),
},
}
.write_async(writer)
@ -428,7 +431,7 @@ async fn handle_registered_socket<'a>(
body: ServerMessageBody::N004MyInfo {
client: user.nickname.clone(),
hostname: config.server_name.clone(),
softname: "kek-0.1.alpha.3".into(),
softname: APP_VERSION.into(),
},
}
.write_async(writer)

View File

@ -10,8 +10,8 @@ use tokio::net::TcpStream;
use lavina_core::repo::{Storage, StorageConfig};
use lavina_core::{player::PlayerRegistry, room::RoomRegistry};
use projection_irc::APP_VERSION;
use projection_irc::{launch, read_irc_message, RunningServer, ServerConfig};
struct TestScope<'a> {
reader: BufReader<ReadHalf<'a>>,
writer: WriteHalf<'a>,
@ -113,10 +113,17 @@ async fn scenario_basic() -> Result<()> {
s.send("PASS password").await?;
s.send("NICK tester").await?;
s.send("USER UserName 0 * :Real Name").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(
format!(
":testserver 004 tester testserver {} r CFILPQbcefgijklmnopqrstvz",
&APP_VERSION
)
.as_str(),
)
.await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?;
s.send("QUIT :Leaving").await?;
@ -161,10 +168,17 @@ async fn scenario_cap_full_negotiation() -> Result<()> {
s.send("CAP END").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(
format!(
":testserver 004 tester testserver {} r CFILPQbcefgijklmnopqrstvz",
&APP_VERSION
)
.as_str(),
)
.await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?;
s.send("QUIT :Leaving").await?;
@ -203,10 +217,17 @@ async fn scenario_cap_short_negotiation() -> Result<()> {
s.send("CAP END").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(
format!(
":testserver 004 tester testserver {} r CFILPQbcefgijklmnopqrstvz",
&APP_VERSION
)
.as_str(),
)
.await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?;
s.send("QUIT :Leaving").await?;
@ -251,10 +272,17 @@ async fn scenario_cap_sasl_fail() -> Result<()> {
s.send("CAP END").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(
format!(
":testserver 004 tester testserver {} r CFILPQbcefgijklmnopqrstvz",
&APP_VERSION
)
.as_str(),
)
.await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?;
s.send("QUIT :Leaving").await?;