From f2c0993342953dcb38492d801dd0c983151ed8ee Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 30 Mar 2023 12:15:52 -0700 Subject: [PATCH] Prevent redirecting mod_list_request packets --- src/pc/network/network.c | 16 +++++++++++----- src/pc/network/packets/packet.c | 2 +- src/pc/network/packets/packet.h | 1 + src/pc/network/packets/packet_mod_list.c | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 7fad37f3..56d8c6c1 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -219,6 +219,17 @@ void network_send_to(u8 localIndex, struct Packet* p) { LOG_ERROR("no data to send"); return; } + + // set destination + if (localIndex == PACKET_DESTINATION_SERVER) { + packet_set_destination(p, 0); + localIndex = (gNetworkPlayerServer != NULL) ? gNetworkPlayerServer->localIndex : 0; + } else { + packet_set_destination(p, p->requestBroadcast + ? PACKET_DESTINATION_BROADCAST + : gNetworkPlayers[(localIndex == 0) ? p->localIndex : localIndex].globalIndex); + } + // sanity checks if (gNetworkType == NT_NONE) { LOG_ERROR("network type error none!"); return; } if (p->error) { LOG_ERROR("packet error!"); return; } @@ -247,11 +258,6 @@ void network_send_to(u8 localIndex, struct Packet* p) { // set the flags again packet_set_flags(p); - // set destination - packet_set_destination(p, p->requestBroadcast - ? PACKET_DESTINATION_BROADCAST - : gNetworkPlayers[(localIndex == 0) ? p->localIndex : localIndex].globalIndex); - p->localIndex = localIndex; // set ordered data (MUST BE IMMEDITAELY BEFORE network_remember_reliable()) diff --git a/src/pc/network/packets/packet.c b/src/pc/network/packets/packet.c index 09aa3f75..69983834 100644 --- a/src/pc/network/packets/packet.c +++ b/src/pc/network/packets/packet.c @@ -161,7 +161,7 @@ void packet_receive(struct Packet* p) { // parse the packet without processing the rest if (packet_initial_read(p)) { - if (gNetworkType == NT_SERVER && p->destGlobalId != PACKET_DESTINATION_BROADCAST && p->destGlobalId != 0 && packetType != PACKET_ACK) { + if (gNetworkType == NT_SERVER && p->destGlobalId != PACKET_DESTINATION_BROADCAST && p->destGlobalId != 0 && packetType != PACKET_ACK && packetType != PACKET_MOD_LIST_REQUEST) { // this packet is meant for someone else struct Packet p2 = { 0 }; packet_duplicate(p, &p2); diff --git a/src/pc/network/packets/packet.h b/src/pc/network/packets/packet.h index 8dfe3d78..c0fdc0f8 100644 --- a/src/pc/network/packets/packet.h +++ b/src/pc/network/packets/packet.h @@ -9,6 +9,7 @@ #define PACKET_LENGTH 3000 #define PACKET_DESTINATION_BROADCAST ((u8)-1) +#define PACKET_DESTINATION_SERVER ((u8)-2) struct NetworkPlayer; diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c index ae0e1ba0..8d343aea 100644 --- a/src/pc/network/packets/packet_mod_list.c +++ b/src/pc/network/packets/packet_mod_list.c @@ -22,7 +22,7 @@ void network_send_mod_list_request(void) { snprintf(version, MAX_VERSION_LENGTH, "%s", get_version()); packet_write(&p, &version, sizeof(u8) * MAX_VERSION_LENGTH); - network_send_to((gNetworkPlayerServer != NULL) ? gNetworkPlayerServer->localIndex : 0, &p); + network_send_to(PACKET_DESTINATION_SERVER, &p); LOG_INFO("sending mod list request"); }