… | |
… | |
47 | if (destroyed ()) |
47 | if (destroyed ()) |
48 | return; |
48 | return; |
49 | |
49 | |
50 | #if HAVE_TCP_INFO |
50 | #if HAVE_TCP_INFO |
51 | // check about once per second, spread evenly over all clients |
51 | // check about once per second, spread evenly over all clients |
52 | if (!((pticks + fd) & 7)) |
52 | // do this only when player is active |
|
|
53 | if (!((pticks + fd) & 7) && pl && pl->active) |
53 | { |
54 | { |
54 | // check time of last ack, and, if too old, kill connection |
55 | // check time of last ack, and, if too old, kill connection |
55 | struct tcp_info tcpi; |
56 | struct tcp_info tcpi; |
56 | socklen_t len = sizeof (tcpi); |
57 | socklen_t len = sizeof (tcpi); |
57 | |
58 | |
58 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
59 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
59 | { |
60 | { |
|
|
61 | if (tcpi.tcpi_snd_mss) |
|
|
62 | mss = tcpi.tcpi_snd_mss; |
|
|
63 | |
60 | rtt = tcpi.tcpi_rtt; |
64 | rtt = tcpi.tcpi_rtt; |
61 | rttvar = tcpi.tcpi_rttvar; |
65 | rttvar = tcpi.tcpi_rttvar; |
62 | |
66 | |
63 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
67 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
64 | { |
68 | { |
… | |
… | |
81 | */ |
85 | */ |
82 | |
86 | |
83 | // write a nop to the socket at least every IDLE_NOP seconds. |
87 | // write a nop to the socket at least every IDLE_NOP seconds. |
84 | if (!outputbuffer.len) |
88 | if (!outputbuffer.len) |
85 | { |
89 | { |
86 | if (last_send + IDLE_PING <= NOW) |
90 | if (last_send + IDLE_PING <= NOW && pl && pl->active) |
87 | { |
91 | { |
88 | // this is a bit ugly, but map1/map1a seem to be the only |
92 | // this is a bit ugly, but map1/map1a seem to be the only |
89 | // nop'able commands and they are quite small. |
93 | // nop'able commands and they are quite small. |
90 | packet sl (mapmode == Map1Cmd ? "map1" : "map1a"); |
94 | packet sl (mapmode == Map1Cmd ? "map1" : "map1a"); |
91 | send_packet (sl); |
95 | send_packet (sl); |