Compare commits
No commits in common. "884081d414094ab1c8fee6d0d1c803d786937391" and "7af59c3ba22b445a261bfd27511da105a9b7cc83" have entirely different histories.
884081d414
...
7af59c3ba2
@ -86,11 +86,8 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
}
|
||||
Event::Death(packet) => {
|
||||
if let Some(packet) = packet {
|
||||
let message_table = state.lua.create_table()?;
|
||||
message_table.set("text", packet.message.to_string())?;
|
||||
message_table.set("ansi_text", packet.message.to_ansi())?;
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("message", message_table)?;
|
||||
table.set("message", packet.message.to_string())?;
|
||||
table.set("player_id", packet.player_id.0)?;
|
||||
call_listeners(&state, "death", table).await;
|
||||
} else {
|
||||
@ -98,14 +95,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
}
|
||||
}
|
||||
Event::Disconnect(message) => {
|
||||
if let Some(message) = message {
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("text", message.to_string())?;
|
||||
table.set("ansi_text", message.to_ansi())?;
|
||||
call_listeners(&state, "disconnect", table).await;
|
||||
} else {
|
||||
call_listeners(&state, "disconnect", ()).await;
|
||||
}
|
||||
call_listeners(&state, "disconnect", message.map(|m| m.to_string())).await;
|
||||
}
|
||||
Event::KeepAlive(id) => call_listeners(&state, "keep_alive", id).await,
|
||||
Event::Login => call_listeners(&state, "login", ()).await,
|
||||
|
@ -1,25 +1,41 @@
|
||||
#[macro_export]
|
||||
macro_rules! crypt {
|
||||
($op:ident, $options:expr, $text:expr) => {{
|
||||
macro_rules! crypt_with {
|
||||
($algo:ident) => {{
|
||||
let encoding = $options.get("encoding").unwrap_or_default();
|
||||
let key = &$options.get::<UserDataRef<AesKey>>("$key")?.inner;
|
||||
match encoding {
|
||||
1 => $algo::<Base64Encoding>::$op($text, &key),
|
||||
2 => $algo::<Base64rEncoding>::$op($text, &key),
|
||||
_ => $algo::<NewBase64rEncoding>::$op($text, &key),
|
||||
macro_rules! crypt_with {
|
||||
($op:ident, $encoding:expr, $key:expr, $text:expr, $algo:ident) => {
|
||||
match $encoding {
|
||||
1 => $algo::<Base64Encoding>::$op($text, $key),
|
||||
2 => $algo::<Base64rEncoding>::$op($text, $key),
|
||||
_ => $algo::<NewBase64rEncoding>::$op($text, $key),
|
||||
}
|
||||
.map_err(|error| Error::external(error.to_string()))?
|
||||
}};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! crypt {
|
||||
($op:ident, $encoding:expr, $options:expr, $text:expr) => {
|
||||
match $options.get("encryption").unwrap_or_default() {
|
||||
1 => CaesarEncryption::$op(&$text, &$options.get("key")?)
|
||||
.map_err(|error| Error::external(error.to_string()))?,
|
||||
2 => crypt_with!(EcbEncryption),
|
||||
3 => crypt_with!(GcmEncryption),
|
||||
_ => crypt_with!(Cfb8Encryption),
|
||||
2 => crypt_with!(
|
||||
$op,
|
||||
$encoding,
|
||||
&$options.get::<UserDataRef<AesKey>>("key")?.inner,
|
||||
&$text,
|
||||
EcbEncryption
|
||||
),
|
||||
3 => crypt_with!(
|
||||
$op,
|
||||
$encoding,
|
||||
&$options.get::<UserDataRef<AesKey>>("key")?.inner,
|
||||
&$text,
|
||||
GcmEncryption
|
||||
),
|
||||
_ => crypt_with!(
|
||||
$op,
|
||||
$encoding,
|
||||
&$options.get::<UserDataRef<AesKey>>("key")?.inner,
|
||||
&$text,
|
||||
Cfb8Encryption
|
||||
),
|
||||
}
|
||||
}};
|
||||
};
|
||||
}
|
||||
|
@ -42,14 +42,24 @@ pub fn register_globals(lua: &Lua, globals: &Table) -> Result<()> {
|
||||
globals.set(
|
||||
"ncr_encrypt",
|
||||
lua.create_function(|_, (options, plaintext): (Table, String)| {
|
||||
Ok(crypt!(encrypt, options, &plaintext))
|
||||
Ok(crypt!(
|
||||
encrypt,
|
||||
options.get("encoding").unwrap_or_default(),
|
||||
options,
|
||||
plaintext
|
||||
))
|
||||
})?,
|
||||
)?;
|
||||
|
||||
globals.set(
|
||||
"ncr_decrypt",
|
||||
lua.create_function(|_, (options, ciphertext): (Table, String)| {
|
||||
Ok(crypt!(decrypt, options, &ciphertext))
|
||||
Ok(crypt!(
|
||||
decrypt,
|
||||
options.get("encoding").unwrap_or_default(),
|
||||
options,
|
||||
ciphertext
|
||||
))
|
||||
})?,
|
||||
)?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user