mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-23 23:57:46 +00:00
Create timestamp_msecs function, run Clippy auto-fix
This commit is contained in:
parent
974efe3824
commit
aee23a200b
5 changed files with 22 additions and 34 deletions
|
@ -48,7 +48,7 @@ impl LoginServerState {
|
|||
if their_password == password {
|
||||
return self
|
||||
.create_session(username)
|
||||
.ok_or_else(|| LoginError::InternalError);
|
||||
.ok_or(LoginError::InternalError);
|
||||
} else {
|
||||
return Err(LoginError::WrongPassword);
|
||||
}
|
||||
|
@ -128,15 +128,9 @@ async fn login_send(
|
|||
Err(err) => {
|
||||
// TODO: see what the official error messages are
|
||||
match err {
|
||||
LoginError::WrongUsername => Html(format!(
|
||||
"window.external.user(\"login=auth,ng,err,Wrong Username\");"
|
||||
)),
|
||||
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\");"
|
||||
)),
|
||||
LoginError::WrongUsername => Html("window.external.user(\"login=auth,ng,err,Wrong Username\");".to_string()),
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,9 +176,9 @@ async fn check_session(
|
|||
Query(params): Query<CheckSessionParams>,
|
||||
) -> String {
|
||||
if state.check_session(¶ms.sid) {
|
||||
return "1".to_string();
|
||||
"1".to_string()
|
||||
} else {
|
||||
return "0".to_string();
|
||||
"0".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use axum::response::{Html, Redirect};
|
||||
use axum::routing::post;
|
||||
use axum::{Router, extract::Form, routing::get};
|
||||
use axum::response::Html;
|
||||
use axum::{Router, routing::get};
|
||||
use kawari::config::get_config;
|
||||
use kawari::setup_default_environment;
|
||||
use minijinja::context;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use kawari::oodle::OodleNetwork;
|
||||
use kawari::packet::{PacketSegment, PacketState, SegmentType, send_keep_alive};
|
||||
|
@ -65,20 +64,13 @@ async fn main() {
|
|||
|
||||
// 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
|
||||
.send_segment(PacketSegment {
|
||||
source_actor: 0,
|
||||
target_actor: 0,
|
||||
segment_type: SegmentType::KeepAlive {
|
||||
id: 0xE0037603u32,
|
||||
timestamp,
|
||||
timestamp: timestamp_secs(),
|
||||
},
|
||||
})
|
||||
.await;
|
||||
|
|
|
@ -16,6 +16,7 @@ pub(crate) fn write_string(str: &String) -> Vec<u8> {
|
|||
c_string.as_bytes_with_nul().to_vec()
|
||||
}
|
||||
|
||||
/// Get the number of seconds since UNIX epoch.
|
||||
pub fn timestamp_secs() -> u32 {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
@ -24,3 +25,13 @@ pub fn timestamp_secs() -> u32 {
|
|||
.try_into()
|
||||
.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()
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use std::{
|
||||
fs::write,
|
||||
io::Cursor,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use binrw::{BinRead, BinWrite, binrw};
|
||||
use tokio::{io::AsyncWriteExt, net::TcpStream};
|
||||
|
||||
use crate::{
|
||||
common::read_string,
|
||||
common::{read_string, timestamp_msecs},
|
||||
oodle::OodleNetwork,
|
||||
packet::{compression::compress, encryption::decrypt},
|
||||
};
|
||||
|
@ -141,20 +140,13 @@ pub async fn send_packet<T: ReadWriteIpcSegment>(
|
|||
state: &mut PacketState,
|
||||
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 size = std::mem::size_of::<PacketHeader>() + data.len();
|
||||
|
||||
let header = PacketHeader {
|
||||
unk1: 0xE2465DFF41A05252, // wtf?
|
||||
unk2: 0x75C4997B4D642A7F, // wtf? x2
|
||||
timestamp,
|
||||
timestamp: timestamp_msecs(),
|
||||
size: size as u32,
|
||||
connection_type: ConnectionType::Lobby,
|
||||
segment_count: segments.len() as u16,
|
||||
|
|
Loading…
Add table
Reference in a new issue