Open Tarig0 opened 6 years ago
To validate anything that should be random, think all we have is dice rolls and shuffle dice and cards we will need to have a seeded random number generator. This will allow for any messages that are sent to each client to be validated.
https://gist.github.com/blixt/f17b47c62508be59987b
It would be easier to have the RNG run on each machine and validate the resulting state of the game. If the game only has two players then there is no way to validate who is cheating. For any games with multiple players at least two other players should agree, and hope there are no ties
The source of the seed could be from the number of players + the initiating players alias + the start time of the game. Otherwise we could get the seed from another RNG source and store it in the log.
The initiating player is the first one to join the game AKA the host, not the first player to take a turn
String.prototype.hashCode = function() {
var hash = 0, i, chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
One peer hosts the other's are subscribe to the host and notifies host of relevant actions.
All peers will have a log which they can use to host the game if they wish to later