mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-25 04:57:12 +01:00
Removes the need for the internal API (#32185)
* Removes the need for the internal API * Build Rust library --------- Co-authored-by: paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
parent
c925a0396d
commit
f81c60c0bf
@@ -1,7 +1,10 @@
|
||||
mod jobs;
|
||||
mod logging;
|
||||
mod mapmanip;
|
||||
mod mfa;
|
||||
mod milla;
|
||||
mod misc;
|
||||
// If its prefixed with rustlibs, its a port of the rust-g ones
|
||||
mod rustlibs_dmi;
|
||||
mod rustlibs_file;
|
||||
mod rustlibs_git;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{collections::{HashMap, HashSet}, iter::Map};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use super::core::GridMap;
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
use byondapi::value::ByondValue;
|
||||
use totp_rs::{Algorithm, Secret, TOTP};
|
||||
|
||||
const ISSUER: &str = "Paradise Station";
|
||||
|
||||
// This is a common method to ensure parameters stay the same between creation and verification
|
||||
fn instance_totp_manager(secret: String, accname: String) -> TOTP {
|
||||
TOTP::new(
|
||||
Algorithm::SHA1,
|
||||
6,
|
||||
1,
|
||||
30,
|
||||
Secret::Encoded(secret.to_owned()).to_bytes().unwrap(),
|
||||
Some(ISSUER.to_string()),
|
||||
accname.to_owned(),
|
||||
)
|
||||
.unwrap() // who needs safety lmao
|
||||
}
|
||||
|
||||
#[byondapi::bind]
|
||||
fn mfa_generate_secret() -> eyre::Result<ByondValue> {
|
||||
let mfa_secret = Secret::generate_secret().to_encoded().to_string();
|
||||
|
||||
Ok(ByondValue::new_str(mfa_secret)?)
|
||||
}
|
||||
|
||||
#[byondapi::bind]
|
||||
fn mfa_generate_qr(secret: ByondValue, ckey: ByondValue) -> eyre::Result<ByondValue> {
|
||||
let secret_str = secret.get_string()?;
|
||||
let ckey_str = ckey.get_string()?;
|
||||
|
||||
// Get the QR from our secret
|
||||
let png_base64 = instance_totp_manager(secret_str, ckey_str)
|
||||
.get_qr_base64()
|
||||
.unwrap();
|
||||
|
||||
// Send it back
|
||||
Ok(ByondValue::new_str(format!(
|
||||
"data:image/png;base64,{png_base64}"
|
||||
))?)
|
||||
}
|
||||
|
||||
#[byondapi::bind]
|
||||
fn mfa_verify_code(secret: ByondValue, code: ByondValue) -> eyre::Result<ByondValue> {
|
||||
// Code MUST be a string to avoid 0 prefixing issues
|
||||
let secret_str = secret.get_string()?;
|
||||
let code_str = code.get_string()?;
|
||||
|
||||
let totp = instance_totp_manager(secret_str, String::new());
|
||||
|
||||
// Check provided code
|
||||
if totp.check_current(&code_str).unwrap_or(false) {
|
||||
return Ok(ByondValue::new_num(1f32));
|
||||
} else {
|
||||
return Ok(ByondValue::new_num(0f32));
|
||||
}
|
||||
}
|
||||
@@ -318,8 +318,8 @@ mod tests {
|
||||
toxins_: Option<f32>,
|
||||
sleeping_agent_: Option<f32>,
|
||||
agent_b_: Option<f32>,
|
||||
hydrogen: Option<f32>,
|
||||
water_vapor: Option<f32>,
|
||||
hydrogen_: Option<f32>,
|
||||
water_vapor_: Option<f32>,
|
||||
thermal_energy_: Option<f32>,
|
||||
temperature_: Option<f32>,
|
||||
}
|
||||
@@ -333,8 +333,8 @@ mod tests {
|
||||
toxins_: None,
|
||||
sleeping_agent_: None,
|
||||
agent_b_: None,
|
||||
hydrogen: None,
|
||||
water_vapor: None,
|
||||
hydrogen_: None,
|
||||
water_vapor_: None,
|
||||
thermal_energy_: None,
|
||||
temperature_: None,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
use byondapi::value::ByondValue;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[byondapi::bind]
|
||||
fn misc_new_uuid() -> eyre::Result<ByondValue> {
|
||||
let uuid: String = Uuid::new_v4().to_string();
|
||||
Ok(ByondValue::new_str(uuid)?)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ fn submit_request(prep: RequestPrep) -> Result<String> {
|
||||
// TODO: this is a sinful hack, rewrite this as soon as the module is stable on live
|
||||
let response = match prep.req.send_bytes(&prep.body) {
|
||||
Ok(r) => r,
|
||||
Err(ureq::Error::Status(code, r)) => r,
|
||||
Err(ureq::Error::Status(_code, r)) => r,
|
||||
Err(ureq::Error::Transport(t)) => {
|
||||
let mut resp = Response {
|
||||
status_code: 0,
|
||||
|
||||
Reference in New Issue
Block a user