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