This week I've worked on :
- Player in Seat - ServerSide
- TurnBased RoomType: NextTurn, isTurn
- MasterPlayerID for Client Side logic Room Type
- Lock Mechanism
The lock mechanism was flawed by not release locks and to not compare clientside grid with serverside grid.
CLIENT
For example when the client pushes a block from position 25 to 15 it will need to send 15=0,25=2,35=1000 to the server and request a lock on them:
grid[15]=0; // free space
grid[25]=2; // block
grid[35]=1000; // playernr
SERVER
Server receives the lockrequest (15=0,25=2,35=1000)
It checks his own grid if the positions match the client request lock. If the grids are out of sync it will send an error back.
The client will then request a complete grid from the server as it is apparently behind.
If the server grid position matches the requested lock positions a lock will be attempted: (pseudo-code)
attemptposition=new Array();
isOK=true;
for each lockposition{
if(isOK && gridlock[lockposition] == 0){
gridlock[lockposition]=time;
attemptposition.push(lockposition)
}else{
isOK=false;
// there is a lock on one of the
for(each attemptpositon p) gridlock[p]=0;
}
}
When the server was able to lock all gridpositions it will send a success to the client
CLIENT
The client will do a grid request if the return state was an error.
The client will send the changed data to the server when it was success, otherwise it will not do the move as there was/is a lock.
SERVER
When server receives the griddata it will set the new grid values and afterwards set the lockpositions to 0-time.
After each request the server checks the gridlock table if the currenttime - locktime > 2 seconds .. when it finds one it will reset the lock.
CLIENT
Sends unlock to server.
A room with four player-bots ran for over 4 hours and still they were in sync.
Next I will need to figure out how to do classes with overloading / inheritence in TypeScript.
I want all the room types to share code that are common in all rooms.
For instance I need PlayerInSeat, PingTime, getPlayersInRoom etc.. code in all typescript rooms.