--- deliantra/server/include/network.h 2007/01/15 21:06:19 1.8 +++ deliantra/server/include/network.h 2018/11/17 23:33:18 1.37 @@ -1,25 +1,26 @@ /* - * CrossFire, A Multiplayer game for X-windows - * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & 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 file is part of Deliantra, the Roguelike Realtime MMORPG. + * + * 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 + * 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 authors can be reached via e-mail at crossfire@schmorp.de + * 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 */ /* This file defines various flags that both the new client and @@ -40,24 +41,27 @@ * talking about the same values. */ - #ifndef NETWORK_H #define NETWORK_H +//+GPL + #include +#include "compiler.h" + /* Maximum size of any packet we expect. * - * The size must be the same in the server and the client (stupid), and its also NOT - * the maximum buffer size as one would expect, but the maximum buffer size + 1. + * The size must be the same in the server and the client (stupid). + * TODO: make the actual network configurable per client and use 2**16. */ -#define MAXSOCKBUF 10240 +#define MAXSOCKBUF 10239 #define CS_QUERY_YESNO 0x1 /* Yes/no question */ #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. */ @@ -119,22 +123,6 @@ #define CS_STAT_RES_HOLYWORD 116 #define CS_STAT_RES_BLIND 117 -/* Start & end of skill experience + skill level, inclusive. */ -#define CS_STAT_SKILLEXP_START 118 -#define CS_STAT_SKILLEXP_END 129 -#define CS_STAT_SKILLEXP_AGILITY 118 -#define CS_STAT_SKILLEXP_AGLEVEL 119 -#define CS_STAT_SKILLEXP_PERSONAL 120 -#define CS_STAT_SKILLEXP_PELEVEL 121 -#define CS_STAT_SKILLEXP_MENTAL 122 -#define CS_STAT_SKILLEXP_MELEVEL 123 -#define CS_STAT_SKILLEXP_PHYSIQUE 124 -#define CS_STAT_SKILLEXP_PHLEVEL 125 -#define CS_STAT_SKILLEXP_MAGIC 126 -#define CS_STAT_SKILLEXP_MALEVEL 127 -#define CS_STAT_SKILLEXP_WISDOM 128 -#define CS_STAT_SKILLEXP_WILEVEL 129 - /* CS_STAT_SKILLINFO is used as the starting index point. Skill number->name * map is generated dynamically for the client, so a bunch of entries will * be used here. CS_NUM_SKILLS does not match how many skills there really @@ -150,43 +138,9 @@ #define SF_FIREON 0x01 #define SF_RUNON 0x02 -/* The following are the color flags passed to new_draw_info. - * - * We also set up some control flags - * - * NDI = New Draw Info - */ - -/* Color specifications - note these match the order in xutil.c */ -/* Note 2: Black, the default color, is 0. Thus, it does not need to - * be implicitly specified. - */ -#define NDI_BLACK 0 -#define NDI_WHITE 1 -#define NDI_NAVY 2 -#define NDI_RED 3 -#define NDI_ORANGE 4 -#define NDI_BLUE 5 /* Actually, it is Dodger Blue */ -#define NDI_DK_ORANGE 6 /* DarkOrange2 */ -#define NDI_GREEN 7 /* SeaGreen */ -#define NDI_LT_GREEN 8 /* DarkSeaGreen, which is actually paler */ - /* Than seagreen - also background color */ -#define NDI_GREY 9 -#define NDI_BROWN 10 /* Sienna */ -#define NDI_GOLD 11 -#define NDI_TAN 12 /* Khaki */ - -#define NDI_MAX_COLOR 12 /* Last value in */ -#define NDI_COLOR_MASK 0xff /* Gives lots of room for expansion - we are */ - /* using an int anyways, so we have the space */ - /* to still do all the flags */ - - -#define NDI_UNIQUE 0x100 /* Print this out immediately, don't buffer */ -#define NDI_ALL 0x200 /* Inform all players of this message */ - /* Flags for the item command */ enum {a_none, a_readied, a_wielded, a_worn, a_active, a_applied}; + #define F_APPLIED 0x000F #define F_LOCATION 0x00F0 #define F_UNPAID 0x0200 @@ -225,39 +179,44 @@ /* The flag values sent by the updspell command */ #define UPD_SP_MANA 0x01 #define UPD_SP_GRACE 0x02 -#define UPD_SP_DAMAGE 0x04 +#define UPD_SP_LEVEL 0x04 // was UPD_SP_DAMAGE in <= server 2.93, client 2.10 #define SOUND_NORMAL 0 #define SOUND_SPELL 1 -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 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } -}; +//-GPL -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 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } + 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 +using data_n = databuf<0>; +using data8 = databuf<1>; +using data16 = databuf<2>; + +struct ber32 { - unsigned int len; - const void *ptr; + enum { size = 5 }; // maximum length of an encoded ber32 + uint32 val; - data16 (const void *ptr, int len) : len (len), ptr (ptr) { } - data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } - data16 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } + ber32 (uint32 val) : val (val) { } + + static int encoded_size (uint32 val) + { + if (val >= (1 << 7*4)) return 5; + if (val >= (1 << 7*3)) return 4; + if (val >= (1 << 7*2)) return 3; + if (val >= (1 << 7*1)) return 2; + return 1; + } }; /* Contains the base information we use to make up a packet we want to send. */ @@ -301,16 +260,19 @@ packet &operator <<(sint64 v) { return *this << (uint64)v; } // checked - packet &operator <<(const data &v); + packet &operator <<(const ber32 v); + + packet &operator <<(const data_n &v); packet &operator <<(const data8 &v); packet &operator <<(const data16 &v); packet &operator <<(const char *v); - packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } + 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, ...) + void printf (const char *format, ...) ecb_attribute ((format (printf, 2, 3))) { va_list ap; va_start (ap, format); @@ -324,15 +286,5 @@ inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); } inline sint16 net_sint32 (uint8 *data) { return sint32 (net_uint32 (data)); } -struct CS_Stats -{ - int ibytes; /* ibytes, obytes are bytes in, out */ - int obytes; - short max_conn; /* Maximum connections received */ - time_t time_start; /* When we started logging this */ -}; - -extern CS_Stats cst_tot, cst_lst; - #endif