Skip to content

Commit

Permalink
Multiplayer|UI: Fixed Multiplayer server list; allow/disallow joining
Browse files Browse the repository at this point in the history
Disable “Join” button when server disallows joining.

Fixed the “Refresh List” action in the Multiplayer tab in Home. Now
it updates the servers from the master server.

Added “server-allowjoin” cvar to manually prevent new clients from
joining.
  • Loading branch information
skyjake committed Feb 5, 2017
1 parent 0fabcb4 commit b347a6b
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 48 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/network/serverlink.h
Expand Up @@ -50,6 +50,8 @@ class ServerLink : public de::shell::AbstractLink
};
Q_DECLARE_FLAGS(Flags, Flag)

static ServerLink &get();

public:
ServerLink(Flags flags = DiscoverLocalServers);

Expand Down
21 changes: 10 additions & 11 deletions doomsday/apps/client/src/network/base/net_main.cpp
Expand Up @@ -95,17 +95,19 @@ dint gotFrame; ///< @c true if a frame packet has been received.

dd_bool firstNetUpdate = true;

byte monitorMsgQueue;
byte netShowLatencies;
byte netDev;
dfloat netConnectTime;
static byte monitorMsgQueue;
static byte netDev;
#ifdef __SERVER__
static byte netShowLatencies;
static byte netAllowJoin = true;
#endif
//static dfloat netConnectTime;
//dint netCoordTime = 17;
dfloat netConnectTimeout = 10;
dfloat netSimulatedLatencySeconds;

// Local packets are stored into this buffer.
dd_bool reboundPacket;
netbuffer_t reboundStore;
static dd_bool reboundPacket;
static netbuffer_t reboundStore;

#ifdef __CLIENT__
static dint coordTimer;
Expand Down Expand Up @@ -1305,14 +1307,11 @@ void Net_Register()
//C_VAR_CHARPTR ("net-master-path", &::masterPath, 0, 0, 0);
C_VAR_CHARPTR ("net-name", &::playerName, 0, 0, 0);

#ifdef __CLIENT__
C_VAR_FLOAT ("client-connect-timeout", &::netConnectTimeout, CVF_NO_MAX, 0, 0);
#endif

#ifdef __SERVER__
C_VAR_CHARPTR ("server-name", &::serverName, 0, 0, 0);
C_VAR_CHARPTR ("server-info", &::serverInfo, 0, 0, 0);
C_VAR_INT2 ("server-public", &::masterAware, 0, 0, 1, masterAwareChanged);
C_VAR_BYTE2 ("server-allowjoin", &netAllowJoin, 0, 0, 1, masterAwareChanged);
C_VAR_CHARPTR ("server-password", &::netPassword, 0, 0, 0);
C_VAR_BYTE ("server-latencies", &::netShowLatencies, 0, 0, 1);
C_VAR_INT ("server-frame-interval", &::frameInterval, CVF_NO_MAX, 0, 0);
Expand Down
6 changes: 6 additions & 0 deletions doomsday/apps/client/src/network/serverlink.cpp
Expand Up @@ -29,6 +29,7 @@
#include "ui/widgets/taskbarwidget.h"
#include "dd_def.h"
#include "dd_main.h"
#include "clientapp.h"

#include <de/BlockPacket>
#include <de/ByteRefArray>
Expand Down Expand Up @@ -684,3 +685,8 @@ void ServerLink::handleIncomingPackets()
}
}
}

ServerLink &ServerLink::get() // static
{
return ClientApp::serverLink();
}
19 changes: 13 additions & 6 deletions doomsday/apps/client/src/ui/dialogs/serverinfodialog.cpp
Expand Up @@ -40,6 +40,9 @@

using namespace de;

static DialogWidget::RoleFlags const ID_SV_PACKAGES = DialogWidget::Id1;
static DialogWidget::RoleFlags const ID_JOIN = DialogWidget::Id2;

DENG_GUI_PIMPL(ServerInfoDialog)
, DENG2_OBSERVES(ServerLink, MapOutline)
, public PackagesWidget::IPackageStatus
Expand Down Expand Up @@ -86,14 +89,15 @@ DENG_GUI_PIMPL(ServerInfoDialog)
// on what kind of package is being displayed.
self().buttons()
<< new DialogButtonItem(Default | Accept, tr("Close"))
<< new DialogButtonItem(Action, tr("Join Game"), new CallbackAction([this] ()
{
<< new DialogButtonItem(Action | ID_JOIN, tr("Join Game"), new CallbackAction([this] () {
self().accept();
emit self().joinGame();
}))
<< new DialogButtonItem(ActionPopup | Id1, style().images().image("package.icon"), tr("Server"));
<< new DialogButtonItem(ActionPopup | ID_SV_PACKAGES,
style().images().image("package.icon"), tr("Server"));

createWidgets();
self().buttonWidget(ID_JOIN)->disable();
}

bool isPackageHighlighted(String const &) const
Expand Down Expand Up @@ -170,7 +174,7 @@ DENG_GUI_PIMPL(ServerInfoDialog)

// Action buttons.

auto *svBut = self().popupButtonWidget(Id1);
auto *svBut = self().popupButtonWidget(ID_SV_PACKAGES);
svBut->setPopup(*serverPopup);
svBut->setText(tr("Server"));
svBut->setTextAlignment(ui::AlignLeft);
Expand Down Expand Up @@ -282,6 +286,9 @@ DENG_GUI_PIMPL(ServerInfoDialog)
gameState->setText(msg);
}

// Actions.
self().buttonWidget(ID_JOIN)->enable(serverInfo.flags().testFlag(shell::ServerInfo::AllowJoin));

// Local packages.
{
localPackages->setDialogTitle(tr("Local Packages for %1 Multiplayer").arg(gameTitle));
Expand Down Expand Up @@ -330,8 +337,8 @@ DENG_GUI_PIMPL(ServerInfoDialog)
serverPackages->setPopulationEnabled(true);
serverPackages->setManualPackageIds(available);

self().buttonWidget(Id1)->enable();
self().buttonWidget(Id1)->setText(tr("Server: %1").arg(serverInfo.packages().size()));
self().buttonWidget(ID_SV_PACKAGES)->enable();
self().buttonWidget(ID_SV_PACKAGES)->setText(tr("Server: %1").arg(serverInfo.packages().size()));
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/ui/home/multiplayercolumnwidget.cpp
Expand Up @@ -21,16 +21,15 @@
#include "ui/widgets/taskbarwidget.h"
#include "ui/home/headerwidget.h"
#include "ui/clientwindow.h"
#include "clientapp.h"
#include "network/serverlink.h"

#include <doomsday/Games>
#include <de/CallbackAction>
#include <de/PopupButtonWidget>
#include <de/PopupMenuWidget>
#include <de/SignalAction>
#include <de/ui/SubwidgetItem>

#include "ui/commandaction.h"

using namespace de;

DENG_GUI_PIMPL(MultiplayerColumnWidget)
Expand All @@ -49,7 +48,8 @@ DENG_GUI_PIMPL(MultiplayerColumnWidget)
<< new ui::ActionItem(tr("Connect to Server..."),
new SignalAction(&ClientWindow::main().taskBar(),
SLOT(connectToServerManually())))
<< new ui::ActionItem(tr("Refresh List"), new CommandAction("net request"));
<< new ui::ActionItem(tr("Refresh List"), new CallbackAction([] () {
ServerLink::get().discoverUsingMaster(); }));
return menu;
}, ui::Down);

Expand Down
Expand Up @@ -56,6 +56,8 @@ DENG_GUI_PIMPL(MultiplayerPanelButtonWidget)
DoomsdayApp::games().audienceForReadiness() += this;

joinButton = new ButtonWidget;
joinButton->setAttribute(AutomaticOpacity);
joinButton->disable();
joinButton->setText(tr("Join"));
joinButton->useInfoStyle();
joinButton->setSizePolicy(ui::Expand, ui::Expand);
Expand Down Expand Up @@ -189,6 +191,10 @@ void MultiplayerPanelButtonWidget::updateContent(shell::ServerInfo const &info)

icon().setImage(nullptr);
}
if (!info.flags().testFlag(shell::ServerInfo::AllowJoin))
{
d->joinButton->disable();
}
infoText += "\n" _E(C) + String(info.description()) + _E(.);

int const localCount = Game::localMultiplayerPackages(info.gameId()).size();
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/client/src/ui/widgets/homeitemwidget.cpp
Expand Up @@ -218,6 +218,7 @@ HomeItemWidget::HomeItemWidget(Flags flags, String const &name)
, d(new Impl(this))
{
setBehavior(Focusable | ContentClipping);
setAttribute(AutomaticOpacity);
addEventHandler(new Impl::ClickHandler(*this));

Rule const &iconSize = d->label->margins().height() +
Expand Down
43 changes: 18 additions & 25 deletions doomsday/apps/client/src/ui/widgets/multiplayerservermenuwidget.cpp
Expand Up @@ -100,8 +100,6 @@ DENG2_PIMPL(MultiplayerServerMenuWidget)

void linkDiscoveryUpdate(ServerLink const &link) override
{
bool changed = false;

ui::Data &items = self().items();

QSet<String> foundHosts;
Expand All @@ -121,7 +119,6 @@ DENG2_PIMPL(MultiplayerServerMenuWidget)
if (!foundHosts.contains(id))
{
items.remove(idx--);
changed = true;
}
}

Expand All @@ -137,7 +134,6 @@ DENG2_PIMPL(MultiplayerServerMenuWidget)
// Needs to be added.
items.append(new ServerListItem(info,
link.isServerOnLocalNetwork(info.address())));
changed = true;
}
else
{
Expand All @@ -146,33 +142,30 @@ DENG2_PIMPL(MultiplayerServerMenuWidget)
}
}

if (changed)
items.stableSort([] (ui::Item const &a, ui::Item const &b)
{
items.sort([] (ui::Item const &a, ui::Item const &b)
{
auto const &first = a.as<ServerListItem>();
auto const &second = b.as<ServerListItem>();
auto const &first = a.as<ServerListItem>();
auto const &second = b.as<ServerListItem>();

// LAN games shown first.
if (first.isLocal() == second.isLocal())
// LAN games shown first.
if (first.isLocal() == second.isLocal())
{
// Sort by number of players.
if (first.info().playerCount() == second.info().playerCount())
{
// Sort by number of players.
if (first.info().playerCount() == second.info().playerCount())
// Finally, by game ID.
int cmp = first.info().gameId().compareWithCase(second.info().gameId());
if (!cmp)
{
// Finally, by game ID.
int cmp = first.info().gameId().compareWithCase(second.info().gameId());
if (!cmp)
{
// Lastly by server name.
return first.info().name().compareWithoutCase(second.info().name()) < 0;
}
return cmp < 0;
// Lastly by server name.
return first.info().name().compareWithoutCase(second.info().name()) < 0;
}
return first.info().playerCount() - second.info().playerCount() > 0;
return cmp < 0;
}
return first.isLocal();
});
}
return first.info().playerCount() - second.info().playerCount() > 0;
}
return first.isLocal();
});
}

void currentGameChanged(Game const &newGame) override
Expand Down
Expand Up @@ -938,6 +938,9 @@ desc = 1=Enable shiny textures on surfaces of the map.
[rend-tex]
desc = 1=Render with textures. 2=Render with gray texture.

[server-allowjoin]
desc = 1=Allow new clients to join the game.

[server-frame-interval]
desc = Minimum number of tics between sent frames.

Expand Down
7 changes: 5 additions & 2 deletions doomsday/apps/server/src/serverapp.cpp
Expand Up @@ -24,6 +24,8 @@
#include <QDebug>
#include <stdlib.h>

#include <doomsday/console/var.h>

#include <de/CommandLine>
#include <de/Config>
#include <de/Log>
Expand Down Expand Up @@ -269,9 +271,10 @@ shell::ServerInfo ServerApp::currentServerInfo()
// The server player is there, it's just hidden.
info.setMaxPlayers(de::min(svMaxPlayers, DDMAXPLAYERS - (isDedicated ? 1 : 0)));

//info->canJoin = ;
shell::ServerInfo::Flags flags(0);
if (isServer != 0 && Sv_GetNumPlayers() < svMaxPlayers)
if (CVar_Byte(Con_FindVariable("server-allowjoin"))
&& isServer != 0
&& Sv_GetNumPlayers() < svMaxPlayers)
{
flags |= shell::ServerInfo::AllowJoin;
}
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/server/src/serversystem.cpp
Expand Up @@ -260,6 +260,7 @@ RemoteUser &ServerSystem::user(Id const &id) const

bool ServerSystem::isUserAllowedToJoin(RemoteUser &/*user*/) const
{
if (!CVar_Byte(Con_FindVariable("server-allowjoin"))) return false;
// If the server is full, attempts to connect are canceled.
return (Sv_GetNumConnected() < svMaxPlayers);
}
Expand Down
3 changes: 3 additions & 0 deletions doomsday/doc/engine/variable/server-allowjoin.ame
@@ -0,0 +1,3 @@
@summary {
1=Allow new clients to join the game.
}

0 comments on commit b347a6b

Please sign in to comment.