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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/bzfsAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ typedef enum
bz_ePermissionModificationEvent,
bz_eAllowServerShotFiredEvent,
bz_ePlayerDeathFinalizedEvent,
bz_eReloadEvent,
bz_eLastEvent //this is never used as an event, just show it's the last one
} bz_eEventType;

Expand Down Expand Up @@ -1460,6 +1461,20 @@ class BZF_API bz_PermissionModificationData_V1 : public bz_EventData
bool customPerm;
};

class BZF_API bz_ReloadData_V1 : public bz_EventData
{
public:
bz_ReloadData_V1() : bz_EventData(bz_eReloadEvent)
, playerID(-1)
, target("all")
, handled(false)
{}
jwmelto marked this conversation as resolved.
Show resolved Hide resolved

int playerID;
const char* target;
bool handled;
};

// logging
BZF_API void bz_debugMessage ( int debugLevel, const char* message );
BZF_API void bz_debugMessagef( int debugLevel, const char* fmt, ... );
Expand Down Expand Up @@ -2163,6 +2178,7 @@ BZF_API void bz_gameOver(int playerID, bz_eTeamType team = eNoTeam);
BZF_API bool bz_restart ( void );
BZF_API const char* bz_getServerOwner();

BZF_API void bz_reloadAll();
BZF_API void bz_reloadLocalBans();
BZF_API void bz_reloadMasterBans();
BZF_API void bz_reloadGroups();
Expand Down
46 changes: 46 additions & 0 deletions src/bzfs/bzfsAPI.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4286,10 +4286,29 @@ BZF_API const char* bz_getServerOwner()
return getPublicOwner().c_str();
}

BZF_API void bz_reloadAll()
{
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.


bz_reloadLocalBans();
bz_reloadMasterBans();
bz_reloadGroups();
bz_reloadUsers();
bz_reloadHelp();
bz_reloadBadwords();
}

BZF_API void bz_reloadLocalBans()
{
// reload the banlist
logDebugMessage(3,"Reloading bans\n");

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?


clOptions->acl.load();

rescanForBans();
Expand All @@ -4302,6 +4321,11 @@ BZF_API void bz_reloadMasterBans()

// reload the banlist
logDebugMessage(3,"Reloading master bans\n");

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?


clOptions->acl.purgeMasters();

masterBanHandler.start();
Expand All @@ -4310,13 +4334,24 @@ BZF_API void bz_reloadMasterBans()
BZF_API void bz_reloadGroups()
{
logDebugMessage(3,"Reloading groups\n");

bz_ReloadData_V1 event;
event.target = "groups";
worldEventManager.callEvents(bz_eReloadEvent, &event);

groupAccess.clear();
initGroups();
}

BZF_API void bz_reloadUsers()
{
logDebugMessage(3,"Reloading users\n");

bz_ReloadData_V1 event;
event.target = "users";
worldEventManager.callEvents(bz_eReloadEvent, &event);


userDatabase.clear();

if (userDatabaseFile.size())
Expand All @@ -4328,12 +4363,23 @@ BZF_API void bz_reloadHelp()
{
// reload the text chunks
logDebugMessage(3,"Reloading helpfiles\n");

bz_ReloadData_V1 event;
event.target = "helpfiles";
worldEventManager.callEvents(bz_eReloadEvent, &event);


clOptions->textChunker.reload();
}

BZF_API void bz_reloadBadwords()
{
logDebugMessage(3,"Reloading bad words\n");

bz_ReloadData_V1 event;
event.target = "badwords";
worldEventManager.callEvents(bz_eReloadEvent, &event);

clOptions->filter.clear();
loadBadwordsList();
}
Expand Down
13 changes: 13 additions & 0 deletions src/bzfs/commands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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


worldEventManager.callEvents(bz_eReloadEvent, &event);

/* handle subcommands */

bool reload_bans = false;
bool reload_groups = false;
bool reload_users = false;
bool reload_helpfiles = false;
bool reload_badwords = false;

if ((cmd == "") || (cmd == "all"))
{
logDebugMessage(3,"Reload all\n");
Expand Down Expand Up @@ -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?

if (event.handled) {
return true;
}

sendMessage(ServerPlayer, t, "Invalid option for the reload command");
sendMessage(ServerPlayer, t, "Usage: /reload [all|bans|badwords|helpfiles|groups|users]");

return true; // Bail out
}

Expand Down