1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
5 | |
6 | |
6 | This program is free software; you can redistribute it and/or modify |
7 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
51 | #define SOCKET_TIMEOUT2 20 * 1000 |
52 | #define SOCKET_TIMEOUT2 20 * 1000 |
52 | |
53 | |
53 | void |
54 | void |
54 | client::flush () |
55 | client::flush () |
55 | { |
56 | { |
|
|
57 | if (destroyed ()) |
|
|
58 | return; |
|
|
59 | |
56 | #ifdef __linux__ |
60 | #ifdef __linux__ |
57 | // check time of last ack, and, if too old, kill connection |
61 | // check time of last ack, and, if too old, kill connection |
58 | struct tcp_info tcpi; |
62 | struct tcp_info tcpi; |
59 | socklen_t len = sizeof (tcpi); |
63 | socklen_t len = sizeof (tcpi); |
60 | |
64 | |
… | |
… | |
213 | |
217 | |
214 | bool |
218 | bool |
215 | client::may_execute (const packet_type *pkt) const |
219 | client::may_execute (const packet_type *pkt) const |
216 | { |
220 | { |
217 | return (!(pkt->flags & PF_PLAYER) || pl) |
221 | return (!(pkt->flags & PF_PLAYER) || pl) |
218 | && (!(pkt->flags & PF_PLAYING) || (pl && pl->state == ST_PLAYING)); |
222 | && (!(pkt->flags & PF_PLAYING) || state == ST_PLAYING); |
219 | } |
223 | } |
220 | |
224 | |
221 | void |
225 | void |
222 | client::execute (const packet_type *pkt, char *data, int datalen) |
226 | client::execute (const packet_type *pkt, char *data, int datalen) |
223 | { |
227 | { |
… | |
… | |
294 | // callback called when socket is either readable or writable |
298 | // callback called when socket is either readable or writable |
295 | void |
299 | void |
296 | client::socket_cb (iow &w, int got) |
300 | client::socket_cb (iow &w, int got) |
297 | { |
301 | { |
298 | //TODO remove when we have better socket cleanup logic |
302 | //TODO remove when we have better socket cleanup logic |
299 | if (destroyed) |
303 | if (destroyed ()) |
300 | { |
304 | { |
301 | socket_ev.poll (0); |
305 | socket_ev.poll (0); |
302 | return; |
306 | return; |
303 | } |
307 | } |
304 | |
308 | |
… | |
… | |
380 | { |
384 | { |
381 | char *buf = (char *)buf_; |
385 | char *buf = (char *)buf_; |
382 | char *pos = buf; |
386 | char *pos = buf; |
383 | int amt = 0; |
387 | int amt = 0; |
384 | |
388 | |
385 | if (destroyed || !buf) |
389 | if (destroyed () || !buf) |
386 | return; |
390 | return; |
387 | |
391 | |
388 | if ((len + outputbuffer.len) > SOCKETBUFSIZE) |
392 | if ((len + outputbuffer.len) > SOCKETBUFSIZE) |
389 | { |
393 | { |
390 | LOG (llevDebug, "socket on fd %d has overrun internal buffer - marking as dead\n", fd); |
394 | LOG (llevDebug, "socket on fd %d has overrun internal buffer - marking as dead\n", fd); |
… | |
… | |
421 | * shortcut function. |
425 | * shortcut function. |
422 | */ |
426 | */ |
423 | void |
427 | void |
424 | client::send_packet (packet &sl) |
428 | client::send_packet (packet &sl) |
425 | { |
429 | { |
426 | if (destroyed) |
430 | if (destroyed ()) |
427 | return; |
431 | return; |
428 | |
432 | |
429 | if (sl.length () >= MAXSOCKBUF) |
433 | if (sl.length () >= MAXSOCKBUF) |
430 | { |
434 | { |
431 | LOG (llevError, "Trying to send a buffer beyond properly size, len =%d\n", sl.length ()); |
435 | LOG (llevError, "Trying to send a buffer beyond properly size, len =%d\n", sl.length ()); |