diff options
Diffstat (limited to 'src/protocol.h')
-rw-r--r-- | src/protocol.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/protocol.h b/src/protocol.h new file mode 100644 index 0000000..c2af10d --- /dev/null +++ b/src/protocol.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* Emacs style mode select -*- C++ -*- | ||
2 | *----------------------------------------------------------------------------- | ||
3 | * | ||
4 | * | ||
5 | * PrBoom: a Doom port merged with LxDoom and LSDLDoom | ||
6 | * based on BOOM, a modified and improved DOOM engine | ||
7 | * Copyright (C) 1999 by | ||
8 | * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman | ||
9 | * Copyright (C) 1999-2000 by | ||
10 | * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze | ||
11 | * Copyright 2005, 2006 by | ||
12 | * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
27 | * 02111-1307, USA. | ||
28 | * | ||
29 | * DESCRIPTION: | ||
30 | * Doom Network protocol packet definitions. | ||
31 | *-----------------------------------------------------------------------------*/ | ||
32 | |||
33 | #include "doomtype.h" | ||
34 | #include "d_ticcmd.h" | ||
35 | #include "m_swap.h" | ||
36 | |||
37 | enum packet_type_e { | ||
38 | PKT_INIT, // initial packet to server | ||
39 | PKT_SETUP, // game information packet | ||
40 | PKT_GO, // game has started | ||
41 | PKT_TICC, // tics from client | ||
42 | PKT_TICS, // tics from server | ||
43 | PKT_RETRANS, // Request for retransmission | ||
44 | PKT_EXTRA, // Extra info packet | ||
45 | PKT_QUIT, // Player quit game | ||
46 | PKT_DOWN, // Server downed | ||
47 | PKT_WAD, // Wad file request | ||
48 | PKT_BACKOFF, // Request for client back-off | ||
49 | }; | ||
50 | |||
51 | typedef struct { | ||
52 | byte checksum; // Simple checksum of the entire packet | ||
53 | byte type; /* Type of packet */ | ||
54 | byte reserved[2]; /* Was random in prboom <=2.2.4, now 0 */ | ||
55 | unsigned tic; // Timestamp | ||
56 | } PACKEDATTR packet_header_t; | ||
57 | |||
58 | static inline void packet_set(packet_header_t* p, enum packet_type_e t, unsigned long tic) | ||
59 | { p->tic = doom_htonl(tic); p->type = t; p->reserved[0] = 0; p->reserved[1] = 0; } | ||
60 | |||
61 | #ifndef GAME_OPTIONS_SIZE | ||
62 | // From g_game.h | ||
63 | #define GAME_OPTIONS_SIZE 64 | ||
64 | #endif | ||
65 | |||
66 | struct setup_packet_s { | ||
67 | byte players, yourplayer, skill, episode, level, deathmatch, complevel, ticdup, extratic; | ||
68 | byte game_options[GAME_OPTIONS_SIZE]; | ||
69 | byte numwads; | ||
70 | byte wadnames[1]; // Actually longer | ||
71 | }; | ||
72 | |||
73 | /* cph - convert network byte stream to usable ticcmd_t and visa-versa | ||
74 | * - the functions are functionally identical apart from parameters | ||
75 | * - the void* param can be unaligned. By using void* as the parameter | ||
76 | * it means gcc won't assume alignment so won't make false assumptions | ||
77 | * when optimising. So I'm told. | ||
78 | */ | ||
79 | inline static void RawToTic(ticcmd_t* dst, const void* src) | ||
80 | { | ||
81 | memcpy(dst,src,sizeof *dst); | ||
82 | dst->angleturn = doom_ntohs(dst->angleturn); | ||
83 | dst->consistancy = doom_ntohs(dst->consistancy); | ||
84 | } | ||
85 | |||
86 | inline static void TicToRaw(void* dst, const ticcmd_t* src) | ||
87 | { | ||
88 | /* We have to make a copy of the source struct, then do byte swaps, | ||
89 | * and fnially copy to the destination (can't do the swaps in the | ||
90 | * destination, because it might not be aligned). | ||
91 | */ | ||
92 | ticcmd_t tmp = *src; | ||
93 | tmp.angleturn = doom_ntohs(tmp.angleturn); | ||
94 | tmp.consistancy = doom_ntohs(tmp.consistancy); | ||
95 | memcpy(dst,&tmp,sizeof tmp); | ||
96 | } | ||