forked from lavina/lavina
1
0
Fork 0

refactored:

- use server name in welcome message
- use app version of crate in app_version field
This commit is contained in:
homycdev 2024-03-13 22:38:01 +03:00
parent c6fb74a848
commit 47937c236a
2 changed files with 23 additions and 20 deletions

View File

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

View File

@ -113,10 +113,10 @@ async fn scenario_basic() -> Result<()> {
s.send("PASS password").await?; s.send("PASS password").await?;
s.send("NICK tester").await?; s.send("NICK tester").await?;
s.send("USER UserName 0 * :Real Name").await?; s.send("USER UserName 0 * :Real Name").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?; s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?; s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?; s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?; s.expect(":testserver 004 tester testserver lavina_0.0.2-dev r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?; s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?; s.expect_nothing().await?;
s.send("QUIT :Leaving").await?; s.send("QUIT :Leaving").await?;
@ -161,10 +161,10 @@ async fn scenario_cap_full_negotiation() -> Result<()> {
s.send("CAP END").await?; s.send("CAP END").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?; s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?; s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?; s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?; s.expect(":testserver 004 tester testserver lavina_0.0.2-dev r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?; s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?; s.expect_nothing().await?;
s.send("QUIT :Leaving").await?; s.send("QUIT :Leaving").await?;
@ -203,10 +203,10 @@ async fn scenario_cap_short_negotiation() -> Result<()> {
s.send("CAP END").await?; s.send("CAP END").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?; s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?; s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?; s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?; s.expect(":testserver 004 tester testserver lavina_0.0.2-dev r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?; s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?; s.expect_nothing().await?;
s.send("QUIT :Leaving").await?; s.send("QUIT :Leaving").await?;
@ -251,10 +251,10 @@ async fn scenario_cap_sasl_fail() -> Result<()> {
s.send("CAP END").await?; s.send("CAP END").await?;
s.expect(":testserver 001 tester :Welcome to Kek Server").await?; s.expect(":testserver 001 tester :Welcome to testserver Server").await?;
s.expect(":testserver 002 tester :Welcome to Kek Server").await?; s.expect(":testserver 002 tester :Welcome to testserver Server").await?;
s.expect(":testserver 003 tester :Welcome to Kek Server").await?; s.expect(":testserver 003 tester :Welcome to testserver Server").await?;
s.expect(":testserver 004 tester testserver kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz").await?; s.expect(":testserver 004 tester testserver lavina_0.0.2-dev r CFILPQbcefgijklmnopqrstvz").await?;
s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?; s.expect(":testserver 005 tester CHANTYPES=# :are supported by this server").await?;
s.expect_nothing().await?; s.expect_nothing().await?;
s.send("QUIT :Leaving").await?; s.send("QUIT :Leaving").await?;