--- deliantra/server/socket/lowlevel.C 2012/11/08 02:28:21 1.90 +++ deliantra/server/socket/lowlevel.C 2018/12/01 20:22:13 1.101 @@ -1,7 +1,8 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -134,7 +135,7 @@ if (inbuf_len == sizeof (inbuf)) { - send_packet_printf ("drawinfo %d input buffer overflow - closing connection.", NDI_RED | NDI_REPLY); + send_packet_printf ("msg %d log input buffer overflow - closing connection.", NDI_RED | NDI_REPLY); destroy (); return -1; } @@ -152,7 +153,7 @@ /***************************************************************************** * Start of command dispatch area. - * The commands here are protocol commands. + * The commands here are protocol commands. ****************************************************************************/ // SocketCommand, PlayingCommand, should not exist with those ugly casts @@ -169,8 +170,7 @@ * Dispatch table for the server. */ static struct packet_type packets[] = { - {"ncom", PC(NewPlayerCmd) PF_PLAYING | PF_COMMAND6 }, - {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND0 }, + {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND }, {"examine", PC(ExamineCmd) PF_PLAYING }, {"ex", PC(ExCmd) PF_PLAYING }, @@ -210,18 +210,12 @@ static bool always_immediate (const client *ns, const packet_type *pkt, const char *data, int len) { - if (!(pkt->flags & (PF_COMMAND0 | PF_COMMAND6))) + if (!(pkt->flags & PF_COMMAND)) return false; if (!ns->pl || !ns->pl->ob || !ns->pl->ob->map) return false; - if (pkt->flags & PF_COMMAND6) - { - data += 6; - len -= 6; - } - if (len > 4 && data [ 3] == ' ' && !strncmp (data, "say " , 4)) return true; if (len > 5 && data [ 4] == ' ' && !strncmp (data, "chat " , 5)) return true; if (len > 6 && data [ 5] == ' ' && !strncmp (data, "shout " , 6)) return true; @@ -248,7 +242,7 @@ ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); } else - send_packet_printf ("drawinfo %d ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name); + send_packet_printf ("msg %d log ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name); } bool @@ -288,7 +282,7 @@ datalen = 0; } - for (packet_type *pkt = packets; pkt < packets + array_length (packets); ++pkt) + for (packet_type *pkt = packets; pkt < packets + ecb_array_length (packets); ++pkt) if (!strcmp ((char *)inbuf + 2, pkt->name)) { if (pkt->flags & PF_PLAYER && !always_immediate (this, pkt, data, datalen)) @@ -300,7 +294,7 @@ } // If we get here, we didn't find a valid command. - send_packet_printf ("drawinfo %d ERROR: command '%s' not supported.", NDI_RED | NDI_REPLY, (char *)inbuf + 2); + send_packet_printf ("msg %d log ERROR: command '%s' not supported.", NDI_RED | NDI_REPLY, (char *)inbuf + 2); next_packet: inbuf [pkt_len] = save_byte; // rather ugly @@ -353,12 +347,12 @@ if (ws_inbuf_len + 2048 > ws_inbuf_alloc) ws_inbuf = (uint8 *)realloc (ws_inbuf, ws_inbuf_alloc += 4096); - rbuf = ws_inbuf; + rbuf = ws_inbuf + ws_inbuf_len; amount = ws_inbuf_alloc - ws_inbuf_len; } else { - rbuf = inbuf; + rbuf = inbuf + inbuf_len; amount = sizeof (inbuf) - inbuf_len; } @@ -370,7 +364,7 @@ return; } - amount = read (fd, ws_inbuf + ws_inbuf_len, amount); + amount = read (fd, rbuf, amount); if (!amount) { @@ -655,7 +649,7 @@ { packet sl; - sl << data (buf, len); + sl << data_n (buf, len); send_packet (sl); } @@ -697,12 +691,6 @@ send_packet_printf ("msg %d %s %s", color & NDI_CLIENT_MASK, type, msg); } -void -client::send_drawinfo (const char *msg, int flags) -{ - send_msg (flags, "log", msg); -} - /*********************************************************************** * * packet functions/utilities @@ -733,10 +721,10 @@ *--p = (val & 0x7F) | 0x80; } - return *this << data (p, buf + maxlen - p); + return *this << data_n (p, buf + maxlen - p); } -packet &packet::operator <<(const data &v) +packet &packet::operator <<(const data_n &v) { if (room () < v.len) reset (); @@ -755,18 +743,18 @@ packet &packet::operator <<(const data8 &v) { unsigned int len = min (v.len, 0x00FF); - return *this << uint8 (len) << data (v.ptr, len); + return *this << uint8 (len) << data_n (v.ptr, len); } packet &packet::operator <<(const data16 &v) { unsigned int len = min (v.len, 0xFFFF); - return *this << uint16 (len) << data (v.ptr, len); + return *this << uint16 (len) << data_n (v.ptr, len); } packet &packet::operator <<(const char *v) { - return *this << data (v, strlen (v ? v : 0)); + return *this << data_n (v, v ? strlen (v) : 0); } void