Skip to content

Commit

Permalink
Refactor: Began cleaning up network subsystem headers
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 18, 2013
1 parent ba850da commit a91be00
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 75 deletions.
3 changes: 3 additions & 0 deletions doomsday/api/dd_types.h
Expand Up @@ -49,6 +49,9 @@
# endif
#endif

/// Each network node is identified by a number.
typedef unsigned int nodeid_t;

/// @todo Should be a public typedef of a type defined by de::LumpIndex.
typedef int32_t lumpnum_t;
#define LUMPNAME_T_MAXLEN 9
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/de_network.h
Expand Up @@ -29,6 +29,7 @@
#include "network/net_msg.h"
#include "network/net_buf.h"
#include "network/protocol.h"
#include "network/monitor.h"

#ifdef __SERVER__
# include "server/sv_def.h"
Expand Down
6 changes: 5 additions & 1 deletion doomsday/client/include/de_system.h
Expand Up @@ -24,13 +24,17 @@
#include <de/timer.h>

#include "sys_system.h"
#include "network/sys_network.h"
#include "network/masterserver.h"

#ifdef __CLIENT__
# include "network/sys_network.h"
# include "gl/sys_opengl.h"
# include "ui/window.h"
# include "ui/sys_input.h"
#endif

#ifdef __SERVER__
# include "serversystem.h"
#endif

#endif /* LIBDENG_SYSTEM_H */
4 changes: 4 additions & 0 deletions doomsday/client/include/network/masterserver.h
Expand Up @@ -115,4 +115,8 @@ int N_MasterGet(int index, serverinfo_t *info);
} // extern "C"
#endif

extern char *masterAddress;
extern int masterPort;
extern char *masterPath;

#endif // LIBDENG_MASTER_SERVER_H
3 changes: 0 additions & 3 deletions doomsday/client/include/network/net_buf.h
Expand Up @@ -35,9 +35,6 @@ extern "C" {

#define NETBUFFER_MAXSIZE 0x7ffff // 512 KB

// Each network node is identified by a number.
typedef unsigned int nodeid_t;

// Incoming messages are stored in netmessage_s structs.
typedef struct netmessage_s {
struct netmessage_s *next;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/network/net_event.h
Expand Up @@ -25,6 +25,8 @@
#ifndef __DOOMSDAY_NETWORK_EVENT_H__
#define __DOOMSDAY_NETWORK_EVENT_H__

#include "net_main.h"

// Net events.
typedef enum neteventtype_e {
NE_CLIENT_ENTRY,
Expand Down
16 changes: 15 additions & 1 deletion doomsday/client/include/network/net_main.h
Expand Up @@ -27,7 +27,6 @@
#include <stdio.h>
#include "lzss.h"
#include "dd_share.h"
#include "sys_network.h"
#include "net_msg.h"
#include "map/p_mapdata.h"
#include <de/smoother.h>
Expand Down Expand Up @@ -62,6 +61,18 @@ extern "C" {
// 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
Expand Down Expand Up @@ -201,6 +212,9 @@ typedef struct {
int viewConsole;
} client_t;

extern char *serverName, *serverInfo, *playerName;
extern int serverData[];

extern boolean firstNetUpdate;
extern int resendStart; // set when server needs our tics
extern int resendCount;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/network/protocol.h
Expand Up @@ -21,7 +21,7 @@
#ifndef LIBDENG_NETWORK_PROTOCOL_H
#define LIBDENG_NETWORK_PROTOCOL_H

#include "sys_network.h"
//#include "sys_network.h"

/**
* Server protocol version number.
Expand Down
32 changes: 5 additions & 27 deletions doomsday/client/include/network/sys_network.h
Expand Up @@ -23,22 +23,15 @@
#ifndef LIBDENG_SYSTEM_NETWORK_H
#define LIBDENG_SYSTEM_NETWORK_H

#ifndef __CLIENT__
# error "sys_network.h requires __CLIENT__"
#endif

#include "dd_share.h"
#include "net_buf.h"
#include "net_main.h"
#include "monitor.h"

#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;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -49,13 +42,6 @@ extern int maxQueuePackets;
extern char *nptIPAddress;
extern int nptIPPort;

extern char *serverName, *serverInfo, *playerName;
extern int serverData[];

extern char *masterAddress;
extern int masterPort;
extern char *masterPath;

void N_Register(void);
void N_SystemInit(void);
void N_SystemShutdown(void);
Expand All @@ -70,16 +56,8 @@ boolean N_Connect(void);
boolean N_Disconnect(void);
#endif

#ifdef __SERVER__
boolean N_ServerOpen(void);
boolean N_ServerClose(void);
#endif

void N_TerminateNode(nodeid_t id);

int N_GetNodeSocket(nodeid_t id);
boolean N_HasNodeJoined(nodeid_t id);
//boolean N_GetNodeName(nodeid_t id, char *name);

int N_GetHostCount(void);
boolean N_GetHostInfo(int index, struct serverinfo_s *info);
Expand Down
7 changes: 2 additions & 5 deletions doomsday/client/src/network/net_event.cpp
Expand Up @@ -64,8 +64,10 @@ static int mqHead, mqTail;
static netevent_t netEventQueue[NETEVENT_QUEUE_LEN];
static int neqHead, neqTail;

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

// CODE --------------------------------------------------------------------

Expand Down Expand Up @@ -257,11 +259,6 @@ void N_Update(void)
#endif // __SERVER__

#ifdef __CLIENT__
case NE_TERMINATE_NODE:
// The server receives this event when a client's connection is broken.
N_TerminateNode(nevent.id);
break;

case NE_END_CONNECTION:
// A client receives this event when the connection is
// terminated.
Expand Down
4 changes: 1 addition & 3 deletions doomsday/client/src/network/protocol.cpp
Expand Up @@ -23,9 +23,7 @@
#include "de_platform.h"
#include "de_console.h"
#include "de_misc.h"

#include "network/protocol.h"
#include "network/sys_network.h"
#include "de_network.h"

boolean Protocol_Receive(nodeid_t from)
{
Expand Down
36 changes: 4 additions & 32 deletions doomsday/client/src/network/sys_network.cpp
Expand Up @@ -22,7 +22,7 @@

// HEADER FILES ------------------------------------------------------------

#ifdef __SERVER__
#ifndef __CLIENT__
# error "sys_network.cpp is only for __CLIENT__"
#endif

Expand All @@ -41,9 +41,7 @@
#include "dd_def.h"
#include "network/net_main.h"
#include "network/net_event.h"
#ifdef __CLIENT__
# include "network/net_demo.h"
#endif
#include "network/net_demo.h"
#include "network/protocol.h"
#include "client/cl_def.h"
#include "map/p_players.h"
Expand All @@ -52,7 +50,6 @@
#include <de/Socket>
#include <de/LegacyCore>
#include <de/LegacyNetwork>
#include <QCryptographicHash>

#define MAX_NODES 1

Expand Down Expand Up @@ -103,6 +100,7 @@ static foundhost_t located;
void N_Register(void)
{
C_VAR_CHARPTR("net-ip-address", &nptIPAddress, 0, 0, 0);
C_VAR_INT("net-ip-port", &nptIPPort, CVF_NO_MAX, 0, 0);

#ifdef _DEBUG
C_CMD("netfreq", NULL, NetFreqs);
Expand Down Expand Up @@ -130,7 +128,7 @@ void N_SystemShutdown(void)
if(netGame)
{
// We seem to be shutting down while a netGame is running.
Con_Execute(CMDS_DDAY, isServer ? "net server close" : "net disconnect", true, false);
Con_Execute(CMDS_DDAY, "net disconnect", true, false);
}

// Any queued messages will be destroyed.
Expand All @@ -148,11 +146,6 @@ void N_IPToString(char *buf, ipaddress_t *ip)
sprintf(buf, "%s:%i", ip->host, ip->port);
}

de::duint16 N_ServerPort()
{
return (!nptIPPort ? DEFAULT_TCP_PORT : nptIPPort);
}

boolean N_GetHostInfo(int index, struct serverinfo_s *info)
{
if(!located.valid || index != 0)
Expand Down Expand Up @@ -180,32 +173,13 @@ boolean N_HasNodeJoined(nodeid_t id)
return netNodes[id].hasJoined;
}

#if 0
/**
* Returns the player name associated with the given network node.
*/
String N_GetNodeName(nodeid_t id)
{
if(!netNodes[id].sock)
{
return "-unknown-";
}
return netNodes[id].name;
}
#endif

#ifdef __CLIENT__

void N_TerminateNode(nodeid_t id)
{
netnode_t *node = &netNodes[id];

if(!node->sock)
return; // There is nothing here...

// Remove the node from the set of active sockets.
//LegacyNetwork_SocketSet_Remove(sockSet, node->sock);

// Close the socket and forget everything about the node.
LegacyNetwork_Close(node->sock);
memset(node, 0, sizeof(*node));
Expand Down Expand Up @@ -495,5 +469,3 @@ void N_ListenNodes(void)
N_ClientListenUnjoined();
N_ClientListen();
}

#endif // __CLIENT__
2 changes: 1 addition & 1 deletion doomsday/server/include/server/sv_def.h
Expand Up @@ -23,7 +23,7 @@

#include "dd_def.h"
#include "network/protocol.h"
#include "network/sys_network.h"
//#include "network/sys_network.h"
#include <de/Record>

struct material_s;
Expand Down
11 changes: 10 additions & 1 deletion doomsday/server/include/serversystem.h
Expand Up @@ -71,6 +71,15 @@ class ServerSystem : public de::System
};

ServerSystem &App_ServerSystem();
void Server_Register(); // old-fashioned cvars

void Server_Register(); // old-fashioned cvars
boolean N_ServerOpen(void);
boolean N_ServerClose(void);
void N_TerminateNode(nodeid_t id);
int N_GetNodeSocket(nodeid_t id);
boolean N_HasNodeJoined(nodeid_t id);
void N_PrintNetworkStatus(void);

extern int nptIPPort; // cvar

#endif // SERVERSYSTEM_H
1 change: 1 addition & 0 deletions doomsday/server/src/serversystem.cpp
Expand Up @@ -21,6 +21,7 @@
#include "server/sv_def.h"
#include "network/net_main.h"
#include "network/net_event.h"
#include "network/monitor.h"
#include "con_main.h"
#include "map/gamemap.h"
#include "map/p_players.h"
Expand Down

0 comments on commit a91be00

Please sign in to comment.