mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-05 03:46:11 +00:00
send game hash to server each second
This commit is contained in:
+18
-10
@@ -241,21 +241,29 @@ export class GameImpl implements Game {
|
||||
|
||||
this.execs.push(...inited);
|
||||
this.unInitExecs = unInited;
|
||||
this._ticks++;
|
||||
if (this._ticks % 100 == 0) {
|
||||
let hash = 1;
|
||||
this._players.forEach((p) => {
|
||||
hash += p.hash();
|
||||
});
|
||||
consolex.log(`tick ${this._ticks}: hash ${hash}`);
|
||||
}
|
||||
for (const player of this._players.values()) {
|
||||
// Players change each to so always add them
|
||||
this.addUpdate(player.toUpdate());
|
||||
}
|
||||
if (this.ticks() % 10 == 0) {
|
||||
this.addUpdate({
|
||||
type: GameUpdateType.Hash,
|
||||
tick: this.ticks(),
|
||||
hash: this.hash(),
|
||||
});
|
||||
}
|
||||
this._ticks++;
|
||||
return this.updates;
|
||||
}
|
||||
|
||||
private hash(): number {
|
||||
let hash = 1;
|
||||
this._players.forEach((p) => {
|
||||
hash += p.hash();
|
||||
});
|
||||
return hash;
|
||||
}
|
||||
|
||||
terraNullius(): TerraNullius {
|
||||
return this._terraNullius;
|
||||
}
|
||||
@@ -494,14 +502,14 @@ export class GameImpl implements Game {
|
||||
|
||||
sendEmojiUpdate(msg: EmojiMessage): void {
|
||||
this.addUpdate({
|
||||
type: GameUpdateType.EmojiUpdate,
|
||||
type: GameUpdateType.Emoji,
|
||||
emoji: msg,
|
||||
});
|
||||
}
|
||||
|
||||
setWinner(winner: Player): void {
|
||||
this.addUpdate({
|
||||
type: GameUpdateType.WinUpdate,
|
||||
type: GameUpdateType.Win,
|
||||
winnerID: winner.smallID(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@ export enum GameUpdateType {
|
||||
BrokeAlliance,
|
||||
AllianceExpired,
|
||||
TargetPlayer,
|
||||
EmojiUpdate,
|
||||
WinUpdate,
|
||||
Emoji,
|
||||
Win,
|
||||
Hash,
|
||||
}
|
||||
|
||||
export type GameUpdate =
|
||||
@@ -49,7 +50,8 @@ export type GameUpdate =
|
||||
| DisplayMessageUpdate
|
||||
| TargetPlayerUpdate
|
||||
| EmojiUpdate
|
||||
| WinUpdate;
|
||||
| WinUpdate
|
||||
| HashUpdate;
|
||||
|
||||
export interface TileUpdateWrapper {
|
||||
type: GameUpdateType.Tile;
|
||||
@@ -133,7 +135,7 @@ export interface TargetPlayerUpdate {
|
||||
}
|
||||
|
||||
export interface EmojiUpdate {
|
||||
type: GameUpdateType.EmojiUpdate;
|
||||
type: GameUpdateType.Emoji;
|
||||
emoji: EmojiMessage;
|
||||
}
|
||||
|
||||
@@ -145,6 +147,12 @@ export interface DisplayMessageUpdate {
|
||||
}
|
||||
|
||||
export interface WinUpdate {
|
||||
type: GameUpdateType.WinUpdate;
|
||||
type: GameUpdateType.Win;
|
||||
winnerID: number;
|
||||
}
|
||||
|
||||
export interface HashUpdate {
|
||||
type: GameUpdateType.Hash;
|
||||
tick: Tick;
|
||||
hash: number;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export class UnitImpl implements Unit {
|
||||
}
|
||||
|
||||
hash(): number {
|
||||
return this.tile() + simpleHash(this.type());
|
||||
return this.tile() + simpleHash(this.type()) * this._id;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
||||
Reference in New Issue
Block a user