… | |
… | |
50 | // check about once per second, spread evenly over all clients |
50 | // check about once per second, spread evenly over all clients |
51 | // do this only when player is active |
51 | // do this only when player is active |
52 | if (!((pticks + fd) & 7) && pl && pl->active) |
52 | if (!((pticks + fd) & 7) && pl && pl->active) |
53 | { |
53 | { |
54 | // check time of last ack, and, if too old, kill connection |
54 | // check time of last ack, and, if too old, kill connection |
55 | struct tcp_info tcpi; |
|
|
56 | socklen_t len = sizeof (tcpi); |
55 | socklen_t len = sizeof (tcpi); |
57 | |
56 | |
58 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
57 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
59 | { |
58 | { |
60 | if (tcpi.tcpi_snd_mss) |
59 | if (tcpi.tcpi_snd_mss) |
61 | mss = tcpi.tcpi_snd_mss; |
60 | mss = tcpi.tcpi_snd_mss; |
62 | |
61 | |
63 | rtt = tcpi.tcpi_rtt; |
62 | //fprintf (stderr, "uack %d sst %d cwnd %d mss %d pmtu %d\n", |
64 | rttvar = tcpi.tcpi_rttvar; |
63 | // tcpi.tcpi_unacked, tcpi.tcpi_snd_ssthresh, tcpi.tcpi_snd_cwnd, tcpi.tcpi_advmss, tcpi.tcpi_pmtu); |
65 | |
64 | |
66 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
65 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
67 | { |
66 | { |
68 | send_msg (NDI_RED, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); |
67 | send_msg (NDI_RED | NDI_REPLY, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); |
69 | write_outputbuffer (); |
68 | write_outputbuffer (); |
70 | |
69 | |
71 | LOG (llevDebug, "connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, |
70 | LOG (llevDebug, "connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, |
72 | (unsigned)tcpi.tcpi_last_ack_recv, (unsigned)tcpi.tcpi_last_data_sent, (unsigned)tcpi.tcpi_unacked); |
71 | (unsigned)tcpi.tcpi_last_ack_recv, (unsigned)tcpi.tcpi_last_data_sent, (unsigned)tcpi.tcpi_unacked); |
73 | destroy (); |
72 | destroy (); |
… | |
… | |
165 | if (inbuf_len >= 2 + pkt_len) |
164 | if (inbuf_len >= 2 + pkt_len) |
166 | return 2 + pkt_len; |
165 | return 2 + pkt_len; |
167 | |
166 | |
168 | if (inbuf_len == sizeof (inbuf)) |
167 | if (inbuf_len == sizeof (inbuf)) |
169 | { |
168 | { |
170 | send_packet_printf ("drawinfo %d input buffer overflow - closing connection.", NDI_RED); |
169 | send_packet_printf ("drawinfo %d input buffer overflow - closing connection.", NDI_RED | NDI_REPLY); |
171 | destroy (); |
170 | destroy (); |
172 | return -1; |
171 | return -1; |
173 | } |
172 | } |
174 | } |
173 | } |
175 | |
174 | |
… | |
… | |
269 | ((void (*)(char *, int, player *))pkt->cb)((char *)data, datalen, pl); |
268 | ((void (*)(char *, int, player *))pkt->cb)((char *)data, datalen, pl); |
270 | else |
269 | else |
271 | ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); |
270 | ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); |
272 | } |
271 | } |
273 | else |
272 | else |
274 | send_packet_printf ("drawinfo %d ERROR: you cannot execute '%s' now.", NDI_RED, pkt->name); |
273 | send_packet_printf ("drawinfo %d ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name); |
275 | } |
274 | } |
276 | |
275 | |
277 | bool |
276 | bool |
278 | client::handle_packet () |
277 | client::handle_packet () |
279 | { |
278 | { |
… | |
… | |
320 | |
319 | |
321 | goto next_packet; |
320 | goto next_packet; |
322 | } |
321 | } |
323 | |
322 | |
324 | // If we get here, we didn't find a valid command. |
323 | // If we get here, we didn't find a valid command. |
325 | send_packet_printf ("drawinfo %d ERROR: command '%s' not supported.", NDI_RED, (char *)inbuf + 2); |
324 | send_packet_printf ("drawinfo %d ERROR: command '%s' not supported.", NDI_RED | NDI_REPLY, (char *)inbuf + 2); |
326 | next_packet: |
325 | next_packet: |
327 | skip_packet (pkt_len); |
326 | skip_packet (pkt_len); |
328 | |
327 | |
329 | // input buffer has space again |
328 | // input buffer has space again |
330 | socket_ev.poll (socket_ev.poll () | PE_R); |
329 | socket_ev.poll (socket_ev.poll () | PE_R); |
… | |
… | |
523 | client::send_msg (int color, const char *type, const char *msg) |
522 | client::send_msg (int color, const char *type, const char *msg) |
524 | { |
523 | { |
525 | if (msg_is_special (msg)) |
524 | if (msg_is_special (msg)) |
526 | cfperl_send_msg (this, color, type, msg); |
525 | cfperl_send_msg (this, color, type, msg); |
527 | else if (can_msg) |
526 | else if (can_msg) |
528 | send_packet_printf ("msg %d %s %s", color, type, msg); |
527 | send_packet_printf ("msg %d %s %s", color & NDI_CLIENT_MASK, type, msg); |
529 | else if (color < 0) |
528 | else if (color < 0) |
530 | return; // client cannot handle this |
529 | return; // client cannot handle this |
531 | else |
530 | else |
532 | send_packet_printf ("drawinfo %d %s", color, msg); |
531 | send_packet_printf ("drawinfo %d %s", color & NDI_COLOR_MASK, msg); |
533 | } |
532 | } |
534 | |
533 | |
535 | void |
534 | void |
536 | client::send_drawinfo (const char *msg, int flags) |
535 | client::send_drawinfo (const char *msg, int flags) |
537 | { |
536 | { |