Skip to content

refactor(Core/Account): Move account flag logic from AccountMgr to WorldSession#22558

Merged
Kitzunu merged 5 commits into
azerothcore:masterfrom
Kitzunu:store-things
Jul 27, 2025
Merged

refactor(Core/Account): Move account flag logic from AccountMgr to WorldSession#22558
Kitzunu merged 5 commits into
azerothcore:masterfrom
Kitzunu:store-things

Conversation

@Kitzunu
Copy link
Copy Markdown
Member

@Kitzunu Kitzunu commented Jul 25, 2025

Replaces direct database queries for account flags with an in-memory AccountFlagsContainer, improving performance and consistency. Updates flag modification logic to update both the in-memory store and the database asynchronously. Adjusts related function signatures and usage to reflect the new approach.

Changes Proposed:

This PR proposes changes to:

  • Core (units, players, creatures, game systems).
  • Scripts (bosses, spell scripts, creature scripts).
  • Database (SAI, creatures, etc).

This pull request refactors the handling of account flags in the login and session management system. The changes consolidate account flag management logic, improve code organization, and streamline database interactions. The most important updates include replacing redundant database statements, removing unused methods, and introducing new methods in the WorldSession class for flag validation and updates.

Database Changes:

  • Replaced LOGIN_UPD_ADD_ACCOUNT_FLAG and LOGIN_UPD_REMOVE_ACCOUNT_FLAG with a single LOGIN_UPD_SET_ACCOUNT_FLAG statement for updating account flags in the database (src/server/database/Database/Implementation/LoginDatabase.cpp, src/server/database/Database/Implementation/LoginDatabase.h). [1] [2]

Codebase Simplification:

  • Removed the HasAccountFlag, UpdateAccountFlag, and ValidateAccountFlags methods from AccountMgr as they are no longer needed (src/server/game/Accounts/AccountMgr.cpp, src/server/game/Accounts/AccountMgr.h). [1] [2]
  • Eliminated the invocation of AccountMgr::ValidateAccountFlags in WorldSocket::HandleAuthSessionCallback and replaced it with a call to the new WorldSession::ValidateAccountFlags method (src/server/game/Server/WorldSocket.cpp). [1] [2]

New Functionality in WorldSession:

  • Added _accountFlags as a member of WorldSession to store account flags in memory (src/server/game/Server/WorldSession.h).
  • Introduced GetAccountFlags, HasAccountFlag, UpdateAccountFlag, and ValidateAccountFlags methods in WorldSession to manage and validate account flags directly (src/server/game/Server/WorldSession.h, src/server/game/Server/WorldSession.cpp). [1] [2]

Constructor Updates:

  • Updated the WorldSession constructor to accept accountFlags as a parameter and initialize the _accountFlags member (src/server/game/Server/WorldSession.cpp, src/server/game/Server/WorldSession.h). [1] [2] [3]

Issues Addressed:

  • Closes

SOURCE:

The changes have been validated through:

  • Live research (checked on live servers, e.g Classic WotLK, Retail, etc.)
  • Sniffs (remember to share them with the open source community!)
  • Video evidence, knowledge databases or other public sources (e.g forums, Wowhead, etc.)
  • The changes promoted by this pull request come partially or entirely from another project (cherry-pick). Cherry-picks must be committed using the proper --author tag in order to be accepted, thus crediting the original authors, unless otherwise unable to be found

Tests Performed:

This PR has been:

  • Tested in-game by the author.
  • Tested in-game by other community members/someone else other than the author/has been live on production servers.
  • This pull request requires further testing and may have edge cases to be tested.

How to Test the Changes:

  • This pull request can be tested by following the reproduction steps provided in the linked issue
  • This pull request requires further testing. Provide steps to test your changes. If it requires any specific setup e.g multiple players please specify it as well.

Known Issues and TODO List:

  • [ ]
  • [ ]

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.

Replaces direct database queries for account flags with an in-memory AccountFlagsContainer, improving performance and consistency. Updates flag modification logic to update both the in-memory store and the database asynchronously. Adjusts related function signatures and usage to reflect the new approach.
@github-actions github-actions Bot added CORE Related to the core file-cpp Used to trigger the matrix build labels Jul 25, 2025
@Takenbacon
Copy link
Copy Markdown
Contributor

It is not thread safe to be accessing or modifying a global container in the socket (network threads)

@Kitzunu
Copy link
Copy Markdown
Member Author

Kitzunu commented Jul 25, 2025

Aight, how would I go about making it threadsafe?

@Kitzunu
Copy link
Copy Markdown
Member Author

Kitzunu commented Jul 25, 2025

Would a mutex suffice for that?

Account flag management functions and storage have been removed from AccountMgr and implemented as member functions in WorldSession. WorldSession now stores account flags per session, and related logic is updated accordingly. This change improves encapsulation and reduces global state.
@Kitzunu Kitzunu changed the title refactor(Core/Account): account flag management to use in-memory store refactor(Core/Account): Move account flag logic from AccountMgr to WorldSession Jul 25, 2025
Moved HasAccountFlag implementation to header as an inline method and added GetAccountFlags accessor. This improves code clarity and provides direct access to account flags.
@Kitzunu
Copy link
Copy Markdown
Member Author

Kitzunu commented Jul 25, 2025

Right, now it is stored per session and not globally. Thanks :)

@Kitzunu
Copy link
Copy Markdown
Member Author

Kitzunu commented Jul 25, 2025

@Kitzunu Kitzunu merged commit 3f46e05 into azerothcore:master Jul 27, 2025
@Kitzunu Kitzunu deleted the store-things branch July 27, 2025 06:54
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 Ready to be Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants