1 /** @file d_net.h Common code related to net games. 2 * 3 * Connecting to/from a netgame server. Netgame events (player and world) and 4 * netgame commands. 5 * 6 * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 7 * @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net> 8 * 9 * @par License 10 * GPL: http://www.gnu.org/licenses/gpl.html 11 * 12 * <small>This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by the 14 * Free Software Foundation; either version 2 of the License, or (at your 15 * option) any later version. This program is distributed in the hope that it 16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 17 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 18 * Public License for more details. You should have received a copy of the GNU 19 * General Public License along with this program; if not, see: 20 * http://www.gnu.org/licenses</small> 21 */ 22 23 #ifndef LIBCOMMON_NETWORK_DEF_H 24 #define LIBCOMMON_NETWORK_DEF_H 25 26 #include "doomsday.h" 27 #include <de/reader.h> 28 #include <de/writer.h> 29 #ifdef __cplusplus 30 # include <de/String> 31 # include <doomsday/uri.h> 32 #endif 33 34 #define NETBUFFER_MAXMESSAGE 255 35 36 #ifdef __JHEXEN__ 37 #define PLR_COLOR(pl, x) (((unsigned)(x)) > 7? (pl) % 8 : (x)) 38 #else 39 #define PLR_COLOR(pl, x) (((unsigned)(x)) > 3? (pl) % 4 : (x)) 40 #endif 41 42 // This playerstate is used to signal that a player should be removed 43 // from the world (he has quit netgame). 44 #define PST_GONE 0x1000 45 46 // Game packet types. (DON'T CHANGE THESE) 47 enum { 48 GPT_GAME_STATE = DDPT_FIRST_GAME_EVENT, 49 GPT_WEAPON_FIRE, 50 GPT_PLANE_MOVE, 51 GPT_MESSAGE, // Non-chat messages. 52 GPT_CONSOLEPLAYER_STATE, 53 GPT_PLAYER_STATE, 54 GPT_PSPRITE_STATE, 55 GPT_SOUND, 56 GPT_SECTOR_SOUND, 57 GPT_FLOOR_MOVE_SOUND, 58 GPT_CEILING_MOVE_SOUND, 59 GPT_INTERMISSION, 60 GPT_RESERVED1, // Old GPT_FINALE, now handled by the engine. 61 GPT_PLAYER_INFO, 62 GPT_SAVE, 63 GPT_LOAD, 64 GPT_CLASS, // jHexen: player class notification. 65 GPT_CONSOLEPLAYER_STATE2, 66 GPT_PLAYER_STATE2, 67 GPT_YELLOW_MESSAGE, // jHexen: yellow message. 68 GPT_PAUSE, 69 GPT_RESERVED2, // Old GPT_FINALE2, now handled by the engine. 70 GPT_CHEAT_REQUEST, 71 GPT_JUMP_POWER, // Jump power (0 = no jumping) 72 GPT_ACTION_REQUEST, 73 GPT_PLAYER_SPAWN_POSITION, 74 GPT_DAMAGE_REQUEST, // Client requests damage on a target. 75 GPT_MOBJ_IMPULSE, // Momenum to apply on a mobj. 76 GPT_FLOOR_HIT_REQUEST, 77 GPT_MAYBE_CHANGE_WEAPON, // Server suggests weapon change. 78 GPT_FINALE_STATE, // State of the InFine script. 79 GPT_LOCAL_MOBJ_STATE, // Set a state on a mobj and enable local actions. 80 GPT_TOTAL_COUNTS, // Total kill, item, secret counts in the map. 81 GPT_DISMISS_HUDS // Hide client's automap, inventory (added in 1.15) 82 }; 83 84 #if 0 85 // This packet is sent by servers to clients when the game state 86 // changes. 87 typedef struct { 88 byte gameMode; 89 byte flags; 90 byte episode, map; 91 byte deathmatch:2; 92 byte monsters:1; 93 byte respawn:1; 94 byte jumping:1; 95 #if __JHEXEN__ 96 byte randomclass:1; 97 #endif 98 byte skill:3; 99 short gravity; // signed fixed-8.8 100 #if __JHEXEN__ 101 float damagemod; // netMobDamageModifier (UNUSED) 102 float healthmod; // netMobHealthModifier (UNUSED) 103 #elif __JSTRIFE__ 104 float damagemod; // netMobDamageModifier (UNUSED) 105 float healthmod; // netMobHealthModifier (UNUSED) 106 #endif 107 } packet_gamestate_t; 108 #endif 109 110 // Player action requests. 111 enum { 112 GPA_FIRE = 1, 113 GPA_USE = 2, 114 GPA_CHANGE_WEAPON = 3, 115 GPA_USE_FROM_INVENTORY = 4 116 }; 117 118 // Game state flags. 119 #define GSF_CHANGE_MAP 0x01 // Map has changed. 120 #define GSF_CAMERA_INIT 0x02 // After gamestate follows camera init. 121 #define GSF_DEMO 0x04 // Only valid during demo playback. 122 123 // Player state update flags. 124 #define PSF_STATE 0x0001 // Dead or alive / armor type. 125 #define PSF_ARMOR_TYPE 0x0001 // Upper four bits of the 1st byte. 126 #define PSF_HEALTH 0x0002 127 #define PSF_ARMOR_POINTS 0x0004 128 #define PSF_INVENTORY 0x0008 129 #define PSF_POWERS 0x0010 130 #define PSF_KEYS 0x0020 131 #define PSF_FRAGS 0x0040 132 #define PSF_VIEW_HEIGHT 0x0080 133 #define PSF_OWNED_WEAPONS 0x0100 134 #define PSF_AMMO 0x0200 135 #define PSF_MAX_AMMO 0x0400 136 #define PSF_COUNTERS 0x0800 // Kill, item and secret counts. 137 #define PSF_PENDING_WEAPON 0x1000 138 #define PSF_READY_WEAPON 0x2000 139 #define PSF_MORPH_TIME 0x4000 140 #define PSF_LOCAL_QUAKE 0x8000 141 142 // Player state update II flags. 143 #define PSF2_OWNED_WEAPONS 0x00000001 144 #define PSF2_STATE 0x00000002 // Includes cheatflags. 145 146 #if __JDOOM__ || __JDOOM64__ 147 #define PSF_REBORN 0x37f7 148 #endif 149 150 #ifdef __JHERETIC__ 151 #define PSF_REBORN 0x77ff 152 #endif 153 154 #ifdef __JHEXEN__ 155 #define PSF_ARMOR PSF_ARMOR_POINTS // For convenience. 156 #define PSF_WEAPONS (PSF_PENDING_WEAPON | PSF_READY_WEAPON) 157 #define PSF_REBORN 0xf7ff 158 #endif 159 160 // Intermission flags. 161 #define IMF_BEGIN 0x01 162 #define IMF_END 0x02 163 #define IMF_STATE 0x04 164 #define IMF_TIME 0x08 165 166 // Ticcmd flags. 167 #define CMDF_FORWARDMOVE 0x01 168 #define CMDF_SIDEMOVE 0x02 169 #define CMDF_ANGLE 0x04 170 #define CMDF_LOOKDIR 0x08 171 #define CMDF_BUTTONS 0x10 172 #define CMDF_LOOKFLY 0x20 173 #define CMDF_ARTI 0x40 174 #define CMDF_CHANGE_WEAPON 0x80 175 176 #define CMDF_BTN_ATTACK 0x01 177 #define CMDF_BTN_USE 0x02 178 #define CMDF_BTN_JUMP 0x04 179 #define CMDF_BTN_PAUSE 0x08 180 #define CMDF_BTN_SUICIDE 0x10 // Now ignored in ticcmds 181 182 // Console commands. 183 DENG_EXTERN_C ccmdtemplate_t netCCmds[]; 184 185 DENG_EXTERN_C float netJumpPower; 186 187 #ifdef __cplusplus 188 extern "C" { 189 #endif 190 191 Writer1 *D_NetWrite(void); 192 193 Reader1 *D_NetRead(byte const *buffer, size_t len); 194 195 void D_NetClearBuffer(void); 196 197 // Networking. 198 int D_NetServerOpen(int before); 199 200 /** 201 * Called when a network server closes. 202 * 203 * Duties include: 204 * Restoring global state variables 205 */ 206 int D_NetServerClose(int before); 207 208 /** 209 * Called when the network server starts. 210 * 211 * Duties include: 212 * Updating global state variables and initializing all players' settings 213 */ 214 int D_NetServerStarted(int before); 215 216 int D_NetConnect(int before); 217 218 int D_NetDisconnect(int before); 219 220 long int D_NetPlayerEvent(int plrNumber, int peType, void *data); 221 222 /** 223 * Issues a damage request when a client is trying to damage another player's mobj. 224 * 225 * @return @c true = no further processing of the damage should be done else, process the 226 * damage as normally. 227 */ 228 dd_bool D_NetDamageMobj(struct mobj_s *target, struct mobj_s *inflictor, struct mobj_s *source, int damage); 229 230 int D_NetWorldEvent(int type, int tic, void *data); 231 232 void D_HandlePacket(int fromplayer, int type, void *data, size_t length); 233 234 void *D_NetWriteCommands(int numCommands, void *data); 235 236 void *D_NetReadCommands(size_t pktLength, void *data); 237 238 /** 239 * Register the console commands and variables of the common netcode. 240 */ 241 void D_NetConsoleRegister(void); 242 243 /** 244 * Show message on screen and play chat sound. 245 * 246 * @param msg Ptr to the message to print. 247 */ 248 void D_NetMessage(int player, char const *msg); 249 250 /** 251 * Show message on screen. 252 * 253 * @param msg 254 */ 255 void D_NetMessageNoSound(int player, char const *msg); 256 257 #ifdef __cplusplus 258 } // extern "C" 259 260 de::String D_NetDefaultEpisode(); 261 de::Uri D_NetDefaultMap(); 262 #endif 263 264 #endif // LIBCOMMON_NETWORK_DEF_H 265