/* GNU General Public License version 3 notice Copyright (C) 2012 Mihawk . All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see < http://www.gnu.org/licenses/ >. */ /** Requests a server information and returns everything parsed in a ServerInfo struct */ #ifndef SERVERQUERY_H #define SERVERQUERY_H #include #include class QUdpSocket; struct Player { int id; QString team; QString name; QString skin; int frags; int time; int ping; int topColor; int bottomColor; bool spectator; }; typedef QList PlayerList; struct ServerRule { QString rule; QString value; }; typedef QList ServerRules; class ServerQuery : public QObject { Q_OBJECT public: enum Error { NoError, TimedOutError, EmptyResponseError, InvalidResponseError, InvalidInfoStringError, InvalidPlayerInfoError, SendError, HostLookupError, ConnectionError, UnknownError }; explicit ServerQuery(QObject *parent = 0); ~ServerQuery(); bool setAddress(const QString &address, quint16 port = 27500); bool setAddress(const QHostAddress &address, quint16 port = 27500); const QHostAddress& address() const; quint16 port() const; bool query(bool pingServer = false); void run(); bool isActive() const; PlayerList playerList() const; ServerRules serverRules() const; QString serverRuleValue(const QString& ruleName) const; signals: void error(ServerQuery::Error err); void finished(); private slots: void parseServerInfo(); void socketError(QAbstractSocket::SocketError err); private: QUdpSocket* mySocket; QHostAddress myAddress; quint16 myPort; PlayerList myPlayers; ServerRules myRules; quint16 myPing; bool myIsProxyFlag; bool myActiveFlag; static char ourReadableCharsTable[256]; static bool ourReadableCharsTableInitialized; int ping(int count = 3, int timeout = 1000); static void fillReadableCharsTable(); public: static QString convertNameFun(const QString &name); }; #endif // SERVERQUERY_H