1 /** @file 2 * 3 * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 4 * @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net> 5 * 6 * @par License 7 * GPL: http://www.gnu.org/licenses/gpl.html 8 * 9 * <small>This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by the 11 * Free Software Foundation; either version 2 of the License, or (at your 12 * option) any later version. This program is distributed in the hope that it 13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 * Public License for more details. You should have received a copy of the GNU 16 * General Public License along with this program; if not, see: 17 * http://www.gnu.org/licenses</small> 18 */ 19 20 /** 21 * Network Subsystem. 22 */ 23 24 #ifndef LIBDENG_NETWORK_H 25 #define LIBDENG_NETWORK_H 26 27 #include <stdio.h> 28 #include "dd_share.h" 29 #include "net_msg.h" 30 #include <de/Record> 31 #include <de/smoother.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #define BIT(x) (1 << (x)) 38 39 #define NSP_BROADCAST -1 // For Net_SendBuffer. 40 41 // Flags for console text from the server. 42 // Change with server version? 43 #define SV_CONSOLE_PRINT_FLAGS (CPF_WHITE|CPF_LIGHT|CPF_GREEN) 44 45 // A modest acktime used by default for new clients (1 sec ping). 46 #define ACK_DEFAULT 1000 47 48 #define MONITORTICS 7 49 50 #define LOCALTICS 10 // Built ticcmds are stored here. 51 #define BACKUPTICS 70 // Two seconds worth of tics. 52 53 // The number of mobjs that can be stored in the input/visible buffer. 54 // The server won't send more mobjs than this. 55 #define MAX_CLMOBJS 80 56 57 #define DEFAULT_TCP_PORT 13209 58 #define DEFAULT_UDP_PORT 13209 59 60 typedef void (*expectedresponder_t)(int, const byte*, int); 61 62 // If a master action fails, the action queue is emptied. 63 typedef enum { 64 MAC_REQUEST, // Retrieve the list of servers from the master. 65 MAC_WAIT, // Wait for the server list to arrive. 66 MAC_LIST // Print the server list in the console. 67 } masteraction_t; 68 69 // Packet types. 70 // PKT = sent by anyone 71 // PSV = only sent by server 72 // PCL = only sent by client 73 enum { 74 // Messages and responses. 75 PCL_HELLO = 0, 76 PKT_OK = 1, 77 PKT_CANCEL = 2, // unused? 78 PKT_PLAYER_INFO = 3, 79 PKT_CHAT = 4, 80 PSV_FINALE = 5, 81 PKT_PING = 6, 82 PSV_HANDSHAKE = 7, 83 PSV_SERVER_CLOSE = 8, 84 PSV_FRAME = 9, // obsolete 85 PSV_PLAYER_EXIT = 10, 86 PSV_CONSOLE_TEXT = 11, 87 PCL_ACK_SHAKE = 12, 88 PSV_SYNC = 13, 89 PSV_MATERIAL_ARCHIVE = 14, 90 PCL_FINALE_REQUEST = 15, 91 PKT_LOGIN = 16, 92 PCL_ACK_SETS = 17, 93 PKT_COORDS = 18, 94 PKT_DEMOCAM = 19, 95 PKT_DEMOCAM_RESUME = 20, 96 PCL_HELLO2 = 21, // Includes game ID 97 PSV_FRAME2 = 22, // Frame packet v2 98 PSV_FIRST_FRAME2 = 23, // First PSV_FRAME2 after map change 99 PSV_SOUND2 = 24, // unused? 100 PSV_STOP_SOUND = 25, 101 PCL_ACKS = 26, 102 PSV_PLAYER_FIX_OBSOLETE = 27, // Fix angles/pos/mom (without console number). 103 PCL_ACK_PLAYER_FIX = 28, // Acknowledge player fix. /* 28 */ 104 PKT_COMMAND2 = 29, 105 PSV_PLAYER_FIX = 30, // Fix angles/pos/mom. 106 PCL_GOODBYE = 31, 107 PSV_MOBJ_TYPE_ID_LIST = 32, 108 PSV_MOBJ_STATE_ID_LIST = 33, 109 110 // Game specific events. 111 PKT_GAME_MARKER = DDPT_FIRST_GAME_EVENT, // 64 112 }; 113 114 // Use the number defined in dd_share.h for sound packets. 115 // This is for backwards compatibility. 116 #define PSV_SOUND 71 /* DDPT_SOUND */ 117 118 #define RESENDCOUNT 10 119 #define HANDSHAKECOUNT 17 120 //#define UPDATECOUNT 20 121 122 // These dd-flags are packed (i.e. included in mobj deltas). 123 #define DDMF_PACK_MASK 0x3cfff1ff 124 125 // A client's acknowledgement threshold depends on the average of his 126 // acknowledgement times. 127 #define NUM_ACK_TIMES 8 128 129 // The consolePlayer's camera position is written to the demo file 130 // every 3rd tic. 131 #define LOCALCAM_WRITE_TICS 3 132 133 // Maximum length of a token in the textual representation of 134 // serverinfo. 135 #define SVINFO_TOKEN_LEN 128 136 #define SVINFO_VALID_LABEL_LEN 16 137 138 extern char *serverName, *serverInfo, *playerName; 139 //extern int serverData[]; 140 141 extern dd_bool firstNetUpdate; 142 extern int resendStart; // set when server needs our tics 143 extern int resendCount; 144 extern int oldEnterTics; 145 extern int numClMobjs; 146 extern dd_bool serverPublic; 147 extern int netGame; 148 extern int realTics, availableTics; 149 extern int isServer, isClient; 150 extern dd_bool allowNetTraffic; // Should net traffic be allowed? 151 extern float netSimulatedLatencySeconds; 152 extern int gotFrame; 153 154 void Net_Register(void); 155 void Net_Init(void); 156 void Net_Shutdown(void); 157 dd_bool Net_GetPacket(void); 158 void Net_SendBuffer(int to_player, int sp_flags); 159 void Net_SendPlayerInfo(int srcPlrNum, int destPlrNum); 160 void Net_InitGame(void); 161 void Net_StartGame(void); 162 void Net_StopGame(void); 163 void Net_SendPing(int player, int count); 164 void Net_PingResponse(void); 165 void Net_ShowPingSummary(int player); 166 void Net_WriteChatMessage(int from, int toMask, const char* message); 167 void Net_ShowChatMessage(int plrNum, const char* message); 168 int Net_TimeDelta(byte now, byte then); 169 void Net_Update(void); 170 void Net_ResetTimer(void); 171 void Net_Ticker(timespan_t time); 172 173 /** 174 * Does drawing for the engine's HUD, not just the net. 175 */ 176 void Net_Drawer(void); 177 178 dd_bool Net_IsLocalPlayer(int pNum); 179 180 //void ServerInfo_Print(serverinfo_t const *info, int index); 181 182 /** 183 * Converts textual data to a serverinfo struct. Returns true if the 184 * label/value pair is recognized. 185 */ 186 //dd_bool ServerInfo_FromString(serverinfo_t *info, char const *valuePair); 187 188 //void ServerInfo_FromRecord(serverinfo_t *info, de::Record const &rec); 189 190 #ifdef __cplusplus 191 } // extern "C" 192 #endif 193 194 de::String Net_UserAgent(); 195 196 #endif /* LIBDENG_NETWORK_H */ 197