24 #include "plugins/engineplugin.h" 25 #include "rconpassworddialog.h" 26 #include "remoteconsole.h" 27 #include "serverapi/rconprotocol.h" 28 #include "serverapi/server.h" 29 #include "strings.hpp" 30 #include "ui_remoteconsole.h" 31 #include "widgets/serverconsole.h" 34 #include <QMessageBox> 35 #include <QScopedPointer> 38 DClass<RemoteConsole> :
public Ui::RemoteConsole
55 connect(dlg, SIGNAL(rejected()),
this, SLOT(close()));
56 while (d->protocol ==
nullptr)
58 int ret = dlg->exec();
59 if (ret == QDialog::Accepted)
65 ServerPtr server = dlg->selectedEngine()->server(QHostAddress(address), port);
66 if (!server->hasRcon())
68 QMessageBox::critical(
this, RemoteConsole::tr(
"No RCon support"), RemoteConsole::tr(
"The selected source port has no RCon support."));
71 d->protocol = server->rcon();
73 if (d->protocol !=
nullptr)
76 setWindowIcon(d->server->icon());
79 d->protocol->sendPassword(dlg->connectPassword());
83 QMessageBox::critical(
this, RemoteConsole::tr(
"RCon failure"), RemoteConsole::tr(
"Failed to create RCon protocol for the server."));
93 RemoteConsole::RemoteConsole(ServerPtr server, QWidget *parent)
97 d->protocol = server->rcon();
100 setWindowIcon(server->icon());
101 changeServerName(server->name());
103 if (d->protocol !=
nullptr)
106 showPasswordDialog();
110 QMessageBox::critical(parent, tr(
"RCon Failure"),
111 tr(
"Failed to connect RCon to server %1:%2").arg(
112 server->address().toString()).arg(server->port()));
116 RemoteConsole::~RemoteConsole()
120 void RemoteConsole::construct()
123 d->protocol =
nullptr;
125 d->console->layout()->addWidget(d->serverConsole);
126 connect(d->actionDisconnect, SIGNAL(triggered()),
this, SLOT(disconnectFromServer()));
129 setAttribute(Qt::WA_DeleteOnClose);
132 void RemoteConsole::changeServerName(
const QString &name)
134 setWindowTitle(name + tr(
" - Remote Console"));
137 void RemoteConsole::closeEvent(QCloseEvent *event)
139 if (d->protocol && d->protocol->isConnected())
140 d->protocol->disconnectFromServer();
144 void RemoteConsole::invalidPassword()
146 QMessageBox::critical(
this, tr(
"Invalid Password"), tr(
"The password you entered appears to be invalid."));
147 showPasswordDialog();
150 void RemoteConsole::disconnectFromServer()
153 d->protocol->disconnectFromServer();
158 void RemoteConsole::showPasswordDialog()
162 connect(dlg, SIGNAL(rejected()),
this, SLOT(close()));
163 int ret = dlg->exec();
164 if (ret == QDialog::Accepted)
165 d->protocol->sendPassword(dlg->connectPassword());
169 d->serverConsole->setFocus();
172 void RemoteConsole::standardInit()
175 connect(d->serverConsole, SIGNAL(messageSent(
const QString&)), d->protocol, SLOT(sendCommand(
const QString&)));
176 connect(d->protocol, SIGNAL(disconnected()),
this, SLOT(close()));
177 connect(d->protocol, SIGNAL(messageReceived(
const QString&)), d->serverConsole, SLOT(appendMessage(
const QString&)));
178 connect(d->protocol, SIGNAL(invalidPassword()),
this, SLOT(invalidPassword()));
179 connect(d->protocol, SIGNAL(playerListUpdated()),
this, SLOT(updatePlayerList()));
180 connect(d->protocol, SIGNAL(serverNameChanged(
const QString&)),
this, SLOT(changeServerName(
const QString&)));
183 void RemoteConsole::updatePlayerList()
185 const QList<Player> &list = d->protocol->players();
187 d->playerTable->setRowCount(list.size());
188 for (
int i = 0; i < list.size(); ++i)
190 QString name = list[i].nameFormatted();
191 auto newItem =
new QTableWidgetItem(name);
192 d->playerTable->setItem(i, 0, newItem);
static void translateServerAddress(const QString &addressString, QString &hostname, unsigned short &port, const QString &defaultAddress)
Translates string in format "hostname:port" to atomic values.
Remote console protocol interface.