--- deliantra/server/include/network.h 2006/12/15 19:59:19 1.1 +++ deliantra/server/include/network.h 2007/04/10 09:35:23 1.10 @@ -1,26 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 1992 Frank Tore Johansen - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 2005, 2006 The Crossfire+ Development Team - - 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 authors can be reached via e-mail at crossfire-devel@real-time.com -*/ + * 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 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 authors can be reached via e-mail at crossfire@schmorp.de + */ /* This file defines various flags that both the new client and * newserver uses. These should never be changed, only expanded. @@ -41,27 +41,22 @@ */ -#ifndef NEWCLIENT_H -#define NEWCLIENT_H +#ifndef NETWORK_H +#define NETWORK_H -/* Maximum size of any packet we expect. Using this makes it so we don't need to - * allocated and deallocated the same buffer over and over again and the price - * of using a bit of extra memory. It also makes the code simpler. +#include + +/* 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. */ #define MAXSOCKBUF 10240 - #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 */ -#define CS_SAY_NORMAL 0x1 /* Normal say command */ -#define CS_SAY_SHOUT 0x2 /* Text is shouted. */ -#define CS_SAY_GSAY 0x4 /* Text is group say command */ - /* 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. @@ -265,6 +260,14 @@ data16 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } }; +struct ber32 +{ + enum { size = 5 }; // maximum length of an encoded ber32 + uint32 val; + + ber32 (uint32 val) : val (val) { } +}; + /* Contains the base information we use to make up a packet we want to send. */ struct packet { @@ -276,7 +279,12 @@ uint8 *cur; uint8 buf_ [hdrlen + bufsize + 256]; - packet () { reset (); } + packet () + { + reset (); + } + + packet (const char *name); uint8 operator [](unsigned int i) const { return buf_ [i + hdrlen]; } uint8 &operator [](unsigned int i) { return buf_ [i + hdrlen]; } @@ -301,6 +309,8 @@ packet &operator <<(sint64 v) { return *this << (uint64)v; } // checked + packet &operator <<(const ber32 v); + packet &operator <<(const data &v); packet &operator <<(const data8 &v); packet &operator <<(const data16 &v); @@ -308,7 +318,15 @@ packet &operator <<(const char *v); packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } - void printf (const char *format, ...); + void vprintf (const char *format, va_list ap); + + void printf (const char *format, ...) + { + va_list ap; + va_start (ap, format); + vprintf (format, ap); + va_end (ap); + } }; inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; }