Jump to content
Fou-lu

Plugin Overloading - Bug Report?

Recommended Posts

 

I apologize if this is posted in the wrong location.

 

When programming a plugin that uses overloading, I realized that the way it is in the Hercules tutorial doesn't work.

 

image.png.3cd869cc76a16d41516bcaadfa48fd52.png

 

When reproducing what the tutorial asks for, placing it inside the "server_ready" function, overloading does not work. I needed to put it in the "plugin_init" function for it to work.

 

image.png.c811980d68a2d7f35ea0d8345114aeb1.png

 

 

Share this post


Link to post
Share on other sites

You are right, looks like "server_ready" is not part of the HPM events, so it is never called. I think the docs actually meant "server_online" (which means the server is ready / online).

 

I generally prefer using plugin_init, as you said, since server_online runs after several processing already happened (e.g. config loading). So the tutorial should probably use "plugin_init" instead.

 

Nice finding!

 

Do you want to PR a fix to the docs? :) If not, I can edit it later

Share this post


Link to post
Share on other sites

better not do direct overloading without reason. Because it may break other plugins if you not do correct overloading.

better use hpm overload things

 

Share this post


Link to post
Share on other sites
11 hours ago, 4144 said:

better not do direct overloading without reason. Because it may break other plugins if you not do correct overloading.

better use hpm overload things

 

by "hpm overload things" you mean hookPre/hookPost?

 

As far as I remember, overloading, as in "I want to completely skip hercules original function" (maybe it should actually be called override?) were always made with a direct assignment to the interface (like in the original post here), while hookPre/hookPost would be used if you want to keep the original code running, but wants to do something else before/after it.

 

Example: https://github.com/HerculesWS/Hercules/blob/stable/src/plugins/db2sql.c#L1180

 

I am not aware of another method for overloading/overriding.

 

I do agree that you should only do it if you have a reason to, but is there a better way to overload/override than a direct assignment?

Share this post


Link to post
Share on other sites
On 4/16/2024 at 10:07 PM, KirieZ said:

Do you want to PR a fix to the docs? :) If not, I can edit it later

 

Perfect. I have now submitted the change on GitHub.

 

On 4/17/2024 at 10:18 AM, 4144 said:

better not do direct overloading without reason. Because it may break other plugins if you not do correct overloading.

better use hpm overload things

 

I share the same doubt as KirieZ. As far as I know and have learned about HPM Plugins, the only method to overwrite/replace a function is through this way.

I know about HookPre and HookPost, however, in some situations where you want to remove a piece of code within the function, these solutions don't work, forcing you to resort to overloading.

Of course, whenever possible, I will adhere to HookPre and HookPost, and I can identify well when this is necessary.

Share this post


Link to post
Share on other sites

hpm overloading i mean hookPre/hookPost

Direct overloading i mean for example

clif->special_popup = my_special_popup

direct overloading may break other plugins.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.