… | |
… | |
51 | #define SOCKET_TIMEOUT2 20 * 1000 |
51 | #define SOCKET_TIMEOUT2 20 * 1000 |
52 | |
52 | |
53 | void |
53 | void |
54 | client::flush () |
54 | client::flush () |
55 | { |
55 | { |
|
|
56 | if (destroyed ()) |
|
|
57 | return; |
|
|
58 | |
56 | #ifdef __linux__ |
59 | #ifdef __linux__ |
57 | // check time of last ack, and, if too old, kill connection |
60 | // check time of last ack, and, if too old, kill connection |
58 | struct tcp_info tcpi; |
61 | struct tcp_info tcpi; |
59 | socklen_t len = sizeof (tcpi); |
62 | socklen_t len = sizeof (tcpi); |
60 | |
63 | |
… | |
… | |
187 | {"ncom", PC(NewPlayerCmd) PF_PLAYING }, |
190 | {"ncom", PC(NewPlayerCmd) PF_PLAYING }, |
188 | {"command", PC(PlayerCmd) PF_PLAYING }, |
191 | {"command", PC(PlayerCmd) PF_PLAYING }, |
189 | |
192 | |
190 | {"examine", PC(ExamineCmd) PF_PLAYING }, |
193 | {"examine", PC(ExamineCmd) PF_PLAYING }, |
191 | {"apply", PC(ApplyCmd) PF_PLAYING }, |
194 | {"apply", PC(ApplyCmd) PF_PLAYING }, |
192 | {"reply", PC(ReplyCmd) 0 }, |
|
|
193 | {"lookat", PC(LookAt) PF_PLAYING }, |
195 | {"lookat", PC(LookAt) PF_PLAYING }, |
194 | {"lock", PC(LockItem) PF_PLAYING }, |
196 | {"lock", PC(LockItem) PF_PLAYING }, |
195 | {"mark", PC(MarkItem) PF_PLAYING }, |
197 | {"mark", PC(MarkItem) PF_PLAYING }, |
196 | {"move", PC(MoveCmd) PF_PLAYING }, |
198 | {"move", PC(MoveCmd) PF_PLAYING }, |
197 | {"ext", PC(ExtCmd) 0 }, /* CF+ */ |
199 | {"ext", PC(ExtCmd) 0 }, /* CF+ */ |
198 | {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */ |
200 | {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */ |
199 | {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ |
201 | {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ |
200 | |
202 | |
|
|
203 | {"reply", SC(ReplyCmd) 0 }, |
201 | {"exti", SC(ExtiCmd) 0 }, /* CF+ */ |
204 | {"exti", SC(ExtiCmd) 0 }, /* CF+ */ |
202 | {"addme", SC(AddMeCmd) 0 }, |
205 | {"addme", SC(AddMeCmd) 0 }, |
203 | {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */ |
206 | {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */ |
204 | {"requestinfo", SC(RequestInfo) 0 }, |
207 | {"requestinfo", SC(RequestInfo) 0 }, |
205 | {"setfacemode", SC(SetFaceMode) 0 }, |
208 | {"setfacemode", SC(SetFaceMode) 0 }, |
… | |
… | |
213 | |
216 | |
214 | bool |
217 | bool |
215 | client::may_execute (const packet_type *pkt) const |
218 | client::may_execute (const packet_type *pkt) const |
216 | { |
219 | { |
217 | return (!(pkt->flags & PF_PLAYER) || pl) |
220 | return (!(pkt->flags & PF_PLAYER) || pl) |
218 | && (!(pkt->flags & PF_PLAYING) || (pl && pl->state == ST_PLAYING)); |
221 | && (!(pkt->flags & PF_PLAYING) || state == ST_PLAYING); |
219 | } |
222 | } |
220 | |
223 | |
221 | void |
224 | void |
222 | client::execute (const packet_type *pkt, char *data, int datalen) |
225 | client::execute (const packet_type *pkt, char *data, int datalen) |
223 | { |
226 | { |
… | |
… | |
294 | // callback called when socket is either readable or writable |
297 | // callback called when socket is either readable or writable |
295 | void |
298 | void |
296 | client::socket_cb (iow &w, int got) |
299 | client::socket_cb (iow &w, int got) |
297 | { |
300 | { |
298 | //TODO remove when we have better socket cleanup logic |
301 | //TODO remove when we have better socket cleanup logic |
299 | if (status == Ns_Dead) |
302 | if (destroyed ()) |
300 | { |
303 | { |
301 | socket_ev.poll (0); |
304 | socket_ev.poll (0); |
302 | return; |
305 | return; |
303 | } |
306 | } |
304 | |
307 | |
… | |
… | |
380 | { |
383 | { |
381 | char *buf = (char *)buf_; |
384 | char *buf = (char *)buf_; |
382 | char *pos = buf; |
385 | char *pos = buf; |
383 | int amt = 0; |
386 | int amt = 0; |
384 | |
387 | |
385 | if (status == Ns_Dead || !buf) |
388 | if (destroyed () || !buf) |
386 | return; |
389 | return; |
387 | |
390 | |
388 | if ((len + outputbuffer.len) > SOCKETBUFSIZE) |
391 | if ((len + outputbuffer.len) > SOCKETBUFSIZE) |
389 | { |
392 | { |
390 | LOG (llevDebug, "socket on fd %d has overrun internal buffer - marking as dead\n", fd); |
393 | LOG (llevDebug, "socket on fd %d has overrun internal buffer - marking as dead\n", fd); |
… | |
… | |
421 | * shortcut function. |
424 | * shortcut function. |
422 | */ |
425 | */ |
423 | void |
426 | void |
424 | client::send_packet (packet &sl) |
427 | client::send_packet (packet &sl) |
425 | { |
428 | { |
426 | if (status == Ns_Dead) |
429 | if (destroyed ()) |
427 | return; |
430 | return; |
428 | |
431 | |
429 | if (sl.length () >= MAXSOCKBUF) |
432 | if (sl.length () >= MAXSOCKBUF) |
430 | { |
433 | { |
431 | LOG (llevError, "Trying to send a buffer beyond properly size, len =%d\n", sl.length ()); |
434 | LOG (llevError, "Trying to send a buffer beyond properly size, len =%d\n", sl.length ()); |
… | |
… | |
477 | /*********************************************************************** |
480 | /*********************************************************************** |
478 | * |
481 | * |
479 | * packet functions/utilities |
482 | * packet functions/utilities |
480 | * |
483 | * |
481 | **********************************************************************/ |
484 | **********************************************************************/ |
|
|
485 | |
|
|
486 | packet::packet (const char *name) |
|
|
487 | { |
|
|
488 | reset (); |
|
|
489 | |
|
|
490 | int len = strlen (name); |
|
|
491 | memcpy (cur, name, len); cur += len; |
|
|
492 | *cur++ = ' '; |
|
|
493 | } |
482 | |
494 | |
483 | packet &packet::operator <<(const data &v) |
495 | packet &packet::operator <<(const data &v) |
484 | { |
496 | { |
485 | if (room () < v.len) |
497 | if (room () < v.len) |
486 | reset (); |
498 | reset (); |