GitHub Documentation Patreon donate button

Raspberry PI and Colyseus ( and Haxe)



  • Raspberry PI & Colyseus ( & Haxe )

    Currently there are two basic ways to deploy my Colyseus server:

    • (Virtual) Host on premise or in the cloud
    • Docker container running on premise or in the cloud

    For my Console system I wanted to run Colyseus and Haxe on a Raspberry PI.
    You could use this as a low budget computer for testing purposes or use port forwarding on your router to host it to the rest of the world.

    The steps below could be used to create a nodejs server and you can avoid all the extra steps to get haxe working.

    For small multiplayer games or for turnbased/idle games this would be a cheap way to run a server from your home.

    The procedure for a Virtual Raspberry PI (VirtualBox/XenServer) is much simpler because the x86 can work with lix.
    Unfortunately I haven't managed to get lix working on the real (ARM) hardware. It defaults to an incompatible distribution.

    If anyone knows how to tell lix to get the ARM based executables that would make this procedure a lot easier

    Installation Steps:

    Components:

    • Raspberry PI B v1.2 : 1GB Ram, 4x 1.2 Ghz Cores
    • Stretch image 2018-11-13-raspbian-stretch from https://distrowatch.com/?newsid=10376
    • Use Win32DiskImage/RUFUS to write the image to a 16GB SD card. The haxe software that we will install brings it to 14 GB!

    Boot raspbian (default it will use DHCP to get an IP address)
    Open terminal : sudo su - (Become root)

    vi /etc/ssh/sshd_config 
    

    change permitRootLogin to : permitRootLogin yes

    change password for root : passwd root

    Allow putty / ssh into the PI

    systemctl enable ssh
    systemctl start ssh
    

    Update/upgrade

    apt update
    apt upgrade
    
    rpi-update
    

    restart the PI

    Get the IP address:

    ip addr show      
    

    login as root to do the (remote) installation

    cd /root
    #nodejs
    #curl -sL https://deb.nodesource.com/setup_8.x | bash - # used for x86 version of pi
    curl -sL https://deb.nodesource.com/setup_10.x | bash -
    apt-get -y install nodejs
    node -v
    npm -v
    

    You can install the node stuff for Colyseus and run the NodeJS version.

    But I wanted HaXe so these are the steps we need to make before we can compile the neko and haxe versions

    If you are on x86 versions you can use the serjek example github files and use ' lix download' to download the binaries.

    But for now I had to compile the ARM versions:

    # ---------------
    # Neko / HaXe / Colyseus-hxjs 
    # ---------------
    # base software packages  
    # execute line after line (do not copy-paste-run!)
    mkdir -p ~/Development/haxe/{dev,lib,source}
    cd ~/Development/haxe/source
    apt-get install -y build-essential git cmake
    apt-get install -y libgc-dev libgc1c2 libpcre3 libpcre3-dev
    apt-get install -y apache2-dev libmariadb-client-lgpl-dev-compat    
    apt-get install -y libsqlite3-0 sqlite3 libsqlite3-dev    
    apt-get install -y libgtk2.0-dev
    apt-get install -y libudev-dev
    apt-get install -y libasound2-dev
    apt-get install -y zlib1g libmariadb2 libmbedtls-dev libmbedcrypto0 libmbedtls10 libmbedx509-0
    apt-get install -y m4 ocaml ocaml-native-compilers libpcre-ocaml-dev libextlib-ocaml libextlib-ocaml-dev opam
    apt-get install -y openssl libssl-dev 
    

    Interactive setup/install:

    opam init
    ocamlc -config|grep arch # should be arm 
    #interactive:
    opam install conf-m4 ocamlfind sedlex depext xml-light extlib rope ptmap sha
    

    We are ready to install neko and haxe:

    export HAXE_VERSION='4.0.0-rc.2'
    export NEKO_VERSION='v2-2-0'
    
    cd /root
    eval `opam config env`
    #
    #Neko install
    #
    git clone --recursive  https://github.com/HaxeFoundation/neko -b $NEKO_VERSION
    cd neko 
    mkdir build
    cd build
    cmake -DRELOCATABLE=OFF ..
    make
    make install
    

    Test the neko by typing in neko and check that the version is 2.2.0

      
    #
    # haxe install
    #  
    eval `opam config env`
    cd ~/Development/haxe/source
    git clone --recursive https://github.com/HaxeFoundation/haxe -b $HAXE_VERSION
    cd haxe
    make
    make tools
    make install  
      
    

    haxe --version # should give you 4.0.0-rc.2

    Setting up the libraries to run the examples

    haxelib setup
    # default /usr/lib/haxe/lib
     
    # yarn
    npm i yarn -g
    yarn
    
    # Get Haxe Libraries
    cd /usr/lib/haxe/lib
    # haxelib git colyseus-hxjs https://github.com/serjek/colyseus-hxjs
    git clone https://github.com/serjek/colyseus-hxjs
    
    

    Unfortunately I'm not good enough with haxe and lix libraries and I needed a hack to get
    the colyseus-hxjs library to work with the compiled ARM versions.

    Apparently the required versions are different from the default haxelib installations.
    Since I know that the lix steps worked for x86 installations I used a mix of installation steps to get it to work.

    npm i lix -g
    
    cd /root
    git clone https://github.com/serjek/colyseus-hxjs-examples.git
    cd /root/colyseus-hxjs-examples
    # We are still going to download the latest haxe_libraries but we are using the haxelib versions later
    lix download
    haxelib install tink_core
    haxelib install tink_lang
    haxelib install hxnodejs
    
    # Now we need to copy some of the /root/haxe/haxe_libraries to the haxelib libraries:
    mkdir -p /usr/lib/haxe/lib/colyseus-hxjs/git/src
    cp -r /root/haxe/haxe_libraries/colyseus-hxjs/0.0.0/github/*6  /usr/lib/haxe/lib/colyseus-hxjs/git
    mv /usr/lib/haxe/lib/colyseus-hxjs/git/*6/src  /usr/lib/haxe/lib/colyseus-hxjs/git/src
    cp -r /root/haxe/haxe_libraries/hxnodejs/6.9.1/haxelib/src/ /usr/lib/haxe/lib/hxnodejs/10,0,0
    
    echo "git" > /usr/lib/haxe/lib/colyseus-hxjs/.current
    
    haxelib list
    

    With these hacked haxe libraries we can then run the steps to create node versions from the haxe code:

    haxe server.hxml
    
    cd bin/server
    yarn
    node index.js
    
    

    You can now tell your client to connect to the examples.

    My pre-alpha Stencyl Extension Server was used by myself to run the TicTacToe game.

    For that I installed a webserver on the PI and uploaded both the server code and the client code to the Raspberry PI:

    #
    # Apache WebServer
    #
    apt-get install apache2
    systemctl enable apache2
    

    Copy your project to /var/www/html
    and
    Visit your game with a browser to the following URL: http://raspberry_pi_ip_address

    You can use win32diskimage to create an image from the SD card as a back-up.


 

GitHub Documentation Patreon donate button

© 2019 Endel Dreyer