Skip to content

Commit

Permalink
Refactor|Client|Network: Cleaned up server info functions
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 30, 2014
1 parent 9572fcb commit 07c52dc
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 42 deletions.
10 changes: 6 additions & 4 deletions doomsday/client/include/network/net_main.h
Expand Up @@ -255,22 +255,24 @@ void Net_Ticker(timespan_t time);
*/
void Net_Drawer(void);

dd_bool Net_IsLocalPlayer(int pNum);
dd_bool Net_IsLocalPlayer(int pNum);

void Net_PrintServerInfo(int index, serverinfo_t *info);
void ServerInfo_Print(serverinfo_t const *info, int index);

/**
* Converts textual data to a serverinfo struct. Returns true if the
* label/value pair is recognized.
*/
dd_bool Net_StringToServerInfo(char const *valuePair, serverinfo_t *info);
dd_bool ServerInfo_FromString(serverinfo_t *info, char const *valuePair);

void Net_RecordToServerInfo(de::Record const &rec, serverinfo_t *info);
void ServerInfo_FromRecord(serverinfo_t *info, de::Record const &rec);

#ifdef __cplusplus
} // extern "C"
#endif

de::String ServerInfo_AsStyledText(serverinfo_t const *sv);

de::String Net_UserAgent();

#endif /* LIBDENG_NETWORK_H */
2 changes: 1 addition & 1 deletion doomsday/client/src/network/masterserver.cpp
Expand Up @@ -237,7 +237,7 @@ bool MasterWorker::parseResponse(const QByteArray& response)

if(info)
{
Net_StringToServerInfo(Str_Text(&line), info);
ServerInfo_FromString(info, Str_Text(&line));
}
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/network/net_event.cpp
Expand Up @@ -180,13 +180,13 @@ void N_NETicker(timespan_t time)
break;

case MAC_LIST:
Net_PrintServerInfo(0, NULL);
ServerInfo_Print(NULL, 0);
num = i = N_MasterGet(0, 0);
while(--i >= 0)
{
serverinfo_t info;
N_MasterGet(i, &info);
Net_PrintServerInfo(i, &info);
ServerInfo_Print(&info, i);
}
LOG_NET_VERBOSE("%i server%s found") << num << (num != 1 ? "s were" : " was");
N_MARemove();
Expand Down
38 changes: 33 additions & 5 deletions doomsday/client/src/network/net_main.cpp
Expand Up @@ -59,6 +59,7 @@

#include <de/Value>
#include <de/Version>
#include <de/charsymbols.h>

// MACROS ------------------------------------------------------------------

Expand Down Expand Up @@ -802,11 +803,38 @@ void Net_Ticker(timespan_t time)
}
}

de::String ServerInfo_AsStyledText(serverinfo_t const *sv)
{
#define TABBED(A, B) _E(Ta)_E(l) " " A _E(.) " " _E(\t) B "\n"
return de::String(_E(b) "%1" _E(.) "\n%2\n" _E(T`)
TABBED("Joinable:", "%5")
TABBED("Players:", "%3 / %4%13")
TABBED("Game:", "%9\n%10\n%12 %11")
TABBED("PWADs:", "%14")
TABBED("Address:", "%6:%7")
TABBED("Ping:", "%8 ms (approx)"))
.arg(sv->name)
.arg(sv->description)
.arg(sv->numPlayers)
.arg(sv->maxPlayers)
.arg(sv->canJoin? "Yes" : "No") // 5
.arg(sv->address)
.arg(sv->port)
.arg(sv->ping)
.arg(sv->plugin)
.arg(sv->gameIdentityKey) // 10
.arg(sv->gameConfig)
.arg(sv->map)
.arg(!de::String(sv->clientNames).isEmpty()? de::String(_E(2) " (%1)" _E(.)).arg(sv->clientNames) : "")
.arg(de::String(sv->pwads).isEmpty()? de::String(DENG2_CHAR_MDASH) : de::String(sv->pwads)); // 14
#undef TABBED
}

/**
* Prints server/host information into the console. The header line is
* printed if 'info' is NULL.
*/
void Net_PrintServerInfo(int index, serverinfo_t *info)
void ServerInfo_Print(serverinfo_t const *info, int index)
{
/// @todo Update table for de::Log. -jk
///
Expand Down Expand Up @@ -1256,7 +1284,7 @@ D_CMD(Net)
serverinfo_t info;
if(Net_ServerLink().foundServerInfo(index, &info))
{
Net_PrintServerInfo(index, &info);
ServerInfo_Print(&info, index);
Net_ServerLink().connectDomain(de::String("%1:%2").arg(info.address).arg(info.port), 5);
}
}
Expand Down Expand Up @@ -1321,9 +1349,9 @@ static dd_bool tokenize(char const *line, char *label, char *value, int max)
return true;
}

void Net_RecordToServerInfo(de::Record const &rec, serverinfo_t *info)
void ServerInfo_FromRecord(serverinfo_t *info, de::Record const &rec)
{
memset(info, 0, sizeof(*info));
de::zapPtr(info);

info->port = (int) rec["port"].value().asNumber();
info->version = (int) rec["ver" ].value().asNumber();
Expand All @@ -1348,7 +1376,7 @@ void Net_RecordToServerInfo(de::Record const &rec, serverinfo_t *info)
#undef COPY_STR
}

dd_bool Net_StringToServerInfo(const char *valuePair, serverinfo_t *info)
dd_bool ServerInfo_FromString(serverinfo_t *info, char const *valuePair)
{
char label[SVINFO_TOKEN_LEN], value[SVINFO_TOKEN_LEN];

Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/network/serverlink.cpp
Expand Up @@ -96,7 +96,7 @@ DENG2_PIMPL(ServerLink)
do
{
ch = Str_GetLine(line, ch);
Net_StringToServerInfo(Str_Text(line), &svInfo);
ServerInfo_FromString(&svInfo, Str_Text(line));
}
while(*ch);

Expand All @@ -116,8 +116,8 @@ DENG2_PIMPL(ServerLink)
<< discovered.size()
<< (discovered.size() != 1 ? "s have" : " has");

Net_PrintServerInfo(0, NULL);
Net_PrintServerInfo(0, &svInfo);
ServerInfo_Print(NULL, 0);
ServerInfo_Print(&svInfo, 0);

notifyDiscoveryUpdate();
}
Expand Down Expand Up @@ -174,7 +174,7 @@ DENG2_PIMPL(ServerLink)
foreach(Address sv, finder.foundServers())
{
serverinfo_t info;
Net_RecordToServerInfo(finder.messageFromServer(sv), &info);
ServerInfo_FromRecord(&info, finder.messageFromServer(sv));

// Update the address in the info, which is missing because this
// information didn't come from the master.
Expand Down
27 changes: 2 additions & 25 deletions doomsday/client/src/ui/dialogs/multiplayerdialog.cpp
Expand Up @@ -183,30 +183,7 @@ DENG_GUI_PIMPL(MultiplayerDialog)
.arg(sv.map));

// Extra information.
#define TABBED(A, B) _E(Ta)_E(l) " " A _E(.) " " _E(\t) B "\n"
info->document()
.setText(String(_E(b) "%1" _E(.) "\n%2\n" _E(T`)
TABBED("Joinable:", "%5")
TABBED("Players:", "%3 / %4%13")
TABBED("Game:", "%9\n%10\n%12 %11")
TABBED("PWADs:", "%14")
TABBED("Address:", "%6:%7")
TABBED("Ping:", "%8 ms (approx)"))
.arg(sv.name)
.arg(sv.description)
.arg(sv.numPlayers)
.arg(sv.maxPlayers)
.arg(sv.canJoin? "Yes" : "No") // 5
.arg(sv.address)
.arg(sv.port)
.arg(sv.ping)
.arg(sv.plugin)
.arg(sv.gameIdentityKey) // 10
.arg(sv.gameConfig)
.arg(sv.map)
.arg(!String(sv.clientNames).isEmpty()? String(_E(2) " (%1)" _E(.)).arg(sv.clientNames) : "")
.arg(String(sv.pwads).isEmpty()? String(DENG2_CHAR_MDASH) : String(sv.pwads))); // 14
#undef TABBED
info->document().setText(ServerInfo_AsStyledText(&sv));
}
catch(Error const &)
{
Expand Down Expand Up @@ -284,7 +261,7 @@ DENG_GUI_PIMPL(MultiplayerDialog)
MultiplayerDialog::MultiplayerDialog(String const &name)
: DialogWidget(name, WithHeading), d(new Instance(this))
{
heading().setText(tr("Multiplayer"));
heading().setText(tr("Multiplayer Games"));

LabelWidget *lab = LabelWidget::newWithText(tr("Games from Master Server and local network:"), &area());

Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/ui/widgets/multiplayermenuwidget.cpp
Expand Up @@ -21,6 +21,7 @@
#include "CommandAction"

#include <de/ui/ActionItem>
#include <de/ui/SubwidgetItem>

using namespace de;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -403,7 +403,7 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
<< new ui::SubwidgetItem(style().images().image("updater"), tr("Updater"), ui::Left, makeUpdaterSettings);

d->mainMenu->items()
<< new ui::SubwidgetItem(tr("Multiplayer..."), ui::Left, makePopup<MultiplayerDialog>)
<< new ui::SubwidgetItem(tr("Multiplayer Games..."), ui::Left, makePopup<MultiplayerDialog>)
<< new ui::Item(ui::Item::Separator)
<< new ui::ActionItem(tr("Check for Updates..."), new CommandAction("updateandnotify"))
<< new ui::ActionItem(tr("About Doomsday"), new SignalAction(this, SLOT(showAbout())))
Expand Down

0 comments on commit 07c52dc

Please sign in to comment.