1 // Emacs style mode select -*- C++ -*- 2 //----------------------------------------------------------------------------- 3 // 4 // $Id:$ 5 // 6 // Copyright (C) 1993-1996 by id Software, Inc. 7 // 8 // This source is available for distribution and/or modification 9 // only under the terms of the DOOM Source Code License as 10 // published by id Software. All rights reserved. 11 // 12 // The source is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 // for more details. 16 // 17 // DESCRIPTION: 18 // Networking stuff. 19 // 20 //----------------------------------------------------------------------------- 21 22 23 #ifndef __D_NET__ 24 #define __D_NET__ 25 26 #include "doomtype.h" 27 #include "doomdef.h" 28 #include "d_ticcmd.h" 29 30 31 // 32 // Network play related stuff. 33 // There is a data struct that stores network 34 // communication related stuff, and another 35 // one that defines the actual packets to 36 // be transmitted. 37 // 38 39 #define DOOMCOM_ID 0x12345678l 40 #define MAXNETNODES 8 // max computers in a game 41 #define BACKUPTICS 36 // number of tics to remember 42 #define MAXTICDUP 5 43 #define LOCALCMDTICS (BACKUPTICS*MAXTICDUP) 44 45 46 #ifdef DJGPP 47 // The DOS drivers provide a pretty skimpy buffer. 48 // Probably not enough. 49 #define MAX_MSGLEN (BACKUPTICS*10) 50 #else 51 #define MAX_MSGLEN 14000 52 #endif 53 54 #define CMD_SEND 1 55 #define CMD_GET 2 56 57 // 58 // Network packet data. 59 // 60 struct doomcom_t 61 { 62 DWORD id; // should be DOOMCOM_ID 63 SWORD intnum; // DOOM executes an int to execute commands 64 65 // communication between DOOM and the driver 66 SWORD command; // CMD_SEND or CMD_GET 67 SWORD remotenode; // dest for send, set by get (-1 = no packet). 68 SWORD datalength; // bytes in doomdata to be sent 69 70 // info common to all nodes 71 SWORD numnodes; // console is always node 0. 72 SWORD ticdup; // 1 = no duplication, 2-5 = dup for slow nets 73 #ifdef DJGPP 74 SWORD pad[5]; // keep things aligned for DOS drivers 75 #endif 76 77 // info specific to this node 78 SWORD consoleplayer; 79 SWORD numplayers; 80 #ifdef DJGPP 81 SWORD angleoffset; // does not work, but needed to preserve 82 SWORD drone; // alignment for DOS drivers 83 #endif 84 85 // packet data to be sent 86 BYTE data[MAX_MSGLEN]; 87 88 }; 89 90 91 class FDynamicBuffer 92 { 93 public: 94 FDynamicBuffer (); 95 ~FDynamicBuffer (); 96 97 void SetData (const BYTE *data, int len); 98 BYTE *GetData (int *len = NULL); 99 100 private: 101 BYTE *m_Data; 102 int m_Len, m_BufferLen; 103 }; 104 105 extern FDynamicBuffer NetSpecs[MAXPLAYERS][BACKUPTICS]; 106 107 // Create any new ticcmds and broadcast to other players. 108 void NetUpdate (void); 109 110 // Broadcasts special packets to other players 111 // to notify of game exit 112 void D_QuitNetGame (void); 113 114 //? how many ticks to run? 115 void TryRunTics (void); 116 117 //Use for checking to see if the netgame has stalled 118 void Net_CheckLastReceived(int); 119 120 // [RH] Functions for making and using special "ticcmds" 121 void Net_NewMakeTic (); 122 void Net_WriteByte (BYTE); 123 void Net_WriteWord (short); 124 void Net_WriteLong (int); 125 void Net_WriteFloat (float); 126 void Net_WriteString (const char *); 127 void Net_WriteBytes (const BYTE *, int len); 128 129 void Net_DoCommand (int type, BYTE **stream, int player); 130 void Net_SkipCommand (int type, BYTE **stream); 131 132 void Net_ClearBuffers (); 133 134 135 // Netgame stuff (buffers and pointers, i.e. indices). 136 137 // This is the interface to the packet driver, a separate program 138 // in DOS, but just an abstraction here. 139 extern doomcom_t doomcom; 140 141 extern struct ticcmd_t localcmds[LOCALCMDTICS]; 142 143 extern int maketic; 144 extern int nettics[MAXNETNODES]; 145 extern int netdelay[MAXNETNODES][BACKUPTICS]; 146 extern int nodeforplayer[MAXPLAYERS]; 147 148 extern ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS]; 149 extern int ticdup; 150 151 // [RH] 152 // New generic packet structure: 153 // 154 // Header: 155 // One byte with following flags. 156 // One byte with starttic 157 // One byte with master's maketic (master -> slave only!) 158 // If NCMD_RETRANSMIT set, one byte with retransmitfrom 159 // If NCMD_XTICS set, one byte with number of tics (minus 3, so theoretically up to 258 tics in one packet) 160 // If NCMD_QUITTERS, one byte with number of players followed by one byte with each player's consolenum 161 // If NCMD_MULTI, one byte with number of players followed by one byte with each player's consolenum 162 // - The first player's consolenum is not included in this list, because it always matches the sender 163 // 164 // For each tic: 165 // Two bytes with consistancy check, followed by tic data 166 // 167 // Setup packets are different, and are described just before D_ArbitrateNetStart(). 168 169 #define NCMD_EXIT 0x80 170 #define NCMD_RETRANSMIT 0x40 171 #define NCMD_SETUP 0x20 172 #define NCMD_MULTI 0x10 // multiple players in this packet 173 #define NCMD_QUITTERS 0x08 // one or more players just quit (packet server only) 174 #define NCMD_COMPRESSED 0x04 // remainder of packet is compressed 175 176 #define NCMD_XTICS 0x03 // packet contains >2 tics 177 #define NCMD_2TICS 0x02 // packet contains 2 tics 178 #define NCMD_1TICS 0x01 // packet contains 1 tic 179 #define NCMD_0TICS 0x00 // packet contains 0 tics 180 181 #endif 182