Skip to content

Commit

Permalink
Server: Use a Beacon to announce presence of a server locally
Browse files Browse the repository at this point in the history
The beacon is supplied with an up-to-date serverinfo_t so that clients
can immediately know what is going on at the server.
  • Loading branch information
skyjake committed Feb 4, 2013
1 parent ad456a2 commit 85d4cb4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions doomsday/client/src/network/sys_network.cpp
Expand Up @@ -43,6 +43,9 @@
#ifdef __SERVER__
# include "server/sv_def.h"
# include "shellusers.h"
# include "map/gamemap.h"
# include <de/Beacon>
# include <de/ByteRefArray>
#endif
#include "network/protocol.h"
#include "client/cl_def.h"
Expand Down Expand Up @@ -101,6 +104,11 @@ static int sockSet;
static int joinedSockSet;
static foundhost_t located;

#ifdef __SERVER__
// Beacon for informing clients that a server is present.
static de::Beacon beacon(53209);
#endif

void N_Register(void)
{
C_VAR_CHARPTR("net-ip-address", &nptIPAddress, 0, 0, 0);
Expand Down Expand Up @@ -451,6 +459,10 @@ boolean N_ServerOpen(void)
// Let the master server know that we are running a public server.
N_MasterAnnounceServer(true);
}

// Start the beacon.
beacon.start();

return true;
}

Expand All @@ -459,6 +471,9 @@ boolean N_ServerClose(void)
if(!N_IsAvailable())
return false;

// Stop the beacon.
beacon.stop();

if(masterAware && N_UsingInternet())
{
// Bye-bye, master server.
Expand Down Expand Up @@ -707,8 +722,25 @@ void N_PrintNetworkStatus(void)
Con_Message(" port for hosting games (net-ip-port): %i\n", Con_GetInteger("net-ip-port"));
}

void N_ServerUpdateBeacon()
{
// Update the status message in the server's presence beacon.
if(serverSock && theMap)
{
serverinfo_t info;
Sv_GetInfo(&info);

QScopedPointer<de::Record> rec(Sv_InfoToRecord(&info));
de::Block msg;
de::Writer(msg).withHeader() << *rec;
beacon.setMessage(msg);
}
}

void N_ListenNodes(void)
{
N_ServerUpdateBeacon();

// This is only for the server.
N_ServerListenUnjoinedNodes();
N_ServerListenJoinedNodes();
Expand Down
2 changes: 2 additions & 0 deletions doomsday/server/include/server/sv_def.h
Expand Up @@ -24,6 +24,7 @@
#include "dd_def.h"
#include "network/protocol.h"
#include "network/sys_network.h"
#include <de/Record>

struct material_s;

Expand Down Expand Up @@ -69,6 +70,7 @@ int Sv_Latency(byte cmdTime);
void Sv_Kick(int who);
void Sv_GetInfo(serverinfo_t* info);
size_t Sv_InfoToString(serverinfo_t* info, ddstring_t* msg);
de::Record * Sv_InfoToRecord(serverinfo_t *info);
int Sv_GetNumPlayers(void);
int Sv_GetNumConnected(void);
boolean Sv_CheckBandwidth(int playerNumber);
Expand Down
32 changes: 32 additions & 0 deletions doomsday/server/src/server/sv_main.cpp
Expand Up @@ -35,6 +35,9 @@
#include "api_materialarchive.h"
#include "map/r_world.h"

#include <de/ArrayValue>
#include <de/NumberValue>

// This is absolute maximum bandwidth rating. Frame size is practically
// unlimited with this score.
#define MAX_BANDWIDTH_RATING 100
Expand Down Expand Up @@ -109,6 +112,35 @@ void Sv_GetInfo(serverinfo_t* info)
info->loadedFilesCRC = F_LoadedFilesCRC();
}

de::Record *Sv_InfoToRecord(serverinfo_t *info)
{
de::Record *rec = new de::Record;

rec->addNumber ("port", info->port);
rec->addText ("name", info->name);
rec->addText ("info", info->description);
rec->addNumber ("ver", info->version);
rec->addText ("game", info->plugin);
rec->addText ("mode", info->gameIdentityKey);
rec->addText ("setup", info->gameConfig);
rec->addText ("iwad", info->iwad);
rec->addNumber ("wcrc", info->loadedFilesCRC);
rec->addText ("pwads", info->pwads);
rec->addText ("map", info->map);
rec->addNumber ("nump", info->numPlayers);
rec->addNumber ("maxp", info->maxPlayers);
rec->addBoolean("open", info->canJoin);
rec->addText ("plrn", info->clientNames);

de::ArrayValue &data = rec->addArray("data").value<de::ArrayValue>();
for(uint i = 0; i < sizeof(info->data) / sizeof(info->data[0]); ++i)
{
data << de::NumberValue(info->data[i]);
}

return rec;
}

/**
* @return Length of the string.
*/
Expand Down

0 comments on commit 85d4cb4

Please sign in to comment.