Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Client|UI|Network: Game selection menu fetches games from master server
The client's ServerFinder can now fetch servers from the master
server. Currently this is done when MPSelectionWidget is created,
however it should also be doable manually.
  • Loading branch information
skyjake committed Feb 5, 2014
1 parent 7884ced commit 94bfb43
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
5 changes: 5 additions & 0 deletions doomsday/client/include/network/serverlink.h
Expand Up @@ -61,6 +61,11 @@ class ServerLink : public de::shell::AbstractLink
*/
void discover(de::String const &domain);

/**
* Asks the master server for information about currently running servers.
*/
void discoverUsingMaster();

bool isDiscovering() const;

int foundServerCount() const;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/network/masterserver.cpp
Expand Up @@ -241,7 +241,7 @@ bool MasterWorker::parseResponse(const QByteArray& response)
}
}

LOG_NET_MSG("Received %i servers") << serverCount();
LOG_NET_MSG("Received %i servers from master") << serverCount();

Str_Free(&line);
Str_Free(&msg);
Expand Down
66 changes: 60 additions & 6 deletions doomsday/client/src/network/serverlink.cpp
Expand Up @@ -18,14 +18,18 @@

#include "de_platform.h"
#include "network/serverlink.h"

#include "network/masterserver.h"
#include "network/net_main.h"
#include "network/net_buf.h"
#include "network/net_demo.h"
#include "network/net_event.h"
#include "network/protocol.h"
#include "client/cl_def.h"
#include "dd_def.h"

#include <QTimer>
#include <de/memory.h>
#include <de/GuiApp>
#include <de/Socket>
#include <de/Message>
#include <de/ByteRefArray>
Expand All @@ -45,19 +49,25 @@ enum LinkState
};

DENG2_PIMPL(ServerLink)
, DENG2_OBSERVES(Loop, Iteration)
{
shell::ServerFinder finder; ///< Finding local servers.
LinkState state;
bool fetching;
typedef QMap<Address, serverinfo_t> Servers;
Servers discovered;
Servers fromMaster;

Instance(Public *i)
: Base(i),
state(None)
: Base(i)
, state(None)
, fetching(false)
{}

~Instance()
{}
{
Loop::appLoop().audienceForIteration -= this;
}

void notifyDiscoveryUpdate()
{
Expand Down Expand Up @@ -166,12 +176,50 @@ DENG2_PIMPL(ServerLink)
return true;
}

void fetchFromMaster()
{
if(fetching) return;

fetching = true;
N_MAPost(MAC_REQUEST);
N_MAPost(MAC_WAIT);
Loop::appLoop().audienceForIteration += this;
}

void loopIteration()
{
DENG2_ASSERT(fetching);

if(N_MADone())
{
fetching = false;
Loop::appLoop().audienceForIteration -= this;

fromMaster.clear();
int const count = N_MasterGet(0, 0);
for(int i = 0; i < count; i++)
{
serverinfo_t info;
N_MasterGet(i, &info);
fromMaster.insert(Address::parse(info.address, info.port), info);
}

notifyDiscoveryUpdate();
}
}

Servers allFound() const
{
Servers all = discovered;

// Append from master (if available).
DENG2_FOR_EACH_CONST(Servers, i, fromMaster)
{
all.insert(i.key(), i.value());
}

// Append the ones from the server finder.
foreach(Address sv, finder.foundServers())
foreach(Address const &sv, finder.foundServers())
{
serverinfo_t info;
ServerInfo_FromRecord(&info, finder.messageFromServer(sv));
Expand Down Expand Up @@ -271,9 +319,15 @@ void ServerLink::discover(String const &domain)
d->state = Discovering;
}

void ServerLink::discoverUsingMaster()
{
d->fetchFromMaster();
}

bool ServerLink::isDiscovering() const
{
return (d->state == Discovering || d->state == WaitingForInfoResponse);
return (d->state == Discovering || d->state == WaitingForInfoResponse ||
d->fetching);
}

int ServerLink::foundServerCount() const
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/gameselectionwidget.cpp
Expand Up @@ -83,7 +83,7 @@ DENG_GUI_PIMPL(GameSelectionWidget)
owner->self.add(makeTitle(headingText));
title().setFont("title");
title().setTextColor("inverted.text");
title().setHoverTextColor("inverted.accent", ButtonWidget::ReplaceColor);
title().setHoverTextColor("inverted.text", ButtonWidget::ReplaceColor);
title().setAlignment(ui::AlignLeft);
title().margins().setLeft("");

Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/widgets/mpselectionwidget.cpp
Expand Up @@ -228,6 +228,8 @@ MPSelectionWidget::MPSelectionWidget()
: MenuWidget("mp-selection"), d(new Instance(this))
{
setGridSize(3, ui::Filled, 0, ui::Expand);

d->link().discoverUsingMaster();
}

void MPSelectionWidget::setColumns(int numberOfColumns)
Expand Down

0 comments on commit 94bfb43

Please sign in to comment.