forked from lavina/lavina
code edited
This commit is contained in:
parent
ad00fe759a
commit
5eb0385012
|
@ -126,9 +126,9 @@ impl PlayerConnection {
|
||||||
Ok(deferred.await?)
|
Ok(deferred.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handler in [Player::check_user_existance].
|
/// Handler in [Player::check_user_existence].
|
||||||
#[tracing::instrument(skip(self), name = "PlayerConnection::send_dialog_message")]
|
#[tracing::instrument(skip(self), name = "PlayerConnection::check_user_existence")]
|
||||||
pub async fn check_user_existance(&self, recipient: PlayerId) -> Result<GetInfoResult> {
|
pub async fn check_user_existence(&self, recipient: PlayerId) -> Result<GetInfoResult> {
|
||||||
let (promise, deferred) = oneshot();
|
let (promise, deferred) = oneshot();
|
||||||
let cmd = ClientCommand::GetInfo { recipient, promise };
|
let cmd = ClientCommand::GetInfo { recipient, promise };
|
||||||
self.player_handle.send(ActorCommand::ClientCommand(cmd, self.connection_id.clone())).await;
|
self.player_handle.send(ActorCommand::ClientCommand(cmd, self.connection_id.clone())).await;
|
||||||
|
@ -520,7 +520,7 @@ impl Player {
|
||||||
let _ = promise.send(());
|
let _ = promise.send(());
|
||||||
}
|
}
|
||||||
ClientCommand::GetInfo { recipient, promise } => {
|
ClientCommand::GetInfo { recipient, promise } => {
|
||||||
let result = self.check_user_existance(recipient).await;
|
let result = self.check_user_existence(recipient).await;
|
||||||
let _ = promise.send(result);
|
let _ = promise.send(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -619,9 +619,9 @@ impl Player {
|
||||||
self.broadcast_update(update, connection_id).await;
|
self.broadcast_update(update, connection_id).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), name = "Player::check_user_existance")]
|
#[tracing::instrument(skip(self), name = "Player::check_user_existence")]
|
||||||
async fn check_user_existance(&self, recipient: PlayerId) -> GetInfoResult {
|
async fn check_user_existence(&self, recipient: PlayerId) -> GetInfoResult {
|
||||||
if self.storage.check_user_existance(recipient.as_inner().as_ref()).await.unwrap() {
|
if self.storage.check_user_existence(recipient.as_inner().as_ref()).await.unwrap() {
|
||||||
GetInfoResult::UserExists
|
GetInfoResult::UserExists
|
||||||
} else {
|
} else {
|
||||||
GetInfoResult::UserDoesntExist
|
GetInfoResult::UserDoesntExist
|
||||||
|
|
|
@ -56,8 +56,8 @@ impl Storage {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), name = "Storage::check_user_existance")]
|
#[tracing::instrument(skip(self), name = "Storage::check_user_existence")]
|
||||||
pub async fn check_user_existance(&self, username: &str) -> Result<bool> {
|
pub async fn check_user_existence(&self, username: &str) -> Result<bool> {
|
||||||
let mut executor = self.conn.lock().await;
|
let mut executor = self.conn.lock().await;
|
||||||
let result: Option<(String,)> = sqlx::query_as("select name from users where name = ?;")
|
let result: Option<(String,)> = sqlx::query_as("select name from users where name = ?;")
|
||||||
.bind(username)
|
.bind(username)
|
||||||
|
|
|
@ -46,7 +46,7 @@ async fn handle_nick_target(nick: Str, body: IrcConnection<'_, impl AsyncWrite +
|
||||||
} = body;
|
} = body;
|
||||||
|
|
||||||
if let GetInfoResult::UserDoesntExist =
|
if let GetInfoResult::UserDoesntExist =
|
||||||
player_connection.check_user_existance(PlayerId::from(nick.clone())?).await?
|
player_connection.check_user_existence(PlayerId::from(nick.clone())?).await?
|
||||||
{
|
{
|
||||||
IrcResponseMessage::empty_tags(
|
IrcResponseMessage::empty_tags(
|
||||||
Some(server_name.clone()),
|
Some(server_name.clone()),
|
||||||
|
|
|
@ -1,143 +1,7 @@
|
||||||
use std::{net::IpAddr, time::SystemTime};
|
|
||||||
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::{prelude::Str, response::WriteResponse, Chan};
|
use crate::{prelude::Str, response::WriteResponse};
|
||||||
|
|
||||||
/// "<client> <nick> :has client certificate fingerprint <fingerprint>"
|
|
||||||
/// Clients MUST only be sent this numeric if they are either using the WHOIS command on themselves
|
|
||||||
/// or they are an operator.
|
|
||||||
struct RplWhoisCertfp276 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
fingerprint: Str,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "<client> <nick> :has identified for this nick"
|
|
||||||
struct RplWhoisRegNick307 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
}
|
|
||||||
/// "<client> <nick> <username> <host> * :<realname>"
|
|
||||||
pub struct RplWhoIsUser311 {
|
|
||||||
client: Str,
|
|
||||||
/// unique name
|
|
||||||
nick: Str,
|
|
||||||
/// username not unique
|
|
||||||
username: Option<Str>,
|
|
||||||
/// server name
|
|
||||||
host: Str,
|
|
||||||
realname: Str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RplWhoIsUser311 {
|
|
||||||
pub fn new(client: Str, nick: Str, username: Option<Str>, host: Str, realname: Str) -> Self {
|
|
||||||
RplWhoIsUser311 {
|
|
||||||
client,
|
|
||||||
nick,
|
|
||||||
username,
|
|
||||||
host,
|
|
||||||
realname,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// "<client> <nick> <server> :<server info>"
|
|
||||||
struct RplWhoisServer312 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
server: Str,
|
|
||||||
/// description of the server
|
|
||||||
server_info: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "<client> <nick> :is an IRC operator"
|
|
||||||
struct RplWhoisOperator313 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sent as a reply to the WHOIS command, this numeric indicates how long the client with the nickname <nick> has been idle.
|
|
||||||
/// <secs> is the number of seconds since the client has been active.
|
|
||||||
/// Servers generally denote specific commands (for instance, perhaps JOIN, PRIVMSG, NOTICE, etc) as updating the ‘idle time’,
|
|
||||||
/// and calculate this off when the idle time was last updated.
|
|
||||||
/// <signon> is a unix timestamp representing when the user joined the network. The text used in the last param of this message may vary.
|
|
||||||
struct RplWhoisIdle317 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
/// number of seconds client been active
|
|
||||||
secs: f32,
|
|
||||||
sigon: SystemTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PrefixedChan {
|
|
||||||
prefix: Option<Str>,
|
|
||||||
chan: Chan,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RplWhoisChannels319 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
highest_membership: PrefixedChan,
|
|
||||||
/// The last parameter of this numeric is a list of [prefix]<channel> pairs,
|
|
||||||
/// delimited by a SPACE character (' ', 0x20).
|
|
||||||
/// RPL_WHOISCHANNELS can be sent multiple times in the same whois reply,
|
|
||||||
/// if the target is on too many channels to fit in a single message.
|
|
||||||
chanels: [PrefixedChan; 20],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// is used for extra human-readable information on the client with nickname <nick>.
|
|
||||||
/// This should only be used for non-essential information,
|
|
||||||
/// that does not need to be machine-readable or understood by client software.
|
|
||||||
struct RplWhoisSpecial320 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
}
|
|
||||||
/// "<client> <nick> <account> :is logged in as"
|
|
||||||
struct RplWhoisAccount330 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
account: Str,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "<client> <nick> :is actually ..."
|
|
||||||
/// "<client> <nick> <host|ip> :Is actually using host"
|
|
||||||
/// "<client> <nick> <username>@<hostname> <ip> :Is actually using host"
|
|
||||||
struct RplWhoisActually338 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
username: Str,
|
|
||||||
/// CANNOT start with a colon (':', 0x3A)
|
|
||||||
host: Str,
|
|
||||||
ip: IpAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "<client> <nick> :is connecting from *@localhost 127.0.0.1"
|
|
||||||
struct RplWhoisHost378 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
host: Str,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Mode(Str);
|
|
||||||
/// "<client> <nick> :is using modes +ailosw"
|
|
||||||
struct RplWhoisModes379 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
modes: Vec<Mode>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "<client> <nick> :is using a secure connection"
|
|
||||||
struct RplWhoisSecure671 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
is_secure: bool,
|
|
||||||
}
|
|
||||||
/// "<client> <nick> :<message>"
|
|
||||||
struct RplAway301 {
|
|
||||||
client: Str,
|
|
||||||
nick: Str,
|
|
||||||
default_away_message: Str,
|
|
||||||
}
|
|
||||||
pub struct RplEndOfWhois318 {
|
pub struct RplEndOfWhois318 {
|
||||||
client: Str,
|
client: Str,
|
||||||
nick: Str,
|
nick: Str,
|
||||||
|
@ -147,30 +11,6 @@ impl RplEndOfWhois318 {
|
||||||
RplEndOfWhois318 { client, nick }
|
RplEndOfWhois318 { client, nick }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WriteResponse for RplWhoIsUser311 {
|
|
||||||
async fn write_response(&self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
|
||||||
writer.write_all(b"311 ").await?;
|
|
||||||
writer.write_all(self.client.as_bytes()).await?;
|
|
||||||
writer.write_all(b" ").await?;
|
|
||||||
writer.write_all(self.nick.as_bytes()).await?;
|
|
||||||
if let Some(username) = &self.username {
|
|
||||||
writer.write_all(b" ").await?;
|
|
||||||
writer.write_all(username.as_bytes()).await?;
|
|
||||||
}
|
|
||||||
writer.write_all(b" ").await?;
|
|
||||||
writer.write_all(self.host.as_bytes()).await?;
|
|
||||||
writer.write_all(b" ").await?;
|
|
||||||
writer.write_all("*".as_bytes()).await?;
|
|
||||||
writer.write_all(b" ").await?;
|
|
||||||
writer.write_all(b" :").await?;
|
|
||||||
//todo no entity in db that represents whole irc user entity
|
|
||||||
writer.write_all("<realname>".as_bytes()).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WriteResponse for RplEndOfWhois318 {
|
impl WriteResponse for RplEndOfWhois318 {
|
||||||
async fn write_response(&self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
async fn write_response(&self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
||||||
writer.write_all(b"318 ").await?;
|
writer.write_all(b"318 ").await?;
|
||||||
|
|
Loading…
Reference in New Issue