Prevent redirecting mod_list_request packets

This commit is contained in:
MysterD 2023-03-30 12:15:52 -07:00
parent e8fa45cab4
commit f2c0993342
4 changed files with 14 additions and 7 deletions

View file

@ -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())

View file

@ -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);

View file

@ -9,6 +9,7 @@
#define PACKET_LENGTH 3000
#define PACKET_DESTINATION_BROADCAST ((u8)-1)
#define PACKET_DESTINATION_SERVER ((u8)-2)
struct NetworkPlayer;

View file

@ -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");
}