Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Breaking up net_main and parts of the old network subsystem. Lots of ancient cruft here.
  • Loading branch information
skyjake committed Jul 17, 2020
1 parent 1b32ca8 commit 84e6ce9
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 493 deletions.
26 changes: 0 additions & 26 deletions doomsday/apps/api/dd_share.h
Expand Up @@ -804,32 +804,6 @@ enum {
};
///@}

/*
* Information about a multiplayer server. @ingroup network
*
* This structure is not sent over the network. The information is only sent either
* as plain text or as a serialized Record.
*/
/*typedef struct serverinfo_s {
int version;
char name[64];
char description[80];
int numPlayers, maxPlayers;
char canJoin;
char address[64];
int port;
unsigned short ping; ///< Milliseconds.
char plugin[32]; ///< Game plugin and version.
char gameIdentityKey[17];
char gameConfig[40];
char map[20];
char clientNames[128];
unsigned int loadedFilesCRC;
char iwad[32]; ///< Obsolete.
char pwads[128];
int data[3];
} serverinfo_t;*/

/**
* @defgroup netPackets Network Packets
* @ingroup network
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/network/net_buf.h
Expand Up @@ -54,7 +54,7 @@ typedef struct {
#pragma pack()

typedef struct netbuffer_s {
int player; // Recipient or sender.
int player; // Recipient or sender (can be NSP_BROADCAST).
size_t length; // Number of bytes in the data buffer.
size_t headerLength; // 1 byte at the moment.

Expand Down
4 changes: 4 additions & 0 deletions doomsday/apps/client/include/network/net_demo.h
Expand Up @@ -28,6 +28,10 @@
# error Demos are not available in a SERVER build
#endif

// The consolePlayer's camera position is written to the demo file
// every 3rd tic.
#define LOCALCAM_WRITE_TICS 3

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
17 changes: 10 additions & 7 deletions doomsday/apps/client/include/network/net_event.h
Expand Up @@ -31,15 +31,20 @@
typedef enum neteventtype_e {
NE_CLIENT_ENTRY,
NE_CLIENT_EXIT,
//NE_END_CONNECTION
//NE_TERMINATE_NODE
} neteventtype_t;

typedef struct netevent_s {
neteventtype_t type;
nodeid_t id;
} netevent_t;

// If a master action fails, the action queue is emptied.
typedef enum {
MAC_REQUEST, // Retrieve the list of servers from the master.
MAC_WAIT, // Wait for the server list to arrive.
MAC_LIST // Print the server list in the console.
} masteraction_t;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -48,12 +53,10 @@ void N_MAPost(masteraction_t act);
dd_bool N_MADone(void);
void N_MAClear(void);

void N_NEPost(netevent_t * nev);
void N_NEPost(netevent_t *nev);
dd_bool N_NEPending(void);
void N_NETicker(timespan_t time);

void N_TerminateClient(int console);
void N_Update(void);
dd_bool N_NEGet(netevent_t *nev);
void N_NETicker(void);

#ifdef __cplusplus
} // extern "C"
Expand Down
104 changes: 2 additions & 102 deletions doomsday/apps/client/include/network/net_main.h
Expand Up @@ -34,107 +34,8 @@
extern "C" {
#endif

#define BIT(x) (1 << (x))

#define NSP_BROADCAST -1 // For Net_SendBuffer.

// Flags for console text from the server.
// Change with server version?
#define SV_CONSOLE_PRINT_FLAGS (CPF_WHITE|CPF_LIGHT|CPF_GREEN)

// A modest acktime used by default for new clients (1 sec ping).
#define ACK_DEFAULT 1000

#define MONITORTICS 7

#define LOCALTICS 10 // Built ticcmds are stored here.
#define BACKUPTICS 70 // Two seconds worth of tics.

// The number of mobjs that can be stored in the input/visible buffer.
// The server won't send more mobjs than this.
#define MAX_CLMOBJS 80

#define DEFAULT_TCP_PORT 13209
#define DEFAULT_UDP_PORT 13209

typedef void (*expectedresponder_t)(int, const byte*, int);

// If a master action fails, the action queue is emptied.
typedef enum {
MAC_REQUEST, // Retrieve the list of servers from the master.
MAC_WAIT, // Wait for the server list to arrive.
MAC_LIST // Print the server list in the console.
} masteraction_t;

// Packet types.
// PKT = sent by anyone
// PSV = only sent by server
// PCL = only sent by client
enum {
// Messages and responses.
PCL_HELLO = 0,
PKT_OK = 1,
PKT_CANCEL = 2, // unused?
PKT_PLAYER_INFO = 3,
PKT_CHAT = 4,
PSV_FINALE = 5,
PKT_PING = 6,
PSV_HANDSHAKE = 7,
PSV_SERVER_CLOSE = 8,
PSV_FRAME = 9, // obsolete
PSV_PLAYER_EXIT = 10,
PSV_CONSOLE_TEXT = 11,
PCL_ACK_SHAKE = 12,
PSV_SYNC = 13,
PSV_MATERIAL_ARCHIVE = 14,
PCL_FINALE_REQUEST = 15,
PKT_LOGIN = 16,
PCL_ACK_SETS = 17,
PKT_COORDS = 18,
PKT_DEMOCAM = 19,
PKT_DEMOCAM_RESUME = 20,
PCL_HELLO2 = 21, // Includes game ID
PSV_FRAME2 = 22, // Frame packet v2
PSV_FIRST_FRAME2 = 23, // First PSV_FRAME2 after map change
PSV_SOUND2 = 24, // unused?
PSV_STOP_SOUND = 25,
PCL_ACKS = 26,
PSV_PLAYER_FIX_OBSOLETE = 27, // Fix angles/pos/mom (without console number).
PCL_ACK_PLAYER_FIX = 28, // Acknowledge player fix. /* 28 */
PKT_COMMAND2 = 29,
PSV_PLAYER_FIX = 30, // Fix angles/pos/mom.
PCL_GOODBYE = 31,
PSV_MOBJ_TYPE_ID_LIST = 32,
PSV_MOBJ_STATE_ID_LIST = 33,

// Game specific events.
PKT_GAME_MARKER = DDPT_FIRST_GAME_EVENT, // 64
};

// Use the number defined in dd_share.h for sound packets.
// This is for backwards compatibility.
#define PSV_SOUND 71 /* DDPT_SOUND */

#define RESENDCOUNT 10
#define HANDSHAKECOUNT 17
//#define UPDATECOUNT 20

// These dd-flags are packed (i.e. included in mobj deltas).
#define DDMF_PACK_MASK 0x3cfff1ff

// A client's acknowledgement threshold depends on the average of his
// acknowledgement times.
#define NUM_ACK_TIMES 8

// The consolePlayer's camera position is written to the demo file
// every 3rd tic.
#define LOCALCAM_WRITE_TICS 3

// Maximum length of a token in the textual representation of
// serverinfo.
#define SVINFO_TOKEN_LEN 128
#define SVINFO_VALID_LABEL_LEN 16

typedef struct netstate_s
{
dd_bool firstUpdate;
Expand Down Expand Up @@ -164,9 +65,8 @@ void Net_ShowChatMessage(int plrNum, const char* message);
int Net_TimeDelta(byte now, byte then);
void Net_Update(void);
void Net_ResetTimer(void);
void Net_Ticker(timespan_t time);

dd_bool Net_IsLocalPlayer(int pNum);
void Net_Ticker(void);
dd_bool Net_IsLocalPlayer(int pNum);

#ifdef __cplusplus
} // extern "C"
Expand Down
5 changes: 3 additions & 2 deletions doomsday/apps/client/src/client/cl_infine.cpp
Expand Up @@ -19,12 +19,13 @@

#include "de_base.h"
#include "client/cl_infine.h"

#include <de/legacy/memory.h>
#include "network/net_main.h"
#include "network/net_msg.h"
#include "ui/infine/finaleinterpreter.h"

#include <doomsday/network/protocol.h>
#include <de/legacy/memory.h>

static finaleid_t currentFinale;
static finaleid_t remoteFinale;

Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/client/src/client/cl_player.cpp
Expand Up @@ -21,6 +21,7 @@
#include "client/cl_player.h"
#include "api_client.h"
#include "network/net_main.h"
#include "network/net_demo.h"
#include "world/map.h"
#include "world/p_players.h"
#include <doomsday/network/protocol.h>
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/client/src/dd_loop.cpp
Expand Up @@ -248,7 +248,7 @@ static void baseTicker(timespan_t time)
DoomsdayApp::plugins().callAllHooks(HOOK_TICKER, 0, &time);

// The netcode gets to tick, too.
Net_Ticker(time);
Net_Ticker();
}

/**
Expand Down Expand Up @@ -378,7 +378,6 @@ timespan_t DD_CurrentTickDuration()
void Loop_RunTics()
{
// Do a network update first.
N_Update();
Net_Update();

// Check the clock.
Expand Down
86 changes: 1 addition & 85 deletions doomsday/apps/client/src/network/base/net_event.cpp
Expand Up @@ -39,8 +39,6 @@ using namespace de;

#define MASTER_QUEUE_LEN 16
#define NETEVENT_QUEUE_LEN 32
#define MASTER_HEARTBEAT 120 ///< seconds.
#define MASTER_UPDATETIME 3 ///< seconds.

// The master action queue.
static masteraction_t masterQueue[MASTER_QUEUE_LEN];
Expand All @@ -50,11 +48,6 @@ static dint mqHead, mqTail;
static netevent_t netEventQueue[NETEVENT_QUEUE_LEN];
static dint neqHead, neqTail;

#ifdef __SERVER__
// Countdown for master updates.
static timespan_t masterHeartbeat;
#endif

/**
* Add a master action command to the queue. The master action stuff really
* doesn't belong in this file...
Expand Down Expand Up @@ -148,27 +141,8 @@ dd_bool N_NEGet(netevent_t *nev)
/**
* Handles low-level net tick stuff: communication with the master server.
*/
void N_NETicker(timespan_t time)
void N_NETicker(void)
{
#if !defined(__SERVER__)
DE_UNUSED(time);
#endif

#ifdef __SERVER__
if(netState.netGame)
{
::masterHeartbeat -= time;

// Update master periodically.
if(::serverPublic && App_ServerSystem().isListening() &&
world::World::get().hasMap() && ::masterHeartbeat < 0)
{
::masterHeartbeat = MASTER_HEARTBEAT;
N_MasterAnnounceServer(true);
}
}
#endif

// Is there a master action to worry about?
masteraction_t act;
if(N_MAGet(&act))
Expand Down Expand Up @@ -207,61 +181,3 @@ void N_NETicker(timespan_t time)
}
}
}

/**
* The event list is checked for arrivals and exits, and the 'clients' and 'players'
* arrays are updated accordingly.
*/
void N_Update()
{
#ifdef __SERVER__
netevent_t nevent;

// Are there any events to process?
while(N_NEGet(&nevent))
{
switch(nevent.type)
{
case NE_CLIENT_ENTRY: {
// Assign a console to the new player.
Sv_PlayerArrives(nevent.id, App_ServerSystem().user(nevent.id).name());

// Update the master.
::masterHeartbeat = MASTER_UPDATETIME;
break; }

case NE_CLIENT_EXIT:
Sv_PlayerLeaves(nevent.id);

// Update the master.
::masterHeartbeat = MASTER_UPDATETIME;
break;

default: DE_ASSERT_FAIL("N_Update: Invalid value"); break;
}
}
#endif // __SERVER__
}

/**
* The client is removed from the game without delay. This is used when the server
* needs to terminate a client's connection abnormally.
*/
void N_TerminateClient(dint console)
{
#ifdef __SERVER__
DE_ASSERT(console >= 0 && console < DDMAXPLAYERS);
if(!DD_Player(console)->isConnected())
return;

LOG_NET_NOTE("Terminating connection to console %i (player '%s')")
<< console << DD_Player(console)->name;

App_ServerSystem().terminateNode(DD_Player(console)->remoteUserId);

// Update the master.
::masterHeartbeat = MASTER_UPDATETIME;
#else
DE_UNUSED(console);
#endif
}

0 comments on commit 84e6ce9

Please sign in to comment.