Fix sync valid packet issues for the server (#1228)
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows-opengl (push) Waiting to run
Build coop / build-windows-directx (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run

* Fix erroneous sync valid packets

When the server received a sync valid packet from another player, it would also set the server player's level. This simple fix makes this no longer happen.

* Fix sync valid packets with host

Okay, so it turns out that the host was unable to differentiate between packets meant to validate other players, and packets meant to validate itself (sent when entering a level another player is already in). I changed so that the packet also includes who the sync packet is validating. Requires an additional byte, as well as adding an argument to network_send_sync_valid.

* Don't have server inform itself

Fixes HOOK_ON_SYNC_VALID being called twice
This commit is contained in:
Emily♥ 2026-05-07 11:23:57 -04:00 committed by GitHub
parent 3886c1181e
commit 149cb10153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 25 additions and 21 deletions

View file

@ -617,7 +617,7 @@ void network_update(void) {
bool inCredits = (np->currActNum == 99);
if (gNetworkType == NT_SERVER && (npAny == NULL || inCredits)) {
// no NetworkPlayer in the level
network_send_sync_valid(np, np->currCourseNum, np->currActNum, np->currLevelNum, np->currAreaIndex);
network_send_sync_valid(np, np->currCourseNum, np->currActNum, np->currLevelNum, np->currAreaIndex, false);
return;
}

View file

@ -315,7 +315,7 @@ void network_send_area(struct NetworkPlayer* toNp);
void network_receive_area(struct Packet* p);
// packet_sync_valid.c
void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex);
void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex, bool informServer);
void network_receive_sync_valid(struct Packet* p);
// packet_level_spawn_info.c

View file

@ -121,7 +121,7 @@ void network_send_area(struct NetworkPlayer* toNp) {
}
// send sync valid
network_send_sync_valid(toNp, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex);
network_send_sync_valid(toNp, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex, false);
}
packet_ordered_end();

View file

@ -15,7 +15,7 @@ static void player_changed_area(struct NetworkPlayer *np, s16 courseNum, s16 act
bool inCredits = (np->currActNum == 99);
if (npLevelAreaMatch == NULL || inCredits) {
// no NetworkPlayer in the level
network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex);
network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex, false);
return;
}

View file

@ -17,7 +17,7 @@ static void player_changed_level(struct NetworkPlayer *np, s16 courseNum, s16 ac
bool inCredits = (np->currActNum == 99);
if (npAny == NULL || inCredits) {
// no NetworkPlayer in the level
network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex);
network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex, false);
return;
}

View file

@ -46,7 +46,7 @@ void network_send_level(struct NetworkPlayer* toNp, bool sendArea) {
network_send_area(toNp);
} else {
// send sync valid
network_send_sync_valid(toNp, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, -1);
network_send_sync_valid(toNp, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, -1, false);
}
}
packet_ordered_end();

View file

@ -4,7 +4,7 @@
//#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h"
void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex, bool informServer) {
bool wasSyncValid = (toNp->currLevelSyncValid && toNp->currAreaSyncValid);
// set the NetworkPlayers sync valid
@ -24,30 +24,34 @@ void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actN
}
u8 myGlobalIndex = gNetworkPlayerLocal->globalIndex;
u8 forGlobalIndex = toNp->globalIndex;
struct Packet p = { 0 };
packet_init(&p, PACKET_SYNC_VALID, true, PLMT_NONE);
packet_write(&p, &courseNum, sizeof(s16));
packet_write(&p, &actNum, sizeof(s16));
packet_write(&p, &levelNum, sizeof(s16));
packet_write(&p, &areaIndex, sizeof(s16));
packet_write(&p, &myGlobalIndex, sizeof(u8));
network_send_to(toNp->localIndex, &p);
packet_write(&p, &courseNum, sizeof(s16));
packet_write(&p, &actNum, sizeof(s16));
packet_write(&p, &levelNum, sizeof(s16));
packet_write(&p, &areaIndex, sizeof(s16));
packet_write(&p, &myGlobalIndex, sizeof(u8));
packet_write(&p, &forGlobalIndex, sizeof(u8));
network_send_to((informServer ? gNetworkPlayerServer->localIndex : toNp->localIndex), &p);
LOG_INFO("tx sync valid");
}
void network_receive_sync_valid(struct Packet* p) {
LOG_INFO("rx sync valid");
s16 courseNum, actNum, levelNum, areaIndex;
u8 fromGlobalIndex;
u8 fromGlobalIndex, forGlobalIndex;
packet_read(p, &courseNum, sizeof(s16));
packet_read(p, &actNum, sizeof(s16));
packet_read(p, &levelNum, sizeof(s16));
packet_read(p, &areaIndex, sizeof(s16));
packet_read(p, &fromGlobalIndex, sizeof(u8));
packet_read(p, &forGlobalIndex, sizeof(u8));
LOG_INFO("rx sync valid: from global %d, for global %d", fromGlobalIndex, forGlobalIndex);
if (gNetworkType != NT_SERVER) {
bool isOurSyncValid = (forGlobalIndex == gNetworkPlayerLocal->globalIndex);
if (isOurSyncValid) {
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
if (courseNum != gCurrCourseNum || actNum != gCurrActStarNum || levelNum != gCurrLevelNum || (areaIndex != gCurrAreaIndex && areaIndex != -1)) {
LOG_ERROR("rx sync valid: received an improper location");
@ -55,7 +59,7 @@ void network_receive_sync_valid(struct Packet* p) {
}
}
struct NetworkPlayer* np = (gNetworkType != NT_SERVER) ? gNetworkPlayerLocal : &gNetworkPlayers[p->localIndex];
struct NetworkPlayer* np = network_player_from_global_index(forGlobalIndex);
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
LOG_ERROR("Receiving sync valid from inactive player!");
return;
@ -65,15 +69,15 @@ void network_receive_sync_valid(struct Packet* p) {
np->currLevelSyncValid = true;
np->currAreaSyncValid = true;
if (np == gNetworkPlayerLocal && !wasSyncValid) {
if (isOurSyncValid && !wasSyncValid) {
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
smlua_call_event_hooks(HOOK_ON_SYNC_VALID);
}
// inform server
if (fromGlobalIndex != gNetworkPlayerServer->globalIndex) {
if (gNetworkType != NT_SERVER && fromGlobalIndex != gNetworkPlayerServer->globalIndex) {
LOG_INFO("informing server of sync valid");
network_send_sync_valid(gNetworkPlayerServer, courseNum, actNum, levelNum, areaIndex);
network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex, true);
}
// we're no longer syncing