Running multiplayer extensions server



Install Virtual Box: Download Virtual Box for your system


Download the virtual machine Docker VM with PHP54 and MySQL


Virtual Machine Settings : check the Network. It should be on Bridge Mode!

Information of VM:
  • handson (holuser) password: oracle
  • root password : oracle
  • IPAddress : 192.168.0.100
  • Port : 5444
  • Gateway : 192.168.1.254


  • To change the IP Address:
  • Login to VM
  • Applications : Favorites: Terminal

    Modify /etc/sysconfig/network-scripts/ifcfg-enp0s3

    vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
    IPADDR=192.168.0.100 (change this to a new IP address in your network )
    NETMASK=255.255.0.0 (change this to your netmask, usually 255.255.255.0)
    GATEWAY=192.168.1.254 (change this to your default gateway, usually your router : 192.168.x.1)
    :wq # write quit the changes


    service network restart
    Start Docker:

     docker run -p 192.168.0.100:5444:80 --name php54 -v /root/php54:/home/extern -t -d php54mysql_stencyldocker sh -c "/home/extern/start.sh"
     

    If you get an error that it is already in use: docker stop [id]; docker rm [id] and repeat docker run

    Information:
     docker ps

    Something like this:
    xxxxxxxxx php54mysql "/bin/bash -c /home/…" 5 seconds ago Up 4 seconds 192.168.0.100:5444->80/tcp php54
    

    Test the page:
    Browse to your IP address with the port 5444 : http://192.168.0.100:5444 You should see the stencyl application ID generator



    In stencyl use the folling URL in the blocks:
    http://192.168.0.100:5444/stencyl.php


    Available from the internet



    In case you want your virtual box-virtual machine accessable from the global internet you need to portforward from your router.
    It depends what router you have if that is possible and if your service providers allows portforwarding.
    If you can portforward you can portforward for instance the global port 5444 to your internal port

    For instance (not specific for any router) 5444:192.168.0.100:5444

    So then your global IP address can be used in the stencyl block:

    http://194.34.211.16:5444/stencyl.php


    How was the virtual machine made


    Download Virtual Machine from oracle : Select one of Oracle Linux Images for Hands-On Labs (DOC-1017486.ova)
    Start VirtualBox and Do File : Import appliance

    Open the OVA file
    change settings of virtual machine:(Settings)

  • Turn off USB
  • Change Network mode from NAT to bridge




  • Hands-on account password : oracle
  • applications : Favorites : Terminal
  •  sudo su - # password : oracle 

    Change root password:
    passwd root
    
    Change the network settings so that you can have a fixed IP address even after restarting the Virtual Machine:
  • vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
  • BOOTPROTO=none
    IPADDR=192.168.0.100
    NETMASK=255.255.0.0
    GATEWAY=192.168.1.254
    
    * vi /etc/sysctl.conf
    net.ipv4.ip_forward=1
    
    * service network restart
    Check settings
  • ip address
  • # Check the ip address of the virtual machine
    # in my case:
    inet 192.168.0.100/16 brd 192.168.255.255 scope global enp0s3
    

    Download the docker image: Stencyl Multiplayer Extension Server

    Download the docker mysql and php files archive: : Stencyl Multiplayer Extension Server
    Or use wget to get them:
  • cd /tmp
  • wget http://photoquesting.com/stencyl/docker_php54mysql.tar.gz
  • wget http://photoquesting.com/stencyl/docker_php54mysql_files.tar.gz

  • Put them on the right place:
  • cd /root
  • cp /tmp/docker_php54mysql.tar.gz .
  • gzip -d docker_php54mysql.tar.gz

  • mkdir /root/php54
  • cd /root/php54
  • cp /tmp/docker_php54mysql_files.tar.gz . # there where you downloaded the _files.tar.gz
  • gunzip docker_php54mysql_files.tar.gz
  • tar xvf docker_php54mysql_files.tar
  • mkdir php
  • mv *.php php/.


  • cd /root
  • cat docker_php54mysql.tar | docker import - php54mysql_stencyl
  • docker images
  • REPOSITORY TAG IMAGE ID CREATED SIZE
    php54mysql_stencyldocker latest xxxxxxxxxxxx 17 seconds ago 567 MB
    

    Make the Virtual Machine accessable from your computer with putty:
  • vi /etc/ssh/sshd_config

  • # search for PermitRootLogin and enable it
    # :wq

  • service sshd restart

  • putty 192.168.0.100
  • root / oracle login

  • docker run -p ::80 --name php54 -v /root/php54:/home/extern -t -d php54mysql sh -c "/home/extern/start.sh"

  • Where -v is pointing to the volume : /root/php54 and makes it internally available on /home/extern
    For instance in my case:
  • docker run -p 192.168.0.100:5444:80 --name php54 -v /root/php54:/home/extern -t -d php54mysql_stencyl sh -c "/home/extern/start.sh"
  • Check the Generator page: http://192.168.0.100:5444

    In stencyl use the folling URL in the connection blocks: http://192.168.0.100:5444/stencyl.php In case you want your virtual box-virtual machine accessable from the global internet you need to portforward from your router.
    It depends what router you have if that is possible and if your service providers allows portforwarding.
    If you can portforward you can portforward for instance the global port 5444 to your internal port
    For instance (not specific for any router) 5444:192.168.0.100:5444
    So then your global IP address can be used in the stencyl block:
       http://194.34.211.16:5444/php/stencyl.php
       

    How was the docker image made?



    We are creating a docker LAMP (Linux Apache MySQL PHP)
  • centos 6
  • PHP 5.4
  • MySQL
  • Apache


  • mkdir /root/php54
  • mkdir /root/docker
  • Get the Docker PHP Source files.
  • cd /root/php54
  • Download http://photoquesting.com/stencyl/stencyl_mp_v1.tar
  • wget http://photoquesting.com/stencyl/stencyl_mp_v1.tar
  • tar xvf stencyl_mp_v1.tar
  • cd /root/docker
  • vi db.sql
  • SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123St@ncyl456');
    create database stencyl;
    grant all privileges on stencyl.* to root@localhost;
    use stencyl;
    create table test (id int, name varchar(20));
    insert into test values (1, ' DEF ');
    commit;
    select * from test;
    show tables;
    select * from test;
    
  • vi /root/php54/start.sh
  • #/bin/bash
    service mysqld restart
    sleep 10
    service httpd restart
    sleep 10
    date +"%H %M %S" >> /home/extern/debug.log
    sleep infinity
    
  • chmod +x /root/php54/start.sh
  • cd /root/docker
  • vi Dockerfile
  • #
    # Docker create: docker build -t php45mysql .
    #
    FROM centos:6
    MAINTAINER root
    LABEL Description="PHP 5.4, MySQL, Apache" \
    License="Apache License 2.0" \
    Usage=" docker run -p [youripaddress]:5444:80 --name php54 --dns=[serviceprovider-dns-ipaddress] --dns-search=[serviceprovider-dns-search-domain] -v /root/php54:/home/extern/ -t -d centos sh -c \"/bin/bash\" " \
    Version="1.0"
    # Zet de rnpvsquid15 proxy server voor het update proces
    RUN yum -y update && yum clean all
    RUN yum -y install httpd && yum clean all
    RUN yum -y install gcc php-pear php-devel make openssl-devel && yum clean all
    RUN yum install -y \
    httpd \
    php \
    php-common \
    php-mbstring \
    mysql \
    mysql-server \
    php-mysql
    ENV LOG_STDOUT **Boolean**
    ENV LOG_STDERR **Boolean**
    ENV LOG_LEVEL warn
    ENV ALLOW_OVERRIDE All
    ENV DATE_TIMEZONE UTC
    
    # Creating Database/Tables (only onetime!!)
    COPY db.sql /tmp/db.sql
    # Start/Create MySQL Database
    RUN /etc/init.d/mysqld start && sleep 30 && mysqladmin password 123St@ncyl456 && sleep 30 && mysql -u root -p mysql --password=123St@ncyl456 < /tmp/db.sql && sleep 10
    RUN mkdir -p /home/extern/lib
    #
    # lib folder is moved to external location .. so tell mySQL where it is
    RUN cp -r /var/lib/mysql/*.* /home/extern/lib/.
    RUN sed 's/datadir=\/var\/lib\/mysql/datadir=\/home\/extern\/lib/' /etc/my.cnf > /etc/my2.cnf; mv -f /etc/my2.cnf /etc/my.cnf
    # Set Apache homepage to our PHP directory
    RUN echo -e "  \n DocumentRoot /home/extern/php \n " >> /etc/httpd/conf/httpd.conf
    # RUN mkdir /home/extern
    RUN chown -R apache:apache /var/www/html
    # enable MySQL
    RUN chkconfig mysqld on
    
    VOLUME /var/www/html
    VOLUME /var/log/httpd
    EXPOSE 80
    # starting http / mysql
    ENTRYPOINT ["/bin/bash","-c","/home/extern/start.sh"]
    
  • docker build -t php54mysql .
  • Wait till the statement : succesfully built is given
  • docker images
  • 
    REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
    php54mysql          latest              xxxxxxxxxxxx        About a minute ago   735 MB
    centos              6                   xxxxxxxxxxxx        15 months ago        194 MB
    
    
  • docker run -p 192.168.0.100:5444:80 --name php54 --dns=80.69.67.67 --dns-search=colo.transip.net -v /root/php54:/home/extern/ -t -d php54mysql sh -c "/home/extern/start.sh"docker run -p 192.168.0.100:5444:80 --name php54 --dns=80.69.67.67 --dns-search=colo.transip.net -v /root/php54:/home/extern/ -t -d php54mysql sh -c "/home/extern/start.sh"
  • docker ps
  • xxxxxxxxx php54mysql "/bin/bash -c /home/…" 5 seconds ago Up 4 seconds xxxxxxxx:5444->80/tcp php54
    
    In Docker:
    docker exec -ti php54 /bin/bash
    
  • chown -R apache:apache /home/extern
  • cd /home/extern
  • chown -R mysql:mysql /home/extern/lib
  • Possible : mysqladmin password 123St@ncyl456
  • mysql -u root -p mysql --password=123St@ncyl456
  • create database stencyl; grant all privileges on stencyl.* to root@localhost; exit
  • vi /home/extern/connect.php
  • < QuestionMark  php
    $mysql_host = "localhost";
    $mysql_database = "stencyl";
    $mysql_user = "root";
    $mysql_password = "123St@ncyl456";
            $db=mysql_connect($mysql_host, $mysql_user, $mysql_password);
            mysql_select_db($mysql_database,$db);
    QuestionMark>
    
  • yum -y install wget
  • wget http://photoquesting.com/stencyl/creation/create_db.txt
  • < QuestionMark php
    /*
            Manual actions:
     ========
      mysql -u root -p mysql
      create database stencyl;
      grant all privileges on stencyl.* to root@localhost;
     =========
    */
    
            # connect.php -> connects to Stencyl database
            include "connect.php";
    
    
            //
            // ScoreBoard creation
            //
            // scoreboard_apps : id, app_id, email, secret_id
            // scoreboards     : id, app_id, level, name, text, number, time
            // scoreboard_stats: id, app_id, action, time
            //
    
            $sql="CREATE TABLE IF NOT EXISTS stencyl_apps (id INT PRIMARY KEY  NOT N                                                                                                                          ULL AUTO_INCREMENT , app_id VARCHAR(12), email VARCHAR(30), secret_id INT, acces                                                                                                                          sed BIGINT(8),isdebug VARCHAR(20), created DATETIME, free VARCHAR(2))";
            mysql_query($sql);
    
            $sql="CREATE TABLE IF NOT EXISTS stencyl_scoreboards (id INT PRIMARY KEY                                                                                                                            NOT NULL AUTO_INCREMENT , app_id VARCHAR(12), level INT, name VARCHAR(255), te                                                                                                                          xt VARCHAR(255), number INT, time VARCHAR(40))";
            mysql_query($sql);
    
            $sql="CREATE TABLE IF NOT EXISTS stencyl_scoreboard_stats (id INT PRIMAR                                                                                                                          Y KEY  NOT NULL AUTO_INCREMENT , app_id VARCHAR(12), action VARCHAR(245), time T                                                                                                                          IMESTAMP)";
            mysql_query($sql);
    
    
            // Property System
            $sql="CREATE TABLE IF NOT EXISTS stencyl_property_lockids (id INT PRIMAR                                                                                                                          Y KEY NOT NULL AUTO_INCREMENT, app_id VARCHAR(12), clientip VARCHAR(30), time TI                                                                                                                          MESTAMP)";
            mysql_query($sql);
    
            // Maximum size mysql > 5.0.3 is 65.000 varchar column
            $sql="CREATE TABLE IF NOT EXISTS stencyl_property_table (id INT PRIMARY                                                                                                                           KEY NOT NULL AUTO_INCREMENT, app_id VARCHAR(12), property_name VARCHAR(4000), pr                                                                                                                          operty_value TEXT, property_lock VARCHAR(40), time TIMESTAMP)";
            mysql_query($sql);
    
    
            // Counter System
            $sql="CREATE TABLE IF NOT EXISTS stencyl_counters (app_id varchar(12) no                                                                                                                          t null, counter_name varchar(1000), counter_id bigint not null auto_increment, p                                                                                                                          rimary key (app_id,counter_id)) engine=myisam";
            $msql=mysql_query($sql);
    
    
            // Message System
            $sql="CREATE TABLE IF NOT EXISTS stencyl_messages (id INT(11) NOT NULL A                                                                                                                          UTO_INCREMENT, app_id VARCHAR(25), roomid INT(11), playerid INT(11), time TIMEST                                                                                                                          AMP, message TEXT, PRIMARY  KEY (id))";
            mysql_query($sql);
    
    
    /*
            db : id, acc_id, db_name
            tbl : id, db_id, tbl_name
            fld : id, db_id, tbl_id, fld_name
            row : id, db_id, tbl_id, fld_id, row_id, value
    */
    
    
            // check the existence of objects
            $sql="CREATE TABLE IF NOT EXISTS stencyl_db (id INT PRIMARY KEY  NOT NUL                                                                                                                          L AUTO_INCREMENT , acc_id INT, db_name VARCHAR(30))";
            mysql_query($sql);
            $sql="CREATE TABLE IF NOT EXISTS stencyl_tbl (id INT PRIMARY KEY NOT NUL                                                                                                                          L AUTO_INCREMENT , db_id INT, tbl_name VARCHAR(30))";
            mysql_query($sql);
            $sql="CREATE TABLE IF NOT EXISTS stencyl_fld (id INT PRIMARY KEY NOT NUL                                                                                                                          L AUTO_INCREMENT , db_id INT, tbl_id INT, fld_name VARCHAR(30))";
            mysql_query($sql);
            $sql="CREATE TABLE IF NOT EXISTS stencyl_row (id INT PRIMARY KEY NOT NUL                                                                                                                          L AUTO_INCREMENT , db_id INT, tbl_id INT, fld_id INT, row_id INT, value TEXT)";
            mysql_query($sql);
    
            // Rooms
    /*
            players : id, game_id, email, password, name
            rooms : id, game_id, max, heartbeat
    */
            $sql="CREATE TABLE IF NOT EXISTS stencyl_players (id INT PRIMARY KEY NOT                                                                                                                           NULL AUTO_INCREMENT , game_id VARCHAR(255), email VARCHAR(255), password VARCHA                                                                                                                          R(255), name VARCHAR(255), heart TIMESTAMP, ip VARCHAR(255), turn_elapsed INT)";
            mysql_query($sql);
    
            // Heartbeat is in seconds
            // Roomtype: ACCESS / TURN
            $sql="CREATE TABLE IF NOT EXISTS stencyl_rooms (id INT PRIMARY KEY NOT N                                                                                                                          ULL AUTO_INCREMENT, game_id VARCHAR(255), name VARCHAR(255), number_of_players I                                                                                                                          NT, room_type VARCHAR(255),  heartbeat INT, owner VARCHAR(255), current VARCHAR(                                                                                                                          255), previous VARCHAR(255), turntime INT)";
            mysql_query($sql);
    
    
    //CREATE TABLE IF NOT EXISTS stencyl_counters (app_id varchar(12) not null, coun                                                                                                                          ter_name varchar(1000), counter_id bigint not null auto_increment, primary key (                                                                                                                          app_id,counter_id)) engine=myisam";
            $sql="CREATE TABLE IF NOT EXISTS stencyl_roomdata (room_id INT, player_i                                                                                                                          d INT, seat INT not null auto_increment, PRIMARY KEY (room_id,seat)) engine=myis                                                                                                                          am";
            mysql_query($sql);
    
    
            // SharedData
            $sql="CREATE TABLE IF NOT EXISTS stencyl_shareddata (id INT PRIMARY KEY                                                                                                                           NOT NULL AUTO_INCREMENT , game_id VARCHAR(255), room_id INT, value TEXT)";
            mysql_query($sql);
    
    
            // DEBUG -- REMOVE !!
            $sql="CREATE TABLE IF NOT EXISTS debug (id INT PRIMARY KEY NOT NULL AUTO                                                                                                                          _INCREMENT, text VARCHAR(4000), debugtime TIMESTAMP, app_id VARCHAR(255))";
            mysql_query($sql);
    
    
    
    echo " Tables created !";
    
     QuestionMark >
    
    
    (Change QuestionMark into ?, watchout that you don't have spaces between the ? and the greater / smaller than characters )
  • vi create_db.txt :> change ../connect.php to connect.php
  • php -f create_db.txt
  • vi /etc/httpd/conf/httpd.conf # Change DocumentRoot
  • DocumentRoot "/home/extern"
    
    And in the Virtualhost part (at the end of the file)
     DocumentRoot /home/extern
    
    
  • service httpd restart
  • service mysqld restart
  • mysql -u root -p mysql --password=123St@ncyl456
  • use stencyl;
    insert into stencyl_apps values (1, 'EAPGLLFM', 'bWVfMzZAbXNuLmNvbQ==',807924218, 0,'N',now(),'N');
    insert into stencyl_apps values (2, 'LCAMOJBI', 'bWVfMzZAbXNuLmNvbQ==',736233013, 0,'N',now(),'N');
    insert into stencyl_apps values (3, 'LBNKHDBF', 'bWVfMzZAbXNuLmNvbQ==',454491322, 0,'N',now(),'N');
    commit;
    exit;
    
    Test: Browse 192.168.0.100:5444 (your virtual machine ipaddress)

    If your test works you can save that what you made into a new docker image so that you don't need to change the settings.
    Exit out of the docker

    Save docker container as image
  • docker commit php54
  • docker images
  • REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    none                none                7fb0201e4086        2 seconds ago       735 MB
    
    
    Find the untagged id for the image. In our case : 7fb0201e4086
  • docker tag 7fb0201e4086 php54_v1

  • From now on you can use this start statement:
  • docker run -p 192.168.0.100:5444:80 --name php54 -v /root/php54:/home/extern/ -t -d php54_v1 sh -c "/home/extern/start.sh"
  • Make an image of the docker:
  • docker export php54 > /root/docker/docker_php54mysql.tar
  • Make regular back-ups of your mysql files when you need persistence.
    The MySQL files are located on /root/php54/lib

    In Stencyl

    URL in Stencyl Extensions blocks: http://your_server:5444/stencyl.php
  • http://192.168.0.100:5444/stencyl.php