Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion client/src/api/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,28 @@ class GameManager extends EventEmitter implements AbstractGameManager {

this.explorerIPs.forEach((ip) => {
const explorer = new window.Primus(ip);
const syncChunk = (chunk) => {
this.explorers.forEach((otherExplorer, otherIp) => {
if (ip !== otherIp) {
otherExplorer.emit('sync-chunk', chunk);
}
});
};

explorer.on('sync-map', (chunks) => {
chunks.forEach((chunk) => this.addNewChunk(chunk));
chunks.forEach((chunk) => {
this.addNewChunk(chunk);
syncChunk(chunk);
});
});
explorer.on('new-chunk', (chunk) => {
this.lastChunkPerExplorer.set(ip, chunk.chunkFootprint);
this.addNewChunk(chunk);
this.emit(GameManagerEvent.DiscoveredNewChunk, chunk);
syncChunk(chunk);
});
explorer.on('new-sync-chunk', (chunk) => {
this.addNewChunk(chunk);
});
explorer.on('hash-rate', (hashRate) => {
this.hashRatePerExplorer.set(ip, hashRate);
Expand Down
11 changes: 10 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const answers = await inquirer.prompt([
{
type: 'input',
name: 'initCoords',
message: `Which x,y coords do you want to start mining at? (comma-separated)`,
message: `Which x,y coords do you want to start exploring at? (comma-separated)`,
default: '0,0',
filter: (coords) => {
const [x = 0, y = 0] = coords.split(',').map((i) => i.trim());
Expand Down Expand Up @@ -176,6 +176,15 @@ if (isWebsocketServer) {
spark.on('set-radius', (radius) => {
minerManager.setRadius(radius);
});

spark.on('sync-chunk', (chunk) => {
localStorageManager.updateChunk(chunk, false);
primus.forEach((otherSpark, otherId) => {
if (otherId !== spark.id) {
otherSpark.emit('new-sync-chunk', chunk);
}
});
});
});
}

Expand Down