--- deliantra/server/socket/lowlevel.C 2006/12/19 04:58:05 1.26 +++ deliantra/server/socket/lowlevel.C 2007/01/20 13:47:17 1.32 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The author can be reached via e-mail to mark@pyramid.com -*/ - + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The author can be reached via e-mail to mark@pyramid.com + */ + /** * \file * Low-level socket-related functions. @@ -53,6 +54,9 @@ void client::flush () { + if (destroyed ()) + return; + #ifdef __linux__ // check time of last ack, and, if too old, kill connection struct tcp_info tcpi; @@ -189,7 +193,6 @@ {"examine", PC(ExamineCmd) PF_PLAYING }, {"apply", PC(ApplyCmd) PF_PLAYING }, - {"reply", PC(ReplyCmd) 0 }, {"lookat", PC(LookAt) PF_PLAYING }, {"lock", PC(LockItem) PF_PLAYING }, {"mark", PC(MarkItem) PF_PLAYING }, @@ -198,6 +201,7 @@ {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */ {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ + {"reply", SC(ReplyCmd) 0 }, {"exti", SC(ExtiCmd) 0 }, /* CF+ */ {"addme", SC(AddMeCmd) 0 }, {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */ @@ -215,7 +219,7 @@ client::may_execute (const packet_type *pkt) const { return (!(pkt->flags & PF_PLAYER) || pl) - && (!(pkt->flags & PF_PLAYING) || (pl && pl->state == ST_PLAYING)); + && (!(pkt->flags & PF_PLAYING) || state == ST_PLAYING); } void @@ -296,7 +300,7 @@ client::socket_cb (iow &w, int got) { //TODO remove when we have better socket cleanup logic - if (status == Ns_Dead) + if (destroyed ()) { socket_ev.poll (0); return; @@ -382,10 +386,10 @@ char *pos = buf; int amt = 0; - if (status == Ns_Dead || !buf) + if (destroyed () || !buf) return; - if ((len + outputbuffer.len) > SOCKETBUFSIZE) + if (len + outputbuffer.len > SOCKETBUFSIZE) { LOG (llevDebug, "socket on fd %d has overrun internal buffer - marking as dead\n", fd); destroy (); @@ -423,7 +427,7 @@ void client::send_packet (packet &sl) { - if (status == Ns_Dead) + if (destroyed ()) return; if (sl.length () >= MAXSOCKBUF) @@ -480,6 +484,15 @@ * **********************************************************************/ +packet::packet (const char *name) +{ + reset (); + + int len = strlen (name); + memcpy (cur, name, len); cur += len; + *cur++ = ' '; +} + packet &packet::operator <<(const data &v) { if (room () < v.len)