--- deliantra/server/socket/lowlevel.C 2007/03/01 12:28:17 1.34 +++ deliantra/server/socket/lowlevel.C 2007/05/28 21:22:26 1.42 @@ -1,26 +1,26 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. * - * 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. + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 1992,2007 Frank Tore Johansen + * + * Crossfire TRT 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. * - * The author can be reached via e-mail to mark@pyramid.com + * 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 Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to */ - + /** * \file * Low-level socket-related functions. @@ -192,19 +192,20 @@ {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND0 }, {"examine", PC(ExamineCmd) PF_PLAYING }, + {"ex", PC(ExCmd) PF_PLAYING }, {"apply", PC(ApplyCmd) PF_PLAYING }, {"lookat", PC(LookAt) PF_PLAYING }, {"lock", PC(LockItem) PF_PLAYING }, {"mark", PC(MarkItem) PF_PLAYING }, {"move", PC(MoveCmd) PF_PLAYING }, - {"ext", PC(ExtCmd) 0 }, /* CF+ */ - {"mapredraw", PC(MapRedrawCmd) 0 }, /* Added: phil */ - {"mapinfo", PC(MapInfoCmd) 0 }, /* CF+ */ + {"ext", PC(ExtCmd) 0 }, // CF+ + {"mapredraw", PC(MapRedrawCmd) 0 }, + {"mapinfo", PC(MapInfoCmd) 0 }, // CF+ {"reply", SC(ReplyCmd) 0 }, - {"exti", SC(ExtiCmd) 0 }, /* CF+ */ + {"exti", SC(ExtiCmd) 0 }, // CF+ {"addme", SC(AddMeCmd) 0 }, - {"askface", SC(SendFaceCmd) 0 }, /* Added: phil */ + {"askface", SC(AskFaceCmd) 0 }, {"requestinfo", SC(RequestInfo) 0 }, {"setfacemode", SC(SetFaceMode) 0 }, {"setsound", SC(SetSound) 0 }, @@ -418,7 +419,9 @@ if (len + outputbuffer.len > SOCKETBUFSIZE) { LOG (llevDebug, "socket on fd %d has overrun internal buffer - marking as dead\n", fd); - destroy (); + // shutdown the socket, this is safer than destroying it immediately + // as lots of code in the callchain might still access the map etc. + shutdown (fd, SHUT_RDWR); return; } @@ -504,6 +507,28 @@ send_packet (sl); } +void +client::send_drawinfo (const char *msg, int flags) +{ + send_packet_printf ("drawinfo %d %s", flags, msg); +} + +void +client::send_msg (int color, const char *type, const char *msg) +{ + if (can_msg) + send_packet_printf ("msg %d %s %s", color, type, msg); + else if (color < 0) + return; // client cannot handle this + else if (strchr (msg, '<') || strchr (msg, '&')) + { + //TODO: should escape/modify to old syntax + send_packet_printf ("drawinfo %d %s", color, msg); + } + else + send_packet_printf ("drawinfo %d %s", color, msg); +} + /*********************************************************************** * * packet functions/utilities @@ -519,6 +544,24 @@ *cur++ = ' '; } +packet &packet::operator <<(const ber32 v) +{ + enum { maxlen = 32 / 7 + 1}; + uint8 buf[maxlen]; + uint8 *p = buf + maxlen; + uint32 val = v.val; + + *--p = val & 0x7F; + + while (val > 0x7F) + { + val >>= 7; + *--p = (val & 0x7F) | 0x80; + } + + return *this << data (p, buf + maxlen - p); +} + packet &packet::operator <<(const data &v) { if (room () < v.len)