Fixed area syncing when two clients enter an area around the same time

This commit is contained in:
MysterD 2021-08-23 18:44:32 -07:00
parent 1952c42769
commit d471a23a39
9 changed files with 22 additions and 21 deletions

View file

@ -148,7 +148,7 @@ void network_player_update(void) {
network_player_update_level_popup(); network_player_update_level_popup();
//#ifndef DEVELOPMENT #ifndef DEVELOPMENT
if (gNetworkType == NT_SERVER) { if (gNetworkType == NT_SERVER) {
for (int i = 1; i < MAX_PLAYERS; i++) { for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i]; struct NetworkPlayer* np = &gNetworkPlayers[i];
@ -179,7 +179,7 @@ void network_player_update(void) {
network_send_keep_alive(np->localIndex); network_send_keep_alive(np->localIndex);
} }
} }
//#endif #endif
} }
u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, u8 paletteIndex, char* name) { u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, u8 paletteIndex, char* name) {

View file

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

View file

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

View file

@ -2,7 +2,7 @@
#include "../network.h" #include "../network.h"
#include "../reservation_area.h" #include "../reservation_area.h"
#include "level_table.h" #include "level_table.h"
#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
static void player_changed_area(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { static void player_changed_area(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
@ -20,7 +20,7 @@ static void player_changed_area(struct NetworkPlayer* np, s16 courseNum, s16 act
bool inCredits = (np->currActNum == 99); bool inCredits = (np->currActNum == 99);
if (npLevelAreaMatch == NULL || inCredits) { if (npLevelAreaMatch == NULL || inCredits) {
// no NetworkPlayer in the level // no NetworkPlayer in the level
network_send_sync_valid(np); network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex);
network_send_level_area_inform(np); network_send_level_area_inform(np);
return; return;
} }

View file

@ -2,7 +2,7 @@
#include "../network.h" #include "../network.h"
#include "../reservation_area.h" #include "../reservation_area.h"
#include "level_table.h" #include "level_table.h"
#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
@ -23,7 +23,7 @@ static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 ac
bool inCredits = (np->currActNum == 99); bool inCredits = (np->currActNum == 99);
if (npAny == NULL || inCredits) { if (npAny == NULL || inCredits) {
// no NetworkPlayer in the level // no NetworkPlayer in the level
network_send_sync_valid(np); network_send_sync_valid(np, courseNum, actNum, levelNum, areaIndex);
network_send_level_area_inform(np); network_send_level_area_inform(np);
return; return;
} }

View file

@ -39,9 +39,9 @@ void network_send_chat(char* message, u8 globalIndex) {
network_send(&p); network_send(&p);
#ifdef DEVELOPMENT #ifdef DEVELOPMENT
//print_network_player_table(); print_network_player_table();
//reservation_area_debug(); //reservation_area_debug();
print_sync_object_table(); //print_sync_object_table();
#endif #endif
} }

View file

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include "../network.h" #include "../network.h"
#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
void network_send_keep_alive(u8 localIndex) { void network_send_keep_alive(u8 localIndex) {

View file

@ -7,7 +7,7 @@
#include "behavior_table.h" #include "behavior_table.h"
#include "object_constants.h" #include "object_constants.h"
#include "object_fields.h" #include "object_fields.h"
#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
void network_send_level(struct NetworkPlayer* toNp, bool sendArea) { void network_send_level(struct NetworkPlayer* toNp, bool sendArea) {
@ -43,7 +43,7 @@ void network_send_level(struct NetworkPlayer* toNp, bool sendArea) {
network_send_area(toNp); network_send_area(toNp);
} else { } else {
// send sync valid // send sync valid
network_send_sync_valid(toNp); network_send_sync_valid(toNp, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, -1);
} }
} }
packet_ordered_end(); packet_ordered_end();

View file

@ -1,9 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include "../network.h" #include "../network.h"
#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
void network_send_sync_valid(struct NetworkPlayer* toNp) { void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
// set the NetworkPlayers sync valid // set the NetworkPlayers sync valid
toNp->currLevelSyncValid = true; toNp->currLevelSyncValid = true;
toNp->currAreaSyncValid = true; toNp->currAreaSyncValid = true;
@ -20,11 +20,11 @@ void network_send_sync_valid(struct NetworkPlayer* toNp) {
u8 myGlobalIndex = gNetworkPlayerLocal->globalIndex; u8 myGlobalIndex = gNetworkPlayerLocal->globalIndex;
struct Packet p; struct Packet p;
packet_init(&p, PACKET_SYNC_VALID, true, PLMT_NONE); packet_init(&p, PACKET_SYNC_VALID, true, PLMT_NONE);
packet_write(&p, &toNp->currCourseNum, sizeof(s16)); packet_write(&p, &courseNum, sizeof(s16));
packet_write(&p, &toNp->currActNum, sizeof(s16)); packet_write(&p, &actNum, sizeof(s16));
packet_write(&p, &toNp->currLevelNum, sizeof(s16)); packet_write(&p, &levelNum, sizeof(s16));
packet_write(&p, &toNp->currAreaIndex, sizeof(s16)); packet_write(&p, &areaIndex, sizeof(s16));
packet_write(&p, &myGlobalIndex, sizeof(u8)); packet_write(&p, &myGlobalIndex, sizeof(u8));
network_send_to(toNp->localIndex, &p); network_send_to(toNp->localIndex, &p);
LOG_INFO("tx sync valid"); LOG_INFO("tx sync valid");
@ -43,7 +43,7 @@ void network_receive_sync_valid(struct Packet* p) {
if (gNetworkType != NT_SERVER) { if (gNetworkType != NT_SERVER) {
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex; extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
if (courseNum != gCurrCourseNum || actNum != gCurrActStarNum || levelNum != gCurrLevelNum || areaIndex != gCurrAreaIndex) { if (courseNum != gCurrCourseNum || actNum != gCurrActStarNum || levelNum != gCurrLevelNum || (areaIndex != gCurrAreaIndex && areaIndex != -1)) {
LOG_ERROR("rx sync valid: received an improper location"); LOG_ERROR("rx sync valid: received an improper location");
return; return;
} }
@ -61,7 +61,7 @@ void network_receive_sync_valid(struct Packet* p) {
// inform server // inform server
if (fromGlobalIndex != gNetworkPlayerServer->globalIndex) { if (fromGlobalIndex != gNetworkPlayerServer->globalIndex) {
LOG_INFO("informing server of sync valid"); LOG_INFO("informing server of sync valid");
network_send_sync_valid(gNetworkPlayerServer); network_send_sync_valid(gNetworkPlayerServer, courseNum, actNum, levelNum, areaIndex);
} }
// inform everyone that this player is valid // inform everyone that this player is valid