Added new opcode: PLAYER_STATUS

This commit is contained in:
techmetx11 2024-06-26 21:57:03 +01:00
parent 32aeb2f2f7
commit 9f491c0e7c
No known key found for this signature in database
GPG Key ID: E60B63635FF4E062
5 changed files with 91 additions and 8 deletions

View File

@ -61,7 +61,7 @@ Decrypt a provided `s` signature using the server's current `sig` function code,
|string| *`size`* | The decrypted signature | |string| *`size`* | The decrypted signature |
### `GET_SIGNATURE_TIMESTAMP` (0x03) ### `GET_SIGNATURE_TIMESTAMP` (0x03)
Get the signature timestamp from the server's current player, and return it in the form of a 64-bit integer Get the signature timestamp from the server's current player, and return it in the form of a 64-bit integer. If there's no player, it will return 0 in the `timestamp` (Please check with `PLAYER_STATUS` if the server has a player)
#### Request #### Request
No additional data required No additional data required
@ -70,3 +70,17 @@ No additional data required
| Name | Size (bytes) | Description | | Name | Size (bytes) | Description |
|---------|--------------|----------------------------------------------------------| |---------|--------------|----------------------------------------------------------|
|timestamp| 8 | The signature timestamp from the server's current player | |timestamp| 8 | The signature timestamp from the server's current player |
### `PLAYER_STATUS` (0x04)
Get the server's information about the current player.
#### Request
No additional data required
#### Response
| Name | Size (bytes) | Description |
|----------|--------------|-------------|
|has_player| 1 | If the server has a player, this variable will be `0xFF`, or else, it will be `0x00`|
|player_id | 4 | The server's current player ID, If the server has no player, this will always be `0x00000000`|

View File

@ -15,6 +15,7 @@ pub enum JobOpcode {
DecryptNSignature, DecryptNSignature,
DecryptSignature, DecryptSignature,
GetSignatureTimestamp, GetSignatureTimestamp,
PlayerStatus,
UnknownOpcode, UnknownOpcode,
} }
@ -25,6 +26,7 @@ impl std::fmt::Display for JobOpcode {
Self::DecryptNSignature => write!(f, "DecryptNSignature"), Self::DecryptNSignature => write!(f, "DecryptNSignature"),
Self::DecryptSignature => write!(f, "DecryptSignature"), Self::DecryptSignature => write!(f, "DecryptSignature"),
Self::GetSignatureTimestamp => write!(f, "GetSignatureTimestamp"), Self::GetSignatureTimestamp => write!(f, "GetSignatureTimestamp"),
Self::PlayerStatus => write!(f, "PlayerStatus"),
Self::UnknownOpcode => write!(f, "UnknownOpcode"), Self::UnknownOpcode => write!(f, "UnknownOpcode"),
} }
} }
@ -36,6 +38,7 @@ impl From<u8> for JobOpcode {
0x01 => Self::DecryptNSignature, 0x01 => Self::DecryptNSignature,
0x02 => Self::DecryptSignature, 0x02 => Self::DecryptSignature,
0x03 => Self::GetSignatureTimestamp, 0x03 => Self::GetSignatureTimestamp,
0x04 => Self::PlayerStatus,
_ => Self::UnknownOpcode, _ => Self::UnknownOpcode,
} }
} }
@ -47,6 +50,7 @@ pub struct PlayerInfo {
pub sig_function_name: String, pub sig_function_name: String,
pub signature_timestamp: u64, pub signature_timestamp: u64,
pub player_id: u32, pub player_id: u32,
pub has_player: u8,
} }
pub struct JavascriptInterpreter { pub struct JavascriptInterpreter {
@ -105,6 +109,7 @@ impl GlobalState {
sig_function_name: Default::default(), sig_function_name: Default::default(),
player_id: Default::default(), player_id: Default::default(),
signature_timestamp: Default::default(), signature_timestamp: Default::default(),
has_player: 0x00,
}), }),
js_runtime_pool: runtime_pool, js_runtime_pool: runtime_pool,
} }
@ -130,6 +135,8 @@ pub async fn process_fetch_update<W>(
update_status: status, update_status: status,
signature: Default::default(), signature: Default::default(),
signature_timestamp: Default::default(), signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}) })
.await; .await;
} }
@ -169,7 +176,9 @@ pub async fn process_decrypt_n_signature<W>(
request_id, request_id,
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: String::new(), signature: String::new(),
signature_timestamp: Default::default() signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}).await; }).await;
return; return;
} }
@ -198,7 +207,9 @@ pub async fn process_decrypt_n_signature<W>(
request_id, request_id,
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: String::new(), signature: String::new(),
signature_timestamp: Default::default() signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}).await; }).await;
return; return;
} }
@ -211,7 +222,9 @@ pub async fn process_decrypt_n_signature<W>(
request_id, request_id,
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: decrypted_string, signature: decrypted_string,
signature_timestamp: Default::default() signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}).await; }).await;
}) })
.await; .await;
@ -251,7 +264,9 @@ pub async fn process_decrypt_signature<W>(
request_id, request_id,
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: String::new(), signature: String::new(),
signature_timestamp: Default::default() signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}).await; }).await;
return; return;
} }
@ -283,7 +298,9 @@ pub async fn process_decrypt_signature<W>(
request_id, request_id,
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: String::new(), signature: String::new(),
signature_timestamp: Default::default() signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}).await; }).await;
return; return;
} }
@ -297,6 +314,8 @@ pub async fn process_decrypt_signature<W>(
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: decrypted_string, signature: decrypted_string,
signature_timestamp: Default::default(), signature_timestamp: Default::default(),
has_player: Default::default(),
player_id: Default::default(),
}).await; }).await;
}) })
.await; .await;
@ -323,6 +342,37 @@ pub async fn process_get_signature_timestamp<W>(
update_status: Ok(Default::default()), update_status: Ok(Default::default()),
signature: String::new(), signature: String::new(),
signature_timestamp: timestamp, signature_timestamp: timestamp,
has_player: Default::default(),
player_id: Default::default(),
})
.await;
}
pub async fn process_player_status<W>(
state: Arc<GlobalState>,
stream: Arc<Mutex<W>>,
request_id: u32,
) where
W: SinkExt<OpcodeResponse> + Unpin + Send,
{
let cloned_writer = stream.clone();
let global_state = state.clone();
let player_info = global_state.player_info.lock().await;
let has_player = player_info.has_player;
let player_id = player_info.player_id;
let mut writer = cloned_writer.lock().await;
writer
.send(OpcodeResponse {
opcode: JobOpcode::PlayerStatus,
request_id,
update_status: Ok(Default::default()),
signature: String::new(),
signature_timestamp: Default::default(),
has_player,
player_id,
}) })
.await; .await;
} }

View File

@ -21,7 +21,9 @@ use tokio::{
}; };
use tokio_util::codec::{Decoder, Framed, FramedRead, FramedWrite}; use tokio_util::codec::{Decoder, Framed, FramedRead, FramedWrite};
use crate::jobs::{process_decrypt_signature, process_get_signature_timestamp}; use crate::jobs::{
process_decrypt_signature, process_get_signature_timestamp, process_player_status,
};
macro_rules! break_fail { macro_rules! break_fail {
($res:expr) => { ($res:expr) => {
@ -147,6 +149,14 @@ async fn process_socket(state: Arc<GlobalState>, socket: UnixStream) {
.await; .await;
}); });
} }
JobOpcode::PlayerStatus => {
let cloned_state = state.clone();
let cloned_sink = arc_sink.clone();
tokio::spawn(async move {
process_player_status(cloned_state, cloned_sink, opcode.request_id)
.await;
});
}
_ => { _ => {
continue; continue;
} }

View File

@ -24,6 +24,9 @@ pub struct OpcodeResponse {
pub update_status: Result<(), FetchUpdateStatus>, pub update_status: Result<(), FetchUpdateStatus>,
pub signature: String, pub signature: String,
pub signature_timestamp: u64, pub signature_timestamp: u64,
pub has_player: u8,
pub player_id: u32,
} }
impl Decoder for OpcodeDecoder { impl Decoder for OpcodeDecoder {
@ -44,7 +47,7 @@ impl Decoder for OpcodeDecoder {
let request_id: u32 = u32::from_be_bytes(src[1..5].try_into().unwrap()); let request_id: u32 = u32::from_be_bytes(src[1..5].try_into().unwrap());
match opcode { match opcode {
JobOpcode::ForceUpdate | JobOpcode::GetSignatureTimestamp => { JobOpcode::ForceUpdate | JobOpcode::GetSignatureTimestamp | JobOpcode::PlayerStatus => {
src.advance(5); src.advance(5);
Ok(Some(Opcode { Ok(Some(Opcode {
opcode, opcode,
@ -115,6 +118,11 @@ impl Encoder<OpcodeResponse> for OpcodeDecoder {
dst.put_u32(8); dst.put_u32(8);
dst.put_u64(item.signature_timestamp); dst.put_u64(item.signature_timestamp);
} }
JobOpcode::PlayerStatus => {
dst.put_u32(5);
dst.put_u8(item.has_player);
dst.put_u32(item.player_id);
}
_ => {} _ => {}
} }
Ok(()) Ok(())

View File

@ -173,6 +173,7 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
current_player_info.sig_function_code = sig_code; current_player_info.sig_function_code = sig_code;
current_player_info.sig_function_name = sig_function_name.to_string(); current_player_info.sig_function_name = sig_function_name.to_string();
current_player_info.signature_timestamp = signature_timestamp; current_player_info.signature_timestamp = signature_timestamp;
current_player_info.has_player = 0xFF;
Ok(()) Ok(())
} }