Introduction
This page is dedicated to the instructions that someone needs in order to properly install tw2-stats
into his local enviroment.
During this guide I wll be using Ubuntu 20.04 but any enviroment should work as long as you are able to run docker
commands.
Disclaimer:
Although I'm not against people using it locally for themselfs. I will highly encourage you to either help host it or host it yourself so other
community members can benefit from it as well.
Prerequisites
As mention above the only requirements for seting up tw2-stats is to be able to run from the terminal the following commands:
docker
docker-compose
If you have git
install you can use it, to download the source code:
git clone https://github.com/VMormoris/tw2-stats.git
Installing & running the project
After acquiring the project navigate to the directory where you download the project using the terminal and use the following commands:
docker build -t db.tw2-stats:latest database/
docker build -t tw2-stats:0.4.x .
docker-compose -f tw2-stats.yaml -p "tw2-stats" up -d
This might take a while but once those commands finish you can already visit the webpage. If you are running this on your
pesronal computer, to make sure is running use this link: http://localhost.
If you have already install the project you can start it up with just using the last command:
docker-compose -f tw2-stats.yaml -p "tw2-stats" up -d
Setting up a World
Although the website is already running you will have to manually setup the worlds in order to be able to actually use it. For every
world you want to use, you will have to repeat the four steps bellow making the necessary changes where its need it.
(I will be setting Beta world 8 with world id: zz8
)
1st step - Create a world record on the main database (holds metadata):
docker exec -it db.tw2-stats /bin/bash
su postgres
psql -d tw2-stats
INSERT INTO worlds
(
"wid", "name", "server", "url", "win_condition", "win_ammount",
"tribes", "players", "villages",
"finished", "running", "moral",
"relocation", "night_bonus", "time_offset",
"start"
)
VALUES
(
'zz8', 'Semper', 'beta', 'beta.tribalwars2.com/game.php', 'Domination', 75,
0, 0, 0,
false, true, 'Active', 'Active', 'Inactive', 0, '2018-01-01'
);
\q
2nd step - Create database for the new world (holds the actual data):
psql -c "CREATE DATABASE zz8;"
psql -d zz8 -a -f /home/db/world_db_creation.sql
psql -d zz8 -c "GRANT ALL PRIVILEGES ON DATABASE \"zz8\" TO \"tw2-stats\"; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO \"tw2-stats\"; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO \"tw2-stats\"; GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO \"tw2-stats\";"
psql -d zz8 -c "GRANT CONNECT ON DATABASE \"zz8\" TO api; GRANT USAGE ON SCHEMA public TO api; GRANT SELECT ON ALL TABLES IN SCHEMA public TO api;"
exit
exit
3rd step - Make the website aware of the new database:
First enter the website's container using: docker exec -it website.tw2-stats /bin/bash
, after that you have to edit two
files with your editor of choice (I reccomend using nano
that comes with the container):
In the file .env
add the following line:
DB_DATABASE_ZZ8=zz8
In file config/database.php
add the following array inside the one called connections:
'zz8' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE_ZZ8'),//Change this to match the line added before
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
Start the program:
cd dumper-app
python3 dumper-app.py
If everything work correctly you should be to visit the new world you created at: http://localhost/zz8.
This process of creating worlds and pulling data will be made much easier with the next update.