Setting Up the Game


While you can use any computer to host a RoboRuckus game server, this guide describes how to setup a dedicated game server on a Raspberry Pi with its own Wi-Fi network. A Raspberry Pi with ARMv7 or better is required by ASP.Net Core. This guide also assumes you already have some basic familiarity with the Linux command line. If you’re unfamiliar with the command line, these two guides are a good introduction, and more general information can be found at the official Raspberry Pi documentation.

Materials

Setting Up Raspbian

Following these instructions, download and install Raspbian (preferably the lite version) onto the SD card, and insert the card into your Raspberry Pi. You can either hook your Raspberry Pi up to a keyboard and monitor (via HDMI) to do the set up, or connect to your Raspberry Pi via SSH (see these instructions for SSH). Either way, an Internet connection is required for setup.

To connect via SSH (“headless” mode), connect your Pi to your router via an Ethernet cable then use this Raspberry Pi finder to locate your Pi and note its IP address. Click on the Terminal button to connect via SSH and open a command line. Use raspi-config to expand the file system and optionally setup the internationalization options and change the user password. Alternatively, you can refer to this guide for various methods of connecting to a Raspberry Pi.

If you’re using a Raspberry Pi 3, you can disable the Bluetooth and built in Wi-Fi radios by editing the config.txt file by running sudo nano /boot/config.txt and adding the following lines to the bottom of the file:

dtoverlay=pi3-disable-bt
dtoverlay=pi3-disable-wifi

Press ctrl+x and then y to save and close the file. If you’re planning on using the on-board Wi-Fi you can omit the second line.

Setting Up the Access Point

Before rebooting and reconnecting to your Pi, plug in the Wi-Fi adapter. The below instructions, based on this guide, will setup and configure the Raspberry Pi access point (double-clicking on a code block below will make it easier to copy):

First, run the following commands:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install hostapd isc-dhcp-server libgdiplus

Setting up DHCP server

Edit the dhcpd.conf file by running following command sudo nano /etc/dhcp/dhcpd.conf. Find the lines that read:

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

And change them to read:

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

Next, find the lines that read:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

And change them to read:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Then add the following lines to the bottom of the file:

subnet 192.168.3.0 netmask 255.255.255.0 {
    range 192.168.3.12 192.168.3.200;
    option broadcast-address 192.168.3.255;
    option routers 192.168.3.1;
    default-lease-time 600;
    max-lease-time 7200;
    option domain-name "local";
    option domain-name-servers 192.168.3.1, 8.8.8.8;
}

Save and close the file, then run the sudo nano /etc/default/isc-dhcp-server command. Edit the file so that the two lines with INTERFACES in them resemble the following:

INTERFACESv4="wlan0"
#INTERFACESv6=""

Save and close the file, then run the command sudo rm /var/run/dhcpd.pid.

Set up wlan0 for static IP

Run the sudo nano /etc/network/interfaces command and add the following lines to the end of the file, skipping or replacing any duplicate lines that already exist:

auto lo
auto eth0

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0

iface wlan0 inet static
    address 192.168.3.1
    netmask 255.255.255.0
    post-up /etc/init.d/isc-dhcp-server start
    pre-down /etc/init.d/isc-dhcp-server stop

Save and close the file, then run the commands:

sudo ifconfig wlan0 192.168.3.1
sudo systemctl disable isc-dhcp-server

Configure Access Point

Run the command sudo nano /etc/hostapd/hostapd.conf and change the contents of the file to match the following:

interface=wlan0
driver=nl80211
ssid=RoboRuckus
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
ignore_broadcast_ssid=0
ieee80211n=1
wme_enabled=1

This will create a Wi-Fi access point called RoboRuckus with no password. You can setup a secure network if you want by using the following configuration instead and changing the passphrase to whatever you want:

interface=wlan0
driver=nl80211
ssid=RoboRuckus
country_code=US
hw_mode=g
channel=6
ignore_broadcast_ssid=0
macaddr_acl=0
wpa=2
wpa_passphrase=passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

You will also need to update the BotCode.ino file to use WPA by changing:

Serial.println(sendCommand(F("AT+CWJAP=\"RoboRuckus\","), F("\nOK")));

To this:

Serial.println(sendCommand(F("AT+CWJAP=\"RoboRuckus\",\"passphrase\""), F("\nOK")));

If you want to use the Raspberry Pi’s built in Wi-Fi, omit the line reading driver=nl80211 in each case.

Save and close the file then run the command sudo nano /etc/default/hostapd. Find the line that reads:

#DAEMON_CONF=""

And change it to read:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Be sure to remove the # at the start. Save and close the file then run the command sudo nano /etc/init.d/hostapd and change the line reading:

DAEMON_CONF=

to:

DAEMON_CONF=/etc/hostapd/hostapd.conf

Then save and close the file. Restart your Pi and your access point should now be working.

Setting Up DNS

You can set it up so devices connected to your Raspberry Pi can access the game server by visiting the address roboruckus.com (you may need to flush your DNS cache on the computer connecting to the Raspberry Pi server to get this working; the ipconfig/flushdns command will do this in Windows). To start, you’ll need to set up dnsmasq by running the following command:

sudo apt-get install dnsmasq

Edit the dnsmasq configuration file by running:

sudo nano /etc/dnsmasq.conf

And add the following lines to the bottom of the file:

address=/roboruckus.com/192.168.3.1
address=/www.roboruckus.com/192.168.3.1

Then save and close the file.

Next run:

sudo nano /etc/hosts

And add the following line to the bottom of the file, then close and save it:

192.168.3.1     roboruckus.com  roboruckus

The next step is to install nginx and configure it as a reverse proxy. Run the following commands:

sudo apt-get install nginx
sudo rm /etc/nginx/sites-enabled/default

Then create a new nginx site called roboruckus:

sudo nano /etc/nginx/sites-enabled/roboruckus

Add the below lines to the contents of the file:

server {
 listen   80;
 server_name roboruckus.com www.roboruckus.com;

# Websocket support for playerHub connections.
location /playerHub {
        proxy_pass http://127.0.0.1:8082/playerHub;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
     }

# Redirect all HTTP traffic to Kestrel server.
 location / {
        proxy_pass http://127.0.0.1:8082;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
     }
}

Save your file and restart your Pi to get dnsmasq and nginx working.

Hardware RNG

While the RoboRuckus game already uses the RNGCryptoServiceProvider class to provide high quality random numbers for dealing cards, you can further improve the entropy pool on the Raspberry Pi by enabling its hardware RNG. The following is based on these instructions.

Raspberry Pi 2 Instructions

First, install the RNG-Tools:

sudo apt-get install rng-tools

Next run:

sudo nano /etc/modules

And add the below line to the bottom of the file:

bcm2708_rng

Close and save the file, then run:

sudo nano /etc/default/rng-tools

And set the contents of that file to:

HRNGDEVICE=/dev/hwrng

Close and save the file, then reboot to activate the RNG.

Raspberry Pi 3 Instructions

If you are using a Raspberry Pi 3, enter the following commands instead:

echo bcm2835_rng | sudo tee /etc/modules-load.d/rng-tools.conf
sudo modprobe bcm2835_rng
sudo apt-get install rng-tools
echo 'HRNGDEVICE=/dev/hwrng' | sudo tee --append /etc/default/rng-tools
sudo systemctl enable rng-tools
sudo systemctl start rng-tools
sudo systemctl status -l rng-tools

Reboot to activate the RNG. Whether this makes any real difference remains to be determined, but it can’t hurt.

Setting Up RoboRuckus

Now that the environment is set up, download the RoboRuckus Git repository, saving the file to your computer. Using SFTP, connect to your Raspberry Pi. Extract or open the zip file and copy the folder RoboRuckus from RoboRuckus-master/PiReady/ to your Raspberry Pi home directory. Then run the following commands:

cd RoboRuckus/
chmod 755 RoboRuckus
./RoboRuckus

Game Server Running

A successfully started RoboRuckus game server.

The chmod 755 RoboRuckus command only needs to be run the first time you start the game after coping the files over. To stop the game server press ctrl+c. If the server starts and exits without problems, congratulations, your game is good to go!

Command-Line Arguments

RoboRuckus accepts a number of optional arguments to change the game mode when you launch the program. In general, these arguments can be mixed in any order without problems. To use arguments, add them after the prgram name when launching RoboRuckus, as follows:

./RoboRuckus --options=arg1,arg2,...

Replace arg1 and arg2 (or as many arguments as you want, separating each with a comma) with one or more of the following options:

Botless Mode

Argument: botless

You can run the game in a “botless” mode, for playing the game without physical bots. This will add six “virtual” bots to the game so you can test and play just with a computer, phone, or tablet, but no physical bots needed. You cannot mix the botless mode with physical bots.

Edge Control

Argument: edgecontrol

By default, when a robot is supposed to drive or be pushed off the board, the physical robot will actually drive off the game board. This is to make room for other bots that might need to drive into that space, and to remove it from the game until the game master can re-enter the bot into play. Using edge control, when a robot is supposed to drive off the board it will only drive up to the edge of the board instead, the game will then pause for a few seconds and display a message for the game master to remove the robot from play before the game continues. This is useful when, for whatever reason, you don’t want or can’t have the robots driving off the board at all. It is still recommended to have some sort of barrier around the edge of the board to prevent the bots from accidentally driving off the board.

Compiling for the Raspberry Pi

Since the server code for RoboRuckus is written using the .Net Framework it can run on almost any modern system, including MacOS, Windows, and Linux. You can download the project solution from our GitHub repository and compile it for the system you’re running on using Visual Studio (or Visual Studio Code for MacOS and Linux). Compiling it to run on the Raspberry Pi is, however, more difficult. Here are the steps that you can take to compile RoboRuckus for the Raspberry Pi (these instructions should also work for any ASP.Net Core program you want to run on a Pi). Note that this has only been tested on a Windows computer running Visual Studio, but should still be feasible from MacOS or Linux using the alternative publish command below.

First, if you didn’t install it when you installed VisualStudio, you’ll need modify your install to include the .Net Core SDK, or you can download and install the .Net Core SDK for your platform from here. You’ll also need to install Node.js since NPM is used to manage JavaScript libraries. Once NPM is installed, either from the Package Manager Console in Visual Studio or from the command prompt in the solution directory, run the command:

npm update

Next, you need to publish the project by right-clicking on the RoboRuckus project name in the solution explorer and choosing publish. Select the ARMExport profile and click “Publish”. This will compile and copy the program to the PiReady folder in the solution directory on your computer. You can, if you want, create a new publish profile, just pick “Folder” as the publish target and choose where you want the output to be saved. Be sure to select “linux-arm” as the target runtime and set the deployment mode to “Self-Contained”.

Creat new publis profile

Creating a new publish profile.

Publish profile settings.

Creat new publis profile

Alternatively, you can run the following command from the command prompt in the project’s solution directory:

dotnet publish -r linux-arm -o ..\..\PiReady\RoboRuckus -c Release --self-contained

Once either of those is done, you can copy the contents of the publish directory to your Raspberry Pi and run the program!