liyunfan1223 / mod-playerbots

AzerothCore Playerbots Module
https://discord.gg/NQm5QShwf9
GNU Affero General Public License v3.0
273 stars 146 forks source link

Pre-existing (player)characters Problem - Characters login as bots and log off immediately after #449

Open icemansparks opened 2 months ago

icemansparks commented 2 months ago

Describe the bug After staring up the Server and loggin into a character on a non admin account, the characters from the friendlist and guild are shown to be loggin in and immediately loggin out.

Settings from config:

# auto-login all player alts as bots on player login
AiPlayerbot.BotAutologin = 0

# Allow login other players' characters as bots Default: 0 (disabled)
AiPlayerbot.AllowPlayerBots = 0

# Allow/deny bots from your guild
AiPlayerbot.AllowGuildBots = 0

No error messages are shown in the server console, though. The recurring message of "30 New bots" appears in the server console window instead.

Commit hash 264c533d1fd020234eb1c05005343d86fcca7a39

To Reproduce Steps to reproduce the behavior:

  1. startup auth and world server
  2. login with non-admin account that has a guild with more player account characters in it (same as player account as well as from other players accounts) and also a friendlist with characters from player accounts that are not in the current guild.
  3. Wait about a second or two
  4. See "charactername has come online" and "charactername has gone offline" message in chat.

Expected behavior With the options to deny bots from guild and disabled auto login, the alt characters of the player and other players accounts should not login at all automatically.

Desktop (please complete the following information):

icemansparks commented 2 months ago

Ok seems like I have found the cause for this issue and it is probably not that common.

TL;DR: Custom SQL was used on server setup to add pre-existing player accounts to the account and character database. But in acore_playerbots.playerbots_random_bots the value for "bot" is fixed on server stup and rfrncs bot charactr guids which ar in this case real characters instead.

Long version: As far as I can tell, it is decided if a character is a bot / part of a bot account by looking up the value in acore_playerbots.playerbots_random_bots The table is pre-populated with all the bots that have been created on first initialisation when starting up the server.

The problem in my case now seems to be, that the character IDs are used in this table in the "bot" column to link the character guid to the bot entry. Since the values for the guids of the bots seem to be pre-populated (couldn't find the exact sql file yet), character guid values start at 1, just like the created character entries.

This is the breaking point for my setup as i added character and account entries for already existing user accounts with a custom SQL in the server sql directory (as supposed to). These will be created before all modules, resulting in my character database having real user (player) characters inside them (guid 1-30 in this case). The playerbot character creation now just starts with the next available guid (all good so far) but the association in acore_playerbots.playerbots_random_bots still references fixed guids from the character table (in this case 1-30 are assigned to playerbot accoutns and are therefore identified as such.

Reassigning the bot number to the "free bot character guid" solved the problem as it seems. The following screenshot shows the table after adjusting the first 30 guid values. Screenshot 2024-08-07 193943

Proposed solution (idea): the entries in acore_playerbots.playerbots_random_bots should be based on the bot account character guid values that actually have been created instead of using pre-defined values.

fuzzdeveloper commented 2 months ago

I like the detail here, but I'm wondering how exactly to reproduce this, is it something I could reproduce by creating characters (in the normal way) before using/enabling the bot?

icemansparks commented 2 months ago
  1. set up a server without the module (default azerothcore, same revision)
  2. create an account and some characters on it

Now EITHER:

  1. add the module to the server, switch to playerbots repo for the server as well and recompile
  2. start up server again

OR: (what I did)

  1. create an export of the acore_characters DB (specifically characters table) and acore_authDB (everything more or less)
  2. set up a new server (checkout code including playerbots branch
  3. add the exported SQL file to \azerothcore-wotlk\data\sql\custom\db_characters
  4. build and run the server
icemansparks commented 2 months ago

Ok, I tried to understand how bots and bot accounts are created... if I got it right, it is done in void RandomPlayerbotFactory::CreateRandomBots() ?

Account and bot creation follows the same kind of "for loop": for (uint32 accountNumber = 0; accountNumber < sPlayerbotAIConfig->randomBotAccountCount; ++accountNumber) This, as far as I understand, always starts with accountId = 0 and counts up until the max bot accounts configured in the config sPlayerbotAIConfig->randomBotAccountCount.

This does not take into account any existing "player-made accounts" that are present before module initialization and will always lead to a false assignment of bots to accounts in acore_playerbots.playerbots_random_bots since the assignment starts with accountId = 1 rather than the first bot account.

Example of the accounts table: ScreenShot 2024-08-13_10 55 47

I think a suitable solution could be to find all bot accounts based on the botAccountPrefix, get their AccountIDs, and add them to an array, then instead of an automatic increase for-loop, iterate over all bot accounts from the array and the characters associated with those accounts?

Unfortunately i cannot implement it myself :)