Fix crash in network_send_to()
This commit is contained in:
parent
c5a4c46519
commit
665429483e
|
@ -229,9 +229,14 @@ void network_send_to(u8 localIndex, struct Packet* p) {
|
||||||
packet_set_destination(p, 0);
|
packet_set_destination(p, 0);
|
||||||
localIndex = (gNetworkPlayerServer != NULL) ? gNetworkPlayerServer->localIndex : 0;
|
localIndex = (gNetworkPlayerServer != NULL) ? gNetworkPlayerServer->localIndex : 0;
|
||||||
} else {
|
} else {
|
||||||
|
u8 idx = (localIndex == 0) ? p->localIndex : localIndex;
|
||||||
|
if (idx >= MAX_PLAYERS) {
|
||||||
|
LOG_ERROR("Could not set destination to %u", idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
packet_set_destination(p, p->requestBroadcast
|
packet_set_destination(p, p->requestBroadcast
|
||||||
? PACKET_DESTINATION_BROADCAST
|
? PACKET_DESTINATION_BROADCAST
|
||||||
: gNetworkPlayers[(localIndex == 0) ? p->localIndex : localIndex].globalIndex);
|
: gNetworkPlayers[idx].globalIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanity checks
|
// sanity checks
|
||||||
|
@ -245,6 +250,10 @@ void network_send_to(u8 localIndex, struct Packet* p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gNetworkType == NT_SERVER) {
|
if (gNetworkType == NT_SERVER) {
|
||||||
|
if (localIndex >= MAX_PLAYERS) {
|
||||||
|
LOG_ERROR("Could not get network player %u", localIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
struct NetworkPlayer* np = &gNetworkPlayers[localIndex];
|
struct NetworkPlayer* np = &gNetworkPlayers[localIndex];
|
||||||
// don't send a packet to a player that can't receive it
|
// don't send a packet to a player that can't receive it
|
||||||
if (p->levelAreaMustMatch) {
|
if (p->levelAreaMustMatch) {
|
||||||
|
@ -321,7 +330,9 @@ void network_send_to(u8 localIndex, struct Packet* p) {
|
||||||
|
|
||||||
network_remember_debug_packet(p->packetType, true);
|
network_remember_debug_packet(p->packetType, true);
|
||||||
|
|
||||||
|
if (localIndex < MAX_PLAYERS) {
|
||||||
gNetworkPlayers[localIndex].lastSent = clock_elapsed();
|
gNetworkPlayers[localIndex].lastSent = clock_elapsed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_send(struct Packet* p) {
|
void network_send(struct Packet* p) {
|
||||||
|
|
Loading…
Reference in New Issue