123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /*
- GNU General Public License version 3 notice
- Copyright (C) 2012 Mihawk <luiz@netdome.biz>. 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 <QObject>
- #include <QHostAddress>
- 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<Player> PlayerList;
- struct ServerRule
- {
- QString rule;
- QString value;
- };
- typedef QList<ServerRule> 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
|