1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-08 17:37:46 +00:00

Create timestamp_msecs function, run Clippy auto-fix

This commit is contained in:
Joshua Goins 2025-03-17 17:31:22 -04:00
parent 974efe3824
commit aee23a200b
5 changed files with 22 additions and 34 deletions

View file

@ -48,7 +48,7 @@ impl LoginServerState {
if their_password == password { if their_password == password {
return self return self
.create_session(username) .create_session(username)
.ok_or_else(|| LoginError::InternalError); .ok_or(LoginError::InternalError);
} else { } else {
return Err(LoginError::WrongPassword); return Err(LoginError::WrongPassword);
} }
@ -128,15 +128,9 @@ async fn login_send(
Err(err) => { Err(err) => {
// TODO: see what the official error messages are // TODO: see what the official error messages are
match err { match err {
LoginError::WrongUsername => Html(format!( LoginError::WrongUsername => Html("window.external.user(\"login=auth,ng,err,Wrong Username\");".to_string()),
"window.external.user(\"login=auth,ng,err,Wrong Username\");" LoginError::WrongPassword => Html("window.external.user(\"login=auth,ng,err,Wrong Password\");".to_string()),
)), LoginError::InternalError => Html("window.external.user(\"login=auth,ng,err,Internal Server Error\");".to_string()),
LoginError::WrongPassword => Html(format!(
"window.external.user(\"login=auth,ng,err,Wrong Password\");"
)),
LoginError::InternalError => Html(format!(
"window.external.user(\"login=auth,ng,err,Internal Server Error\");"
)),
} }
} }
} }
@ -182,9 +176,9 @@ async fn check_session(
Query(params): Query<CheckSessionParams>, Query(params): Query<CheckSessionParams>,
) -> String { ) -> String {
if state.check_session(&params.sid) { if state.check_session(&params.sid) {
return "1".to_string(); "1".to_string()
} else { } else {
return "0".to_string(); "0".to_string()
} }
} }

View file

@ -1,8 +1,7 @@
use std::net::SocketAddr; use std::net::SocketAddr;
use axum::response::{Html, Redirect}; use axum::response::Html;
use axum::routing::post; use axum::{Router, routing::get};
use axum::{Router, extract::Form, routing::get};
use kawari::config::get_config; use kawari::config::get_config;
use kawari::setup_default_environment; use kawari::setup_default_environment;
use minijinja::context; use minijinja::context;

View file

@ -1,4 +1,3 @@
use std::time::{SystemTime, UNIX_EPOCH};
use kawari::oodle::OodleNetwork; use kawari::oodle::OodleNetwork;
use kawari::packet::{PacketSegment, PacketState, SegmentType, send_keep_alive}; use kawari::packet::{PacketSegment, PacketState, SegmentType, send_keep_alive};
@ -65,20 +64,13 @@ async fn main() {
// We have send THEM a keep alive // We have send THEM a keep alive
{ {
let timestamp: u32 = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Failed to get UNIX timestamp!")
.as_secs()
.try_into()
.unwrap();
connection connection
.send_segment(PacketSegment { .send_segment(PacketSegment {
source_actor: 0, source_actor: 0,
target_actor: 0, target_actor: 0,
segment_type: SegmentType::KeepAlive { segment_type: SegmentType::KeepAlive {
id: 0xE0037603u32, id: 0xE0037603u32,
timestamp, timestamp: timestamp_secs(),
}, },
}) })
.await; .await;

View file

@ -16,6 +16,7 @@ pub(crate) fn write_string(str: &String) -> Vec<u8> {
c_string.as_bytes_with_nul().to_vec() c_string.as_bytes_with_nul().to_vec()
} }
/// Get the number of seconds since UNIX epoch.
pub fn timestamp_secs() -> u32 { pub fn timestamp_secs() -> u32 {
SystemTime::now() SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
@ -24,3 +25,13 @@ pub fn timestamp_secs() -> u32 {
.try_into() .try_into()
.unwrap() .unwrap()
} }
/// Get the number of milliseconds since UNIX epoch.
pub fn timestamp_msecs() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Failed to get UNIX timestamp!")
.as_millis()
.try_into()
.unwrap()
}

View file

@ -1,14 +1,13 @@
use std::{ use std::{
fs::write, fs::write,
io::Cursor, io::Cursor,
time::{SystemTime, UNIX_EPOCH},
}; };
use binrw::{BinRead, BinWrite, binrw}; use binrw::{BinRead, BinWrite, binrw};
use tokio::{io::AsyncWriteExt, net::TcpStream}; use tokio::{io::AsyncWriteExt, net::TcpStream};
use crate::{ use crate::{
common::read_string, common::{read_string, timestamp_msecs},
oodle::OodleNetwork, oodle::OodleNetwork,
packet::{compression::compress, encryption::decrypt}, packet::{compression::compress, encryption::decrypt},
}; };
@ -141,20 +140,13 @@ pub async fn send_packet<T: ReadWriteIpcSegment>(
state: &mut PacketState, state: &mut PacketState,
compression_type: CompressionType, compression_type: CompressionType,
) { ) {
let timestamp: u64 = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Failed to get UNIX timestamp!")
.as_millis()
.try_into()
.unwrap();
let (data, uncompressed_size) = compress(state, &compression_type, segments); let (data, uncompressed_size) = compress(state, &compression_type, segments);
let size = std::mem::size_of::<PacketHeader>() + data.len(); let size = std::mem::size_of::<PacketHeader>() + data.len();
let header = PacketHeader { let header = PacketHeader {
unk1: 0xE2465DFF41A05252, // wtf? unk1: 0xE2465DFF41A05252, // wtf?
unk2: 0x75C4997B4D642A7F, // wtf? x2 unk2: 0x75C4997B4D642A7F, // wtf? x2
timestamp, timestamp: timestamp_msecs(),
size: size as u32, size: size as u32,
connection_type: ConnectionType::Lobby, connection_type: ConnectionType::Lobby,
segment_count: segments.len() as u16, segment_count: segments.len() as u16,