2010-08-02 08:13:51 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
2018-12-08 00:40:39 +00:00
|
|
|
Copyright (C) 2017 EDuke32 developers and contributors
|
2010-08-02 08:13:51 +00:00
|
|
|
|
|
|
|
This file is part of EDuke32.
|
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
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
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-08-02 08:13:51 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#ifndef netplay_h_
|
|
|
|
#define netplay_h_
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
// As of Nov. of 2018, the version of gcc that the Makefile is using is too old for [[maybe_unused]],
|
|
|
|
// but __attribute__ is GNU C only.
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define EDUKE32_UNUSED __attribute__((unused))
|
|
|
|
#else
|
|
|
|
#define EDUKE32_UNUSED
|
2017-02-19 22:15:44 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-03 20:06:03 +00:00
|
|
|
struct ENetHost;
|
|
|
|
struct ENetPeer;
|
|
|
|
struct ENetAddress;
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2019-09-21 20:53:00 +00:00
|
|
|
BEGIN_DUKE_NS
|
|
|
|
|
2014-02-10 11:00:25 +00:00
|
|
|
// net packet specification/compatibility version
|
|
|
|
#define NETVERSION 1
|
|
|
|
|
2012-12-09 13:24:44 +00:00
|
|
|
extern ENetHost *g_netClient;
|
|
|
|
extern ENetHost *g_netServer;
|
|
|
|
extern ENetPeer *g_netClientPeer;
|
|
|
|
extern char g_netPassword[32];
|
|
|
|
extern int32_t g_netDisconnect;
|
|
|
|
extern int32_t g_netPlayersWaiting;
|
2020-02-03 20:06:03 +00:00
|
|
|
extern uint16_t g_netPort;
|
2012-12-09 13:24:44 +00:00
|
|
|
extern int32_t g_networkMode;
|
2012-12-12 02:53:13 +00:00
|
|
|
extern int32_t g_netIndex;
|
2012-12-09 13:24:44 +00:00
|
|
|
|
2012-05-17 23:54:43 +00:00
|
|
|
#define NET_REVISIONS 64
|
2011-02-25 21:50:19 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
enum netchan_t
|
|
|
|
{
|
|
|
|
CHAN_MOVE, // unreliable movement packets
|
|
|
|
CHAN_GAMESTATE, // gamestate changes... frags, respawns, player names, etc
|
|
|
|
CHAN_CHAT, // chat and RTS
|
|
|
|
CHAN_MISC, // whatever else
|
|
|
|
CHAN_MAX
|
|
|
|
};
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
enum DukePacket_t
|
|
|
|
{
|
|
|
|
PACKET_MASTER_TO_SLAVE,
|
|
|
|
PACKET_SLAVE_TO_MASTER,
|
|
|
|
|
|
|
|
PACKET_NUM_PLAYERS,
|
|
|
|
PACKET_PLAYER_INDEX,
|
|
|
|
PACKET_PLAYER_DISCONNECTED,
|
|
|
|
PACKET_PLAYER_SPAWN,
|
|
|
|
PACKET_FRAG,
|
2014-02-10 11:00:25 +00:00
|
|
|
PACKET_ACK,
|
2010-08-02 08:13:51 +00:00
|
|
|
PACKET_AUTH,
|
2011-03-05 01:41:38 +00:00
|
|
|
PACKET_PLAYER_PING,
|
2010-08-02 08:13:51 +00:00
|
|
|
PACKET_PLAYER_READY,
|
2018-12-08 00:40:39 +00:00
|
|
|
PACKET_WORLD_UPDATE, //[75]
|
2010-08-02 08:13:51 +00:00
|
|
|
|
|
|
|
// any packet with an ID higher than PACKET_BROADCAST is rebroadcast by server
|
|
|
|
// so hacked clients can't create fake server packets and get the server to
|
|
|
|
// send them to everyone
|
|
|
|
// newer versions of the netcode also make this determination based on which
|
|
|
|
// channel the packet was broadcast on
|
|
|
|
|
|
|
|
PACKET_BROADCAST,
|
2018-12-08 00:40:39 +00:00
|
|
|
PACKET_NEW_GAME, // [S->C]
|
2010-08-02 08:13:51 +00:00
|
|
|
PACKET_RTS,
|
|
|
|
PACKET_CLIENT_INFO,
|
|
|
|
PACKET_MESSAGE,
|
|
|
|
PACKET_USER_MAP,
|
|
|
|
|
|
|
|
PACKET_MAP_VOTE,
|
|
|
|
PACKET_MAP_VOTE_INITIATE,
|
|
|
|
PACKET_MAP_VOTE_CANCEL,
|
|
|
|
};
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
|
|
|
|
|
2011-02-25 21:50:19 +00:00
|
|
|
enum netdisconnect_t
|
2010-08-02 08:13:51 +00:00
|
|
|
{
|
|
|
|
DISC_BAD_PASSWORD = 1,
|
2014-02-10 11:00:25 +00:00
|
|
|
DISC_VERSION_MISMATCH,
|
|
|
|
DISC_INVALID,
|
|
|
|
DISC_SERVER_QUIT,
|
|
|
|
DISC_SERVER_FULL,
|
2010-08-02 08:13:51 +00:00
|
|
|
DISC_KICKED,
|
|
|
|
DISC_BANNED
|
|
|
|
};
|
|
|
|
|
2011-02-25 21:50:19 +00:00
|
|
|
enum netmode_t
|
|
|
|
{
|
|
|
|
NET_CLIENT = 0,
|
|
|
|
NET_SERVER,
|
|
|
|
NET_DEDICATED_CLIENT, // client on dedicated server
|
|
|
|
NET_DEDICATED_SERVER
|
|
|
|
};
|
|
|
|
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
//[75]
|
|
|
|
|
|
|
|
typedef struct netWall_s
|
2012-12-12 02:53:13 +00:00
|
|
|
{
|
2018-12-08 00:40:39 +00:00
|
|
|
uint16_t netIndex;
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
int32_t x,
|
|
|
|
y,
|
|
|
|
point2,
|
|
|
|
nextwall,
|
|
|
|
nextsector,
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
cstat,
|
|
|
|
picnum,
|
|
|
|
overpicnum,
|
|
|
|
shade,
|
|
|
|
pal,
|
|
|
|
|
|
|
|
xrepeat,
|
|
|
|
yrepeat,
|
|
|
|
xpanning,
|
|
|
|
ypanning,
|
|
|
|
lotag,
|
2012-05-17 23:54:43 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
hitag,
|
|
|
|
extra;
|
|
|
|
|
|
|
|
} netWall_t;
|
|
|
|
|
2018-12-15 22:33:15 +00:00
|
|
|
// sector struct with all 32 bit entries
|
2018-12-08 00:40:39 +00:00
|
|
|
typedef struct netSector_s
|
2012-12-12 02:53:13 +00:00
|
|
|
{
|
2018-12-08 00:40:39 +00:00
|
|
|
uint16_t netIndex;
|
|
|
|
|
|
|
|
int32_t wallptr,
|
|
|
|
wallnum,
|
|
|
|
ceilingz,
|
|
|
|
floorz,
|
|
|
|
ceilingstat,
|
|
|
|
|
|
|
|
floorstat,
|
|
|
|
ceilingpicnum,
|
|
|
|
ceilingheinum,
|
|
|
|
ceilingshade,
|
|
|
|
ceilingpal,
|
|
|
|
|
|
|
|
ceilingxpanning,
|
|
|
|
ceilingypanning,
|
|
|
|
floorpicnum,
|
|
|
|
floorheinum,
|
|
|
|
floorshade,
|
|
|
|
|
|
|
|
floorpal,
|
|
|
|
floorxpanning,
|
|
|
|
floorypanning,
|
|
|
|
visibility,
|
|
|
|
fogpal,
|
|
|
|
|
|
|
|
lotag,
|
|
|
|
hitag,
|
|
|
|
extra;
|
|
|
|
} netSector_t;
|
|
|
|
|
|
|
|
const uint64_t cSnapshotMemUsage = NET_REVISIONS * (
|
2018-12-15 22:33:15 +00:00
|
|
|
(sizeof(netWall_t) * MAXWALLS)
|
|
|
|
+ (sizeof(netSector_t) * MAXSECTORS)
|
2018-12-08 00:40:39 +00:00
|
|
|
+ (sizeof(netactor_t) * MAXSPRITES)
|
|
|
|
);
|
|
|
|
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
#pragma pack(push,1)
|
|
|
|
typedef struct netmapstate_s
|
|
|
|
{
|
|
|
|
uint32_t revisionNumber;
|
|
|
|
int32_t maxActorIndex;
|
|
|
|
netactor_t actor[MAXSPRITES];
|
|
|
|
netWall_t wall[MAXWALLS];
|
|
|
|
netSector_t sector[MAXSECTORS];
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
} netmapstate_t;
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2012-05-17 23:54:43 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2012-10-28 22:27:53 +00:00
|
|
|
#pragma pack(push,1)
|
2018-12-08 00:40:39 +00:00
|
|
|
typedef struct playerupdate_s
|
2012-12-12 02:53:13 +00:00
|
|
|
{
|
|
|
|
vec3_t pos;
|
|
|
|
vec3_t opos;
|
|
|
|
vec3_t vel;
|
2018-12-08 00:40:39 +00:00
|
|
|
|
|
|
|
fix16_t q16ang;
|
|
|
|
fix16_t q16horiz;
|
|
|
|
fix16_t q16horizoff;
|
|
|
|
|
2012-12-12 02:53:13 +00:00
|
|
|
int16_t ping;
|
|
|
|
int16_t playerindex;
|
|
|
|
int16_t deadflag;
|
|
|
|
int16_t playerquitflag;
|
2012-10-28 22:27:53 +00:00
|
|
|
} playerupdate_t;
|
|
|
|
#pragma pack(pop)
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2012-10-28 22:27:53 +00:00
|
|
|
#pragma pack(push,1)
|
2018-12-08 00:40:39 +00:00
|
|
|
typedef struct newgame_s
|
2012-12-12 02:53:13 +00:00
|
|
|
{
|
|
|
|
int8_t header;
|
|
|
|
int8_t connection;
|
|
|
|
int8_t level_number;
|
|
|
|
int8_t volume_number;
|
|
|
|
int8_t player_skill;
|
|
|
|
int8_t monsters_off;
|
|
|
|
int8_t respawn_monsters;
|
|
|
|
int8_t respawn_items;
|
|
|
|
int8_t respawn_inventory;
|
|
|
|
int8_t marker;
|
|
|
|
int8_t ffire;
|
|
|
|
int8_t noexits;
|
|
|
|
int8_t coop;
|
2012-10-28 22:27:53 +00:00
|
|
|
} newgame_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
extern newgame_t pendingnewgame;
|
2012-10-28 22:27:53 +00:00
|
|
|
|
2012-12-09 13:24:44 +00:00
|
|
|
#ifndef NETCODE_DISABLE
|
|
|
|
|
2012-10-28 22:27:53 +00:00
|
|
|
// Connect/Disconnect
|
2010-08-02 08:13:51 +00:00
|
|
|
void Net_Connect(const char *srvaddr);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
|
|
|
// Packet Handlers
|
2012-12-09 13:24:44 +00:00
|
|
|
#endif
|
2010-08-02 08:13:51 +00:00
|
|
|
void Net_GetPackets(void);
|
2012-12-09 13:24:44 +00:00
|
|
|
#ifndef NETCODE_DISABLE
|
2012-10-28 22:27:53 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
void Net_SendClientInfo(void);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
void Net_SendUserMapName(void);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
|
|
|
void Net_SendMapUpdate(void);
|
2012-12-12 02:53:13 +00:00
|
|
|
|
|
|
|
int32_t Net_InsertSprite(int32_t sect, int32_t stat);
|
|
|
|
void Net_DeleteSprite(int32_t spritenum);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
|
|
|
void Net_SendServerUpdates(void);
|
|
|
|
|
|
|
|
void Net_SendClientUpdate(void);
|
|
|
|
|
|
|
|
void Net_SendMessage(void);
|
|
|
|
|
|
|
|
void Net_StartNewGame();
|
2012-12-12 02:53:13 +00:00
|
|
|
void Net_NotifyNewGame();
|
2012-10-28 22:27:53 +00:00
|
|
|
void Net_SendNewGame(int32_t frommenu, ENetPeer *peer);
|
|
|
|
|
2012-12-12 02:53:13 +00:00
|
|
|
void Net_FillNewGame(newgame_t *newgame, int32_t frommenu);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
|
|
|
void Net_SendMapVoteInitiate(void);
|
|
|
|
|
|
|
|
void Net_SendMapVote(int32_t votefor);
|
|
|
|
|
|
|
|
void Net_SendMapVoteCancel(int32_t failed);
|
2018-12-08 00:40:39 +00:00
|
|
|
|
|
|
|
void Net_StoreClientState(void);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
|
|
|
//////////
|
|
|
|
|
|
|
|
void Net_ResetPrediction(void);
|
2013-08-06 23:54:09 +00:00
|
|
|
void Net_SpawnPlayer(int32_t player);
|
2010-08-02 08:13:51 +00:00
|
|
|
void Net_WaitForServer(void);
|
|
|
|
void faketimerhandler(void);
|
2012-10-28 22:27:53 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
void Net_InitMapStateHistory();
|
|
|
|
void Net_AddWorldToInitialSnapshot();
|
2012-12-12 02:53:13 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
// Debugging
|
|
|
|
int32_t Dbg_PacketSent(enum DukePacket_t iPacketType);
|
2012-12-09 13:24:44 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
void DumpMapStateHistory();
|
2012-12-09 13:24:44 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
void Net_WaitForInitialSnapshot();
|
2012-12-09 13:24:44 +00:00
|
|
|
|
2019-11-01 06:26:49 +00:00
|
|
|
void Net_SendTaunt(int ridiculeNum);
|
|
|
|
void Net_SendRTS(int ridiculeNum);
|
2020-02-03 20:06:03 +00:00
|
|
|
void Net_InitNetwork();
|
|
|
|
void Net_PrintLag(FString& output);
|
2019-11-01 06:26:49 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
#else
|
2012-12-09 13:24:44 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
// note: don't include faketimerhandler in this
|
2012-12-09 13:24:44 +00:00
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
#define Net_Connect(...) ((void)0)
|
2012-12-09 13:24:44 +00:00
|
|
|
|
|
|
|
#define Net_SendClientInfo(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendUserMapName(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendClientSync(...) ((void)0)
|
|
|
|
#define Net_ReceiveClientSync(...) ((void)0)
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
#define Net_SendMapUpdates(...) ((void)0)
|
2012-12-09 13:24:44 +00:00
|
|
|
#define Net_ReceiveMapUpdate(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendServerUpdates(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendClientUpdate(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendMessage(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_StartNewGame(...) ((void)0)
|
|
|
|
#define Net_SendNewGame(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_FillNewGame(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendMapVoteInitiate(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendMapVote(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_SendMapVoteCancel(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_ResetPrediction(...) ((void)0)
|
|
|
|
#define Net_RestoreMapState(...) ((void)0)
|
|
|
|
#define Net_WaitForServer(...) ((void)0)
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
#define Net_InsertSprite(...) ((void)0)
|
2013-01-06 18:56:38 +00:00
|
|
|
#define Net_DeleteSprite(...) ((void)0)
|
|
|
|
|
|
|
|
#define Net_NotifyNewGame(...) ((void)0)
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
#define Net_WaitForInitialSnapshot(...) ((void)0)
|
|
|
|
#define Net_SendMapUpdate(...) ((void)0)
|
|
|
|
#define Net_StoreClientState(...) ((void)0)
|
|
|
|
#define Net_InitMapStateHistory(...) ((void)0)
|
|
|
|
#define Net_AddWorldToInitialSnapshot(...) ((void)0)
|
|
|
|
#define DumpMapStateHistory(...) ((void)0)
|
|
|
|
|
2019-11-01 06:26:49 +00:00
|
|
|
#define Net_SendTaunt(...) ((void)0)
|
|
|
|
#define Net_SendRTS(...) ((void)0)
|
|
|
|
|
2018-12-08 00:40:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-09 13:24:44 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-21 20:53:00 +00:00
|
|
|
END_DUKE_NS
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#endif // netplay_h_
|