WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 451d525

Browse files
Fix objects owned by Multiplayer host not being properly migrated when host changes (#7078)
1 parent c755946 commit 451d525

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Extensions/Multiplayer/multiplayerobjectruntimebehavior.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ namespace gdjs {
120120

121121
private _isOwnerAsPlayerOrHost() {
122122
const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();
123+
const isHost = gdjs.multiplayer.isCurrentPlayerHost();
123124

124125
const isOwnerOfObject =
125126
currentPlayerNumber === this.playerNumber || // Player as owner.
126-
(currentPlayerNumber === 1 && this.playerNumber === 0); // Host as owner.
127+
(isHost && this.playerNumber === 0); // Host as owner.
127128

128129
return isOwnerOfObject;
129130
}
@@ -455,8 +456,8 @@ namespace gdjs {
455456

456457
// Before sending the destroy message, we set up the object representing the peers
457458
// that we need an acknowledgment from.
458-
// If we are player 1, we are connected to everyone, so we expect an acknowledgment from everyone.
459-
// If we are another player, we are only connected to player 1, so we expect an acknowledgment from player 1.
459+
// If we are the host, we are connected to everyone, so we expect an acknowledgment from everyone.
460+
// If we are another player, we are only connected to the host, so we expect an acknowledgment from the host.
460461
// In both cases, this represents the list of peers the current user is connected to.
461462
const otherPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();
462463
const {
@@ -508,7 +509,7 @@ namespace gdjs {
508509

509510
// Update the ownership locally, so the object can be used immediately.
510511
// This is a prediction to allow snappy interactions.
511-
// If we are player 1 or host, we will have the ownership immediately anyway.
512+
// If we are host, we will have the ownership immediately anyway.
512513
// If we are another player, we will have the ownership as soon as the host acknowledges the change.
513514
// If the host does not send an acknowledgment, we will revert the ownership.
514515
const previousObjectPlayerNumber = this.playerNumber;
@@ -564,8 +565,8 @@ namespace gdjs {
564565
});
565566
// Before sending the changeOwner message, if we are becoming the new owner,
566567
// we want to ensure this message is acknowledged, by everyone we're connected to.
567-
// If we are player 1, we are connected to everyone, so we expect an acknowledgment from everyone.
568-
// If we are another player, we are only connected to player 1, so we expect an acknowledgment from player 1.
568+
// If we are the host, we are connected to everyone, so we expect an acknowledgment from everyone.
569+
// If we are another player, we are only connected to the host, so we expect an acknowledgment from the host.
569570
// In both cases, this represents the list of peers the current user is connected to.
570571
if (newObjectPlayerNumber === currentPlayerNumber) {
571572
const otherPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();
@@ -581,7 +582,7 @@ namespace gdjs {
581582
expectedMessageName: changeOwnerAcknowledgedMessageName,
582583
otherPeerIds,
583584
// If we are not the host, we should revert the ownership if the host does not acknowledge the change.
584-
shouldCancelMessageIfTimesOut: currentPlayerNumber !== 1,
585+
shouldCancelMessageIfTimesOut: !gdjs.multiplayer.isCurrentPlayerHost(),
585586
});
586587
}
587588

Extensions/Multiplayer/multiplayertools.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ namespace gdjs {
770770

771771
// When the countdown starts, if we are player number 1, we are chosen as the host.
772772
// We then send the peerId to others so they can connect via P2P.
773+
// TODO: this should be sent by the backend, in case the lobby starts without a player 1.
773774
if (getCurrentPlayerNumber() === 1) {
774775
sendPeerId();
775776
}

0 commit comments

Comments
 (0)