From ef379281141c95ee830e44ffb25d83e450f7c6fe Mon Sep 17 00:00:00 2001 From: "Leroy.H.Y" Date: Sun, 13 Oct 2019 14:19:43 +0800 Subject: [PATCH] [add] Added sock UDP and fixed a few bugs, now using a proper build versioning number Former-commit-id: bfd5b5f042e1462b03e95c44045f577403849246 --- 3rdparty/x2struct | 2 +- Build.Counter | 1 + Qv2ray.pro | 9 +- src/Qv2rayBase.h | 6 +- src/QvConfigUpgrade.cpp | 3 +- src/QvCoreConfigOperations_Generation.cpp | 14 ++- src/QvCoreInteractions.cpp | 1 + src/main.cpp | 1 + src/ui/w_InboundEditor.cpp | 115 ++++++++++++---------- src/ui/w_InboundEditor.ui | 2 +- src/ui/w_MainWindow.cpp | 4 +- src/ui/w_MainWindow.ui | 8 +- src/ui/w_PrefrencesWindow.cpp | 17 ++++ src/ui/w_PrefrencesWindow.h | 4 + src/ui/w_PrefrencesWindow.ui | 107 +++++++++++++++++--- 15 files changed, 215 insertions(+), 79 deletions(-) create mode 100644 Build.Counter diff --git a/3rdparty/x2struct b/3rdparty/x2struct index d3971065..07e828dd 160000 --- a/3rdparty/x2struct +++ b/3rdparty/x2struct @@ -1 +1 @@ -Subproject commit d397106558a75a41e760126c15efdf30ec9cc33f +Subproject commit 07e828ddd2e0a78e565b61c2f135b12462947663 diff --git a/Build.Counter b/Build.Counter new file mode 100644 index 00000000..987e7ca9 --- /dev/null +++ b/Build.Counter @@ -0,0 +1 @@ +77 diff --git a/Qv2ray.pro b/Qv2ray.pro index 3268b01f..07fe7fdf 100644 --- a/Qv2ray.pro +++ b/Qv2ray.pro @@ -11,9 +11,14 @@ TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS CONFIG += c++11 openssl-linked lrelease embed_translations -VERSION = 1.99.99.5 -DEFINES += QV_MAJOR_VERSION=\"\\\"$${VERSION}\\\"\" +# Now read build number file. +_BUILD_NUMBER=$$cat(Build.Counter) +_BUILD_NUMBER = $$num_add($$_BUILD_NUMBER, 1) +write_file("Build.Counter", _BUILD_NUMBER) +VERSION = 1.99.99.$$_BUILD_NUMBER + +DEFINES += QV_MAJOR_VERSION=\"\\\"$${VERSION}\\\"\" SOURCES += \ src/main.cpp \ src/QvConfigUpgrade.cpp \ diff --git a/src/Qv2rayBase.h b/src/Qv2rayBase.h index 30ef28a8..07bbc985 100644 --- a/src/Qv2rayBase.h +++ b/src/Qv2rayBase.h @@ -62,6 +62,8 @@ namespace Qv2ray // SOCKS int socks_port; bool socks_useAuth; + bool socksUDP; + string socksLocalIP; AccountObject socksAccount; // HTTP int http_port; @@ -73,8 +75,10 @@ namespace Qv2ray socks_port = socksPort; http_port = httpPort; listenip = listen; + socksLocalIP = "0.0.0.0"; + socksUDP = true; } - XTOSTRUCT(O(listenip, socks_port, socks_useAuth, socksAccount, http_port, http_useAuth, httpAccount)) + XTOSTRUCT(O(listenip, socks_port, socks_useAuth, socksAccount, socksUDP, socksLocalIP, http_port, http_useAuth, httpAccount)) }; struct Qv2rayConfig { diff --git a/src/QvConfigUpgrade.cpp b/src/QvConfigUpgrade.cpp index 95acb31d..3ebe376f 100644 --- a/src/QvConfigUpgrade.cpp +++ b/src/QvConfigUpgrade.cpp @@ -5,7 +5,7 @@ #include "QvUtils.h" -#define UPDATELOG(msg) LOG(MODULE_CONFIG, "[" + to_string(fromVersion) + "-" + to_string(fromVersion + 1) + "] --> " msg) +#define UPDATELOG(msg) LOG(MODULE_CONFIG, " [" + to_string(fromVersion) + "-" + to_string(fromVersion + 1) + "] --> " msg) namespace Qv2ray { @@ -78,6 +78,7 @@ namespace Qv2ray case 6: { root["enableStats"] = true; UPDATELOG("Default statistics enabled.") + break; } } diff --git a/src/QvCoreConfigOperations_Generation.cpp b/src/QvCoreConfigOperations_Generation.cpp index 4620731e..a1555224 100644 --- a/src/QvCoreConfigOperations_Generation.cpp +++ b/src/QvCoreConfigOperations_Generation.cpp @@ -119,7 +119,12 @@ namespace Qv2ray accounts.append(GetRootObject(acc)); } - JADD(auth, accounts, udp, ip, userLevel) + if (udp) { + JADD(auth, accounts, udp, ip, userLevel) + } else { + JADD(auth, accounts, userLevel) + } + RROOT } @@ -208,7 +213,10 @@ namespace Qv2ray socksInBoundObject.insert("port", gConf.inBoundSettings.socks_port); socksInBoundObject.insert("protocol", "socks"); socksInBoundObject.insert("tag", "socks_IN"); - auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", QList() << gConf.inBoundSettings.socksAccount); + auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", + QList() << gConf.inBoundSettings.socksAccount, + gConf.inBoundSettings.socksUDP, + QSTRING(gConf.inBoundSettings.socksLocalIP)); socksInBoundObject.insert("settings", socksInSettings); inboundsList.append(socksInBoundObject); } @@ -237,7 +245,7 @@ namespace Qv2ray // TODO // // We don't want to add MUX into the first one in the list..... - // However, this can be added to the Connection Edit Window... + // TODO: However, this can be added to the Connection Edit Window... //QJsonObject first = outbounds.first().toObject(); //first.insert("mux", GetRootObject(gConf.mux)); //outbounds[0] = first; diff --git a/src/QvCoreInteractions.cpp b/src/QvCoreInteractions.cpp index b515c423..bc7bd62d 100644 --- a/src/QvCoreInteractions.cpp +++ b/src/QvCoreInteractions.cpp @@ -98,6 +98,7 @@ namespace Qv2ray void Qv2Instance::StopVCore() { vProcess->close(); + lastData = QMap(); VCoreStatus = STOPPED; } diff --git a/src/main.cpp b/src/main.cpp index 1b940b1c..e8910836 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,6 +104,7 @@ int main(int argc, char *argv[]) LOG(MODULE_UI, "Found Translator: " + lang.toStdString()) } } + // Qv2ray Initialize if (!initQv()) return -1; diff --git a/src/ui/w_InboundEditor.cpp b/src/ui/w_InboundEditor.cpp index 13c486fc..71998567 100644 --- a/src/ui/w_InboundEditor.cpp +++ b/src/ui/w_InboundEditor.cpp @@ -159,20 +159,24 @@ void InboundEditor::on_httpRemoveUserBtn_clicked() PREPARE_RETURN if (ui->httpAccountListBox->currentRow() != -1) { - auto userpass = ui->httpAccountListBox->currentItem(); + auto item = ui->httpAccountListBox->currentItem(); auto list = httpSettings["accounts"].toArray(); for (int i = 0 ; i < list.count(); i++) { auto user = list[i].toObject(); + auto entry = user["user"].toString() + ":" + user["pass"].toString(); - if (user["user"].toString() + ":" + user["pass"].toString() == userpass->text()) { + if (entry == item->text().trimmed()) { list.removeAt(i); - ui->httpAccountListBox->removeItemWidget(userpass); - return; + httpSettings["accounts"] = list; + LOG(MODULE_UI, "Removed http inbound user " + entry.toStdString()) + ui->httpAccountListBox->takeItem(ui->httpAccountListBox->currentRow()); } } + + //QvMessageBox(this, tr("Removing a user"), tr("No user has been removed. Why?")); } else { - QvMessageBox(this, tr("Removing a user"), tr("You haven't selected a user yet,")); + QvMessageBox(this, tr("Removing a user"), tr("You haven't selected a user yet.")); } } @@ -193,13 +197,68 @@ void InboundEditor::on_httpAddUserBtn_clicked() } } + ui->httpAddUserTxt->clear(); + ui->httpAddPasswordTxt->clear(); QJsonObject entry; entry["user"] = user; entry["pass"] = pass; list.append(entry); + ui->httpAccountListBox->addItem(user + ":" + pass); httpSettings["accounts"] = list; } +void InboundEditor::on_socksRemoveUserBtn_clicked() +{ + PREPARE_RETURN + + if (ui->socksAccountListBox->currentRow() != -1) { + auto item = ui->socksAccountListBox->currentItem(); + auto list = socksSettings["accounts"].toArray(); + + for (int i = 0 ; i < list.count(); i++) { + auto user = list[i].toObject(); + auto entry = user["user"].toString() + ":" + user["pass"].toString(); + + if (entry == item->text().trimmed()) { + list.removeAt(i); + socksSettings["accounts"] = list; + LOG(MODULE_UI, "Removed http inbound user " + entry.toStdString()) + ui->socksAccountListBox->takeItem(ui->socksAccountListBox->currentRow()); + return; + } + } + } else { + QvMessageBox(this, tr("Removing a user"), tr("You haven't selected a user yet.")); + } +} + +void InboundEditor::on_socksAddUserBtn_clicked() +{ + PREPARE_RETURN + auto user = ui->socksAddUserTxt->text(); + auto pass = ui->socksAddPasswordTxt->text(); + // + auto list = socksSettings["accounts"].toArray(); + + for (int i = 0 ; i < list.count(); i++) { + auto _user = list[i].toObject(); + + if (_user["user"].toString() == user) { + QvMessageBox(this, tr("Add a user"), tr("This user exists already.")); + return; + } + } + + ui->socksAddUserTxt->clear(); + ui->socksAddPasswordTxt->clear(); + QJsonObject entry; + entry["user"] = user; + entry["pass"] = pass; + list.append(entry); + ui->socksAccountListBox->addItem(user + ":" + pass); + socksSettings["accounts"] = list; +} + void InboundEditor::on_strategyCombo_currentIndexChanged(const QString &arg1) { PREPARE_RETURN @@ -259,52 +318,6 @@ void InboundEditor::on_socksUserLevelSB_valueChanged(int arg1) socksSettings["userLevel"] = arg1; } -void InboundEditor::on_socksRemoveUserBtn_clicked() -{ - PREPARE_RETURN - - if (ui->socksAccountListBox->currentRow() != -1) { - auto userpass = ui->socksAccountListBox->currentItem(); - auto list = socksSettings["accounts"].toArray(); - - for (int i = 0 ; i < list.count(); i++) { - auto user = list[i].toObject(); - - if (user["user"].toString() + ":" + user["pass"].toString() == userpass->text()) { - list.removeAt(i); - ui->socksAccountListBox->removeItemWidget(userpass); - return; - } - } - } else { - QvMessageBox(this, tr("Removing a user"), tr("You haven't selected a user yet,")); - } -} - -void InboundEditor::on_socksAddUserBtn_clicked() -{ - PREPARE_RETURN - auto user = ui->socksAddUserTxt->text(); - auto pass = ui->socksAddPasswordTxt->text(); - // - auto list = socksSettings["accounts"].toArray(); - - for (int i = 0 ; i < list.count(); i++) { - auto _user = list[i].toObject(); - - if (_user["user"].toString() == user) { - QvMessageBox(this, tr("Add a user"), tr("This user exists already.")); - return; - } - } - - QJsonObject entry; - entry["user"] = user; - entry["pass"] = pass; - list.append(entry); - socksSettings["accounts"] = list; -} - void InboundEditor::on_dokoIPAddrTxt_textEdited(const QString &arg1) { PREPARE_RETURN diff --git a/src/ui/w_InboundEditor.ui b/src/ui/w_InboundEditor.ui index 915eb3c0..82da713e 100644 --- a/src/ui/w_InboundEditor.ui +++ b/src/ui/w_InboundEditor.ui @@ -294,7 +294,7 @@ - 1 + 0 diff --git a/src/ui/w_MainWindow.cpp b/src/ui/w_MainWindow.cpp index 388ef1f7..c541638a 100644 --- a/src/ui/w_MainWindow.cpp +++ b/src/ui/w_MainWindow.cpp @@ -262,8 +262,8 @@ void MainWindow::on_stopButton_clicked() ui->startButton->setEnabled(true); ui->stopButton->setEnabled(false); // - ui->netspeedLabel->setText(""); - ui->dataamountLabel->setText(""); + ui->netspeedLabel->setText("0.00 B/s\r\n0.00 B/s"); + ui->dataamountLabel->setText("0.00 B\r\n0.00 B"); } } diff --git a/src/ui/w_MainWindow.ui b/src/ui/w_MainWindow.ui index be1a5796..361641eb 100644 --- a/src/ui/w_MainWindow.ui +++ b/src/ui/w_MainWindow.ui @@ -251,8 +251,8 @@ - 0.00 KB/s -0.00 KB/s + 0.00 B/s +0.00 B/s @@ -325,8 +325,8 @@ - 0.00 KB -0.00 KB + 0.00 B +0.00 B diff --git a/src/ui/w_PrefrencesWindow.cpp b/src/ui/w_PrefrencesWindow.cpp index 29bca5e4..26dde8cd 100644 --- a/src/ui/w_PrefrencesWindow.cpp +++ b/src/ui/w_PrefrencesWindow.cpp @@ -55,6 +55,10 @@ PrefrencesWindow::PrefrencesWindow(QWidget *parent) : QDialog(parent), ui->socksAuthPasswordTxt->setEnabled(have_socks && CurrentConfig.inBoundSettings.socks_useAuth); ui->socksAuthUsernameTxt->setText(QSTRING(CurrentConfig.inBoundSettings.socksAccount.user)); ui->socksAuthPasswordTxt->setText(QSTRING(CurrentConfig.inBoundSettings.socksAccount.pass)); + // Socks UDP Options + ui->socksUDPCB->setChecked(CurrentConfig.inBoundSettings.socksUDP); + ui->socksUDPIP->setEnabled(CurrentConfig.inBoundSettings.socksUDP); + ui->socksUDPIP->setText(QSTRING(CurrentConfig.inBoundSettings.socksLocalIP)); // // ui->vCoreAssetsPathTxt->setText(QSTRING(CurrentConfig.v2AssetsPath)); @@ -363,3 +367,16 @@ void PrefrencesWindow::on_httpPortLE_valueChanged(int arg1) NEEDRESTART CurrentConfig.inBoundSettings.http_port = arg1; } + +void PrefrencesWindow::on_socksUDPCB_stateChanged(int arg1) +{ + NEEDRESTART + CurrentConfig.inBoundSettings.socksUDP = arg1 == Qt::Checked; + ui->socksUDPIP->setEnabled(arg1 == Qt::Checked); +} + +void PrefrencesWindow::on_socksUDPIP_textEdited(const QString &arg1) +{ + NEEDRESTART + CurrentConfig.inBoundSettings.socksLocalIP = arg1.toStdString(); +} diff --git a/src/ui/w_PrefrencesWindow.h b/src/ui/w_PrefrencesWindow.h index 6f3bf9fb..a2cb1df4 100644 --- a/src/ui/w_PrefrencesWindow.h +++ b/src/ui/w_PrefrencesWindow.h @@ -77,6 +77,10 @@ class PrefrencesWindow : public QDialog void on_statsPortBox_valueChanged(int arg1); + void on_socksUDPCB_stateChanged(int arg1); + + void on_socksUDPIP_textEdited(const QString &arg1); + private: bool IsConnectionPropertyChanged = false; bool finishedLoading = false; diff --git a/src/ui/w_PrefrencesWindow.ui b/src/ui/w_PrefrencesWindow.ui index a33d240e..64af6b51 100644 --- a/src/ui/w_PrefrencesWindow.ui +++ b/src/ui/w_PrefrencesWindow.ui @@ -7,7 +7,7 @@ 0 0 710 - 380 + 417 @@ -213,7 +213,11 @@ - + + + 0.0.0.0 + + @@ -271,7 +275,11 @@ - + + + user + + @@ -281,7 +289,39 @@ - + + + pass + + + + + + + SOCKS UDP + + + + + + + Local IP + + + + + + + Enabled + + + + + + + 127.0.0.1 + + @@ -341,7 +381,11 @@ - + + + user + + @@ -351,7 +395,11 @@ - + + + pass + + @@ -496,7 +544,7 @@ - + @@ -529,7 +577,7 @@ - + @@ -580,7 +628,7 @@ - + @@ -631,7 +679,7 @@ - + Qt::Vertical @@ -644,7 +692,7 @@ - + @@ -657,7 +705,7 @@ - + Qt::Vertical @@ -670,7 +718,7 @@ - + @@ -708,6 +756,39 @@ + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Built Time + + + + + + + + 10 + + + + + +