Skip to content

Local environment setup

Juho Snellman edited this page Oct 2, 2019 · 5 revisions

This is not a step-by-step guide, but should shed some light along the way.

Software & versions:

You'll need the following software in addition to the game itself. The site currently runs on a Debian 9 installation, with a definitely working combination of .deb versions in parenthesis.

  • Postgres 9 (postgresql-9.6 9.6.15-0+deb9u1)
  • Apache 2.4 (apache2 2.4.25-3+deb)
  • FastCGI 2.4.7 (libapache2-mod-fastcgi 2.4.7~0910052141-1.1+deb8u1)
  • Perl 5.18+ (perl 5.24.1-3+deb)
  • The following perl modules from CPAN:
    • Bytes::Random::Secure CGI::PSGI Clone Crypt::Blowfish Crypt::CBC Crypt::Eksblowfish::Bcrypt Data::Password::Common DBD::Pg DBI Digest::SHA1 Exporter::Easy File::Slurp indirect JSON Math::Random::MT Method::Signatures::Simple Moose Readonly Statistics::Descriptive Task::Plack Term::ReadLine Text::Diff Text::Template

Deploying the source

The site should not be served directly from the source directory. The script deploy.pl is used to copy it to www-devel, www-staging or www-prod. The www-devel directory will have symlinks (for instant reloading), the other two directories will have copies of the files that have been optimized for allowing more efficient caching.

Directories

Ensure the log directories are made. If you're running the default installation and about to deploy with

perl deploy.pl www-devel

then first run:

mkdir logs
mkdir www-devel
mkdir www-devel/logs
mkdir www-devel/data/log

Apache configuration

See config/apache.conf for an example configuration. You'll need to edit some paths.

Site configuration

Copy config/config-example.json, edit to taste, and make sure the TZ_CONFIG variable is initialized appropriately when running the app from the Apache configuration file.

DB schema setup

Create a database named terra-mystica, and make sure you grant access to it for the user that the app is running as.

Execute the SQL statements from schema/schema.sql to initialize the database with the correct schema.

DB secrets table

The following command generates an SQL statement to populate some encryption keys that need to be different on every installation of the site.

perl -e "printf qq(insert into secret (secret, shared_iv) values ('\\x%x%x'::bytea, '\\x%x'::bytea);), map { rand 2**32 } 0..2"

Map population

The following SQL statements initialize the map data in the database.

INSERT INTO	map_variant (id, terrain) 
	VALUES	('95a66999127893f5925a5f591d54f8bcb9a670e6', 'E brown x brown black yellow x gray green red blue yellow blue E red yellow x blue gray red x x x yellow brown black gray E green black x x x brown green yellow x x x x E yellow gray green yellow black x blue red brown x green blue green E x x brown x x red black green gray x brown black E green red x x green x x x brown blue x gray red E gray x yellow gray blue red green x red gray x black E black blue x black brown gray blue x yellow black x red blue E gray green x red yellow black yellow x blue brown x brown E'), 
			('be8f6ebf549404d015547152d5f2a1906ae8dd90', 'brown gray green blue brown red brown black red blue green red black E yellow x x yellow black x x yellow green x x yellow E x x black x gray x green x black x red x x E green blue yellow x x red blue x red x gray brown E black brown red blue yellow brown green yellow x x green black red E gray green x x black gray x x x brown gray yellow E x x x gray x red x green x yellow black blue brown E yellow blue brown x x x blue black x gray brown red E blue black gray blue red green yellow brown gray x blue green gray E');

Alternatively, lodev formats:

U,S,G,B,U,R,U,K,R,B,G,R,K;
Y,I,I,Y,K,I,I,Y,G,I,I,Y;
I,I,K,I,S,I,G,I,K,I,R,I,I;
G,B,Y,I,I,R,B,I,R,I,S,U;
K,U,R,B,Y,U,G,Y,I,I,G,K,R;
S,G,I,I,K,S,I,I,I,U,S,Y;
I,I,I,S,I,R,I,G,I,Y,K,B,U;
Y,B,U,I,I,I,B,K,I,S,U,R;
B,K,S,B,R,G,Y,U,S,I,B,G,S;
;
U,I,U,K,Y,I,S,G,R,B,Y,B;
R,Y,I,B,S,R,I,I,I,Y,U,K,S;
G,K,I,I,I,U,G,Y,I,I,I,I;
Y,S,G,Y,K,I,B,R,U,I,G,B,G;
I,I,U,I,I,R,K,G,S,I,U,K;
G,R,I,I,G,I,I,I,U,B,I,S,R;
S,I,Y,S,B,R,G,I,R,S,I,K;
K,B,I,K,U,S,B,I,Y,K,I,R,B;
S,G,I,R,Y,K,Y,I,B,U,I,U;