Compare commits
No commits in common. "2cf4265732b2f7d783a267934e74297467929299" and "505b1a26afa737e9289db5e75c951bf0f2dec78d" have entirely different histories.
2cf4265732
...
505b1a26af
@ -1,15 +1,11 @@
|
|||||||
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
|
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
|
||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
use mlua::{Error, Result, Table, UserDataRef};
|
use mlua::{Function, Table};
|
||||||
use ncr::{
|
use ncr::utils::prepend_header;
|
||||||
encoding::{Base64Encoding, Base64rEncoding, NewBase64rEncoding},
|
|
||||||
encryption::{CaesarEncryption, Cfb8Encryption, EcbEncryption, Encryption, GcmEncryption},
|
|
||||||
utils::prepend_header,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
State, crypt,
|
State,
|
||||||
lua::{eval, exec, nochatreports::key::AesKey, reload},
|
lua::{eval, exec, reload},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
||||||
@ -23,20 +19,15 @@ pub struct CommandSource {
|
|||||||
|
|
||||||
impl CommandSource {
|
impl CommandSource {
|
||||||
pub fn reply(&self, message: &str) {
|
pub fn reply(&self, message: &str) {
|
||||||
fn encrypt(options: &Table, plaintext: &str) -> Result<String> {
|
|
||||||
Ok(crypt!(encrypt, options, &prepend_header(plaintext)))
|
|
||||||
}
|
|
||||||
|
|
||||||
for mut chunk in message
|
for mut chunk in message
|
||||||
.chars()
|
.chars()
|
||||||
.collect::<Vec<char>>()
|
.collect::<Vec<char>>()
|
||||||
.chunks(if self.ncr_options.is_some() { 150 } else { 236 })
|
.chunks(if self.ncr_options.is_some() { 150 } else { 236 })
|
||||||
.map(|chars| chars.iter().collect::<String>())
|
.map(|chars| chars.iter().collect::<String>())
|
||||||
{
|
{
|
||||||
if let Some(ciphertext) = self
|
if let Some(options) = &self.ncr_options
|
||||||
.ncr_options
|
&& let Ok(encrypt) = self.state.lua.globals().get::<Function>("ncr_encrypt")
|
||||||
.as_ref()
|
&& let Ok(ciphertext) = encrypt.call::<String>((options, prepend_header(&chunk)))
|
||||||
.and_then(|options| encrypt(options, &chunk).ok())
|
|
||||||
{
|
{
|
||||||
chunk = ciphertext;
|
chunk = ciphertext;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ use crate::{
|
|||||||
replay::recorder::Recorder,
|
replay::recorder::Recorder,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub async fn handle_event(client: Client, event: Event, state: State) -> Result<()> {
|
pub async fn handle_event(client: Client, event: Event, state: State) -> Result<()> {
|
||||||
match event {
|
match event {
|
||||||
Event::AddPlayer(player_info) => {
|
Event::AddPlayer(player_info) => {
|
||||||
|
@ -3,8 +3,9 @@ macro_rules! crypt {
|
|||||||
($op:ident, $options:expr, $text:expr) => {{
|
($op:ident, $options:expr, $text:expr) => {{
|
||||||
macro_rules! crypt_with {
|
macro_rules! crypt_with {
|
||||||
($algo:ident) => {{
|
($algo:ident) => {{
|
||||||
|
let encoding = $options.get("encoding").unwrap_or_default();
|
||||||
let key = &$options.get::<UserDataRef<AesKey>>("key")?.0;
|
let key = &$options.get::<UserDataRef<AesKey>>("key")?.0;
|
||||||
match $options.get("encoding").unwrap_or_default() {
|
match encoding {
|
||||||
1 => $algo::<Base64Encoding>::$op($text, &key),
|
1 => $algo::<Base64Encoding>::$op($text, &key),
|
||||||
2 => $algo::<Base64rEncoding>::$op($text, &key),
|
2 => $algo::<Base64rEncoding>::$op($text, &key),
|
||||||
_ => $algo::<NewBase64rEncoding>::$op($text, &key),
|
_ => $algo::<NewBase64rEncoding>::$op($text, &key),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user