ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/lowlevel.C
(Generate patch)

Comparing deliantra/server/socket/lowlevel.C (file contents):
Revision 1.26 by root, Tue Dec 19 04:58:05 2006 UTC vs.
Revision 1.30 by pippijn, Sat Jan 6 14:42:31 2007 UTC

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
53void 54void
54client::flush () 55client::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
187 {"ncom", PC(NewPlayerCmd) PF_PLAYING }, 191 {"ncom", PC(NewPlayerCmd) PF_PLAYING },
188 {"command", PC(PlayerCmd) PF_PLAYING }, 192 {"command", PC(PlayerCmd) PF_PLAYING },
189 193
190 {"examine", PC(ExamineCmd) PF_PLAYING }, 194 {"examine", PC(ExamineCmd) PF_PLAYING },
191 {"apply", PC(ApplyCmd) PF_PLAYING }, 195 {"apply", PC(ApplyCmd) PF_PLAYING },
192 {"reply", PC(ReplyCmd) 0 },
193 {"lookat", PC(LookAt) PF_PLAYING }, 196 {"lookat", PC(LookAt) PF_PLAYING },
194 {"lock", PC(LockItem) PF_PLAYING }, 197 {"lock", PC(LockItem) PF_PLAYING },
195 {"mark", PC(MarkItem) PF_PLAYING }, 198 {"mark", PC(MarkItem) PF_PLAYING },
196 {"move", PC(MoveCmd) PF_PLAYING }, 199 {"move", PC(MoveCmd) PF_PLAYING },
197 {"ext", PC(ExtCmd) 0 }, /* CF+ */ 200 {"ext", PC(ExtCmd) 0 }, /* CF+ */
198 {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */ 201 {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */
199 {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ 202 {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */
200 203
204 {"reply", SC(ReplyCmd) 0 },
201 {"exti", SC(ExtiCmd) 0 }, /* CF+ */ 205 {"exti", SC(ExtiCmd) 0 }, /* CF+ */
202 {"addme", SC(AddMeCmd) 0 }, 206 {"addme", SC(AddMeCmd) 0 },
203 {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */ 207 {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */
204 {"requestinfo", SC(RequestInfo) 0 }, 208 {"requestinfo", SC(RequestInfo) 0 },
205 {"setfacemode", SC(SetFaceMode) 0 }, 209 {"setfacemode", SC(SetFaceMode) 0 },
213 217
214bool 218bool
215client::may_execute (const packet_type *pkt) const 219client::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
221void 225void
222client::execute (const packet_type *pkt, char *data, int datalen) 226client::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
295void 299void
296client::socket_cb (iow &w, int got) 300client::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 (status == Ns_Dead) 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 (status == Ns_Dead || !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 */
423void 427void
424client::send_packet (packet &sl) 428client::send_packet (packet &sl)
425{ 429{
426 if (status == Ns_Dead) 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 ());
477/*********************************************************************** 481/***********************************************************************
478 * 482 *
479 * packet functions/utilities 483 * packet functions/utilities
480 * 484 *
481 **********************************************************************/ 485 **********************************************************************/
486
487packet::packet (const char *name)
488{
489 reset ();
490
491 int len = strlen (name);
492 memcpy (cur, name, len); cur += len;
493 *cur++ = ' ';
494}
482 495
483packet &packet::operator <<(const data &v) 496packet &packet::operator <<(const data &v)
484{ 497{
485 if (room () < v.len) 498 if (room () < v.len)
486 reset (); 499 reset ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines