More networking adjustments

Adjusted when a join request is sent, and who it is sent to
Adjusted default course/act/level/area for new players
Added a sequence id to level area inform
Adjusted reliable packets to be sent half as frequently
This commit is contained in:
MysterD 2021-06-26 15:28:51 -07:00
parent 99308a3145
commit f13b7990a0
7 changed files with 38 additions and 21 deletions

View file

@ -34,7 +34,6 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res
discord_activity_update(false);
gNetworkUserIds[0] = lobby->owner_id;
network_send_join_request();
}
static void on_activity_join(UNUSED void* data, const char* secret) {

View file

@ -78,6 +78,7 @@ bool network_init(enum NetworkType inNetworkType) {
gOverrideEeprom = NULL;
} else if (gNetworkType == NT_CLIENT) {
network_player_connected(NPT_SERVER, 0);
network_send_join_request();
}
LOG_INFO("initialized");

View file

@ -172,11 +172,11 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex) {
memset(np, 0, sizeof(struct NetworkPlayer));
np->connected = true;
np->currLevelAreaSeqId = 0;
if (!np->currAreaSyncValid) {
np->currCourseNum = -1;
np->currActNum = -1;
np->currLevelNum = -1;
np->currAreaIndex = -1;
if (gNetworkType == NT_SERVER && !np->currAreaSyncValid) {
np->currCourseNum = 0;
np->currActNum = 0;
np->currLevelNum = 16;
np->currAreaIndex = 1;
np->currLevelSyncValid = false;
np->currAreaSyncValid = false;
}

View file

@ -25,7 +25,7 @@ void network_send_join_request(void) {
struct Packet p;
packet_init(&p, PACKET_JOIN_REQUEST, true, false);
network_send_to(0, &p);
network_send_to(gNetworkPlayerServer->localIndex, &p);
LOG_INFO("sending join request");
}

View file

@ -1,14 +1,24 @@
#include <stdio.h>
#include "../network.h"
#include "level_table.h"
#define DISABLE_MODULE_LOG 1
//#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h"
static u16 sLevelAreaInformSeq[MAX_PLAYERS][MAX_PLAYERS] = { 0 };
void network_send_level_area_inform(struct NetworkPlayer* np) {
assert(gNetworkType == NT_SERVER);
for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np2 = &gNetworkPlayers[i];
if (!np2->connected) { return; }
if (np2->localIndex == np->localIndex) { continue; }
u16 seq = ++sLevelAreaInformSeq[np->globalIndex][i];
struct Packet p;
packet_init(&p, PACKET_LEVEL_AREA_INFORM, true, false);
packet_write(&p, &seq, sizeof(u16));
packet_write(&p, &np->globalIndex, sizeof(u8));
packet_write(&p, &np->currCourseNum, sizeof(s16));
packet_write(&p, &np->currActNum, sizeof(s16));
@ -16,7 +26,8 @@ void network_send_level_area_inform(struct NetworkPlayer* np) {
packet_write(&p, &np->currAreaIndex, sizeof(s16));
packet_write(&p, &np->currLevelSyncValid, sizeof(u8));
packet_write(&p, &np->currAreaSyncValid, sizeof(u8));
network_send(&p);
network_send_to(np2->localIndex, &p);
}
LOG_INFO("tx level area inform");
}
@ -26,9 +37,11 @@ void network_receive_level_area_inform(struct Packet* p) {
assert(gNetworkType != NT_SERVER);
u16 seq;
u8 globalIndex;
s16 courseNum, actNum, levelNum, areaIndex;
u8 levelSyncValid, areaSyncValid;
packet_read(p, &seq, sizeof(u16));
packet_read(p, &globalIndex, sizeof(u8));
packet_read(p, &courseNum, sizeof(s16));
packet_read(p, &actNum, sizeof(s16));
@ -44,6 +57,11 @@ void network_receive_level_area_inform(struct Packet* p) {
}
if (np == gNetworkPlayerLocal) { return; }
if (sLevelAreaInformSeq[0][globalIndex] >= seq && abs(sLevelAreaInformSeq[0][globalIndex] - seq) < 256) {
LOG_INFO("Received old level area inform seq: %d vs %d", sLevelAreaInformSeq[0][globalIndex], seq);
return;
}
sLevelAreaInformSeq[0][globalIndex] = seq;
np->currCourseNum = courseNum;
np->currActNum = actNum;

View file

@ -4,8 +4,8 @@
// two-player hack: the localIndex for resending packets can be 0... this means reply to last person received from. THIS WILL NOT WORK with more than two players
#define RELIABLE_RESEND_RATE 0.10f
#define MAX_RESEND_ATTEMPTS 20
#define RELIABLE_RESEND_RATE 0.20f
#define MAX_RESEND_ATTEMPTS 10
struct PacketLinkedList {
struct Packet p;

View file

@ -89,7 +89,6 @@ static bool ns_socket_initialize(enum NetworkType networkType) {
gOpenConnectMenu = TRUE;
gNetworkType = NT_CLIENT;
network_send_join_request();
}
LOG_INFO("initialized");