2007-07-28 06:41:51 -07:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
2009-02-10 10:01:48 -08:00
|
|
|
Copyright (C) 2007-2009 Warzone Resurrection Project
|
2007-07-28 06:41:51 -07:00
|
|
|
|
|
|
|
Warzone 2100 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.
|
|
|
|
|
|
|
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-08-08 11:50:28 -07:00
|
|
|
/*
|
|
|
|
* Nettypes.h
|
|
|
|
*
|
|
|
|
*/
|
2007-07-28 06:41:51 -07:00
|
|
|
|
|
|
|
#ifndef __INCLUDE_LIB_NETPLAY_NETTYPES_H__
|
|
|
|
#define __INCLUDE_LIB_NETPLAY_NETTYPES_H__
|
|
|
|
|
2007-12-24 15:36:02 -08:00
|
|
|
#include "lib/framework/frame.h"
|
2007-08-08 11:50:28 -07:00
|
|
|
#include "netplay.h"
|
2009-02-10 09:23:18 -08:00
|
|
|
#include "lib/framework/vector.h"
|
2007-08-08 11:50:28 -07:00
|
|
|
|
|
|
|
typedef enum packetDirectionEnum
|
|
|
|
{
|
|
|
|
PACKET_ENCODE,
|
|
|
|
PACKET_DECODE,
|
|
|
|
PACKET_INVALID
|
|
|
|
} PACKETDIR;
|
|
|
|
|
2007-11-25 04:12:03 -08:00
|
|
|
void NETbeginEncode(uint8_t type, uint8_t player);
|
2008-02-13 12:25:12 -08:00
|
|
|
void NETbeginDecode(uint8_t type);
|
2007-11-25 04:12:03 -08:00
|
|
|
BOOL NETend(void);
|
2007-08-08 11:50:28 -07:00
|
|
|
BOOL NETint8_t(int8_t *ip);
|
|
|
|
BOOL NETuint8_t(uint8_t *ip);
|
|
|
|
BOOL NETint16_t(int16_t *ip);
|
|
|
|
BOOL NETuint16_t(uint16_t *ip);
|
|
|
|
BOOL NETint32_t(int32_t *ip);
|
|
|
|
BOOL NETuint32_t(uint32_t *ip);
|
2007-08-17 07:02:17 -07:00
|
|
|
BOOL NETfloat(float* fp);
|
2007-08-08 11:50:28 -07:00
|
|
|
BOOL NETbool(BOOL *bp);
|
|
|
|
BOOL NETnull(void);
|
|
|
|
BOOL NETstring(char *str, uint16_t maxlen);
|
2008-01-11 13:39:41 -08:00
|
|
|
BOOL NETbin(char *str, uint16_t maxlen);
|
2007-08-08 11:50:28 -07:00
|
|
|
|
2008-04-05 08:34:55 -07:00
|
|
|
PACKETDIR NETgetPacketDir(void);
|
2008-02-16 05:39:23 -08:00
|
|
|
|
2008-03-23 06:48:25 -07:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
template <typename EnumT>
|
|
|
|
BOOL NETenum(EnumT* enumPtr)
|
|
|
|
{
|
2008-03-23 07:00:30 -07:00
|
|
|
int32_t val;
|
|
|
|
|
|
|
|
if (NETgetPacketDir() == PACKET_ENCODE)
|
|
|
|
val = *enumPtr;
|
2008-03-23 06:48:25 -07:00
|
|
|
|
2008-03-23 07:00:30 -07:00
|
|
|
const BOOL retVal = NETint32_t(&val);
|
2008-03-23 06:48:25 -07:00
|
|
|
|
2008-03-23 07:00:30 -07:00
|
|
|
if (NETgetPacketDir() == PACKET_DECODE)
|
|
|
|
*enumPtr = static_cast<EnumT>(val);
|
|
|
|
|
|
|
|
return retVal;
|
2008-03-23 06:48:25 -07:00
|
|
|
}
|
|
|
|
#else
|
2008-02-29 17:24:45 -08:00
|
|
|
// FIXME: Causes tons of warnings: <enumPtr> is used unitialised in this function
|
2007-08-08 11:50:28 -07:00
|
|
|
#define NETenum(enumPtr) \
|
2008-03-23 06:33:27 -07:00
|
|
|
do \
|
2007-08-08 11:50:28 -07:00
|
|
|
{ \
|
|
|
|
int32_t _val = (NETgetPacketDir() == PACKET_ENCODE) ? *(enumPtr) : 0; \
|
|
|
|
\
|
|
|
|
NETint32_t(&_val); \
|
|
|
|
\
|
|
|
|
*(enumPtr) = _val; \
|
2008-03-23 06:33:27 -07:00
|
|
|
} while(0)
|
2008-03-23 06:48:25 -07:00
|
|
|
#endif
|
2007-08-08 11:50:28 -07:00
|
|
|
|
2007-12-24 15:36:02 -08:00
|
|
|
BOOL NETVector3uw(Vector3uw* vp);
|
|
|
|
|
2008-01-02 09:08:29 -08:00
|
|
|
/**
|
|
|
|
* Get player who is the source of the current packet.
|
|
|
|
* @see selectedPlayer
|
|
|
|
*/
|
|
|
|
int NETgetSource(void);
|
|
|
|
|
2007-10-15 11:09:18 -07:00
|
|
|
void NETtest(void);
|
2007-07-28 06:41:51 -07:00
|
|
|
|
2007-08-08 11:50:28 -07:00
|
|
|
#endif
|