Setup Guide (Linux) - d-zone-org/d-zone GitHub Wiki

Requirements

If you want to run D-Zone for your Discord server, you will need the following:

  • A computer to run the node server
    • The computer you're on right now would be fine, or you can use a node.js hosting service.
  • A port available on the node server for the websocket
    • This means port forwarding on your router, like when you host a game server.
  • A web host or local host for the client files
    • If hosting on HTTPS, you will need to provide an SSL certificate (try Let's Encrypt)
    • People tend to get stuck on this one, please find a web host before proceeding.

Install Nodejs

First, you must install Nodejs. It's recommended to use the latest LTS release.

To install the latest node do the following:

apt update
apt install -y nodejs
nodejs --version

If the last command returns the latest LTS version, your all set!

Installation

It's suggested to use git, as this is already installed and is easier to update then using the zip methode. Simply type the following:

git clone https://github.com/vegeta897/d-zone
cd d-zone

Then install the node modules that are needed to run d-zone: npm install --no-optional If all goes well, you should now have a node_modules folder.

You can update D-Zone now by just typing git pull.

Configure token

Set the env variable or make a .env file in the d-zone folder and add the following:

token=yourtokenhere

Change yourtokenhere to the correct bot token that you can get here.

Configure discord-config.json

Copy and rename the discord-config-example.json to discord-config.json and set the default d-zone server:

{
  "url": "http://youripordomain.com/web/index.html",
  "infoCommand": "!d-zone",
  "servers": [
    {
      "id": "1234567891234567",
      "default": true,
      "ignoreChannels": ["members-Only","testing"],
      "password": "This is optional"
    }
  ]
}

Change the url to the public ip adres. With curl icanhazip.com you can find the ip address. If you use a domain, use that in the url field instead.

Change the id to the default id of your own server. You can find this by going to: Location Server ID

If you don't want to use a password for a server remove the line as followed:

{
  "url": "http://youripordomain.com/web/index.html",
  "infoCommand": "!d-zone",
  "servers": [
    {
      "id": "1234567891234567",
      "default": true,
      "ignoreChannels": ["members-Only","testing"]
    }
  ]
}

Easy update discord-config.json

If you want an easier way to automatically include all servers your bot resides in, simply after you added your bot token and then run the update script by doing: ./update-configuration.sh. If you already have servers in your config with optional parameters, they will not be overwritten.

Re-run this command whenever a new server has joined, or has left.

Configure discord-config.json

Check if the port the websocket will run on is free with: sudo lsof -i -P -n | grep LISTEN | grep :3000. Change 3000 to any port you wish to use. If nothing shows up, it's free. Copy and rename the socket-config-example.json to socket-config.json.

The following should be present:

{
  "address": "192.168.0.1",
  "port": "3000",
  "secure": false
}

Make sure to use the domain or ip corresponding to what is filled in here.

After filling in the socket-config.json, run the following command to generate the bundle.js: npm run-script build.

Only repeat this when the socket-config.json has changed.

Webhosting

To serve the view of D-Zone, a web server needs to be setup. In this instruction nginx is used. Because nginx is best for static websites like D-Zone, and is generally faster then Apache2.

Install nginx

apt install -y nginx
systemctl status nginx

If it says active (running) nginx is working.

Copy web files

Given that you have the d-zone in your home folder: rsync -r --delete --exclude 'web/script/' /home/user/d-zone/web/ /var/www/html/

This will sync the newest files to the other place. It also includes folders. It also will delete any files or foldes that are no longer present at one of the locations. And it will exclude the web/script/ folder. As this isn't required for the website.

Starting D-Zone

Now that everything is inplace, type the following to start D-Zone. Given that your in the project folder: npm start

Check trough your webbrowser if d-zone is running.

  • If you get the upgrade required error you have visited the websocket.
  • If you get stuck on connecting... check if the port is indeed open.

Running D-Zone with HTTPS

If you are hosting with HTTPS enabled (recommended), you need to also set your cert and key variables to the full paths of your certificates. To this, it's recommanded to use certbot. Just follow the instructions and check if HTTPS is indeed working.

To make D-Zone work with HTTPS, set the following in the .env file:

token=yourtokenhere
cert=/etc/letsencrypt/live/yourdomain.com/fullchain.pem
key=/etc/letsencrypt/live/yourdomain.com/privkey.pem

Change in the socket-config.json the secure field from false to true:

{
  "address": "192.168.0.1",
  "port": "3000",
  "secure": true
}

Lastly, change in discord-config.json the HTTP url to HTTPS.

{
  "url": "https://yourdomainonly.com/",
  "infoCommand": "!d-zone",
  "servers": [
    {
      "id": "1234567891234567",
      "default": true,
      "ignoreChannels": ["members-Only","testing"],
      "password": "This is optional"
    }
  ]
}

Again, repeat npm run-script build and restart D-Zone. If you visit it on HTTPS it should work still.

Running as a Service

To keep D-Zone running, a proces manager needs to be used so it can continue to run after the terminal session has been closed.

pm2

Install pm2 by doing:

npm install pm2@latest -g

To start D-Zone with pm2 type the following once:

pm2 start npm -- start --name=D-Zone

Type the following to start D-Zone when the system start:

pm2 startup
pm2 save

Documenation about pm2.

Systemd

nano /etc/systemd/system/d-zone.service Then type the following:

[Unit]
Description=D-Zone

[Service]
WorkingDirectory=/home/user/d-zone/
ExecStart=/usr/bin/npm start
Type=simple
Restart=on-failure
StandardOutput=syslog 
StandardError=syslog
SyslogIdentifier=D-Zone

[Install]
WantedBy=multi-user.target

Change the WorkingDirectory to the directory where the D-Zone project is located. To start it type:

systemctl daemon-reload
systemctl start d-zone.service

To start D-Zone with the system, type the following:

systemctl deamon-reload
systemctl enable d-zone.service

Documenation about systemd.

Notes

Respect the privacy of the users in your Discord server. By creating a D-Zone for your server without a password, you are allowing anyone with the URL to view any conversations your bot has permission to see.

The build script creates a minified bundle file with no source mapping, while watch is not minified but is quicker to run and has source mapping. So, watch is good for development and build is good for deployment. If you have no idea what this means, use build