24 #include "plugins/engineplugin.h" 25 #include "serverapi/rconprotocol.h" 26 #include "serverapi/server.h" 27 #include "widgets/serverconsole.h" 28 #include "remoteconsole.h" 29 #include "rconpassworddialog.h" 31 #include "ui_remoteconsole.h" 34 #include <QMessageBox> 35 #include <QScopedPointer> 38 DClass<RemoteConsole> :
public Ui::RemoteConsole
54 connect(dlg, SIGNAL(rejected()),
this, SLOT(close()));
55 while(d->protocol == NULL)
57 int ret = dlg->exec();
58 if(ret == QDialog::Accepted)
64 d->server = dlg->selectedEngine()->
server(QHostAddress(address), port);
65 if(!d->server->hasRcon())
67 QMessageBox::critical(
this, tr(
"No RCon support"), tr(
"The source port selected has no RCon support."));
71 d->protocol = d->server->rcon();
73 if(d->protocol != NULL)
75 setWindowIcon(d->server->icon());
78 d->protocol->sendPassword(dlg->connectPassword());
87 RemoteConsole::RemoteConsole(ServerPtr server, QWidget *parent)
90 d->protocol = server->rcon();
94 setWindowIcon(server->icon());
95 changeServerName(server->name());
97 if (d->protocol != NULL)
103 QMessageBox::critical(parent, tr(
"RCon Failure"),
104 tr(
"Failed to connect RCon to server %1:%2").arg(
105 server->address().toString()).arg(server->port()));
109 RemoteConsole::~RemoteConsole()
113 void RemoteConsole::changeServerName(
const QString &name)
115 setWindowTitle(name + tr(
" - Remote Console"));
118 void RemoteConsole::closeEvent(QCloseEvent *event)
120 if(d->protocol && d->protocol->isConnected())
121 d->protocol->disconnectFromServer();
125 void RemoteConsole::invalidPassword()
127 QMessageBox::critical(
this, tr(
"Invalid Password"), tr(
"The password you entered appears to be invalid."));
128 showPasswordDialog();
133 return d->protocol != NULL;
136 void RemoteConsole::disconnectFromServer()
140 d->protocol->disconnectFromServer();
148 void RemoteConsole::showPasswordDialog()
152 connect(dlg, SIGNAL(rejected()),
this, SLOT(close()));
153 int ret = dlg->exec();
154 if(ret == QDialog::Accepted)
156 d->protocol->sendPassword(dlg->connectPassword());
161 d->serverConsole->setFocus();
164 void RemoteConsole::standardInit()
168 d->console->layout()->addWidget(d->serverConsole);
171 setAttribute(Qt::WA_DeleteOnClose);
173 if(d->protocol == NULL)
179 connect(d->actionDisconnect, SIGNAL(triggered()),
this, SLOT(disconnectFromServer()));
180 connect(d->serverConsole, SIGNAL(messageSent(
const QString &)), d->protocol, SLOT(sendCommand(
const QString &)));
181 connect(d->protocol, SIGNAL(disconnected()),
this, SLOT(close()));
182 connect(d->protocol, SIGNAL(messageReceived(
const QString &)), d->serverConsole, SLOT(appendMessage(
const QString &)));
183 connect(d->protocol, SIGNAL(invalidPassword()),
this, SLOT(invalidPassword()));
184 connect(d->protocol, SIGNAL(playerListUpdated()),
this, SLOT(updatePlayerList()));
185 connect(d->protocol, SIGNAL(serverNameChanged(
const QString &)),
this, SLOT(changeServerName(
const QString &)));
188 void RemoteConsole::updatePlayerList()
190 const QList<Player> &list = d->protocol->players();
192 d->playerTable->setRowCount(list.size());
193 for(
int i = 0; i < list.size(); ++i)
195 QString name = list[i].nameFormatted();
196 QTableWidgetItem* newItem =
new QTableWidgetItem(name);
197 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.
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.