… | |
… | |
40 | |
40 | |
41 | #ifdef __linux__ |
41 | #ifdef __linux__ |
42 | # include <sys/types.h> |
42 | # include <sys/types.h> |
43 | # include <sys/socket.h> |
43 | # include <sys/socket.h> |
44 | # include <netinet/in.h> |
44 | # include <netinet/in.h> |
45 | # define TCP_HZ 1000 // sorry... |
|
|
46 | # include <netinet/tcp.h> |
45 | # include <netinet/tcp.h> |
47 | #endif |
46 | #endif |
48 | |
47 | |
49 | // use a really low timeout, as it doesn't cost any bandwidth, and you can |
48 | // use a really low timeout, as it doesn't cost any bandwidth, and you can |
50 | // easily die in 20 seconds... |
49 | // easily die in 20 seconds... |
51 | #define SOCKET_TIMEOUT1 10 |
50 | #define SOCKET_TIMEOUT1 10 * 1000 |
52 | #define SOCKET_TIMEOUT2 20 |
51 | #define SOCKET_TIMEOUT2 20 * 1000 |
53 | |
52 | |
54 | void |
53 | void |
55 | client::flush () |
54 | client::flush () |
56 | { |
55 | { |
57 | #ifdef __linux__ |
56 | #ifdef __linux__ |
… | |
… | |
64 | unsigned int diff = tcpi.tcpi_last_ack_recv - tcpi.tcpi_last_data_sent; |
63 | unsigned int diff = tcpi.tcpi_last_ack_recv - tcpi.tcpi_last_data_sent; |
65 | |
64 | |
66 | rtt = tcpi.tcpi_rtt; |
65 | rtt = tcpi.tcpi_rtt; |
67 | rttvar = tcpi.tcpi_rttvar; |
66 | rttvar = tcpi.tcpi_rttvar; |
68 | |
67 | |
69 | if (tcpi.tcpi_unacked && SOCKET_TIMEOUT1 * TCP_HZ < diff && diff < 0x80000000UL // ack delayed for 20s |
68 | if (tcpi.tcpi_unacked && SOCKET_TIMEOUT1 < diff && diff < 0x80000000UL // ack delayed for 20s |
70 | && SOCKET_TIMEOUT2 * TCP_HZ < tcpi.tcpi_last_data_sent) // no data sent for 10s |
69 | && SOCKET_TIMEOUT2 < tcpi.tcpi_last_data_sent) // no data sent for 10s |
71 | { |
70 | { |
72 | LOG (llevDebug, "Connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, |
71 | LOG (llevDebug, "Connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, |
73 | (unsigned) tcpi.tcpi_last_ack_recv, (unsigned) tcpi.tcpi_last_data_sent, (unsigned) tcpi.tcpi_unacked); |
72 | (unsigned) tcpi.tcpi_last_ack_recv, (unsigned) tcpi.tcpi_last_data_sent, (unsigned) tcpi.tcpi_unacked); |
74 | destroy (); |
73 | destroy (); |
75 | } |
74 | } |
… | |
… | |
188 | {"ncom", PC(NewPlayerCmd) PF_PLAYING }, |
187 | {"ncom", PC(NewPlayerCmd) PF_PLAYING }, |
189 | {"command", PC(PlayerCmd) PF_PLAYING }, |
188 | {"command", PC(PlayerCmd) PF_PLAYING }, |
190 | |
189 | |
191 | {"examine", PC(ExamineCmd) PF_PLAYING }, |
190 | {"examine", PC(ExamineCmd) PF_PLAYING }, |
192 | {"apply", PC(ApplyCmd) PF_PLAYING }, |
191 | {"apply", PC(ApplyCmd) PF_PLAYING }, |
193 | {"reply", PC(ReplyCmd) PF_IMMEDIATE }, |
192 | {"reply", PC(ReplyCmd) 0 }, |
194 | {"lookat", PC(LookAt) PF_PLAYING }, |
193 | {"lookat", PC(LookAt) PF_PLAYING }, |
195 | {"lock", PC(LockItem) PF_PLAYING }, |
194 | {"lock", PC(LockItem) PF_PLAYING }, |
196 | {"mark", PC(MarkItem) PF_PLAYING }, |
195 | {"mark", PC(MarkItem) PF_PLAYING }, |
197 | {"move", PC(MoveCmd) PF_PLAYING }, |
196 | {"move", PC(MoveCmd) PF_PLAYING }, |
198 | {"exti", PC(ExtCmd) PF_IMMEDIATE }, /* CF+ */ |
|
|
199 | {"ext", PC(ExtCmd) 0 }, /* CF+ */ |
197 | {"ext", PC(ExtCmd) 0 }, /* CF+ */ |
200 | {"mapredraw", PC(MapRedrawCmd) PF_IMMEDIATE }, /* Added: phil */ |
198 | {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */ |
201 | {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ |
199 | {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ |
202 | |
200 | |
|
|
201 | {"exti", SC(ExtiCmd) 0 }, /* CF+ */ |
203 | {"addme", SC(AddMeCmd) PF_IMMEDIATE }, |
202 | {"addme", SC(AddMeCmd) 0 }, |
204 | {"askface", SC(SendFaceCmd) PF_IMMEDIATE }, /* Added: phil */ |
203 | {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */ |
205 | {"requestinfo", SC(RequestInfo) PF_IMMEDIATE }, |
204 | {"requestinfo", SC(RequestInfo) 0 }, |
206 | {"setfacemode", SC(SetFaceMode) PF_IMMEDIATE }, |
205 | {"setfacemode", SC(SetFaceMode) 0 }, |
207 | {"setsound", SC(SetSound) PF_IMMEDIATE }, |
206 | {"setsound", SC(SetSound) 0 }, |
208 | {"setup", SC(SetUp) PF_IMMEDIATE }, |
207 | {"setup", SC(SetUp) 0 }, |
209 | {"version", SC(VersionCmd) PF_IMMEDIATE }, |
208 | {"version", SC(VersionCmd) 0 }, |
210 | {"toggleextendedinfos", SC(ToggleExtendedInfos) PF_IMMEDIATE }, /*Added: tchize */ |
209 | {"toggleextendedinfos", SC(ToggleExtendedInfos) 0 }, /*Added: tchize */ |
211 | {"toggleextendedtext", SC(ToggleExtendedText) PF_IMMEDIATE }, /*Added: tchize */ |
210 | {"toggleextendedtext", SC(ToggleExtendedText) 0 }, /*Added: tchize */ |
212 | {"asksmooth", SC(AskSmooth) PF_IMMEDIATE }, /*Added: tchize (smoothing technologies) */ |
211 | {"asksmooth", SC(AskSmooth) 0 }, /*Added: tchize (smoothing technologies) */ |
213 | }; |
212 | }; |
214 | |
213 | |
215 | bool |
214 | bool |
216 | client::may_execute (const packet_type *pkt) const |
215 | client::may_execute (const packet_type *pkt) const |
217 | { |
216 | { |
… | |
… | |
271 | } |
270 | } |
272 | |
271 | |
273 | for (packet_type *pkt = packets; pkt < packets + (sizeof (packets) / sizeof (packets[0])); ++pkt) |
272 | for (packet_type *pkt = packets; pkt < packets + (sizeof (packets) / sizeof (packets[0])); ++pkt) |
274 | if (!strcmp ((char *)inbuf + 2, pkt->name)) |
273 | if (!strcmp ((char *)inbuf + 2, pkt->name)) |
275 | { |
274 | { |
276 | if (pkt->flags & PF_IMMEDIATE) |
275 | if (pkt->flags & PF_PLAYER) |
|
|
276 | queue_command (pkt, data, datalen); |
|
|
277 | else |
277 | execute (pkt, data, datalen); |
278 | execute (pkt, data, datalen); |
278 | else |
|
|
279 | queue_command (pkt, data, datalen); |
|
|
280 | |
279 | |
281 | goto next_packet; |
280 | goto next_packet; |
282 | } |
281 | } |
283 | |
282 | |
284 | /* If we get here, we didn't find a valid command. Logging |
283 | // If we get here, we didn't find a valid command. |
285 | * this might be questionable, because a broken client/malicious |
|
|
286 | * user could certainly send a whole bunch of invalid commands. |
|
|
287 | */ |
|
|
288 | send_packet_printf ("drawinfo %d ERROR: command '%s' not supported.", NDI_RED, (char *)inbuf + 2); |
284 | send_packet_printf ("drawinfo %d ERROR: command '%s' not supported.", NDI_RED, (char *)inbuf + 2); |
289 | next_packet: |
285 | next_packet: |
290 | skip_packet (pkt_len); |
286 | skip_packet (pkt_len); |
291 | |
287 | |
292 | // input buffer has space again |
288 | // input buffer has space again |
… | |
… | |
359 | |
355 | |
360 | // called whenever we have additional commands to process |
356 | // called whenever we have additional commands to process |
361 | void |
357 | void |
362 | client::cmd_cb (iw &w) |
358 | client::cmd_cb (iw &w) |
363 | { |
359 | { |
364 | if (handle_packet () /*|| handle_command ()*/)//TODO: re-enable async command execution(?) |
360 | if (handle_packet ()) |
365 | w.start (); |
361 | w.start (); |
366 | else |
362 | else |
367 | flush (); |
363 | flush (); |
368 | } |
364 | } |
369 | |
365 | |
… | |
… | |
482 | * |
478 | * |
483 | * packet functions/utilities |
479 | * packet functions/utilities |
484 | * |
480 | * |
485 | **********************************************************************/ |
481 | **********************************************************************/ |
486 | |
482 | |
|
|
483 | packet::packet (const char *name) |
|
|
484 | { |
|
|
485 | reset (); |
|
|
486 | |
|
|
487 | int len = strlen (name); |
|
|
488 | memcpy (cur, name, len); cur += len; |
|
|
489 | *cur++ = ' '; |
|
|
490 | } |
|
|
491 | |
487 | packet &packet::operator <<(const data &v) |
492 | packet &packet::operator <<(const data &v) |
488 | { |
493 | { |
489 | if (room () < v.len) |
494 | if (room () < v.len) |
490 | reset (); |
495 | reset (); |
491 | else |
496 | else |