From 348f9ae68c8ec5ca50eb2705e37e08dc2b3535e1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 27 Sep 2020 12:23:22 +0200 Subject: [PATCH] - moved i_net into 'common' to bring it in line with Raze. --- src/CMakeLists.txt | 2 +- src/{ => common/engine}/i_net.cpp | 43 ++++++++++++---- src/common/engine/i_net.h | 85 +++++++++++++++++++++++++++++++ src/d_main.cpp | 5 ++ src/d_net.cpp | 1 - src/d_net.h | 62 +--------------------- src/g_game.cpp | 3 -- src/i_net.h | 8 --- 8 files changed, 125 insertions(+), 84 deletions(-) rename src/{ => common/engine}/i_net.cpp (95%) create mode 100644 src/common/engine/i_net.h delete mode 100644 src/i_net.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f81705436..bc9181f2c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -844,7 +844,6 @@ set (PCH_SOURCES gameconfigfile.cpp gitinfo.cpp hu_scores.cpp - i_net.cpp m_cheat.cpp m_misc.cpp playsim/p_acs.cpp @@ -1115,6 +1114,7 @@ set (PCH_SOURCES common/engine/sc_man.cpp common/engine/palettecontainer.cpp common/engine/stringtable.cpp + common/engine/i_net.cpp common/engine/i_interface.cpp common/engine/renderstyle.cpp common/engine/v_colortables.cpp diff --git a/src/i_net.cpp b/src/common/engine/i_net.cpp similarity index 95% rename from src/i_net.cpp rename to src/common/engine/i_net.cpp index f90cae6fc..06058691a 100644 --- a/src/i_net.cpp +++ b/src/common/engine/i_net.cpp @@ -1,7 +1,9 @@ +// Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit +// $Id: i_net.c,v 1.2 1997/12/29 19:50:54 pekangas Exp $ +// +// Copyright (C) 1993-1996 by id Software, Inc. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -16,7 +18,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see http://www.gnu.org/licenses/ // -//----------------------------------------------------------------------------- +// +// +// Alternatively the following applies: +// +// This source is available for distribution and/or modification +// only under the terms of the DOOM Source Code License as +// published by id Software. All rights reserved. +// +// The source is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License +// for more details. +// // // DESCRIPTION: // Low-level networking code. Uses BSD sockets for UDP networking. @@ -53,16 +67,15 @@ # endif #endif -#include "doomtype.h" #include "i_system.h" -#include "d_net.h" #include "m_argv.h" #include "m_crc32.h" -#include "d_player.h" #include "st_start.h" -#include "m_misc.h" #include "engineerrors.h" #include "cmdlib.h" +#include "printf.h" +#include "i_interface.h" +#include "templates.h" #include "i_net.h" @@ -91,6 +104,10 @@ typedef int SOCKET; typedef int socklen_t; #endif +bool netgame, multiplayer; +int consoleplayer; // i.e. myconnectindex in Build. +doomcom_t doomcom; + // // NETWORKING // @@ -143,6 +160,12 @@ struct PreGamePacket uint8_t TransmitBuffer[TRANSMIT_SIZE]; +FString GetPlayerName(int num) +{ + if (sysCallbacks && sysCallbacks->GetPlayerName) return sysCallbacks->GetPlayerName(sendplayer[num]); + else return FStringf("Player %d", num + 1); +} + // // UDPsocket // @@ -272,12 +295,12 @@ void PacketGet (void) if (StartScreen != NULL) { StartScreen->NetMessage ("The connection from %s was dropped.\n", - players[sendplayer[node]].userinfo.GetName()); + GetPlayerName(node).GetChars()); } else { Printf("The connection from %s was dropped.\n", - players[sendplayer[node]].userinfo.GetName()); + GetPlayerName(node).GetChars()); } doomcom.data[0] = 0x80; // NCMD_EXIT @@ -945,7 +968,7 @@ int I_InitNetwork (void) v = Args->CheckValue ("-dup"); if (v) { - doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP); + doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP); } else { diff --git a/src/common/engine/i_net.h b/src/common/engine/i_net.h new file mode 100644 index 000000000..e50955295 --- /dev/null +++ b/src/common/engine/i_net.h @@ -0,0 +1,85 @@ +#ifndef __I_NET_H__ +#define __I_NET_H__ + +#include + +// Called by D_DoomMain. +int I_InitNetwork (void); +void I_NetCmd (void); + +enum ENetConstants +{ + MAXNETNODES = 8, // max computers in a game + DOOMCOM_ID = 0x12345678, + BACKUPTICS = 36, // number of tics to remember + MAXTICDUP = 5, + LOCALCMDTICS =(BACKUPTICS*MAXTICDUP), + MAX_MSGLEN = 14000, + + CMD_SEND = 1, + CMD_GET = 2, +}; + +// [RH] +// New generic packet structure: +// +// Header: +// One byte with following flags. +// One byte with starttic +// One byte with master's maketic (master -> slave only!) +// If NCMD_RETRANSMIT set, one byte with retransmitfrom +// If NCMD_XTICS set, one byte with number of tics (minus 3, so theoretically up to 258 tics in one packet) +// If NCMD_QUITTERS, one byte with number of players followed by one byte with each player's consolenum +// If NCMD_MULTI, one byte with number of players followed by one byte with each player's consolenum +// - The first player's consolenum is not included in this list, because it always matches the sender +// +// For each tic: +// Two bytes with consistancy check, followed by tic data +// +// Setup packets are different, and are described just before D_ArbitrateNetStart(). + +enum ENCMD +{ + NCMD_EXIT = 0x80, + NCMD_RETRANSMIT = 0x40, + NCMD_SETUP = 0x20, + NCMD_MULTI = 0x10, // multiple players in this packet + NCMD_QUITTERS = 0x08, // one or more players just quit (packet server only) + NCMD_COMPRESSED = 0x04, // remainder of packet is compressed + + NCMD_XTICS = 0x03, // packet contains >2 tics + NCMD_2TICS = 0x02, // packet contains 2 tics + NCMD_1TICS = 0x01, // packet contains 1 tic + NCMD_0TICS = 0x00, // packet contains 0 tics +}; + +// +// Network packet data. +// +struct doomcom_t +{ + uint32_t id; // should be DOOMCOM_ID + int16_t intnum; // DOOM executes an int to execute commands + +// communication between DOOM and the driver + int16_t command; // CMD_SEND or CMD_GET + int16_t remotenode; // dest for send, set by get (-1 = no packet). + int16_t datalength; // bytes in data to be sent + +// info common to all nodes + int16_t numnodes; // console is always node 0. + int16_t ticdup; // 1 = no duplication, 2-5 = dup for slow nets + +// info specific to this node + int16_t consoleplayer; + int16_t numplayers; + +// packet data to be sent + uint8_t data[MAX_MSGLEN]; + +}; + +extern doomcom_t doomcom; +extern bool netgame, multiplayer; + +#endif diff --git a/src/d_main.cpp b/src/d_main.cpp index b8c0675ea..d168c829b 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2830,6 +2830,10 @@ FString System_GetLocationDescription() } +FString System_GetPlayerName(int node) +{ + return players[node].userinfo.GetName(); +} //========================================================================== // // DoomSpecificInfo @@ -3071,6 +3075,7 @@ static int D_DoomMain_Internal (void) System_GetSceneRect, System_GetLocationDescription, System_M_Dim, + System_GetPlayerName, }; sysCallbacks = &syscb; diff --git a/src/d_net.cpp b/src/d_net.cpp index 22b2e9a2e..d41285f63 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -82,7 +82,6 @@ extern FString savegamefile; extern short consistancy[MAXPLAYERS][BACKUPTICS]; -doomcom_t doomcom; #define netbuffer (doomcom.data) enum { NET_PeerToPeer, NET_PacketServer }; diff --git a/src/d_net.h b/src/d_net.h index 352a01eb2..309ea4d34 100644 --- a/src/d_net.h +++ b/src/d_net.h @@ -31,67 +31,7 @@ #include "doomtype.h" #include "doomdef.h" #include "d_protocol.h" - - -// -// Network play related stuff. -// There is a data struct that stores network -// communication related stuff, and another -// one that defines the actual packets to -// be transmitted. -// - -#define DOOMCOM_ID 0x12345678l -#define MAXNETNODES 8 // max computers in a game -#define BACKUPTICS 36 // number of tics to remember -#define MAXTICDUP 5 -#define LOCALCMDTICS (BACKUPTICS*MAXTICDUP) - - -#ifdef DJGPP -// The DOS drivers provide a pretty skimpy buffer. -// Probably not enough. -#define MAX_MSGLEN (BACKUPTICS*10) -#else -#define MAX_MSGLEN 14000 -#endif - -#define CMD_SEND 1 -#define CMD_GET 2 - -// -// Network packet data. -// -struct doomcom_t -{ - uint32_t id; // should be DOOMCOM_ID - int16_t intnum; // DOOM executes an int to execute commands - -// communication between DOOM and the driver - int16_t command; // CMD_SEND or CMD_GET - int16_t remotenode; // dest for send, set by get (-1 = no packet). - int16_t datalength; // bytes in doomdata to be sent - -// info common to all nodes - int16_t numnodes; // console is always node 0. - int16_t ticdup; // 1 = no duplication, 2-5 = dup for slow nets -#ifdef DJGPP - int16_t pad[5]; // keep things aligned for DOS drivers -#endif - -// info specific to this node - int16_t consoleplayer; - int16_t numplayers; -#ifdef DJGPP - int16_t angleoffset; // does not work, but needed to preserve - int16_t drone; // alignment for DOS drivers -#endif - -// packet data to be sent - uint8_t data[MAX_MSGLEN]; - -}; - +#include "i_net.h" class FDynamicBuffer { diff --git a/src/g_game.cpp b/src/g_game.cpp index 5b991de39..515686cdb 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -155,13 +155,10 @@ bool noblit; // for comparative timing purposes bool viewactive; -bool netgame; // only true if packets are broadcast -bool multiplayer; bool multiplayernext = false; // [SP] Map coop/dm implementation player_t players[MAXPLAYERS]; bool playeringame[MAXPLAYERS]; -int consoleplayer; // player taking events int gametic; time_t epochoffset = 0; // epoch start in seconds (0 = January 1st, 1970) diff --git a/src/i_net.h b/src/i_net.h deleted file mode 100644 index 63b91c63d..000000000 --- a/src/i_net.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __I_NET_H__ -#define __I_NET_H__ - -// Called by D_DoomMain. -int I_InitNetwork (void); -void I_NetCmd (void); - -#endif