Build a private WoW server with Playerbots and AI chat using CMangos on Ubuntu 24.04

In a previous post, we built a private World of Warcraft server running the Wrath of the Lich King expansion with TrinityCore. This time we’re building another WotLK server including PlayerBots with CMangos. After having played around with these PlayerBots I was really pleased with their behavior. I definately prefer them over the NPCBots we used in the previous post. What made it even more interesting was to have the bots connect to a local AI system that greatly improves what these bots can/will talk about with you. It’s a really good and also fun addition to the entire experience of playing with bots. I think this comes as close as you can get compared to playing with real people. Dare I say it is even more fun? I dare, but I won’t 🙂 It comes pretty darn close though! We’ll be using CMangos to build our server on a Ubuntu 24.04 server. By the way, we’re doing another WotLK realm in this example, but pretty much exactly the same can be accomplished for a Vanilla or TBC realm. Check out the CMangos site to find out more in case you would be interested in this.

1. Some prerequisites

sudo apt install build-essential gcc g++ automake git-core autoconf make patch p7zip-full libmysql++-dev mysql-server libtool libssl-dev grep binutils zlib1g-dev libbz2-dev cmake libboost-all-dev g++-12

We will want to run our server under a dedicated user for it. So let’s go ahead and create a folder /games, and then we create a new user with the home folder set to /games/wow

sudo mkdir /games
sudo useradd wow -m -d /games/wow

In case you forget to set a password or want to change it later, use this command:

sudo passwd wow

Now we’re going to log in as this new user and continue the setup from there.

su wow

This doesn’t automatically bring us to our home folder, so make sure you go to your home folder.

cd ~

In the home folder, we’re making a new folder named cmangos with a subfolder named build. Like so:

mkdir -r /games/wow/cmangos \
cd cmangos

2. Building the server

Clone the following repositories in to the /games/wow/cmangos folder.

git clone https://github.com/cmangos/mangos-wotlk.git mangos
git clone https://github.com/cmangos/wotlk-db.git
git clone https://github.com/cmangos/playerbots

Now let’s cd in to the build folder

mkdir build
cd build

The cmake command below will create the configuration for make, which we’ll be using in the step afterward.
– Note that in the line below, we specified the location where we want to store the server files eventually right after -DCMAKE_INSTALL_PREFIX= We also specified that we want to use Playerbots and AHbot.

cmake ../mangos -DCMAKE_INSTALL_PREFIX=/games/wow/cmangos -DBUILD_PLAYERBOTS=ON -DBUILD_AHBOT=ON -DPCH=1 -DDEBUG=0 

Before we continue to the next step, it would be interesting to know how many cores your server has available for the build process. The more, the merrier, and the faster the make process will complete.

lscpu

Remember the number that you are seeing on your hardware.

The next step will take a long time before it completes. Depending on your hardware, this could be anywhere between 10 minutes to an hour. It will be much faster when we use multiple cores in your CPU. So use the amount, or below it, from what you remembered from the previous step, and set it to where you see X in the next line.

make -jX

Don’t worry too much when you see all sorts of generated warnings. There can be many, but it has never failed to succesfully compile. Do, perhaps now you should go ahead and grab yourself a cup of coffee or a nice cold beer. You deserved it!

Once this long process is done, use the next line to copy the server files to their correct location.

make install

When we go back to the cmangos folder, we should see two new subfolders in it named bin and etc.

cd .. && ls -la

Now that we’re here, we might as well create two new folder that we’ll be using later on.

mkdir logs data

The templates for configuration files of the server are located in the etc folder. We need to copy these templates to new files that the server will be able to read.

cp etc/mangosd.conf.dist etc/mangosd.conf
cp etc/realmd.conf.dist etc/realmd.conf
cp etc/anticheat.conf.dist etc/anticheat.conf
cp etc/aiplayerbot.conf.dist etc/aiplayerbot.conf
cp etc/ahbot.conf.dist etc/ahbot.conf

We’ll return to these config files later on to properly set them up.

3. Setting up the databases

On Ubuntu 24.04 nowadays, a password is automatically put in place by the system. Since we don’t know this password, we’ll need to log in as root for the first time like this:

sudo mysql

The next two lines can be used to specify our own password for the root user. Make sure you choose something different as ‘yourpassword’ here.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
EXIT;

It’s good practice to secure your mysql database with this command:

mysql_secure_installation

Feel free to pick the options that will suit you best. I’ve chosen to answer the setup questions this way:

(N for unix_socket)
(N to Change root password)
(Y to remove anonymous users)
(Y to allow root login remotely)
(Y to remove the test database)
(Y to reload privilige table)

Now we can log in to MySQL so we can start creating the required databases.

mysql -u root -p

You will be asked to enter a password. Enter your root password that we’ve set in the previous steps.

We’re going to create a new database user and grant it permissions to create new databases. The installer script (InstallFullDB.sh) that we’ll be running later on will use this user to create and fill the required databases for us.

CREATE USER 'wow'@'localhost' IDENTIFIED BY 'mangos' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;
GRANT USAGE ON * . * TO 'wow'@'localhost';
EXIT;

Now head in to the classic-db folder from where we will run the database setup script.

cd wotlk-db

Run the script

sudo ./InstallFullDB.sh

Choose option 9.

The script will have created a new configuration file in the same folder named InstallFullDB.config

We’re going to edit this config file before we run the script a second time.

nano InstallFullDB.config

Look for these lines shown below in the config file and change them. Please note that the CORE_PATH should be set to where we cloned the repository. Also enable the options for AHBOT and PLAYERBOTS.

CORE_PATH=”/games/wow/cmangos/mangos”
AHBOT=”YES”
PLAYERBOTS_DB=”YES”

Save the file (ctrl+x, and choose y to save it, and press enter to overwrite the current file)

Now we’re going to run the script a second time. It should start filling the databases.

sudo ./InstallFullDB.sh

Choose option 4
(root)
(roots password)
Option 1
DeleteAll
Press “Space key
Option 9

{Note versions of DB now show in the top}

Option 9

Now that the databases are filled, we’ll need to change an entry so the connecting clients will know where the server is located and where to connect to. We’ll do this change directly in mysql. So, first log in:

mysql -uwow -pmangos

Enter the next line to open the correct database:

use wotlkrealmd

Then we’re going to paste in the lines shown below. But hold on! Please make sure that you edit the line below so it will show a name for your realm that you prefer and the correct IP address of your server. Replace ‘Classic-With-Bots’ with whatever name you want. This name will be seen from the client when choosing a realm to play on. Also replace ‘192.168.1.81’ with your server’s IP address.

DELETE FROM realmlist WHERE id=1;
INSERT INTO realmlist (id, name, address, port, icon, realmflags, timezone, allowedSecurityLevel)
VALUES ('1', 'Classic-With-Bots', '192.168.1.81', '8085', '1', '0', '1', '0');
EXIT;

4. Server configuration

We’ll need to change a couple of variables in the configuration files we copied earlier in the etc folder.

cd /games/wow/cmangos/etc

Type this to show all the files in this folder:

ls -la

Open the mangos.conf file with nano, or any other text editor you might prefer.

nano mangosd.conf

These variables need to be changed so they will look something like this:

DataDir = “/games/wow/cmangos/data”
LogsDir = “/games/wow/cmangos/logs”

Same thing for the realmd.conf file.

nano realmd.conf

LogsDir = “/games/wow/cmangos/logs”

Don’t forget to save the config files before exiting.

5. Import the data files

cd /games/wow/cmangos

This will download a zipped file that contains all the data files we need:

wget https://cdn.puntenel.nl/files/var/compressed/3.3.5a/data.7z

Unpack the 7z file and set permissions:

7z x data.7z -odata
chmod -R 755 data

Once the unpacking completes it is safe to remove the zipped file:

rm data.7z

6. Running the server

Now we’re going to start the server, and hopefully everything should run without any errors.

cd /games/wow/cmangos/bin

Realmd is the process that will allow us to log on to the server. Once you started it, you’ll want to keep it running, so to continue you will need to open up a second terminal window and continue from there.

./realmd

In this new terminal window we’re going to login as user wow and cd into the correct folder.

su wow
cd ~/cmangos/bin

Typing ./mangosd should be sufficient,

./mangosd

but optionally you could also specify what config files it should use, in case you want to have different ones. You can do this like so:

./mangosd -c /games/wow/cmangos/etc/mangosd.conf -a /games/wow/cmangos/etc/ahbot.cfg

It will take some time for the server to fully startup. In fact, the last time I did this, it took well over an hour or two to populate the database. Luckily it only takes this long the very first time you start the server. It will go a lot faster next time. So, just let it run, while you can go do other things in the meantime. Like, going outside, enjoy the sun, talk to some people. 😀

7. Creating your account

Once you see lines that start with Avg Diff or Max Diff, press enter to go to the command prompt. When you do this, the start of the line should say mangos>

From this prompt you can create an account for yourself and assign GameMaster rights to the account. Be sure to use your desired name instead of ANewAccount, and also set something else for APassword.

account create ANewAccount APassword
account set gmlevel ANewAccount 3 -1
account set addon ANewAccount 2

This creates your account with your choice of name and also sets the password. The second step makes your account a GM with all the required rights to manage the server. The third step flags your account so it can play TBC and WotLK. 0=classic, 1=tbc, 2=wotlk.

I’ve noticed that it can be tricky to enter the command when the server is still showing the Max/Avg Diff messages. What I did was copy the entire line ‘account create ANewAccount APassword’, press enter at the server’s prompt and immediately paste in the line and enter again.

Once you have created an account, you should now be able to log on to the game. I’m sure you want to test it out now, right? Go right ahead, and when you return, we can talk a bit more on how to configure the Playerbots addon.
When you are done checking out to see if the server works, you can use the command below to properly shutdown the server:

server shutdown 1

8. Configure behavior of Playerbots

The Playerbots addon for your server has a ton of options that you can edit to your wishes. Some options allow you to completely change how your bots will function. All the options are specified in the etc/aiplayerbot.conf file. I suggest you take a look at this file and see for yourself. Feel free to test how many bots your server can handle before it runs out of resources.

cd ~
nano etc/aiplayerbot.conf

Don’t forget that you will need to restart the server when you made changes to the config file.

On request, I recently shared a copy of the config file that I personally prefer to use. It’s a decent setup, so feel free to try it out yourself. This config can be found in this gist: https://gist.github.com/ustoopia/1dbfe9aeff120fe21ec712afd8d9e22e

9. Connect the bots to an AI.

The playerbots can be greatly enhanced when we connect them to an AI. We’ll install our own AI engine locally with Koboldcpp. It’s super easy to setup. Just follow these simple steps below. This will work for anybody, regardless of hardware requirements. But, please know that if your server has an Nvidia graphics card, then there’s a much better way to run the AI. For more info on that, check out the github page https://github.com/LostRuins/koboldcpp.

mkdir /games/wow/cmangos/ai
cd /games/wow/cmangos/ai

Download Koboldcpp to this folder

wget https://github.com/LostRuins/koboldcpp/releases/download/v1.80.3/koboldcpp-linux-x64-nocuda

Change the permissions so we can execute the file

chmod +x koboldcpp-linux-x64-nocuda

Now we’re going to download the language model, this shouldn’t take too long.

wget https://huggingface.co/mradermacher/Llama-3.2-1B-Instruct-Uncensored-GGUF/resolve/main/Llama-3.2-1B-Instruct-Uncensored.Q8_0.gguf?download=true -O Llama-3.2-1B-Instruct-Uncensored.Q8_0.gguf

Once the download has completed, we can start the A.I. engine by simply entering this:

/koboldcpp-linux-x64-nocuda --model Llama-3.2-1B-Instruct-Uncensored.Q8_0.gguf --threads 4

It should look something like this once it has started up:

Now we’ll need to edit the aiplayerbot.conf file to specify the address where the server can reach the AI engine.

nano /games/wow/cmangos/etc/aiplayerbot.conf

AiPlayerbot.LLMApiEndpoint = http://localhost:5001/api/v1/generate

These line is normally commented out by default. So you only need to remove the # at the front of this line. And afterwards don’t forget to restart your server.

Log in to the World, and create a group with a bot or several bots. Summon them to your location. In party or raid chat type the following to enable the use of AI for the bots:

/p nc +ai chat

Disabling it is the same command, but with a – instead of the +.

Now you can talk about anything you want with your bots. Ask them what they want to go do next. Or tell them how bad their gear is. Or whatever! Once they start responding, you should be monitoring the CPU usage of the server. Now obviously it depends on your hardware whether you can run your server with AI chat enabled or not. And learning how many resources the AI will consume is the first step in determining this. I’ve learned that it is OK if the AI uses 100% CPU resources for short times when it responds to you, but when you notice it takes long to respond, while running at 100% for extended times, then you shouldn’t be running the AI. Also, when the AI is “thinking” you should try to determine if it has any negative impact in other processes, like the mangosd that runs the World. It shouldn’t. When it does, disable the AI.

10. That’s a wrap

That pretty much wraps up this tutorial! I hope it was useful to some of you. Feel free to leave a comment in case you have any questions. And most important of all: Have fun!