Commit Graph

118 Commits

Author SHA1 Message Date
blinkysc
10213d8381 Add thread safety for group operations (#1816)
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>
2025-11-21 21:55:55 +01:00
Alex Dcnh
0c1700c117 CORE - Improved language detection for bots (#1784)
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.**
2025-11-21 15:56:03 +01:00
kadeshar
85c7009fe1 Codestyle fix (#1797)
Warning:
Dont change this PR as draft to make it testable


DONT REVIEW UNTIL Codestyle C++ workflow dont pass
2025-11-05 21:10:17 +01:00
Wishmaster117
d0ac9452f4 Fix Opcode dispatch, trusts every queued packet to have a handler 2025-10-11 11:26:09 +02:00
bash
31ed5cbb65 fixes 2025-10-09 20:52:32 +02:00
bash
cf4f0f6dc7 renamed function name 2025-10-06 21:07:43 +02:00
bash
1faf20f567 removeFromGroup replaced with worldpackets 2025-10-05 20:05:56 +02:00
bash
0cc15411c1 license update (#1674) 2025-09-30 15:19:44 +02:00
Revision
fcb956ec1b Removed unnecessary spaces 2025-09-19 22:43:50 +02:00
Revision
ace813516d Replaced tabs with spaces 2025-09-19 21:00:09 +02:00
bash
c9b4cfa184 [Revert] Threading leftover which belonged to other related PRs's (once green needs be merged) (#1583)
* 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.
2025-08-20 20:13:45 +02:00
bash
8d51092d42 As requested revert for threadfixes last few days (#1552)
* 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.
2025-08-12 22:10:47 +02:00
Alex Dcnh
3fff58df1a [Large server fix] #1537 Serialize playerBots/botLoading with a mutex and use snapshot-based loops to fix concurrency crashes (#1540)
* MoveSplineInitArgs::Validate: expression 'velocity > 0.01f' failed for GUID Full

* Update BotMovementUtils.h

* Playerbots: guard against invalid-Z teleports

* Update PlayerbotMgr.cpp
2025-08-12 08:15:22 +02:00
Alex Dcnh
4e3ac609bd Fix: prevent MoveSplineInitArgs::Validate velocity asserts (velocity > 0.01f) for bots, pets, and charmed units (#1534)
* MoveSplineInitArgs::Validate: expression 'velocity > 0.01f' failed for GUID Full

* Update BotMovementUtils.h
2025-08-12 01:53:48 +02:00
Alex Dcnh
e4ea8e2694 Harden playerbot logout & packet dispatch; add null-safety in chat hooks and RPG checks (#1529) 2025-08-11 16:27:25 +02:00
Alex Dcnh
872e417613 Playerbots/LFG: fix false not eligible & dungeon 0/type 0, add clear diagnostics (#1521)
Tested
2025-08-10 21:23:02 +02:00
Alex Dcnh
966bf1d6af Correct side effects of merge f5ef5bd1c2 (#1512)
* Update PlayerbotMgr.h

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.h

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.h

* Update PlayerbotMgr.cpp

* Update PlayerbotMgr.h

* Update PlayerbotMgr.h
2025-08-08 20:36:03 +02:00
Alex Dcnh
f5ef5bd1c2 Fix ACCESS_VIOLATION in mod-playerbots: purge stale AIs, add thread-safety, and harden HasRealPlayerMaster (#1507) 2025-08-07 00:31:00 +02:00
Yunfan Li
ee99b66d04 Sync with azerothcore (#1492) 2025-08-02 16:10:49 +08:00
Alex Dcnh
ba9cb5a256 Add optional gender parameter to .playerbot bot addclass command (#1491) 2025-08-01 21:45:29 +02:00
NoxMax
db7a17ffde Fix: Properly track RNDbot and AddClass accounts, and login faction balance issue (#1434)
* AssignAccountTypes & AddRandomBots

Fix: Properly track RNDbot and AddClass accounts, and login faction balance issue

* code style edits

* fix addclass init on first build of playerbots_account_type
2025-07-27 14:13:20 +08:00
bash
720c063716 Update PlayerbotMgr.cpp (#1414) 2025-07-02 21:54:52 +02:00
Alex Dcnh
57a2c9a742 Update PlayerbotMgr.cpp (#1412)
Remove double #include "ChannelMngr.h"
2025-07-02 20:27:04 +02:00
EricksOliveira
f8660bc939 Do not disband alt bots group when master goes away (#702)
* 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>
2025-05-25 00:19:11 +02:00
Revision
dc703cc897 Fixed a typo in filename and renamed table for consistency (#1279)
* 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
2025-05-10 13:47:22 +02:00
Icemansparks
0574ac5eff feature - (#1100) Linking of "trusted" accounts to allow altbot-control apart from own account or guild (#1267)
* 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
2025-05-05 15:06:29 +02:00
EricksOliveira
34a888978e Fix: Prevent concurrent bot initializations during .playerbot init= commands (#1227)
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.
2025-04-27 12:47:02 +02:00
Cryo81
07e4dec70d Warning fix + ilvl function fix (#1210)
* 1 variable order warning fixed
70 unused variable warning fixed

* Fixed GetEquipGearScore function

---------

Co-authored-by: Julien MAS <julien.mas81@gmail.com>
2025-04-20 14:26:42 +08:00
Yunfan Li
19447c3914 Enable new rpg strategy by default (#1192)
* 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
2025-04-11 20:31:38 +08:00
Yunfan Li
3f52563ca7 Move LoadFromDB from player session to world session (#1173) 2025-04-08 20:54:51 +08:00
kadeshar
c93bf38463 - Fixed checking MaxAddedBots (#1083) 2025-03-17 15:47:48 +08:00
xSparky911x
54c8909ddb add ability to add or remove character with same name as account (#1070)
* 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
2025-03-16 12:45:42 +08:00
Yunfan Li
62e0235e73 Scripts and sessions update to align with acore (#987) 2025-02-22 12:08:53 +08:00
Yunfan Li
49b046f36c Allow addclass bots that are not in a real guild (#970) 2025-02-14 18:45:17 +01:00
kadeshar
bf195efaea - Fixed loading WorldPosition from string to fix RTSC points loading (#965)
- Restored loading from playerbots_db_store
- Added deletion before saving to playerbots_db_store
2025-02-13 11:39:20 +01:00
Yunfan Li
14bdc0ec5a Always allow addclass bots login and init (#946)
* Change the way to check addclass bots and allow adding them by characters name

* Always addclass bots login and init

* Comments and message
2025-02-05 12:56:37 +08:00
Yunfan Li
fef67081ec Improve login and init permission for rndbots and addclass bots (#930)
* Improve login and init permission for rndbots and addclass-bots

* Add AllowAcountBots config

* Update config description
2025-02-03 19:46:49 +08:00
Yunfan Li
c2a023afa2 Leave group on login instead of disband group if group is invalid 2025-01-19 17:10:11 +08:00
SaW
453fa4b4f5 Fix reload command security (#774) 2024-12-14 17:55:06 +01:00
EricksOliveira
c8dd44fe93 Fix Logs LOG_ERROR for LOG_DEBUG 2024-10-20 11:46:16 -03:00
EricksOliveira
65b6e15ea1 Fix Crash - OnBotLogin
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.
2024-10-18 09:27:46 -03:00
Yunfan Li
8d524cdaf0 [Combat formation] Compatible with naxx and avoid aoe 2024-09-26 20:01:10 +08:00
Yunfan Li
311bdbd91b Serveral crashes fix 2024-09-07 12:08:38 +08:00
Yunfan Li
406949f6dd Misdirection and tricks of the trade 2024-09-04 20:08:44 +08:00
Yunfan Li
484a2ae458 Item usage and equip initialization 2024-09-04 18:08:19 +08:00
Yunfan Li
f804ba2d65 Speed up addclass with pre calculation 2024-08-31 19:58:28 +08:00
Yunfan Li
6d9aba4066 SaveToDB in randomize 2024-08-20 00:34:35 +08:00
Yunfan Li
e983f9be00 [Crash fix] Duplicate loading bot 2024-08-19 23:31:32 +08:00
Atidot3
25b010dd1e Merge code line 2024-08-04 12:04:06 +02:00
Yunfan Li
53611c9040 Run clang-format 2024-08-04 10:23:36 +08:00