Categories
Gaming

Making a customised world in Don’t Starve Together

Customising your world in Don’t Starve Together is pretty simple – you just need to know where the configuration goes and what to put in the file.

Creating a worldgenoverride.lua

This file allows you to fine tune your DST experience and is specific to the shard you are customising – for instance, if you want to customise your Forest shard called Master, you’d place your worldgenoverride.lau in:

~/.klei/DoNotStarveTogether/Cluster_1/Master/worldgenoverride.lua

What do I put in the file?

For my config on the Anxiety Hour server, I specified a medium sized world and a couple of other fairly self explanatory changes:

return {
        override_enabled = true,
        overrides = {
                world_size = "medium",
                deerclops = "never",
                touchstone = "often"
        }
}

What can I say, we die alot.

Categories
MacOS X NPM

Installing & using Node & NPM on MacOS X

To install NPM & Node simply go to the Node web site and install the latest stable version from the downloads page; or use the link on the Node homepage.

To check the installation simply use the methods described below to check the respective versions of NPM & Node.

NPM

NPM stands for Node Package Manager and is a way to quick install packages for Node with all their dependencies.

To check your installed version of NPM from the terminal use:

npm -v

If you use NPM regularly you’ll get nudged occasionally to upgrade – if you see something similar to the following in your CLI, just follow the instructions:

A subtle nudge to update you NPM install – just follow the instructions.

If you need to update your version of NPM and you get errors with the above command, use the following to escalate your privileges:

sudo npm install -g npm stable

Afterwards, check your installed version:

All sorted, now running the latest stable version.

Node

Node is basically JavaScript running on the backend of your server – it can easily replace other more traditional backend languages such as PHP and Java meaning you can use JavaScript for your full stack.

To check your installed version of Node from the terminal use:

node -v

To upgrade Node, simply use NPM with the following command:

Removing NPM & Node from MacOS X

To remove both NPM & Node from your Mac, use the following commands:

cd /usr/local/lib

sudo rm -rf ./node*

cd /usr/local/include

sudo rm -rf ./node*

cd /usr/local/bin

sudo rm -rf ./npm

sudo rm -rf ./node

cd ~

rm -rf ./.npm

You can check to see if your NPM & Node installs return anything using the version command:

node -v

If there are any other areas of NPM or Node that require removal, let me know in the comments.

Categories
Gaming Ubuntu Server

Adding mods to your Don’t Starve Together server

Adding mods to your dedicated Don’t Starve Together server on Ubuntu Server can be a little fiddly – to get started you’ll need the mod IDs from the Steam Workshop. Once you have those they need to be added to a file in a specific format.

Open the file below:

vi ~/dontstarvetogether_dedicated_server/mods/dedicated_server_mods_setup.lua

The syntax is explained in the file – as per the files instructions, adding the mod Global Positions looks like this:

ServerModSetup("378160973")

You can add as many mods as you need, just add them on a new line each time.

Once this is done you need to configure your mod – create a file called modoverrides.lua in your cluster:

vi ~/.klei/DoNotStarveTogether/Cluster_1/Master/modoverrides.lua

Now add your configuration: if you aren’t sure what needs to be added, try making a local game with the mod enabled and copy from your local game file.

A common mod called Global Positions has a set up similar to this:

return {
  ["workshop-378160973"] = {
    configuration_options = {
      ENABLEPINGS = true,
      FIREOPTIONS = 2,
      OVERRIDEMODE = false,
      SHAREMINIMAPPROGRESS = true,
      SHOWFIREICONS = true,
      SHOWPLAYERICONS = true,
      SHOWPLAYERSOPTIONS = 2
    },
    enabled = true 
  }
}

Once you have configured these two files, simply restart your game and the mods should load.

If you want to remove these at any point simply remove the relevant configurations from the files above.

Categories
Gaming Ubuntu Server

Set up a Don’t Starve Together server on Ubuntu Server 18.04

In this post we’ll be setting up a dedicated Don’t Starve Together server with Caves on Ubuntu Server 18.04 for use with Windows, Mac and Linux clients. Sadly, neither Playstation nor Xbox players will be able to connect.

If you’re not sure what I’m talking about, maybe check out the Don’t Starve Together pages on the Klei web site.

Klei describes Don’t Starve Together as an uncompromising wilderness survival game, all I know is it’s alot of fun to play with friends.

Like playing the game, setting it up is a lot less stressful once you know what to do…


Preparation

Before we can begin setting up our game server, we need to install some dependencies:

dpkg --add-architecture i386;

apt install libstdc++6:i386 libgcc1:i386 libcurl4-gnutls-dev:i386 wget screen


New user

Create a new user to install all the relevant game files into – this keeps file management easy and means you can easily remove the installation at a later date if you need to.

adduser dont-starve

Switch to the new user:

su - dont-starve


SteamCMD install

Don’t Starve is downloaded and updated from the Steam platform. To do this we need to install the SteamCMD package.

First let’s make a folder for it to live in:

mkdir -p ~/steamcmd/

cd ~/steamcmd/

Download and unpack the SteamCMD package:

wget "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz"

tar -xvzf steamcmd_linux.tar.gz

We’re done with SteamCMD for now, head back to the home root:

cd ~


Get cluster token and cluster config

To configure your Don’t Starve Together server you should now head over to the Klei accounts website: https://accounts.klei.com/

At the bottom of the DST page, you can create a new server:

Creating the Anxiety Hour Don’t Starve together server, Warly’s Kitchen

Once the new server has been created you’ll need to configure it. You can do this manually but it saves you alot of headaches to just use the wizard – click the `Configure` link under your new server key:

For a quick setup, use Klei’s configure wizard initially

Choose some settings that make sense to you, you can always change these at a later date in your config files if you need to.

Once filled in you can download the Zip archive, extract the content, and place the folder `MyDediServer` inside ~/.klei/DoNotStarveTogether/


Startup script

To start your game server you’ll need a startup script – create a new file in your home root:

vi ~/run_dedicated_servers.sh

Drop the following into this file:

#!/bin/bash

steamcmd_dir="$HOME/steamcmd"
install_dir="$HOME/dontstarvetogether_dedicated_server"
cluster_name="MyDediServer"
dontstarve_dir="$HOME/.klei/DoNotStarveTogether"

function fail()
{
	echo Error: "$@" >&2
	exit 1
}

function check_for_file()
{
	if [ ! -e "$1" ]; then
		fail "Missing file: $1"
	fi
}

cd "$steamcmd_dir" || fail "Missing $steamcmd_dir directory!"

check_for_file "steamcmd.sh"
check_for_file "$dontstarve_dir/$cluster_name/cluster.ini"
check_for_file "$dontstarve_dir/$cluster_name/cluster_token.txt"
check_for_file "$dontstarve_dir/$cluster_name/Master/server.ini"
check_for_file "$dontstarve_dir/$cluster_name/Caves/server.ini"

./steamcmd.sh +force_install_dir "$install_dir" +login anonymous +app_update 343050 +quit

check_for_file "$install_dir/bin"

cd "$install_dir/bin" || fail

run_shared=(./dontstarve_dedicated_server_nullrenderer)
run_shared+=(-console)
run_shared+=(-cluster "$cluster_name")
run_shared+=(-monitor_parent_process $$)

"${run_shared[@]}" -shard Caves  | sed 's/^/Caves:  /' &
"${run_shared[@]}" -shard Master | sed 's/^/Master: /'

Save the file and make it executable:

chmod u+x ~/run_dedicated_servers.sh


Starting your server

If you are staying in your terminal screen while you play, you can simply run the bash script directly:

~/run_dedicated_server.sh

This will update your server and start it up ready to connect. You’ll see lots of text on the screen as it starts, this is the game console. Be aware that if you close your terminal window or disconnect from SSH you will also close your running game server.

If you want to start your server without entering the console, so you can close your terminal or SSH connection, then use screen like below – where DST is just a easily remembered name for the screen session:

screen -S DST -d -m ~/run_dedicated_servers.sh

To view the game console later, use the following command:

screen -d -r DST


Shutting down your server

From the game console you can shutdown your server using ctrl + c if needed.

Categories
NGINX Ubuntu Server

Simple 301 redirect with NGINX

Just a quick post on 301 redirects in NGINX – for a single URL the syntax is pretty easy as it reflects most other location blocks you’ll be setting up anyway:

location /old/path/ {
    return 301 https://tonymerryfield.co.uk/new/path/;
}

This is a quick way to ensure old URLs still point to relevant content and you retain some of your PageRank too.

If you have other quick solutions to 301s post them below and I’ll add them to this post.

Categories
Javascript

Get content from an API endpoint

XMLHttpRequest()

Until recently a request for data from an API endpoint would typically boil down to this:

let url = '/some/content.json',
	request = new XMLHttpRequest();

request.open('GET', url);
request.responseType = 'json';
request.send();

request.onload = function() {
	console.log(request.response);
}

request.onerror = function () {
	console.log("An error occurred.");
};

It’s not too much code and can handle most requests with little change, but it’s never been very easy for me to remember.


fetch()

Now we have fetch() though, which in my opinion has a much nicer syntax:

const url = '/some/content.json';

fetch(url, {
	'Method': 'GET',
	'Content-Type': 'text/json'
})
.then((response) => {
	return response.json();
})
.then((json) => {
	console.log(json);
})
.catch((error) => {
	console.log("An error occurred.");
});
Categories
NPM

Node Package Manager – Installing packages

The most common task at the beginning of a project is to install the necessary packages – to do this you’ll use the install command a few times:

npm install react --save

To save a few keystrokes, this can be shorted to:

npm i react -S

npm i react-dom -S

--save or -S install the package to the current project – the packages will show up in the package.json under dependencies with a version number, usually the latest:

  "dependencies": {
    "react": "^16.12.0"
  }

Development dependencies

Not all dependencies need to be in the finished project, stuff like dev tools. To install a package only used during the development phase you can swap to --save-dev or -D:

npm i babel-core -D

This will install development dependencies under devDependencies in the package.json:

  "devDependencies": {
    "babel-core": "^6.26.3"
  }

Multiple packages in one install

If you are installing multiple packages at the same time, you can combine your installs into one line:

npm i babel-core babel-loader babel-preset-react -D

It doesn’t really matter if something has already been installed:

  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.6",
    "babel-preset-react": "^6.24.1"
  }

If you wanna get really hardcore with your installs, you can use the following syntax to combine common package names:

npm i babel-{core,loader} babel-preset-react -D

This hurts my head though.


Specific versions

If your project has very specific requirements for what packages are used, you can also load specific versions via NPM:

npm install lodash@4.1.8

Or the latest version in a major version:

npm install lodash@^4.0.0


What happens in the background?

Loading just 5 packages seems easy when you look at it like this, but if you check your projects node_modules folder you’ll see alot happened in the background:

Installing packages in NPM installs all the dependencies for every package.

Every package you install also brings with it all of its dependencies – this can add up quickly on a big project. Our 5 packages has installed 83 packages into our node_modules folder.

Not something you’d want to manage manually…

Categories
Apache Ubuntu Server

Enable Apache caching

To enable caching on Apache web server – simply type the following in on the CLI:

a2enmod expires

With this you can now add caching rules to your Virtual Host:

    <FilesMatch "\.(jpg|png|gif|mp4)$">
        ExpiresActive           On
        ExpiresDefault          "access plus 1 year"
    </FilesMatch>

    <FilesMatch "\.(css|js)$">
        ExpiresActive           On
        ExpiresDefault          "access plus 1 month"
    </FilesMatch>

Your application will need to manage expiring the cached files when things change.

Categories
PHP Ubuntu Server

Installing PHP on Ubuntu Server 18.04 for use in LAMP stack

Before doing any work on your Ubuntu Server, it’s a good idea to update your software repositories using:

apt update

Once that has completed, you can install PHP and some of the packages that integrate it into your stack:

apt install php libapache2-mod-php php-mysql

You may also want to just tidy up what files Apache looks for when someone requests a directory:

vi /etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html
</IfModule>

As usual when making changes to apache, you’ll need to restart your service for changes to take affect:

systemctl restart apache2

Categories
Ubuntu Server

Quick set up for UFW or Ubuntu Firewall on Ubuntu Server 18.04

A quick and easy firewall is included with Ubuntu Server – it is easy to set up.

Before doing any work on your Ubuntu Server, it is good practice to update your software repositories using:

apt update

Before you start making changes to the firewall, it is a good idea to check its status:

ufw status

You can also list any running applications that have registered a profile with the firewall:

ufw app list

If you access your server via SSH then you need to allow that service before you enable the firewall:

ufw allow OpenSSH

If you are enbling a profile that has spaces in the name, simply wrap your service name in quotes:

ufw allow 'Apache Full'

Once you’re sure you’re happy with the firewall setup, enable your firewall:

ufw enable

You can now see what profiles are active by running:

ufw status