ping added

This commit is contained in:
Max-Wilhelm Bruker 2009-04-15 21:43:12 +02:00
parent 99ff7fd15f
commit 8680bce5fc
5 changed files with 16 additions and 2 deletions

View file

@ -34,6 +34,7 @@ void Client::checkTimeout()
return; return;
} }
} }
ping();
} }
void Client::slotSocketError(QAbstractSocket::SocketError error) void Client::slotSocketError(QAbstractSocket::SocketError error)
@ -205,6 +206,11 @@ void Client::disconnectFromServer()
socket->close(); socket->close();
} }
int Client::ping()
{
return cmd("ping");
}
int Client::listGames() int Client::listGames()
{ {
return cmd("list_games"); return cmd("list_games");

View file

@ -62,6 +62,7 @@ public:
void connectToServer(const QString &hostname, unsigned int port, const QString &playername, const QString &password); void connectToServer(const QString &hostname, unsigned int port, const QString &playername, const QString &password);
void disconnectFromServer(); void disconnectFromServer();
int ping();
int listGames(); int listGames();
int listPlayers(); int listPlayers();
int createGame(const QString &description, const QString &password, unsigned int maxPlayers); int createGame(const QString &description, const QString &password, unsigned int maxPlayers);

View file

@ -5,7 +5,7 @@ DlgConnect::DlgConnect(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
hostLabel = new QLabel(tr("&Host:")); hostLabel = new QLabel(tr("&Host:"));
hostEdit = new QLineEdit("localhost"); hostEdit = new QLineEdit("cockatrice.de");
hostLabel->setBuddy(hostEdit); hostLabel->setBuddy(hostEdit);
portLabel = new QLabel(tr("&Port:")); portLabel = new QLabel(tr("&Port:"));

View file

@ -182,6 +182,7 @@ void ServerSocket::readClient()
} }
const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::numberCommands] = { const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::numberCommands] = {
{"ping", false, false, false, QList<QVariant::Type>(), &ServerSocket::cmdPing},
{"login", false, false, false, QList<QVariant::Type>() << QVariant::String {"login", false, false, false, QList<QVariant::Type>() << QVariant::String
<< QVariant::String, &ServerSocket::cmdLogin}, << QVariant::String, &ServerSocket::cmdLogin},
{"list_games", true, false, false, QList<QVariant::Type>(), &ServerSocket::cmdListGames}, {"list_games", true, false, false, QList<QVariant::Type>(), &ServerSocket::cmdListGames},
@ -230,6 +231,11 @@ const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::nu
{"set_active_phase", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePhase} {"set_active_phase", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePhase}
}; };
ReturnMessage::ReturnCode ServerSocket::cmdPing(const QList<QVariant> &params)
{
return ReturnMessage::ReturnOk;
}
ReturnMessage::ReturnCode ServerSocket::cmdLogin(const QList<QVariant> &params) ReturnMessage::ReturnCode ServerSocket::cmdLogin(const QList<QVariant> &params)
{ {
authState = server->checkUserPassword(params[0].toString(), params[1].toString()); authState = server->checkUserPassword(params[0].toString(), params[1].toString());

View file

@ -55,9 +55,10 @@ private:
QList<QVariant::Type> paramTypes; QList<QVariant::Type> paramTypes;
CommandHandler handler; CommandHandler handler;
}; };
static const int numberCommands = 24; static const int numberCommands = 25;
static const CommandProperties commandList[numberCommands]; static const CommandProperties commandList[numberCommands];
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> &params);
ReturnMessage::ReturnCode cmdLogin(const QList<QVariant> &params); ReturnMessage::ReturnCode cmdLogin(const QList<QVariant> &params);
ReturnMessage::ReturnCode cmdListGames(const QList<QVariant> &params); ReturnMessage::ReturnCode cmdListGames(const QList<QVariant> &params);
ReturnMessage::ReturnCode cmdCreateGame(const QList<QVariant> &params); ReturnMessage::ReturnCode cmdCreateGame(const QList<QVariant> &params);