Thanks Endel! It appears that RedisPresence needs a Redis Server!
When using RedisPresence and you don't have a running Redis Server you get this:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
For running a server this quick start is available : https://redis.io/topics/quickstart
I hate to run different things on the server since I want to have deployment by the Extension users as easy as it can be.
Maybe I will revisit this approach when I need persistence.
I've changed the approach to ApplicationIDs and 'just' generate some IDs for the Extension Users.
In the chat I've been told that one of my room-mechanism approach will fail. We will see where this thing is going to crash ...
I'm not promising that I can create a general purpose server for all kinds of clients.
If an approach don't work, extension users still have the ability to change the server themselves.
Although they probably lack the skills, they can hire you guys to make the server for them :D
There will be overhead on the proxy mechanism, but we will see what can be done.
Rather than saying that running logic on client is impossible I still want to try it.
Using the Colyseus server as a proxy to the active client.
For now I've created a turn based mechanism on the server that I need to write some clients for.
The example : 02-state-handler.ts appears to be working correctly with below additions, but I guess that I need to investigate
different types of turn based games and their server-side logic.
These are the steps taken to rotate player activity: (Modify 02-state-handler.ts)
After : something = "This ...
nextPlayer(){
var doNext=false;
for(var m in this.players){
if(doNext){
this.players[m].ActivePlayer=m;
doNext=false;
}else{
if(this.players[m].ActivePlayer != ""){
this.players[m].ActivePlayer="";
doNext=true;
}
}
} // check Next available player
if(doNext){ // if we need to shift but there are no players after : first player
for(var m in this.players){
if(doNext){
this.players[m].ActivePlayer=m;
doNext=false;
}
}// go through all players
} // check first available player
}// ActivePlayer shift
// Changed createPlayer
createPlayer (id: string, room:Room) {
this.players[ id ] = new Player();
if(room.clients.length == 1){ // first player in room
this.players[id].ActivePlayer=id;
}
} // createPlayer
In removePlayer we need to check if the leaving player is the active player and rotate when necessary:
if(this.players[id].ActivePlayer!="")this.nextPlayer();
movePlayer includes a check on activity: After movePlayer(id: string, movement: any){
if(this.players[id].ActivePlayer != id) return; // ignore move when not active
And before the end of the function:
this.nextPlayer(); // after move
Adjusted class Player with the ActivePlayer :
export class Player {
x = Math.floor(Math.random() * 400);
y = Math.floor(Math.random() * 400);
ActivePlayer = "";
}
Adjusted onJoin :
this.state.createPlayer(client.sessionId, this);
When running this example the players can only move when it is their turn.
It is a basic example with no validation on move or if time expired etc..