Skip to content

Commit

Permalink
more logging and better errors
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Mar 14, 2024
1 parent 98f0913 commit b2d8c81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async fn handle_activity_events(
) -> Option<()> {
match events.try_recv().ok()? {
ActivityEvent::Join(join) => {
log::info!("invite proccessing");
let secret = try_cstring(&join.secret).expect("I like null bytes in my strings cool");
JOIN_HANDLER_FUNCTION.lock()(secret.as_ptr())
}
Expand Down
13 changes: 7 additions & 6 deletions src/invite_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ pub static JOIN_HANDLER_FUNCTION: Mutex<JoinHandler> = Mutex::new(default_join_h

type JoinHandler = extern "C" fn(*const c_char);

/// Success/Failure
/// C Compatible Result Enum
///
/// fails if the string is non utf-8 or the pointer is null
#[repr(C)]
#[must_use]
pub enum IniviteHandlerResult {
Sucess,
Failure,
Ok,
NullSecret,
NonUtf8Secret,
}

/// registered as "InviteHandler001"
Expand All @@ -39,15 +40,15 @@ impl InviteHandler {
/// sets a secret for party which will be provided to everyone that joins the party
pub fn set_secret(&self, secret: *const c_char) -> IniviteHandlerResult {
if secret.is_null() {
return IniviteHandlerResult::Failure;
return IniviteHandlerResult::NullSecret;
}

let Some(secret) = unsafe { CStr::from_ptr(secret) }.to_str().ok() else {
return IniviteHandlerResult::Failure;
return IniviteHandlerResult::NonUtf8Secret;
};

PLUGIN.wait().activity.lock().secrets.join = Some(secret.to_string());
IniviteHandlerResult::Sucess
IniviteHandlerResult::Ok
}

/// removes the secret which destroys the party invite
Expand Down

0 comments on commit b2d8c81

Please sign in to comment.