--- deliantra/server/include/network.h 2012/01/03 11:25:32 1.32 +++ deliantra/server/include/network.h 2018/12/05 21:18:37 1.38 @@ -1,24 +1,25 @@ /* * 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 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen - * + * * 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 * Free Software Foundation, either version 3 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 Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . - * + * * The authors can be reached via e-mail to */ @@ -47,7 +48,7 @@ #include -#include "compiler.h" +#include "ecb.h" /* Maximum size of any packet we expect. * @@ -60,7 +61,7 @@ #define CS_QUERY_SINGLECHAR 0x2 /* Single character response expected */ #define CS_QUERY_HIDEINPUT 0x4 /* Hide input being entered */ -/* These are multiplication values that should be used when changing +/* These are multiplication values that should be used when changing * floats to ints, and vice version. MULTI is integer representatin * (float to int), MULTF is float, for going from int to float. */ @@ -185,38 +186,21 @@ //-GPL -struct data -{ - unsigned int len; - const void *ptr; - - data (const void *ptr, int len) : len (len), ptr (ptr) { } - data (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } - data (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } - data (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } -}; - -struct data8 +template +struct databuf { unsigned int len; const void *ptr; - data8 (const void *ptr, int len) : len (len), ptr (ptr) { } - data8 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } - data8 (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } - data8 (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } + databuf (const void *ptr, int len) : len (len), ptr (ptr) { } + databuf (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } + databuf (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } + databuf (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } }; -struct data16 -{ - unsigned int len; - const void *ptr; - - data16 (const void *ptr, int len) : len (len), ptr (ptr) { } - data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } - data16 (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } - data16 (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } -}; +using data_n = databuf<0>; +using data8 = databuf<1>; +using data16 = databuf<2>; struct ber32 { @@ -278,17 +262,17 @@ // checked packet &operator <<(const ber32 v); - packet &operator <<(const data &v); + packet &operator <<(const data_n &v); packet &operator <<(const data8 &v); packet &operator <<(const data16 &v); packet &operator <<(const char *v); - packet &operator <<(shstr_tmp sh) { return *this << data (sh); } - packet &operator <<(const std::string &s) { return *this << data (s.data (), s.size ()); } + packet &operator <<(shstr_tmp sh) { return *this << data_n (sh); } + packet &operator <<(const std::string &s) { return *this << data_n (s.data (), s.size ()); } void vprintf (const char *format, va_list ap); - void printf (const char *format, ...) attribute ((format (printf, 2, 3))) + void printf (const char *format, ...) ecb_attribute ((format (printf, 2, 3))) { va_list ap; va_start (ap, format);