Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. mdotedot
  3. Best
  • Profile
  • More
    • Continue chat with mdotedot
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

Best posts made by mdotedot

Stencyl (HaXe) Extension

This week I've started using Colyseus. I'm going to try to create a HaXe Extension for Stencyl so that I can publish multiplayer games with Colyseus.
Previously I've created a couple of multiplayer extensions for Stencyl but failed to get anything near realtime. Maybe Colyseus can help?!?
From first glance the Colyseus stuff looks great. I love the fact that I can run the server on my own infrastructure.

It will be a long road ahead and I've decided to start this Showcase thread to let you all follow my progress. Maybe you can help me along the way?!?

First I started by porting the example nyancat to a Stencyl game (Using a bitmap for the cat)

Flash publication failed! I've tried to put the flash (swf) on the same server and experimented with crossdomain.xml. But apparently websockets do not care about that.

Working clients:

  • HTML5 (Tested only Chrome)
  • Windows native
  • Mac OSX native
  • iOS (iPad mini)
  • iOS Simulator (iPhone 5s)
  • Android (Samsung S3 Note)
  • Linux
posted in Showcase • 6 Jan 2019, 22:46
RE: Stencyl (HaXe) Extension

After two weeks of further debugging I've now came up with a work around so that it does not crash.

These are the modifications that I needed to make to avoid null pointer crashes:

SocketSys.hx (haxe/net/impl/SocketSys.hx)

					// M.E. the match error.custom(error.blocked) caused null pointer crash
					/*
                    needClose = !(e == 'Blocking' || (Std.is(e, Error) && (
                        (e:Error).match(Error.Custom(Error.Blocked)) ||
                        (e:Error).match(Error.Blocked))
                    ));
					*/
					if((""+e).indexOf("Block") < 0 && (""+e).indexOf("Custom(EOF)") < 0){
						trace('closing socket because of $e');
						needClose=true;
					}
				}

And further down I don't close the socket which caused blocking and crashing things on Android

	if (needClose) {
		//	    close();  // M.E. This will cause Android problems
	}

Room.hx : avoid null pointer exception

private function patch( binaryPatch: Bytes ) {
        // apply patch
		// M.E. Check for null on binaryPatch
		if(binaryPatch == null || this == null || this._previousState == null){
trace("BINARY PATCH IS NULL or this._previousState == null !");
		}else{
			 
			this._previousState = FossilDelta.Apply(this._previousState, binaryPatch);
			// trigger state callbacks
			this.set( MsgPack.decode( this._previousState ) );
			this.onStateChange(this.state);
		}
        
        
    }

FossilDelta.hx in Apply to avoid null pointer exception

	var total=0;
	// M.E. Check for null on src
	  if(src == null)return haxe.io.Bytes.alloc(0);
	  if(delta == null) return haxe.io.Bytes.alloc(0);
	  // M.E. End of modification
	  

And I needed to inform Stencyl about errors in Room.onError or the extension would still use room functions ...

Room.hx connect function

	this.connection.onError = function (e) {
			var message="Possible causes: room's onAuth() failed or maxClients has been reached.";
			if(getGameAttribute("ColyseusErrorMessage") == null)setGameAttribute("ColyseusErrorMessage", ""); setGameAttribute("ColyseusErrorMessage", ""+getGameAttribute("ColyseusErrorMessage")+" "+message); 
            trace(message);
            this.onError(e);
        };

In the application I created an onError routine and that would be hit sometimes but then it will do a new client instance and it starts creating rooms again.

So we don't close the socket on haxe.net level but detect problems in Room and Client on Colyseus level.

Hopefully these changes don't bite me later. I really want to continue working on other methods than Lobby mechanism!

Mac OSX, iOS Simulator, iPhone 5, Windows and Android all work without crashes when creating and leaving rooms now.
I ran a demo-game that left and created rooms every 10 seconds and they kept working for an hour.
Android crashed on one device after an hour. It had done over 100 room creations by that time.
I need to keep that in mind when doing more stuff later on and see if it reoccurs.
(HTML5 never gave problems as it didn't use haxe.net)

posted in Showcase • 17 Mar 2019, 18:47
RE: Stencyl (HaXe) Extension
  • javascript memory consumption was a Stencyl bug. It has to do with drawing stuff, which I obviously did in my test application. Filed a PR on Stencyl Forum for this.
  • Publications:
    iPhone Simulator
    iPhone (Should be fine on iPad as well)
    Mac OSX
    Linux
    Windows
    Android (Tablet+Phone)
    HTML5

So all is fine to continue working on the RoomTypes.

posted in Showcase • 27 Mar 2019, 19:41
RE: Stencyl (HaXe) Extension

The wikipedia linked in the sourcecode of Crypto.hx mentioned :
"but reading the special file \Device\KsecDD does not work as in UNIX"

So I tried another crypto number generator:

haxelib install trandom

Edit the project.xml to include this haxelib

notepad \HaxeToolkit\haxe\lib\haxe-ws\git\src\haxe\net\Crypto.hx
Change this:

	 #if windows

			var randomValue = trandom.TargetRandom.random();
			var bytes = haxe.io.Bytes.alloc(length);
		        bytes.setInt32(0, randomValue);
			return bytes;

                    var input = sys.io.File.read("\\Device\\KsecDD");

                #else

This worked when I did a lime build & test for windows.

When I tried to incorporate the trandom library into Stencyl it gave me problems. There is a define done that is going to add a build.xml file to the publication method and Stencyl does not handle that.

I opted for another approach for the windows build from in Stencyl:

		#if windows
					return  haxe.io.Bytes.ofString(getRandomString(16));
					// This will not work
                    var input = sys.io.File.read("\\Device\\KsecDD");

                #else

getRandomString:

public static function getRandomString(length:Int, ?charactersToUse = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"):String
	{
		var str = "";
		for (i in 0...length){
			str += charactersToUse.charAt( Math.floor((Math.random() *  (Date.now().getTime() % (charactersToUse.length) ) )));
		}
		return str;
	} //getRandomString

It is not as strong as the crypto generator but at least it works.

Confirmed v0.10 & Serjek Externs with Simple Stencyl Extension (Kind of like the NyanCat demo)

  • HTML5
  • Windows
  • Android
  • iOS Simulator
  • iOS on device
  • Macintosh OSX
  • (Oracle) Linux
posted in Showcase • 21 May 2019, 17:45
RE: Stencyl (HaXe) Extension

With the core functionality done, the next room was much faster to create.

RoomType: Turn Based System

Proof Of Concept (sorry for the wall of text which is used to debug stuff)
http://photoquesting.com/Colyseus/ColyseusTurnBasedRoom.gif

This leads to these new blocks in Stencyl:
http://photoquesting.com/Colyseus/ColyseusTurnBlocks.png

When a player leaves the system will pick the next seat as the active seat. If there is no seat after the leaving player the first available seat is selected.

Also, the seat that becomes availabe is added to a stack for next players to join to. (Of course when the Stencyl Developer decides to allow join/rejoining of active game!)

posted in Showcase • 30 May 2019, 09:01
RE: Room details

This is how I do it (in HaXe)

Client Side : Joining/Create a room with options where I add the variable RoomName

	var theOptions:Map<String, Dynamic>=new Map<String,Dynamic>();
	theOptions.set("RoomName", ""+RoomName);

Client Side (getAvailableRooms) this will give you a list off all roomnames created

	client.getAvailableRooms(room_type, function(rooms, ?err) {
		if (err != null) trace("ERROR! " + err);
		for (room in rooms) {
trace(" room ID: "+room.roomId+" room Name: "+room.metadata.RoomName);
		}
		
	}

Server Side :

override function onInit (options:Dynamic) {
trace("Lobby created!", options);
        setMetadata(options); // is from Room documentation: https://docs.colyseus.io/server/room/#setmetadata-metadata
}

posted in Questions & Help • 7 Jun 2019, 07:13
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.

posted in Showcase • 21 Jul 2019, 10:50
RE: Stencyl (HaXe) Extension

Working towards a beta release of the Colyseus Stencyl Extension.

I had already Lock, TurnBased and Raw room-types.

Most of the progress has been made with the Client-As-A-Server concept.
I know that the best way to handle multiplayer is on the server-side.
But many of the Stencyl users are not comfortable writing the server-side logic.

Therefore I attempted for a Client-Server-Relay kind of thing.
The collision and logic is handled on the client side with one of the clients acting as the server.
On that client the real physics objects are hidden and only the data that is send to all players is displayed.

These are the things that are currently made with the Client-As-A-Server approach:

alt pong

Left Window is a Windows executable
Right Window is a web-page

alt physics

I hope to do some more beta-testing with other Stencyl users to gain more information about this approach.

posted in Showcase • 7 Sept 2020, 20:06
RE: Stencyl (HaXe) Extension

Since I want to join the Ludum Dare Jam 47 (2nd October) and make an on-line game we need to make resources public available.
Therefore I have made the Stencyl Extension available as a public beta : Stencyl Colyseus Extension Page

Last days I've worked on the documentation

And I worked on implementing a turn based card game.

alt physics

Sending and receiving data is a breeze with Colyseus.

It all depends on the game-logic and how to show the state of the game.

I hope that the docker container that I provide to the Stencyl users will make running of the server easier for them.

As mentioned before I have made the extension based on the work of serjek (haxe externs) on top of the Colyseus engine.

The server has only three logic parts : Turn based and Locking mechanism and a check on active seat.
All other logic has to run on the client.

Of course most good server implementations need more logic on the server,
but I still am not certain how to provide the stencyl users with a relative easy way to make server-side code.

The best 'feel' you get is when you implement the Lock Room Type for your game. The room-data is kind of like a database server
that allows only one player to modify the data.

But, to be honest, most Stencyl users want to create physics based games. I provide examples how to run a client-as-a-server approach.
That seems to work since all clients see the same 'server'-state. But it is never as fast as it could be with server-side-physics.

I've attempted to create physics logic on the server based on the Box2D library.
The problems arise when doing client side prediction and server lag compensation. I wasn't able to get that to work. The data on the
clients 'jumped' all over the place. It works when you have minimal player interaction on the physics objects, but then the 'client-as-a-server' approach
is way easier to implement.

posted in Showcase • 23 Sept 2020, 11:54

© 2023 Endel Dreyer