Browse Source

Added password support.

This can be used to connect to VIP spec slots
Mihawk 11 years ago
parent
commit
8561216f2e
8 changed files with 51 additions and 8 deletions
  1. 3 1
      ActiveClient.cpp
  2. 2 2
      ActiveClient.h
  3. 3 3
      App.cpp
  4. 1 1
      App.h
  5. 19 0
      Pinger.cpp
  6. 19 0
      Pinger.h
  7. 3 1
      Settings.cpp
  8. 1 0
      Settings.h

+ 3 - 1
ActiveClient.cpp

@@ -26,7 +26,7 @@ along with this program.  If not, see < http://www.gnu.org/licenses/ >.
 #include "Settings.h"
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-ActiveClient::ActiveClient(App *app, QObject *parent):
+ActiveClient::ActiveClient(App *app, const QString& password, QObject *parent):
   QObject(parent),
   myApp(app),
   myClient(new Client(app, this)),
@@ -45,6 +45,8 @@ ActiveClient::ActiveClient(App *app, QObject *parent):
   connect(myQuery, SIGNAL(error(ServerQuery::Error)), SLOT(queryError(ServerQuery::Error)));
 
   myQueryTimer->setSingleShot(true);
+
+  myClient->setPassword(password.toAscii().data());
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

+ 2 - 2
ActiveClient.h

@@ -47,10 +47,10 @@ public:
     Creates a server monitoring object.
 
     @param  app    The application creator of this object
-    @param  supportsSendPrivate Indicates if this server we are monitoring supports sendPrivate
+    @param  password The password needed to connect to this server if any
     @param  parent The parent object (should be the same as the app param)
   */
-  ActiveClient(App* app, QObject *parent = 0);
+  ActiveClient(App* app, const QString &password = "", QObject *parent = 0);
 
   /**
     Destructor

+ 3 - 3
App.cpp

@@ -137,7 +137,7 @@ void App::loadServerList()
       print("Maximum number of servers allowed reached, some servers weren't added to the monitoring list.\n");
       return;
     }
-    addClient(sv.address, sv.port);
+    addClient(sv.address, sv.port, sv.password);
   }
 }
 
@@ -175,7 +175,7 @@ void App::print(const QString &msg)
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-bool App::addClient(const QString &host, quint16 port)
+bool App::addClient(const QString &host, quint16 port, const QString& password)
 {
   ActiveClient* ac;
   QHostAddress ha(host);
@@ -189,7 +189,7 @@ bool App::addClient(const QString &host, quint16 port)
     }
   }
 
-  ac = new ActiveClient(this, this);
+  ac = new ActiveClient(this, password, this);
   ac->setAddress(ha, port);
   ac->client()->setQuakeFolder(Settings::globalInstance()->quakeFolder().toAscii().data());
   ac->client()->setName(Settings::globalInstance()->botName().toAscii().data());

+ 1 - 1
App.h

@@ -145,7 +145,7 @@ public:
     @return  True if its correct, false otherwise
   */
 
-  bool                  addClient(const QString& host, quint16 port);
+  bool                  addClient(const QString& host, quint16 port, const QString &password = "");
   /**
     Checks if the password specified by the user is correct.
 

+ 19 - 0
Pinger.cpp

@@ -1,3 +1,22 @@
+/*
+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/ >.
+*/
+
 #include "Pinger.h"
 #include <QUdpSocket>
 #include <QTime>

+ 19 - 0
Pinger.h

@@ -1,3 +1,22 @@
+/*
+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/ >.
+*/
+
 #ifndef PINGER_H
 #define PINGER_H
 

+ 3 - 1
Settings.cpp

@@ -79,6 +79,8 @@ Settings::ServerList Settings::serverList()
     {
       sv.address = svaddr.at(0);
       sv.port = svaddr.at(1).toUShort();
+      if(svaddr.size() > 2)
+        sv.password = svaddr.at(2);
     }
     else
       continue;
@@ -96,7 +98,7 @@ void Settings::setServerList(ServerList &list)
   for(int i = 0; i < list.size(); ++i)
   {
     ourSettings->setArrayIndex(i);
-    ourSettings->setValue("address", list.at(i).address + ":" + QString::number(list.at(i).port));
+    ourSettings->setValue("address", list.at(i).address + ":" + QString::number(list.at(i).port) + ":" + list.at(i).password);
   }
   ourSettings->endArray();
 }

+ 1 - 0
Settings.h

@@ -40,6 +40,7 @@ public:
   {
     QString address;
     quint16 port;
+    QString password; // Used for spectator VIP slots
   };
   typedef QList<Server> ServerList;