Skip to content

Commit

Permalink
Added the online status option
Browse files Browse the repository at this point in the history
changed backend to use enums and one function for status changing
  • Loading branch information
Latrolage committed Jul 28, 2022
1 parent 2fd1570 commit 0549719
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 33 deletions.
3 changes: 2 additions & 1 deletion autoaccept.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
######################################################################

QT += widgets

CONFIG += c++11
TEMPLATE = app
TARGET = autoaccept
INCLUDEPATH += .
Expand All @@ -27,6 +27,7 @@ RESOURCES += a.qrc

HEADERS += \
base64.h \
enums.h \
generalcurling.h \
leaguefiles.h \
menuclickedactions.h
265 changes: 265 additions & 0 deletions autoaccept.pro.user

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef ENUMS_H
#define ENUMS_H

enum STATUSNUMBERS {
STATUSCHANGE=1,
ONLINE=2,
OFFLINE=3
};

#endif // ENUMS_H
28 changes: 19 additions & 9 deletions generalcurling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata) {
if (methodtype == "GET")
chatmedata += ptr[i];
else {
std::cout << ptr[i];
//std::cout << ptr[i];
}
}
return 0;
}
void curlstuff(const std::string& port, const std::string& pass,const std::string location, const std::string method, std::string* postdata) {
void curlstuff(const std::string& port, const std::string& pass,const std::string location, const std::string method, const short status, std::string* postdata) {
methodtype = method;
//CURLcode ret; //unused
CURL* curl;
Expand All @@ -39,16 +39,26 @@ void curlstuff(const std::string& port, const std::string& pass,const std::strin
if (method == "GET") {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
} else if (method == "PUT") {
if (chatmedata.find("offline") != std::string::npos) {
std::cout << "Skip fakeoffline, (already offline)\n";
return;
}
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
slist1 = curl_slist_append(slist1, "Content-Type: application/json");
chatmedata = std::regex_replace(chatmedata, std::regex("(.*)\"availability\":\".*?\"(.*)"), "$01\"availability\":\"offline\"$02");
switch (status) {
case ONLINE:
if (chatmedata.find(":\"online") != std::string::npos) {
std::cout << "Already online";
return;
}
chatmedata = std::regex_replace(chatmedata, std::regex("(.*)\"availability\":\".*?\"(.*)"), "$01\"availability\":\"online\"$02");
break;

case OFFLINE:
if (chatmedata.find("offline") != std::string::npos) {
std::cout << "Skip fakeoffline, (already offline)\n";
return;
}
chatmedata = std::regex_replace(chatmedata, std::regex("(.*)\"availability\":\".*?\"(.*)"), "$01\"availability\":\"offline\"$02");
break;
}
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, chatmedata.c_str());
// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, chatmedata.c_str());
// curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)933);
}
else {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
Expand Down
4 changes: 3 additions & 1 deletion generalcurling.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string>
#include <QtCore/QDebug>

#include "enums.h"

size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
void curlstuff(const std::string& port, const std::string& pass,const std::string location, const std::string method, std::string* postdata = nullptr);
void curlstuff(const std::string& port, const std::string& pass,const std::string location, const std::string method, const short status=0, std::string* postdata = nullptr);
#endif // GENERALCURLING_H
49 changes: 38 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
#include <QtGui/QIcon>
#include <QtWidgets/QSystemTrayIcon>
#include <QtWidgets/QMenu>
#include <QActionGroup>
#include <QLoggingCategory>

#include "enums.h"

void addStatusActions(QAction *&action, QMenu &menu, QActionGroup &actionGroup) {
action->setCheckable(true);
actionGroup.addAction(action);
menu.addAction(action);
}

int main(int argc, char *argv[])
{
if (argc != 1 && static_cast<std::string>(argv[1]) != "--nopkexec") system("pkexec sh -c 'sysctl -w abi.vsyscall32=0' > /dev/null");
Expand All @@ -16,26 +25,44 @@ int main(int argc, char *argv[])

QMenu menu;
QSystemTrayIcon TrayIcon(QIcon(":systemTrayIcon.png"));
auto menuClicked = new menuClickedActions();

TrayIcon.show();

QAction *autoacceptAction=new QAction("Autoaccept", NULL);
QObject::connect(autoacceptAction, SIGNAL(triggered(bool)), menuClicked, SLOT(accept(bool)));
autoacceptAction->setCheckable(true);
QAction *offlineAction=new QAction("Offline", NULL);
offlineAction->setCheckable(true);
QAction *exitAction=new QAction("Exit", NULL);

menu.addAction(autoacceptAction);
menu.addAction(offlineAction);
autoacceptAction->trigger();


QMenu statusButtonsMenu("Status");
QActionGroup statusActionGroup(nullptr);
menu.addMenu(&statusButtonsMenu);
statusActionGroup.setExclusive(true);
QAction *statusAction=new QAction("Online", NULL); // Online Status
QObject::connect(statusAction, &QAction::triggered, [&menuClicked] (bool checked) {
menuClicked->statusChange(checked, ONLINE);
});
addStatusActions(statusAction, statusButtonsMenu, statusActionGroup);
statusAction=new QAction("Offline", NULL); // Offline Status
QObject::connect(statusAction, &QAction::triggered, [&menuClicked] (bool checked) {
menuClicked->statusChange(checked, OFFLINE);
});
addStatusActions(statusAction, statusButtonsMenu, statusActionGroup);
statusAction=new QAction("None", NULL); // Don't try to force a status
addStatusActions(statusAction, statusButtonsMenu, statusActionGroup);
QObject::connect(statusAction, &QAction::triggered, [&menuClicked] (bool checked) {
menuClicked->statusChange(checked, 0b11111111);
});
// QObject::connect(statusAction, SIGNAL(triggered(bool)), menuClicked, SLOT(statusChange(bool, 0b11111111)));
statusAction->trigger();

QAction *exitAction=new QAction("Exit", NULL);
menu.addAction(exitAction);
QObject::connect(exitAction, SIGNAL(triggered()), &oApp, SLOT(quit()));

TrayIcon.setContextMenu(&menu);
auto menuClicked = new menuClickedActions();

QObject::connect(autoacceptAction, SIGNAL(triggered(bool)), menuClicked, SLOT(accept(bool)));
autoacceptAction->trigger();
QObject::connect(offlineAction, SIGNAL(triggered(bool)), menuClicked, SLOT(offline(bool)));
//offlineAction->trigger();
QObject::connect(exitAction, SIGNAL(triggered()), &oApp, SLOT(quit()));
return oApp.exec();
}
30 changes: 21 additions & 9 deletions menuclickedactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,30 @@ void menuClickedActions::acceptloop() {
}
return;
}
void menuClickedActions::offline(bool checked) {
checked ? (bools |= (0b1<<1)) : (bools &= ~(0b1<<1));
if (bools & (0b1 << 1)) {
std::thread offlineThread(&menuClickedActions::offlineloop, this);
offlineThread.detach();
void menuClickedActions::statusChange(bool checked, short newStatus) {
if (newStatus==0b11111111) {
checked &= newStatus;
curlstuff(database.theportnum(), database.thepassword(), "/lol-chat/v1/me", "PUT", ONLINE);
return;
}
checked ? (bools |= (0b1<<STATUSCHANGE)) : (bools &= ~(0b1<<STATUSCHANGE));
if (checked) {
bools = (0b1 << newStatus) | (bools & 0b1);
}
std::thread statusChangeLoop(&menuClickedActions::statusloop, this, newStatus);
statusChangeLoop.detach();
}
void menuClickedActions::offlineloop() {
while (bools & (0b1 << 1)) {
void menuClickedActions::statusloop(short newStatus) {
while (bools & (0b1 << newStatus)) {
curlstuff(database.theportnum(), database.thepassword(), "/lol-chat/v1/me", "GET"); //data[0]=portnum,data[1]=password
curlstuff(database.theportnum(), database.thepassword(), "/lol-chat/v1/me", "PUT"); //data[0]=portnum,data[1]=password
switch (newStatus) {
case ONLINE:
curlstuff(database.theportnum(), database.thepassword(), "/lol-chat/v1/me", "PUT", ONLINE);
break;
case OFFLINE:
curlstuff(database.theportnum(), database.thepassword(), "/lol-chat/v1/me", "PUT", OFFLINE);
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
}
return;
}
5 changes: 3 additions & 2 deletions menuclickedactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <bitset>

#include "leaguefiles.h"
#include "enums.h"
#include "base64.h"
#include "generalcurling.h"

Expand All @@ -19,11 +20,11 @@ class menuClickedActions : public QObject
unsigned short bools;
void authentication();
void acceptloop();
void offlineloop();
void statusloop(short);
signals:
public slots:
void accept(bool);
void offline(bool);
void statusChange(bool, short);
public:
menuClickedActions();
};
Expand Down

0 comments on commit 0549719

Please sign in to comment.