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

chore(Core/AllMapScript) Update structure #19979

Merged
merged 7 commits into from
Sep 21, 2024
Merged

Conversation

pangolp
Copy link
Contributor

@pangolp pangolp commented Sep 15, 2024

Changes Proposed:

This PR proposes changes to:

  • Hooks

Issues Addressed:

  • Closes

Tests Performed:

This PR has been:

  • Tested in-game by the author.

How to Test the Changes:

  1. When updating the crossfaction pve module, I tried to use the OnDestroyInstance hook and noticed that it was not being called. When checking the rest of the hooks, and remembering that the structure had been updated, I rewrote the files to adapt them and managed to get the hook to work in the module.
  2. Basically, to test the pull request, you should use the hook without this change, and then use the hook with the change. In the first case, it should not be called, and in the second, it should execute without problems.

How to Test AzerothCore PRs

When a PR is ready to be tested, it will be marked as [WAITING TO BE TESTED].

You can help by testing PRs and writing your feedback here on the PR's page on GitHub. Follow the instructions here:

http://www.azerothcore.org/wiki/How-to-test-a-PR

REMEMBER: when testing a PR that changes something generic (i.e. a part of code that handles more than one specific thing), the tester should not only check that the PR does its job (e.g. fixing spell XXX) but especially check that the PR does not cause any regression (i.e. introducing new bugs).

For example: if a PR fixes spell X by changing a part of code that handles spells X, Y, and Z, we should not only test X, but we should test Y and Z as well.

@github-actions github-actions bot added CORE Related to the core file-cpp Used to trigger the matrix build labels Sep 15, 2024
@Helias Helias requested a review from Yehonal September 15, 2024 22:21
@pangolp
Copy link
Contributor Author

pangolp commented Sep 15, 2024

I don't know why the tests fail. Because the compilation finished 100% without problems.
Maybe it's a github actions issue or I don't know what's happening to try to fix it.

@Yehonal
Copy link
Member

Yehonal commented Sep 15, 2024

is the CALL_ENABLED_HOOKS missing in other files too? maybe the refactoring was not complete

@pangolp
Copy link
Contributor Author

pangolp commented Sep 15, 2024

is the CALL_ENABLED_HOOKS missing in other files too? maybe the refactoring was not complete

In PlayerScript, I saw that it was modified, but not in this file, perhaps other files need to be modified.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 15, 2024

We could make a pull request to finish working on all of them, there would be no problem. It would take more time, I suppose, and some additional testing. Perhaps it would be better to divide the work and do it little by little, in case something had to be reverted. Also, if the change is very big, it is more difficult to test.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 15, 2024

Unless your comment refers to hooks inside these files, but which belong to other scripts, then yes, I would probably have to modify them, but I really could use an example, or someone else to help me by committing a commit on this same pull request.

@Yehonal
Copy link
Member

Yehonal commented Sep 15, 2024 via email

@pangolp
Copy link
Contributor Author

pangolp commented Sep 15, 2024

What I'm saying is that if without this macro all the other hooks are not working, probably we should fix them all. But I'd like to ask the original author because I'm not sure what's the problem here and I don't want to make assumptions @Winfidonarleyan @walkline ?

Sounds perfect to me. Let's wait for your reply then.

@Winfidonarleyan
Copy link
Member

What I'm saying is that if without this macro all the other hooks are not

working, probably we should fix them all. But I'd like to ask the original

author because I'm not sure what's the problem here and I don't want to

make assumptions

@Winfidonarleyan @walkline ?

I don't know why not work. Anyway, I don't like this system with selected hooks.

@sudlud
Copy link
Member

sudlud commented Sep 16, 2024

The implementation should be fully backwards compatible, e.g. enabling all hooks of a script if the enable-vector was not provided.

Also I would have expected that the AllMapScript should still have worked before this PR, as the changes are not necessary for it to work? It's just an optimization

@walkline
Copy link
Contributor

Here is the original PR: #18672, where you can find details about the problem it aims to solve.

As @sudlud mentioned, the change is backward compatible, and AllMapScript should work as it is. However, without this change, it would remain unoptimized.

I’m not sure why the CI is crashing, and I can’t debug it at the moment. If someone could provide a crash log, that would be helpful.

@Yehonal
Copy link
Member

Yehonal commented Sep 16, 2024

Here is the original PR: #18672, where you can find details about the problem it aims to solve.

As @sudlud mentioned, the change is backward compatible, and AllMapScript should work as it is. However, without this change, it would remain unoptimized.

I’m not sure why the CI is crashing, and I can’t debug it at the moment. If someone could provide a crash log, that would be helpful.

Besides the CI crashing, why do you think @pangolp is experiencing this issue? If the old hooks are not working anymore, this is definitely a critical problem. Can someone double check and confirm this please?

@Winfidonarleyan why you don't like it? What's your opinion?

@walkline
Copy link
Contributor

I don’t think there are any other issues, and I believe @pangolp used the wrong title (specifically the “fix” part) for this PR, as it is not addressing any bugs.

@Yehonal
Copy link
Member

Yehonal commented Sep 16, 2024

Seems @pangolp is stating that without the new macro, the hooks are not being called at all. Which sounds like a bug to me. But I might misunderstood it

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

You can use the CFPVE module, where we use the hook, and you'll see that it doesn't work, unless this change is made. https://github.com/pangolp/mod-cfpve

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

That doesn't mean, the title of the pull request, maybe it's wrong. But before this change, the hook didn't work for me and I leave you the module to try it yourself or invoke it, to see if it works for you in any module of your own.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

@Yehonal @Winfidonarleyan @walkline @sudlud When I started working on this part of the code specifically

class CfAllMapScript : public AllMapScript
{
public:
    CfAllMapScript() : AllMapScript("CfAllMapScript") { }

    void OnDestroyInstance(MapInstanced* /*mapInstanced*/, Map* map) override
    {
        QueryResult result = CharacterDatabase.Query("SELECT `factionID` FROM `mod_crossfaction_pve` WHERE `instanceID`={}", map->GetInstanceId());

        if (result)
        {
            CharacterDatabase.DirectExecute("DELETE FROM `mod_crossfaction_pve` WHERE `instanceID`={}", map->GetInstanceId());
        }
    }
};

Notice that it was not running. So reviewing the file, I saw that the structure of AllMapScript was not the same as that of PlayerScript, I made only 1 of the changes, so that the specific hook that I am using works for me and I saw that it was executed, That's why I decided to upload the pull request, so that you can tell me if it is correct, and if something needs to be corrected, also let me know, so we can do it and merge it.

Don't focus on the content of the module, because it is a temporary solution to a very specific bug that the crossfaction currently has, but there must be better ways to solve it, however, for now, we came up with that one.

And on the other hand, the title may not be correct, so if someone wants to adapt it, they can do so without problems, so that it is more representative of the problem I am trying to present and correct.

I look forward to any modifications and comments you make on this topic. Thanks in advance.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

In parallel, I would also like to know why the tests failed, why a compilation error, it seems that it is not. The fault seems to be elsewhere. @Helias, can you run the tests again please?, thank you.

@Helias
Copy link
Member

Helias commented Sep 16, 2024

done 👍

@Yehonal
Copy link
Member

Yehonal commented Sep 16, 2024 via email

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

I do understand what you are doing here. What I do not understand is if these hooks were broken, most likely also the other ones that are not using the new CALL_ENABLED_HOOKS might be broken. This PR aims to fix a issue with a specific bug for your specific case, but our interest as AC devs here is to also understand if this is a general problem or not Can someone test it? Also, it would be great to understand the exact reason why it was not working if people are stating that the changes were backward compatible. I don't like to close this case and have possibly fixed/considered half of the problem and forget about the remaing

That seems fine to me. I am available to help with the solution.

@sudlud
Copy link
Member

sudlud commented Sep 16, 2024

@PkllonG did you check your script before PR? So we know if there was actually an issue with allmapscript.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

@PkllonG did you check your script before PR? So we know if there was actually an issue with allmapscript.

I didn't use this PR, The module works fine.

Does it work without this pull request or did you have to use it to make it work?
Because I wanted to use the hook in the custom module that happened, and there was no case, until I applied this change.
You can do a std::cout or something similar, using the OnDestroyInstance to see if the hook call works please. Thank you.

@sudlud
Copy link
Member

sudlud commented Sep 16, 2024

@Yehonal @Winfidonarleyan @walkline @sudlud When I started working on this part of the code specifically

class CfAllMapScript : public AllMapScript
{
public:
    CfAllMapScript() : AllMapScript("CfAllMapScript") { }

    void OnDestroyInstance(MapInstanced* /*mapInstanced*/, Map* map) override
    {
        QueryResult result = CharacterDatabase.Query("SELECT `factionID` FROM `mod_crossfaction_pve` WHERE `instanceID`={}", map->GetInstanceId());

        if (result)
        {
            CharacterDatabase.DirectExecute("DELETE FROM `mod_crossfaction_pve` WHERE `instanceID`={}", map->GetInstanceId());
        }
    }
};

Notice that it was not running. So reviewing the file, I saw that the structure of AllMapScript was not the same as that of PlayerScript, I made only 1 of the changes, so that the specific hook that I am using works for me and I saw that it was executed, That's why I decided to upload the pull request, so that you can tell me if it is correct, and if something needs to be corrected, also let me know, so we can do it and merge it.

Don't focus on the content of the module, because it is a temporary solution to a very specific bug that the crossfaction currently has, but there must be better ways to solve it, however, for now, we came up with that one.

And on the other hand, the title may not be correct, so if someone wants to adapt it, they can do so without problems, so that it is more representative of the problem I am trying to present and correct.

I look forward to any modifications and comments you make on this topic. Thanks in advance.

@pangolp the script you provided works fine on a35f0c4 (current master before this PR).

so @PkllonG and myself have verified that there has been no general issue to AllMapScript.

did you probably forget this on your first test runs:

new CfAllMapScript();

(because that's an issue i just ran into while testing your AllMapScript.)

@pangolp
Copy link
Contributor Author

pangolp commented Sep 16, 2024

@Yehonal @Winfidonarleyan @walkline @sudlud When I started working on this part of the code specifically

class CfAllMapScript : public AllMapScript
{
public:
    CfAllMapScript() : AllMapScript("CfAllMapScript") { }

    void OnDestroyInstance(MapInstanced* /*mapInstanced*/, Map* map) override
    {
        QueryResult result = CharacterDatabase.Query("SELECT `factionID` FROM `mod_crossfaction_pve` WHERE `instanceID`={}", map->GetInstanceId());

        if (result)
        {
            CharacterDatabase.DirectExecute("DELETE FROM `mod_crossfaction_pve` WHERE `instanceID`={}", map->GetInstanceId());
        }
    }
};

Notice that it was not running. So reviewing the file, I saw that the structure of AllMapScript was not the same as that of PlayerScript, I made only 1 of the changes, so that the specific hook that I am using works for me and I saw that it was executed, That's why I decided to upload the pull request, so that you can tell me if it is correct, and if something needs to be corrected, also let me know, so we can do it and merge it.
Don't focus on the content of the module, because it is a temporary solution to a very specific bug that the crossfaction currently has, but there must be better ways to solve it, however, for now, we came up with that one.
And on the other hand, the title may not be correct, so if someone wants to adapt it, they can do so without problems, so that it is more representative of the problem I am trying to present and correct.
I look forward to any modifications and comments you make on this topic. Thanks in advance.

@pangolp the script you provided works fine on a35f0c4 (current master before this PR).

so @PkllonG and myself have verified that there has been no general issue to AllMapScript.

did you probably forget this on your first test runs:

new CfAllMapScript();

(because that's an issue i just ran into while testing your AllMapScript.)

It is included and I always used it, but hey, if they tried the hook and it worked, it would have been my problem I guess.
Could it perhaps have something to do with the operating system? I am using Windows.
It wouldn't be the first time there has been some incompatibility.
With the emails, and the server crash, it did not fail in Ubuntu, but in Windows it did.

void CfpveScripts()
{
    new CfPlayerScript();
    new CfAllMapScript();
    new CfServerScript();
}

@Yehonal
Copy link
Member

Yehonal commented Sep 17, 2024

Ok, thanks for checking. so, considering this, I have another question before approve/merge this PR:

Is the new CALL_ENABLED_HOOKS intended to be used everywhere? If so, this PR might still be worth merging anyway to keep the code up to date, but at the same time, there should be no priority in converting all the other hooks for now

What do you think

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

I'm could keep working on this pull request. I just need to be told what to do, we change the title and we add more commits. I'm not in a hurry to merge it, it's not critical. But he needed some example maybe to finish the work, although I'll try to investigate something on my own. This is the first time I have made a change of this style.

@sudlud
Copy link
Member

sudlud commented Sep 17, 2024

@Yehonal as @walkline mentioned, the enable-hooks-mechanic originated in #18627.

the majority of scripts has been converted already (see referenced PRs in #18627) and there have been no issues so far that I know of.

so the only remaining issue in this PR imo is the failing CI, maybe @pangolp can please merge latest master to ensure everything’s up to date?
It seems the worldserver is crashing on startup in the CI runs, which does not happen in any other of the currently open PRs, so this must be addressed imo.

@Nyeriah
Copy link
Member

Nyeriah commented Sep 17, 2024

What is interesting is the module CI isn't crashing

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

@Yehonal as @walkline mentioned, the enable-hooks-mechanic originated in #18627.

the majority of scripts has been converted already (see referenced PRs in #18627) and there have been no issues so far that I know of.

so the only remaining issue in this PR imo is the failing CI, maybe @pangolp can please merge latest master to ensure everything’s up to date?
It seems the worldserver is crashing on startup in the CI runs, which does not happen in any other of the currently open PRs, so this must be addressed imo.

I'm going to check. But I think there's work to be done here anyway. I will also review the pull request that you mention.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

What is interesting is the module CI isn't crashing

I'm going to review this as well. Thank you.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

  • I'll update the branch to see if the bugs persist, but then I'll have to look at the pull request and finish writing the macros I missed.

  • Sometimes the translator plays tricks on me and that's why, when something is not clear to me, I ask again. Because if I read it in a predetermined way, like this pull request is useless, but then they mention that they are possibly going to merge it and I don't understand anything hahaha. But it's the translator, who by not giving it context, confuses me a little.

😅

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

Do you need me to test if OnDestroyInstance is running before PR?

Yes, please, I tried it and it didn't work for me. That's why I created this pull request.

@sudlud
Copy link
Member

sudlud commented Sep 17, 2024

Do you need me to test if OnDestroyInstance is running before PR?

I already tested it, it works, see my message above. @pangolp please do not tell several people to test the same thing again and again

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

I already tested it, it works, see my message above. @pangolp please do not tell several people to test the same thing again and again

I didn't do it on purpose. Again, since I use a translator, sometimes I can't follow the threads of the conversations or I forget, because I have to use the translator again. The person offered, and I said yes. But I didn't do it with bad intentions. You could put a tested label if not, and people would already know that it was tested.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 17, 2024

  • Provide a module for them to test. https://github.com/pangolp/mod-cfpve
  • Explain the reasons why I made the change (OnDestroyInstance did not work for me without this change)
  • I am available for any changes or improvements that you deem appropriate.
  • I'm in no hurry to merge it.

The only bad thing is that I can't fix the failure in the tests.
Because it's not about compilation.

@pangolp pangolp changed the title fix(Core/AllMapScript) Update structure to use CALL_ENABLED_HOOKS chore(Core/AllMapScript) Update structure to use CALL_ENABLED_HOOKS Sep 17, 2024
@pangolp pangolp changed the title chore(Core/AllMapScript) Update structure to use CALL_ENABLED_HOOKS chore(Core/AllMapScript) Update structure Sep 17, 2024
@pangolp
Copy link
Contributor Author

pangolp commented Sep 19, 2024

Does anyone know why this change is not passing the tests to try to fix it? Because it doesn't seem to be a compilation issue.

@Nyeriah
Copy link
Member

Nyeriah commented Sep 20, 2024

This PR is in a stalemate. The CI is crashing on start up but (to my knowledge) we can't see the crash log produced. I have personally tested this PR and no crash is produced when starting up the server. We, however, cannot merge it with a broken CI.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 21, 2024

This PR is in a stalemate. The CI is crashing on start up but (to my knowledge) we can't see the crash log produced. I have personally tested this PR and no crash is produced when starting up the server. We, however, cannot merge it with a broken CI.

The question would be how to solve this problem...
What is causing it to break...

@pangolp
Copy link
Contributor Author

pangolp commented Sep 21, 2024

If the hook works and since we can't correct the problem in the tests, I think we should close this.

@walkline
Copy link
Contributor

It's crashing because you forgot to add AllMapScript here -

ScriptRegistry<WorldScript>::InitEnabledHooksIfNeeded(WORLDHOOK_END);

@pangolp
Copy link
Contributor Author

pangolp commented Sep 21, 2024

It's crashing because you forgot to add AllMapScript here -

If that happens, I will travel personally and give you a hug haha.

@pangolp
Copy link
Contributor Author

pangolp commented Sep 21, 2024

@walkline You are the hero of the day.
@Nyeriah I've already passed the tests, all yours.

@sudlud sudlud merged commit cfd7bf4 into azerothcore:master Sep 21, 2024
17 checks passed
@pangolp pangolp deleted the mapScript branch September 22, 2024 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CORE Related to the core file-cpp Used to trigger the matrix build To Be Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants