Change ordered packet information to u16, prevent clearing ordered packets during join

This commit is contained in:
MysterD 2023-04-18 23:50:11 -07:00
parent bb924bd533
commit 4b7b71e271
7 changed files with 36 additions and 15 deletions

Binary file not shown.

View File

@ -518,7 +518,6 @@ void network_update_coopnet(void) {
#endif
void network_update(void) {
if (gNetworkStartupTimer > 0) {
gNetworkStartupTimer--;
}
@ -691,4 +690,5 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
#ifdef DISCORD_SDK
discord_activity_update();
#endif
packet_ordered_clear_all();
}

View File

@ -102,8 +102,8 @@ struct Packet {
u16 seqId;
bool sent;
u8 orderedFromGlobalId;
u8 orderedGroupId;
u8 orderedSeqId;
u16 orderedGroupId;
u16 orderedSeqId;
u8 courseNum;
u8 actNum;
u8 levelNum;
@ -147,6 +147,8 @@ struct LSTNetworkType {
size_t size;
};
extern u8 gAllowOrderedPacketClear;
// packet.c
void packet_compress(struct Packet* p, u8** compBuffer, u32* compSize);
bool packet_decompress(struct Packet* p, u8* compBuffer, u32 compSize);
@ -166,6 +168,7 @@ u32 packet_hash(struct Packet* packet);
bool packet_check_hash(struct Packet* packet);
void packet_ordered_begin(void);
void packet_ordered_end(void);
void packet_ordered_clear_all(void);
void packet_set_ordered_data(struct Packet* packet);
// packet_reliable.c
@ -178,7 +181,7 @@ void network_update_reliable(void);
// packet_ordered.c
void packet_ordered_add(struct Packet* p);
void packet_ordered_clear_table(u8 globalIndex, u8 groupdId);
void packet_ordered_clear_table(u8 globalIndex, u16 groupdId);
void packet_ordered_clear(u8 globalIndex);
void packet_ordered_update(void);

View File

@ -255,4 +255,6 @@ void network_receive_join(struct Packet* p) {
smlua_call_event_hooks(HOOK_JOINED_GAME);
extern s16 gChangeLevel;
gChangeLevel = gLevelValues.entryLevel;
gAllowOrderedPacketClear = 1;
}

View File

@ -25,6 +25,7 @@ void network_send_mod_list_request(void) {
network_send_to(PACKET_DESTINATION_SERVER, &p);
LOG_INFO("sending mod list request");
gAllowOrderedPacketClear = 0;
}
void network_receive_mod_list_request(UNUSED struct Packet* p) {

View File

@ -13,14 +13,15 @@ struct OrderedPacketList {
struct OrderedPacketTable {
u8 fromGlobalId;
u8 groupId;
u8 processSeqId;
u16 groupId;
u16 processSeqId;
f32 lastReceived;
struct OrderedPacketList* packets;
struct OrderedPacketTable* next;
};
static struct OrderedPacketTable* orderedPacketTable[MAX_PLAYERS] = { 0 };
u8 gAllowOrderedPacketClear = 1;
static void packet_ordered_check_for_processing(struct OrderedPacketTable* opt) {
// sanity check
@ -159,7 +160,7 @@ void packet_ordered_add(struct Packet* p) {
packet_ordered_add_to_table(opt, p);
}
void packet_ordered_clear_table(u8 globalIndex, u8 groupId) {
void packet_ordered_clear_table(u8 globalIndex, u16 groupId) {
LOG_INFO("clearing out ordered packet table for %d (%d)", globalIndex, groupId);
struct OrderedPacketTable* opt = orderedPacketTable[globalIndex];
@ -196,6 +197,11 @@ void packet_ordered_clear_table(u8 globalIndex, u8 groupId) {
}
void packet_ordered_clear(u8 globalIndex) {
if (!gAllowOrderedPacketClear) {
LOG_INFO("disallowed ordered packets to be cleared");
return;
}
LOG_INFO("clearing out all ordered packet tables for %d", globalIndex);
struct OrderedPacketTable* opt = orderedPacketTable[globalIndex];
@ -219,6 +225,14 @@ void packet_ordered_clear(u8 globalIndex) {
orderedPacketTable[globalIndex] = NULL;
}
void packet_ordered_clear_all(void) {
gAllowOrderedPacketClear = 1;
for (int i = 0; i < MAX_PLAYERS; i++) {
packet_ordered_clear(i);
}
}
void packet_ordered_update(void) {
f32 currentClock = clock_elapsed();
// check all ordered tables for a time out

View File

@ -4,13 +4,13 @@
#define PACKET_FLAG_BUFFER_OFFSET 3
#define PACKET_DESTINATION_BUFFER_OFFSET 4
#define PACKET_ORDERED_SEQ_ID_OFFSET 7
#define PACKET_ORDERED_SEQ_ID_OFFSET 8
static u16 sNextSeqNum = 1;
static bool sOrderedPackets = false;
static u8 sCurrentOrderedGroupId = 0;
static u8 sCurrentOrderedSeqId = 0;
static u16 sCurrentOrderedGroupId = 0;
static u16 sCurrentOrderedSeqId = 0;
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, enum PacketLevelMatchType levelAreaMustMatch) {
memset(packet->buffer, 0, PACKET_LENGTH);
@ -54,8 +54,8 @@ void packet_init(struct Packet* packet, enum PacketType packetType, bool reliabl
// write ordered packet information
if (sOrderedPackets) {
packet_write(packet, &packet->orderedFromGlobalId, sizeof(u8));
packet_write(packet, &packet->orderedGroupId, sizeof(u8));
packet_write(packet, &packet->orderedSeqId, sizeof(u8));
packet_write(packet, &packet->orderedGroupId, sizeof(u16));
packet_write(packet, &packet->orderedSeqId, sizeof(u16));
}
// write location
@ -162,8 +162,8 @@ u8 packet_initial_read(struct Packet* packet) {
// read ordered packet information
if (packetIsOrdered) {
packet_read(packet, &packet->orderedFromGlobalId, sizeof(u8));
packet_read(packet, &packet->orderedGroupId, sizeof(u8));
packet_read(packet, &packet->orderedSeqId, sizeof(u8));
packet_read(packet, &packet->orderedGroupId, sizeof(u16));
packet_read(packet, &packet->orderedSeqId, sizeof(u16));
}
// read location
@ -231,5 +231,6 @@ void packet_set_ordered_data(struct Packet* packet) {
if (packet->orderedGroupId == 0) { return; }
if (packet->orderedSeqId != 0) { return; }
packet->orderedSeqId = sCurrentOrderedSeqId++;
packet->buffer[PACKET_ORDERED_SEQ_ID_OFFSET] = packet->orderedSeqId;
u16* seqId = (u16*)&packet->buffer[PACKET_ORDERED_SEQ_ID_OFFSET];
*seqId = packet->orderedSeqId;
}