Skip to content

Commit

Permalink
Refactor|Server: Cleanup, removed N_TerminateNode()
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 19, 2013
1 parent 71311da commit ff66582
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/src/network/net_event.cpp
Expand Up @@ -172,7 +172,7 @@ void N_NETicker(timespan_t time)
masterHeartbeat -= time;

// Update master every 2 minutes.
if(masterAware && App_ServerSystem().isRunning() && theMap && masterHeartbeat < 0)
if(masterAware && App_ServerSystem().isListening() && theMap && masterHeartbeat < 0)
{
masterHeartbeat = MASTER_HEARTBEAT;
N_MasterAnnounceServer(true);
Expand Down Expand Up @@ -292,7 +292,7 @@ void N_TerminateClient(int console)
Con_Message("N_TerminateClient: '%s' from console %i.\n",
clients[console].name, console);

N_TerminateNode(clients[console].nodeID);
App_ServerSystem().terminateNode(clients[console].nodeID);

// Update the master.
masterHeartbeat = MASTER_UPDATETIME;
Expand Down
18 changes: 14 additions & 4 deletions doomsday/server/include/serversystem.h
Expand Up @@ -21,28 +21,39 @@

#include <de/libdeng2.h>
#include <de/System>
#include "network/net_buf.h" // nodeid_t
#include "dd_types.h" // nodeid_t

/**
* Subsystem for tending to clients.
* @ingroup server
*
* @todo The entire concept of "nodes" should be retired along with
* LegacyNetwork. Instead:
* - Immediately after connecting to a server the socket is put into the
* set of connected sockets.
* - Sockets may request upgrade to Shell user, in which case ownership
* of the socket is given to a ShellUser instance.
* - Sockets may join the game, becoming clients.
* - Silent sockets that hang around too long will be automatically
* terminated if haven't joined the game.
*/
class ServerSystem : public de::System
{
public:
ServerSystem();

~ServerSystem();

/**
* Start listening for client connections.
* Start listening for incoming connections.
*
* @param port TCP port to listen on.
*/
void start(de::duint16 port);

void stop();

bool isRunning() const;
bool isListening() const;

/**
* The client is removed from the game immediately. This is used when the
Expand Down Expand Up @@ -75,7 +86,6 @@ ServerSystem &App_ServerSystem();
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);
Expand Down
20 changes: 6 additions & 14 deletions doomsday/server/src/serversystem.cpp
Expand Up @@ -20,6 +20,7 @@
#include "shellusers.h"
#include "server/sv_def.h"
#include "network/net_main.h"
#include "network/net_buf.h"
#include "network/net_event.h"
#include "network/monitor.h"
#include "con_main.h"
Expand Down Expand Up @@ -55,7 +56,7 @@ typedef struct netnode_s {
char name[256];

/// The node is owned by a client in the game. This becomes true
// when the client issues the JOIN request.
/// when the client issues the JOIN request.
boolean hasJoined;

/// This is the client's remote address.
Expand Down Expand Up @@ -212,8 +213,8 @@ DENG2_PIMPL(ServerSystem)
LegacyNetwork_SocketSet_Remove(sockSet, node->sock);
LegacyNetwork_SocketSet_Add(joinedSockSet, node->sock);

// @todo We should use more discretion with the name. It has
// been provided by an untrusted source.
/// @todo We should use more discretion with the name. It has
/// been provided by an untrusted source.
strncpy(node->name, name, sizeof(node->name) - 1);

// Inform the higher levels of this occurence.
Expand Down Expand Up @@ -553,7 +554,7 @@ void ServerSystem::stop()
d->deinit();
}

bool ServerSystem::isRunning() const
bool ServerSystem::isListening() const
{
return d->isStarted();
}
Expand Down Expand Up @@ -645,7 +646,7 @@ boolean N_ServerOpen(void)

boolean N_ServerClose(void)
{
if(!serverSys->isRunning()) return true;
if(!serverSys->isListening()) return true;

if(masterAware)
{
Expand All @@ -667,20 +668,11 @@ boolean N_ServerClose(void)
return true;
}

/**
* Called from "net info" (server-side).
*/
void N_PrintNetworkStatus(void)
{
serverSys->printStatus();
}

/// @todo Get rid of this.
void N_TerminateNode(nodeid_t id)
{
serverSys->terminateNode(id);
}

String N_GetNodeName(nodeid_t id)
{
return serverSys->nodeName(id);
Expand Down

0 comments on commit ff66582

Please sign in to comment.