Fixes crashes and race conditions when bots perform group/guild/arena
operations by moving thread-unsafe code to world thread.
Potentially fixes#1124
## Changes
- Added operation queue system that runs in world thread
- Group operations (invite, remove, convert to raid, set leader) now
queued
- Arena formation refactored to use queue
- Guild operations changed to use packet queueing
## Testing
Set `MapUpdate.Threads` > 1 in worldserver.conf to enable multiple map
threads, then test:
- Group formation and disbanding
- Arena team formation
- Guild operations (invite, promote, demote, remove)
- Run with TSAN
cmake ../ \
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g -O1" \
-DCMAKE_C_FLAGS="-fsanitize=thread -g -O1" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \
-DCMAKE_INSTALL_PREFIX=/path/to/install \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
build
export
TSAN_OPTIONS="log_path=tsan_report:halt_on_error=0:second_deadlock_stack=1"
./worldserver
The crashes/race conditions should no longer occur with concurrent map
threads.
## New Files
- `PlayerbotOperation.h` - Base class defining the operation interface
(Execute, IsValid, GetPriority)
- `PlayerbotOperations.h` - Concrete implementations:
GroupInviteOperation, GroupRemoveMemberOperation,
GroupConvertToRaidOperation, GroupSetLeaderOperation,
ArenaGroupFormationOperation
- `PlayerbotWorldThreadProcessor.h/cpp` - Singleton processor with
mutex-protected queue, processes operations in WorldScript::OnUpdate
hook, handles batch processing and validation
---------
Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
Co-authored-by: SaW <swerkhoven@outlook.com>
Co-authored-by: bash <hermensb@gmail.com>
I've had this problem for a long time, my bots only speak English even
though I'm playing on a French client.
I suppose this must be the case for some other people who do not have a
large number of players with the same local client.
If we use French DBCs, the bots bug because they only recognize US DBCs.
From what I understand, the language is chosen as follows:
On load, the module reads the entire `ai_playerbot_texts` table and
stores each text variant in a dictionary indexed by the locale ID: the
`text` column remains the default value (English), and the `text_loc1`
to `text_loc8` columns fill slots 1 through 8.
Whenever a real player connects, the module increments a counter for
that player's DBC locale using
`AddLocalePriority(player->GetSession()->GetSessionDbcLocale())`.
When a bot needs a text, `GetLocalePriority()` returns the most
frequently used locale index among currently connected players. The
corresponding string is then retrieved. if the box is empty, we fall
back to the English version (text[0]).
### This PR improve language detection.
**Summary**
- log both the client DBC locale and the account database locale when a
player logs in
- fall back to the account locale when the client reports enUS but the
account is configured for another locale
- keep the existing vote-based selection so bots always speak the
majority language among connected players
**Therefore, the original behavior is maintained. Bots still choose the
most represented language among connected players (the counter is simply
more efficient by prioritizing the account's locale when it differs from
the client's English). For example, if more English-speaking players are
connected, the language will revert to English, as the bots always share
the majority locale.**
* Revert "Correct side effects of merge f5ef5bd1c2 (#1512)"
This reverts commit 966bf1d6af.
* Revert "Fix ACCESS_VIOLATION in mod-playerbots: purge stale AIs, add thread-safety, and harden HasRealPlayerMaster (#1507)"
This reverts commit f5ef5bd1c2.
* Revert "[Large server fix] #1537 Serialize playerBots/botLoading with a mutex and use snapshot-based loops to fix concurrency crashes (#1540)"
This reverts commit 3fff58df1a.
* Revert "[Fix] teleport to invalid map or invalid coordinates (x , y , z 200000, o ) given when teleporting player (g UI d full type player low , name , map , x , y , z , o ) (#1538)"
This reverts commit ca2e2ef0db.
* Revert "Fix: prevent MoveSplineInitArgs::Validate velocity asserts (velocity > 0.01f) for bots, pets, and charmed units (#1534)"
This reverts commit 4e3ac609bd.
* Revert "[Fix issue #1527] : startup crash in tank target selection — add TOCTOU & null-safety guards (#1532)"
This reverts commit c6b0424c29.
* Revert "[Fix issue #1528] Close small window where the “in a BG/arena” state can change between the check (InBattleground() / InArena()) and grabbing the pointer (GetBattleground()), which leads to a null dereference. (#1530)"
This reverts commit 2e0a161623.
* Revert "Harden playerbot logout & packet dispatch; add null-safety in chat hooks and RPG checks (#1529)"
This reverts commit e4ea8e2694.
* Revert "Dont wait to travel when in combat. (#1524)"
This reverts commit ddfa919154.
* Revert "nullptr fix (#1523)"
This reverts commit 380312ffd2.
* Revert "Playerbots/LFG: fix false not eligible & dungeon 0/type 0, add clear diagnostics (#1521)"
This reverts commit 872e417613.
* Revert "nullptr exception (#1520)"
This reverts commit 3d28a81508.
* Revert "Removed bot freezing at startup and system message, not relevant anymore (#1519)"
This reverts commit bcd6f5bc06.
* Do not disband alt bots group when master goes away
* This update makes the original PR functionality optional, which prevents alternative bots (random bots) from automatically leaving the group when the master leaves.
* Fix
---------
Co-authored-by: bash <31279994+hermensbas@users.noreply.github.com>
* Fixed a typo in filename and renamed table for consistency
* Added update file to rename the tables
* Drop old tables if they exist and create new ones if they don't exist already
* Add table to store the security keys for accounts.
* Add table to store relationships between accounts.
* Add a new configuration option to enable or disable trusted account bots.
* add checks for linked accounts
* Handle account linking and chat commands
* fix uppercase typo
* change query & fix chatcommandtable
* add missing functions to header
* move account linking to updates dir
* moved table creation to correct updates folder
* use playerbots db instead of character db
* fix db
* fix install?
* remove duplicated logic and add hashing to stored securityKey
* add object before call
* change chat variable
* rename SQL file for correct execution order
* add header include for ubuntu compatibility
* remove old sql
A simple RAII mechanism with std::unordered_set<ObjectGuid> to track GUIDs of init bots.
Ensures that multiple threads or calls do not execute PlayerbotFactory::Randomize() logic at the same time for the same bot.
* Add RandomBotMinLevelChance
* Save mana only for healer
* Disable addclass dk for low level player
* Target selection and debuff cast with less players in group
* Change default rpg strategy and bots count in config
* Logs clean up
* Improve init=auto
* Remove login logs after initialization
* Rndbots stats for quest
* Prediction chase in reach combat
* Poor & Normal items ensurence for init=auto
* add ability to add or remove character with same name as account
* seperate bot add and bot addacount so that characters with same name as an account doesn't add all toons from that account but adds the character instead if so desired
1. Improvements in error handling: Added detailed logs for cases where botAI or master are null, allowing better failure tracking.
2. Additional null pointer checks: Added checks to ensure that the botAI and master are valid before performing actions dependent on these objects, preventing potential crashes.
3. Optimization in bot login logic: Revised the bot input flow to ensure it is added to the group appropriately depending on its relationship to the master.
Added logic for handling different types of groups (raid, LFG, etc.), including the possibility of automatic conversion to raid if necessary.