Skip to content

Commit

Permalink
Shell|Text: Password challenge response, game state in StatusWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 11, 2013
1 parent 17eb7f6 commit 774461d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
6 changes: 1 addition & 5 deletions doomsday/tools/shell/shell-gui/src/linkwindow.cpp
Expand Up @@ -461,11 +461,7 @@ void LinkWindow::askForPassword()
{
if(d->link)
{
Block response;
response.append("Shell");
response += QCryptographicHash::hash(dlg.textValue().toUtf8(),
QCryptographicHash::Sha1);
*d->link << response;
*d->link << d->link->protocol().passwordResponse(dlg.textValue());
}
return;
}
Expand Down
33 changes: 33 additions & 0 deletions doomsday/tools/shell/shell-text/src/shellapp.cpp
Expand Up @@ -32,6 +32,7 @@
#include <de/shell/ServerFinder>
#include <de/LogBuffer>
#include <QStringList>
#include <QTimer>

using namespace de;
using namespace shell;
Expand Down Expand Up @@ -195,6 +196,26 @@ void ShellApp::closeConnection()
}
}

void ShellApp::askForPassword()
{
InputDialog dlg;
dlg.setDescription(tr("The server requires a password."));
dlg.setPrompt("Password: ");
dlg.lineEdit().setEchoMode(LineEditWidget::PasswordEchoMode);
dlg.lineEdit().setSignalOnEnter(false);

if(dlg.exec(rootWidget()))
{
if(d->link) *d->link << d->link->protocol().passwordResponse(dlg.text());
}
else
{
QTimer::singleShot(1, this, SLOT(closeConnection()));
}

rootWidget().setFocus(d->cli);
}

void ShellApp::askToOpenConnection()
{
OpenConnectionDialog dlg;
Expand Down Expand Up @@ -285,11 +306,23 @@ void ShellApp::handleIncomingPackets()
shell::Protocol &protocol = d->link->protocol();
switch(protocol.recognize(packet.data()))
{
case shell::Protocol::PasswordChallenge:
askForPassword();
break;

case shell::Protocol::ConsoleLexicon:
// Terms for auto-completion.
d->cli->setLexicon(protocol.lexicon(*packet));
break;

case shell::Protocol::GameState: {
Record &rec = static_cast<RecordPacket *>(packet.data())->record();
d->status->setGameState(
rec["mode"].value().asText(),
rec["rules"].value().asText(),
rec["mapId"].value().asText());
break; }

default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions doomsday/tools/shell/shell-text/src/shellapp.h
Expand Up @@ -40,6 +40,7 @@ public slots:
void updateMenuWithFoundServers();
void connectToFoundServer();
void closeConnection();
void askForPassword();
void sendCommandToServer(de::String command);
void handleIncomingPackets();
void disconnected();
Expand Down
17 changes: 17 additions & 0 deletions doomsday/tools/shell/shell-text/src/statuswidget.cpp
Expand Up @@ -27,6 +27,9 @@ DENG2_PIMPL(StatusWidget)
{
Link *link;
QTimer *updateTimer;
String gameMode;
String rules;
String mapId;

Instance(Public &i) : Base(i), link(0)
{
Expand Down Expand Up @@ -60,6 +63,15 @@ void StatusWidget::setShellLink(Link *link)
root().requestDraw();
}

void StatusWidget::setGameState(String const &mode, String const &rules, String const &mapId)
{
d->gameMode = mode;
d->rules = rules;
d->mapId = mapId;

redraw();
}

void StatusWidget::draw()
{
Rectanglei pos = rule().recti();
Expand All @@ -85,6 +97,11 @@ void StatusWidget::draw()
}
else if(d->link->status() == Link::Connected)
{
String msg = d->gameMode;
if(!d->rules.isEmpty()) msg += " (" + d->rules + ")";
if(!d->mapId.isEmpty()) msg += " " + d->mapId;
buf.drawText(Vector2i(1, 0), msg);

TimeDelta elapsed = d->link->connectedAt().since();
String time = String("| %1:%2:%3")
.arg(int(elapsed.asHours()))
Expand Down
4 changes: 3 additions & 1 deletion doomsday/tools/shell/shell-text/src/statuswidget.h
Expand Up @@ -28,7 +28,7 @@ class StatusWidget : public de::shell::TextWidget

public:
StatusWidget(de::String const &name = "");
virtual ~StatusWidget();
virtual ~StatusWidget();

/**
* Sets the shell Link whose status is to be shown on screen.
Expand All @@ -37,6 +37,8 @@ class StatusWidget : public de::shell::TextWidget
*/
void setShellLink(de::shell::Link *link);

void setGameState(de::String const &mode, de::String const &rules, de::String const &mapId);

void draw();

public slots:
Expand Down

0 comments on commit 774461d

Please sign in to comment.