Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bz_eReloadEvent API event #214

Draft
wants to merge 1 commit into
base: 2.4
Choose a base branch
from

Conversation

allejo
Copy link
Member

@allejo allejo commented Aug 20, 2019

This PR will allow plug-ins to safely and easily hook into /reload and bz_reload*() events. This will also allow for custom /reload subcommands without needing to overload the /reload command.

The reason behind this change is to allow plugins to have custom reload functionality.

Copy link
Member

@jwmelto jwmelto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me how/when the worldEventManager should interact here. Some events appear to do normal server-side stuff then dispatch to the event manager to (I guess) allow plugins to have a go. Some of the new calls dispatch first, then do server-side stuff, potentially undoing what a plugin might do.

Seems to me that what is intended to be allowed by plugins ought to be clear in the API. I'm not well versed in the API, but it's confusing to the novice.

{
bz_ReloadData_V1 event;
event.target = "all";
worldEventManager.callEvents(bz_eReloadEvent, &event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since each method individually calls load events, is this redundant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically no, since this will send "all" and each call below will send a different string, but if "all" is exploded on the other side then ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I was thinking that if we want to listen to an explicit bz_reloadAll() or /reload all, it'd be useful to know when that happens even though it would trigger subsequent bz_eReloadEvent.

@@ -2762,13 +2762,20 @@ bool ReloadCommand::operator() (const char *message,

logDebugMessage(3,"Command is %s\n", cmd.c_str());

bz_ReloadData_V1 event;
event.playerID = t;
event.target = cmd.c_str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need validation prior to being shoved down the event manager?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, this would allow for event.target to be "all" at the moment, I can fix that

@@ -2805,8 +2812,14 @@ bool ReloadCommand::operator() (const char *message,
}
else
{
// Allow a plug-in to take over
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the unconditional event manager call is correct, then shouldn't this be moved immediately after it?

I apologize for not being clear on how the event manager interacts; is the point to "do what we do" and allow plugins to extend, or do we allow plugins to override?


bz_ReloadData_V1 event;
event.target = "bans";
worldEventManager.callEvents(bz_eReloadEvent, &event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as noted below, what's the proper interaction with the event manager? Should the call be before the acl.load() like this, meaning this might potentially undo a plugin action, or should the event manager call be after the defined action? Or should the event be tested to see if it was handled?


bz_ReloadData_V1 event;
event.target = "masterbans";
worldEventManager.callEvents(bz_eReloadEvent, &event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method can short-circuit (line 4320 above), meaning the event manager will not dispatch this message. Is that right?

include/bzfsAPI.h Show resolved Hide resolved
@allejo
Copy link
Member Author

allejo commented Aug 21, 2019

@jwmelto since the remaining comments are related, my thinking was that bz_eReloadEvent is sent as a notification event, so it'll only be sent when something actually happens (e.g. the masterban bailing out early).

As for the event.handled, I was thinking that we shouldn't let plug-ins take over built-in bzfs functionality but, we could allow plug-ins to hook into unknown reload events at which point, bzfs silences its failure messages. I know this goes against my original thought of having this event be notification-only. And having a handled could be misleading since you can't take over built-in functionality.

Whether the event should be fired before or after the action, I'm on the fence about.

Thoughts?

@jwmelto
Copy link
Member

jwmelto commented Aug 23, 2019

I don’t know enough to have an informed opinion. As long as the intent is clearly commented and consistent, I defer to those of you who write plugins.

Is the distinction between notification and overridable behavior prevalent? Should the event name reflect that, like bz_eReloadNotification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants