File indexing completed on 2024-05-05 05:40:34
0001 /************************************************************************* 0002 * Copyright (C) 2013 by Renaud Guezennec * 0003 * * 0004 * https://rolisteam.org/ * 0005 * * 0006 * rolisteam is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published * 0008 * by the Free Software Foundation; either version 2 of the License, * 0009 * or (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0020 *************************************************************************/ 0021 #include "services/ipchecker.h" 0022 #include <QNetworkReply> 0023 #include <QNetworkRequest> 0024 #include <QRegularExpression> 0025 #include <QUrl> 0026 0027 IpChecker::IpChecker(QObject* parent) : QObject(parent) {} 0028 0029 QString IpChecker::ipAddress() const 0030 { 0031 return m_ip; 0032 } 0033 void IpChecker::readText(QNetworkReply* p) 0034 { 0035 if(p->error() != QNetworkReply::NoError) 0036 { 0037 m_ip= tr("Error to read server IP."); 0038 } 0039 else 0040 { 0041 m_ip= p->readAll(); 0042 emit ipAddressChanged(m_ip); 0043 } 0044 emit finishedCheck(); 0045 } 0046 void IpChecker::startCheck() 0047 { 0048 #ifdef HAVE_QT_NETWORK 0049 m_manager.reset(new QNetworkAccessManager); 0050 connect(m_manager.get(), &QNetworkAccessManager::finished, this, &IpChecker::readText); 0051 m_manager->get(QNetworkRequest(QUrl("https://rolisteam.org/ip.php"))); 0052 #endif 0053 }