LasTres is a textgame thought to be playable in the browser as an RPG realtime.
Go to file
2023-07-12 18:41:59 +02:00
dbicdh Creating tests to check that map is correctly generated and solving some discovered errors. 2023-07-12 00:37:38 +02:00
docker Removing default config from entrypoint.sh 2023-07-01 06:22:29 +02:00
js-src Adding the logic to be able to open the word selection 2023-07-12 16:56:01 +02:00
lib Adding sending words. 2023-07-12 18:41:59 +02:00
public Adding the logic to be able to open the word selection 2023-07-12 16:56:01 +02:00
script Adding today changes: 2023-06-20 01:48:55 +02:00
t Adding sending words. 2023-07-12 18:41:59 +02:00
templates/root Adding doctype html 2023-06-29 09:14:02 +02:00
.eslintrc.js Adding first screen with pj list, log and list of available locations. 2023-06-13 02:43:52 +02:00
.vimrc Adding first screen with pj list, log and list of available locations. 2023-06-13 02:43:52 +02:00
babel.config.json Adding initial commit. 2023-06-01 08:45:43 +02:00
build_styles.sh Adding initial commit. 2023-06-01 08:45:43 +02:00
Build.PL Creating tests to check that map is correctly generated and solving some discovered errors. 2023-07-12 00:37:38 +02:00
CONTRIBUTING.md Adding Docker guide in a different document. 2023-07-01 05:23:06 +02:00
DOCKER.md Adding clarification. 2023-07-01 05:24:36 +02:00
Dockerfile.template Improving rebuild control. 2023-07-01 05:01:32 +02:00
GUIDE_TO_THE_CODE.md s/you/your/ 2023-07-02 12:24:07 +02:00
install_docker.sh Adding docker actions for database migrations. 2023-07-01 04:48:33 +02:00
las_tres.example.yml Adding initial actions and some documentation. 2023-06-30 19:59:18 +02:00
LICENSE Initial commit 2023-06-01 08:43:18 +02:00
package.json Adding initial commit. 2023-06-01 08:45:43 +02:00
prepare_docker.sh Adding docker actions for database migrations. 2023-07-01 04:48:33 +02:00
README.md More typos. 2023-06-30 21:19:32 +02:00
start_docker.sh Adding the ability of execute pj actions. 2023-07-02 06:35:14 +02:00
tsconfig.json Adding initial commit. 2023-06-01 08:45:43 +02:00
upgrade_docker.sh Adding docker actions for database migrations. 2023-07-01 04:48:33 +02:00
webpack.config.js Adding initial commit. 2023-06-01 08:45:43 +02:00

LasTres

Contributing

Do you know Perl, Typescript, SCSS or React and want to get the best of this program?

You can contribute and make your dreams for this game real.

Contributing guide.

Installation instructions. (Prod)

This is an example, you can configure the server as you please, use this guide as a reference.

This guide uses Debian stable 12, this server requires at least a system compatible with Redis such as Linux, Windows is not compatible with Redis, but you can use it virtualized or with WSL2.

We recommend Linux or at least something Unix-like to deploy both in server and in development this project.

That said features that improve OS compatibility will always be appreciated.

Postgresql notes.

We are going to use the peer authentication that comes preconfigured in Debian, if you are using other OS you should care of pg_hba.conf to be configured as peer for empty address.

This is how it looks on the Debian I used.

You can also configure it with password if the database server is not the same host that the webserver, it is supported by the software.

local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

Creating user

sudo useradd -m las_tres -d /var/lib/las_tres

Installing dependencies.

sudo apt update && \
sudo apt install git postgresql redis nginx pwgen liblocal-lib-perl libpq-dev

Starting an enable dependency services

sudo systemctl daemon-reload && \
sudo systemctl enable redis-server && \
sudo systemctl start redis-server && \
sudo systemctl enable postgresql && \
sudo systemctl start postgresql && \
sudo systemctl enable nginx && \
sudo systemctl start nginx

Configuring the database

( cat << 'EOF'
create user "las_tres";
create database "las_tres";
grant all privileges on database "las_tres" to "las_tres";
alter database "las_tres" owner to "las_tres";
EOF
) | sudo -u postgres psql

Cloning project.

sudo -u las_tres bash -c "$(cat <<'EOF'
cd && \
git clone https://git.owlcode.tech/sergiotarxz/LasTres
EOF
)"

If you are going to change the JS. (Only once.)

sudo apt update && sudo apt install nodejs npm && \
sudo -u las_tres bash -c "$(cat <<'EOF'
cd ~/LasTres && \
npm install
EOF
)"

Deploying your js changes

sudo -u las_tres bash -c "$(cat <<'EOF'
cd ~/LasTres && \
npx webpack
EOF
)"

If you are going to change the css (Only once.)

sudo apt update && sudo apt install sassc

Deploying the css changes

sudo -u las_tres bash -c "$(cat <<'EOF'
cd ~/LasTres && \
bash build_styles.sh
EOF
)"

Configuring NGINX.

(TLS is out of the scope of this tutorial, but you must do it if you want to deploy this server to the public world.)

( cat << 'EOF'
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}
upstream backend_las_tres {
    server 127.0.0.1:3000 fail_timeout=0;
}

server {
  listen 80;
  listen [::]:80;
  server_name las_tres.example.com;
  location /.well-known/acme-challenge/ { allow all; }

  keepalive_timeout    70;
  sendfile             on;
  client_max_body_size 80m;

  gzip on;
  gzip_disable "msie6";
  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/x-icon;

  location / {
        add_header Strict-Transport-Security "max-age=31536000" always;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Proxy "";
        proxy_pass_header Server;

        proxy_pass http://backend_las_tres;
        proxy_buffering on;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        tcp_nodelay on;
  }

}
EOF
) | sudo tee /etc/nginx/sites-enabled/las_tres.conf && \
sudo systemctl reload nginx

Configuring the app

For non standard configurations you should peek the config in las_tres.example.yml copy to las_tres.yml and modify the copy until it suits your needs, patches and issues are welcome if you need more options than example allows you to do.

sudo -u las_tres bash -c "$( cat << 'EOF'
cd ~/LasTres && \
cat << EOF1 > las_tres.yml
secrets:
  - $(pwgen -s 512 1)
database:
  dbname: las_tres
hypnotoad:
  listen:
# Here we have changed it to only listen localhost.
    - http://127.0.0.1:3000
EOF1
EOF
)"

Installing Perl deps

sudo -u las_tres bash -c "$( cat << EOF
if ! grep PERL5LIB ~/.profile; then
	perl -Mlocal::lib 2>/dev/null >> ~/.profile ;
fi && \
source ~/.profile && \
rm -fr ~/.cpan && \
( echo y && echo reload cpan && echo o conf commit ) | perl -MCPAN -Mlocal::lib -e shell && \
cd ~/LasTres && \
perl Build.PL && \
./Build installdeps
EOF
)"

Creating Systemd service

( cat << 'EOF'
[Unit]
Description=LasTres the web text game
After=network.target postgresql.service redis.service

[Service]
User=las_tres
Group=las_tres
WorkingDirectory=/var/lib/las_tres/LasTres/
ExecStart=/bin/bash -c "source /var/lib/las_tres/.profile && hypnotoad -f script/las_tres"
User=las_tres
Group=las_tres
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=las_tres.service
EOF
) | sudo tee /etc/systemd/system/las_tres.service

Deploying the database

If you are installing for the first time.

sudo -u las_tres bash -c "$( cat << EOF
cd ~/LasTres && \
source ~/.profile && \
perl script/install.pl
EOF
)"

If you are migrating from a older version

sudo -u las_tres bash -c "$( cat << EOF
cd ~/LasTres && \
source ~/.profile && \
perl script/upgrade.pl
EOF
)"

Enabling and starting service

sudo systemctl daemon-reload && \
sudo systemctl restart las_tres && \
sudo systemctl enable las_tres