Changed all asserts in packet files to soft asserts

This commit is contained in:
MysterD 2021-08-23 18:58:30 -07:00
parent d471a23a39
commit b2849405b3
17 changed files with 48 additions and 38 deletions

View file

@ -125,7 +125,7 @@ void network_send_to(u8 localIndex, struct Packet* p) {
if (localIndex == 0) {
if (p->buffer[0] != PACKET_JOIN_REQUEST && p->buffer[0] != PACKET_KICK && p->buffer[0] != PACKET_ACK) {
LOG_ERROR("\n####################\nsending to myself, packetType: %d\n####################\n", p->packetType);
assert(false);
SOFT_ASSERT(false);
return;
}
}
@ -172,7 +172,7 @@ void network_send_to(u8 localIndex, struct Packet* p) {
localIndex = gNetworkPlayerServer->localIndex;
}
assert(p->dataLength < PACKET_LENGTH);
SOFT_ASSERT(p->dataLength < PACKET_LENGTH);
// rate limit packets
bool tooManyPackets = false;
@ -304,6 +304,7 @@ void network_update(void) {
network_on_loaded_area();
}
}
SOFT_ASSERT(false);
// update network area timer
network_update_area_timer();

View file

@ -26,6 +26,14 @@ extern struct MarioState gMarioStates[];
? "Client" \
: (gNetworkType == NT_SERVER ? "Server" : " None ")) \
#ifdef DEVELOPMENT
#define SOFT_ASSERT(_condition) { if (!(_condition)) { LOG_ERROR("failed assert at line %d", __LINE__); assert(_condition); } }
#define SOFT_ASSERT_RETURN(_condition, _retval) { if (!(_condition)) { LOG_ERROR("failed assert at line %d", __LINE__); assert(_condition); } }
#else
#define SOFT_ASSERT(_condition) { if (!(_condition)) { LOG_ERROR("failed soft assert at line %d", __LINE__); return; } }
#define SOFT_ASSERT_RETURN(_condition, _retval) { if (!(_condition)) { LOG_ERROR("failed soft assert at line %d", __LINE__); return _retval; } }
#endif
enum NetworkSystemType {
NS_SOCKET,
NS_DISCORD,

View file

@ -68,7 +68,7 @@ void network_send_change_area(void) {
void network_receive_change_area(struct Packet* p) {
LOG_INFO("rx change area");
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
LOG_ERROR("Receiving change area from inactive player!");

View file

@ -75,7 +75,7 @@ void network_send_change_level(void) {
void network_receive_change_level(struct Packet* p) {
LOG_INFO("rx change level");
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
LOG_ERROR("Receiving change level from inactive player!");

View file

@ -1,6 +1,6 @@
#include <stdio.h>
#include "../network.h"
#include "pc/debuglog.h"
#define MAX_CUSTOM_PACKETS 128
struct NetworkCustomPacket {
@ -12,7 +12,7 @@ static u8 onCustomPacketId = 0;
static struct NetworkCustomPacket customPackets[MAX_CUSTOM_PACKETS];
u8 network_register_custom_packet(void (*send_callback)(struct Packet* p, void* params), void (*receive_callback)(struct Packet* p)) {
assert(onCustomPacketId < MAX_CUSTOM_PACKETS);
SOFT_ASSERT_RETURN(onCustomPacketId < MAX_CUSTOM_PACKETS, 0);
u8 i = onCustomPacketId;
customPackets[i].send_callback = send_callback;

View file

@ -26,7 +26,7 @@ static u8 sJoinRequestPlayerPalette;
static char sJoinRequestPlayerName[MAX_PLAYER_STRING];
void network_send_join_request(void) {
assert(gNetworkType == NT_CLIENT);
SOFT_ASSERT(gNetworkType == NT_CLIENT);
gOverrideEeprom = eeprom;
@ -42,7 +42,7 @@ void network_send_join_request(void) {
}
void network_receive_join_request(struct Packet* p) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
LOG_INFO("received join request");
if (p->dataLength > 5) {
@ -59,7 +59,7 @@ void network_receive_join_request(struct Packet* p) {
}
void network_send_join(struct Packet* joinRequestPacket) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
// make palette unique
sJoinRequestPlayerPalette = network_player_unique_palette(sJoinRequestPlayerPalette);
@ -114,7 +114,7 @@ void network_send_join(struct Packet* joinRequestPacket) {
}
void network_receive_join(struct Packet* p) {
assert(gNetworkType == NT_CLIENT);
SOFT_ASSERT(gNetworkType == NT_CLIENT);
if (gNetworkPlayerLocal != NULL) { return; }
LOG_INFO("received join packet");

View file

@ -7,7 +7,7 @@
static u16 sLevelAreaInformSeq[MAX_PLAYERS][MAX_PLAYERS] = { 0 };
void network_send_level_area_inform(struct NetworkPlayer* np) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np2 = &gNetworkPlayers[i];
@ -34,7 +34,7 @@ void network_send_level_area_inform(struct NetworkPlayer* np) {
void network_receive_level_area_inform(struct Packet* p) {
assert(gNetworkType != NT_SERVER);
SOFT_ASSERT(gNetworkType != NT_SERVER);
u16 seq;
u8 globalIndex;

View file

@ -7,8 +7,8 @@
#include "pc/configfile.h"
static void network_send_to_network_players(u8 sendToLocalIndex) {
assert(gNetworkType == NT_SERVER);
assert(sendToLocalIndex != 0);
SOFT_ASSERT(gNetworkType == NT_SERVER);
SOFT_ASSERT(sendToLocalIndex != 0);
u8 connectedCount = network_player_connected_count();
@ -42,7 +42,7 @@ static void network_send_to_network_players(u8 sendToLocalIndex) {
}
void network_send_network_players(void) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
LOG_INFO("sending list of network players to all");
for (int i = 1; i < MAX_PLAYERS; i++) {
if (!gNetworkPlayers[i].connected) { continue; }

View file

@ -145,7 +145,7 @@ struct SyncObject* network_init_object(struct Object *o, float maxSyncDistance)
}
void network_init_object_field(struct Object *o, void* field) {
assert(o->oSyncID != 0);
SOFT_ASSERT(o->oSyncID != 0);
// remember to synchronize this extra field
struct SyncObject* so = &gSyncObjects[o->oSyncID];
u8 index = so->extraFieldCount++;
@ -227,8 +227,8 @@ void network_set_sync_id(struct Object* o) {
syncId = reservation_area_local_grab_id();
}
assert(syncId != 0);
assert(gSyncObjects[syncId].o == NULL);
SOFT_ASSERT(syncId != 0);
SOFT_ASSERT(gSyncObjects[syncId].o == NULL);
o->oSyncID = syncId;
@ -236,7 +236,7 @@ void network_set_sync_id(struct Object* o) {
LOG_INFO("set sync id for object w/behavior %d", get_id_from_behavior(o->behavior));
}
assert(o->oSyncID < MAX_SYNC_OBJECTS);
SOFT_ASSERT(o->oSyncID < MAX_SYNC_OBJECTS);
}
// ----- header ----- //
@ -401,7 +401,7 @@ static void packet_write_object_extra_fields(struct Packet* p, struct Object* o)
// write the extra field
for (u8 i = 0; i < so->extraFieldCount; i++) {
assert(so->extraFields[i] != NULL);
SOFT_ASSERT(so->extraFields[i] != NULL);
packet_write(p, so->extraFields[i], sizeof(u32));
}
}
@ -419,7 +419,7 @@ static void packet_read_object_extra_fields(struct Packet* p, struct Object* o)
// read the extra fields
for (u8 i = 0; i < extraFieldsCount; i++) {
assert(so->extraFields[i] != NULL);
SOFT_ASSERT(so->extraFields[i] != NULL);
packet_read(p, so->extraFields[i], sizeof(u32));
}
}

View file

@ -24,7 +24,7 @@ static struct OrderedPacketTable* orderedPacketTable[MAX_PLAYERS] = { 0 };
static void packet_ordered_check_for_processing(struct OrderedPacketTable* opt) {
// sanity check
assert(opt != NULL);
SOFT_ASSERT(opt != NULL);
struct OrderedPacketList* opl = opt->packets;
struct OrderedPacketList* oplLast = opl;
@ -66,9 +66,9 @@ static void packet_ordered_check_for_processing(struct OrderedPacketTable* opt)
static void packet_ordered_add_to_table(struct OrderedPacketTable* opt, struct Packet* p) {
// sanity check
assert(opt != NULL);
assert(opt->fromGlobalId == p->orderedFromGlobalId);
assert(opt->groupId == p->orderedGroupId);
SOFT_ASSERT(opt != NULL);
SOFT_ASSERT(opt->fromGlobalId == p->orderedFromGlobalId);
SOFT_ASSERT(opt->groupId == p->orderedGroupId);
if (p->orderedSeqId < opt->processSeqId) {
// this packet has already been processed!

View file

@ -95,14 +95,14 @@ void network_remember_reliable(struct Packet* p) {
if (tail == NULL) {
// start of the list
assert(head == NULL);
SOFT_ASSERT(head == NULL);
head = node;
tail = node;
return;
}
// add to end of list
assert(tail->next == NULL);
SOFT_ASSERT(tail->next == NULL);
tail->next = node;
node->prev = tail;
tail = node;

View file

@ -11,7 +11,7 @@
#include "pc/debuglog.h"
void network_send_reservation_list(struct NetworkPlayer* np, u8 syncIds[]) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
struct Packet p;
packet_init(&p, PACKET_RESERVATION_LIST, true, PLMT_NONE);
@ -30,7 +30,7 @@ void network_send_reservation_list(struct NetworkPlayer* np, u8 syncIds[]) {
}
void network_receive_reservation_list(struct Packet* p) {
assert(gNetworkType == NT_CLIENT);
SOFT_ASSERT(gNetworkType == NT_CLIENT);
LOG_INFO("rx reservation list");
u8 courseNum, actNum, levelNum, areaIndex;

View file

@ -11,7 +11,7 @@
#include "pc/debuglog.h"
void network_send_reservation_release(u8 syncId) {
assert(gNetworkType == NT_CLIENT);
SOFT_ASSERT(gNetworkType == NT_CLIENT);
// make sure this is a reserved id
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
@ -32,7 +32,7 @@ void network_send_reservation_release(u8 syncId) {
}
void network_receive_reservation_release(struct Packet* p) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
LOG_INFO("rx reservation release");
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];

View file

@ -11,7 +11,7 @@
#include "pc/debuglog.h"
void network_send_reservation_use(u8 syncId) {
assert(gNetworkType == NT_CLIENT);
SOFT_ASSERT(gNetworkType == NT_CLIENT);
// make sure this is a reserved id
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
@ -32,7 +32,7 @@ void network_send_reservation_use(u8 syncId) {
}
void network_receive_reservation_use(struct Packet* p) {
assert(gNetworkType == NT_SERVER);
SOFT_ASSERT(gNetworkType == NT_SERVER);
LOG_INFO("rx reservation use");
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];

View file

@ -1,10 +1,11 @@
#include <stdio.h>
#include "../network.h"
#include "game/save_file.h"
#include "pc/debuglog.h"
void network_send_save_file(s32 fileIndex) {
if (gNetworkPlayerServer == NULL) { return; }
assert(gNetworkType == NT_CLIENT);
SOFT_ASSERT(gNetworkType == NT_CLIENT);
struct Packet p;
packet_init(&p, PACKET_SAVE_FILE, true, PLMT_NONE);
packet_write(&p, &fileIndex, sizeof(s32));

View file

@ -32,7 +32,7 @@ static u8 generate_parent_id(struct Object* objects[], u8 onIndex, bool sanitize
if (sanitize && o->parentObj->oSyncID == 0) {
return (u8)-1;
}
assert(o->parentObj->oSyncID != 0);
SOFT_ASSERT_RETURN(o->parentObj->oSyncID != 0, (u8)-1);
return (u8)o->parentObj->oSyncID;
}
@ -40,7 +40,7 @@ static u8 generate_parent_id(struct Object* objects[], u8 onIndex, bool sanitize
if (o->parentObj == objects[i]) { return i; }
}
assert(false);
SOFT_ASSERT_RETURN(false, (u8)-1);
}
void network_send_spawn_objects(struct Object* objects[], u32 models[], u8 objectCount) {
@ -49,7 +49,7 @@ void network_send_spawn_objects(struct Object* objects[], u32 models[], u8 objec
void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[], u32 models[], u8 objectCount) {
if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) { return; }
assert(objectCount < MAX_SPAWN_OBJECTS_PER_PACKET);
SOFT_ASSERT(objectCount < MAX_SPAWN_OBJECTS_PER_PACKET);
// prevent sending spawn objects during credits
if (gCurrActStarNum == 99) { return; }

View file

@ -145,7 +145,7 @@ static void reservation_area_unload(struct ReservationArea* unloadRa) {
lastRa = ra;
ra = ra->next;
}
assert(false);
SOFT_ASSERT(false);
}
static void reservation_area_player_left(struct NetworkPlayer* np) {