Possibly fixed Discord issues
This commit is contained in:
parent
52d07c4dde
commit
3eef4076b9
|
@ -97,14 +97,12 @@ void network_player_update(void) {
|
||||||
}
|
}
|
||||||
} else if (gNetworkType == NT_CLIENT) {
|
} else if (gNetworkType == NT_CLIENT) {
|
||||||
bool connectionAlive = false;
|
bool connectionAlive = false;
|
||||||
for (int i = 1; i < MAX_PLAYERS; i++) {
|
struct NetworkPlayer* np = gNetworkPlayerServer;
|
||||||
struct NetworkPlayer* np = &gNetworkPlayers[i];
|
if (!np->connected) { return; }
|
||||||
if (!np->connected) { continue; }
|
float elapsed = (clock() - np->lastReceived) / (float)CLOCKS_PER_SEC;
|
||||||
float elapsed = (clock() - np->lastReceived) / (float)CLOCKS_PER_SEC;
|
if (elapsed <= NETWORK_PLAYER_TIMEOUT * 1.5f) {
|
||||||
if (elapsed <= NETWORK_PLAYER_TIMEOUT * 1.5f) {
|
connectionAlive = true;
|
||||||
connectionAlive = true;
|
return;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!connectionAlive) {
|
if (!connectionAlive) {
|
||||||
network_shutdown();
|
network_shutdown();
|
||||||
|
|
|
@ -71,15 +71,15 @@ void packet_process(struct Packet* p) {
|
||||||
void packet_receive(struct Packet* p) {
|
void packet_receive(struct Packet* p) {
|
||||||
u8 packetType = (u8)p->buffer[0];
|
u8 packetType = (u8)p->buffer[0];
|
||||||
|
|
||||||
|
// send an ACK if requested
|
||||||
|
network_send_ack(p);
|
||||||
|
|
||||||
// refuse packets from unknown players other than join request
|
// refuse packets from unknown players other than join request
|
||||||
if (gNetworkType == NT_SERVER && p->localIndex == UNKNOWN_LOCAL_INDEX && packetType != PACKET_JOIN_REQUEST) {
|
if (gNetworkType == NT_SERVER && p->localIndex == UNKNOWN_LOCAL_INDEX && packetType != PACKET_JOIN_REQUEST) {
|
||||||
network_send_kick(EKT_CLOSE_CONNECTION);
|
network_send_kick(EKT_CLOSE_CONNECTION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send an ACK if requested
|
|
||||||
network_send_ack(p);
|
|
||||||
|
|
||||||
// check if we've already seen this packet
|
// check if we've already seen this packet
|
||||||
if (p->localIndex != 0 && p->seqId != 0 && gNetworkPlayers[p->localIndex].connected) {
|
if (p->localIndex != 0 && p->seqId != 0 && gNetworkPlayers[p->localIndex].connected) {
|
||||||
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
|
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
void network_send_keep_alive(void) {
|
void network_send_keep_alive(void) {
|
||||||
struct Packet p;
|
struct Packet p;
|
||||||
packet_init(&p, PACKET_KEEP_ALIVE, false, false);
|
packet_init(&p, PACKET_KEEP_ALIVE, false, false);
|
||||||
network_send(&p);
|
if (gNetworkType == NT_SERVER) {
|
||||||
|
network_send(&p);
|
||||||
|
} else {
|
||||||
|
network_send_to(gNetworkPlayerServer->localIndex, &p);
|
||||||
|
}
|
||||||
gLastNetworkSend = clock();
|
gLastNetworkSend = clock();
|
||||||
LOG_INFO("sending keep alive");
|
LOG_INFO("sending keep alive");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue