-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
460 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ qrc_*.cpp | |
ui_*.h | ||
Makefile* | ||
*-build-* | ||
Win32/ | ||
|
||
# QtCreator | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "launcher.h" | ||
|
||
namespace JKNetAPI{ | ||
QHostAddress jknethost(""); | ||
bool available; | ||
|
||
void Init(void){ | ||
QFuture<void> data = QtConcurrent::run([]{ | ||
/*Checking...connecting to main server etc... */ | ||
}); | ||
} | ||
|
||
QString* Auth(QString &username, QString &password){ | ||
|
||
return new QString; | ||
} | ||
|
||
bool CheckSession(QString &username, QString &session){ | ||
|
||
return false; | ||
} | ||
|
||
bool ChangePassword(QString &username, QString &oldpassword, QString &newpassword){ | ||
|
||
return false; | ||
} | ||
|
||
QString* GetServers(void){ | ||
|
||
return new QString; | ||
} | ||
|
||
QString* DoRequest(QString &module, QString &request){ | ||
|
||
return new QString; | ||
} | ||
|
||
QString* DoRequest(const char *module, const char *request){ | ||
|
||
return new QString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
|
||
namespace JKNetAPI{ | ||
extern QHostAddress jknethost; | ||
extern bool available; | ||
|
||
void Init(void); | ||
QString* Auth(QString &username, QString &password); | ||
bool CheckSession(QString &username, QString &session); | ||
bool ChangePassword(QString &username, QString &oldpassword, QString &newpassword); | ||
QString* GetServers(void); | ||
|
||
QString* DoRequest(QString &module, QString &request); | ||
QString* DoRequest(const char *module, const char *request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
#include "launcher.h" | ||
|
||
#include <QNetworkAccessManager> | ||
#include <QNetworkRequest> | ||
#include <QNetworkReply> | ||
|
||
|
||
void DoRequest(QString &request) | ||
{ | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
#include "launcher.h" | ||
#include <QRegExp> | ||
|
||
#define SERVER_TIMEOUT 5000 | ||
|
||
ServerAPI::ServerAPI(QString &ip, quint16 port){ | ||
this->ip = ip; | ||
this->port = port; | ||
|
||
if (this->ip.isNull() || this->port == 0) return; | ||
|
||
commsocket = new QUdpSocket(); | ||
commsocket->bind(); | ||
|
||
GetType(); // check server :d | ||
} | ||
|
||
ServerAPI::ServerAPI(QHostAddress &ip, quint16 port){ | ||
this->ip = ip; | ||
this->port = port; | ||
|
||
if (this->ip.isNull() || this->port == 0) return; | ||
|
||
commsocket = new QUdpSocket(); | ||
commsocket->bind(); | ||
|
||
|
||
GetType(); // check server :d | ||
} | ||
|
||
ServerAPI::~ServerAPI(){ | ||
delete commsocket; | ||
} | ||
|
||
ServerAPI::ServerType ServerAPI::GetType(void){ // JKNet Servers | ||
if (ip.isNull()) return SERVER_NULL; | ||
const char *str = "\xFF\xFF\xFF\xFFjknet gettype"; | ||
|
||
commsocket->writeDatagram(str, ip, port); | ||
QTime sendtime = QTime::currentTime(); | ||
sendtime.addMSecs(SERVER_TIMEOUT); | ||
|
||
while (!commsocket->hasPendingDatagrams()) { | ||
if (sendtime <= QTime::currentTime()) return SERVER_NULL; | ||
} | ||
while (commsocket->hasPendingDatagrams()){ // xddd | ||
int len = commsocket->pendingDatagramSize(); | ||
char *response = (char *)malloc(len); | ||
memset(response, 0, len); | ||
|
||
QHostAddress sender; | ||
quint16 senderPort; | ||
commsocket->readDatagram(response, len, &sender, &senderPort); | ||
if (/*(sender != ip) ||*/ (senderPort != port)){ | ||
continue; | ||
} | ||
|
||
QString data(response); | ||
DecodeMessage(data); | ||
/* | ||
*/ | ||
} | ||
|
||
return SERVER_NORMAL; | ||
} | ||
|
||
QMap<QString, QString>* ServerAPI::GetStatus(void){ | ||
if (ip.isNull()) return nullptr; | ||
|
||
QMap<QString, QString>* map; | ||
const char *str = "\xFF\xFF\xFF\xFFgetstatus"; | ||
|
||
commsocket->writeDatagram(str, ip, port); | ||
|
||
QTime sendtime = QTime::currentTime(); | ||
sendtime.addMSecs(SERVER_TIMEOUT); | ||
|
||
while (!commsocket->hasPendingDatagrams()) { | ||
if (sendtime <= QTime::currentTime()) return nullptr; | ||
} | ||
while (commsocket->hasPendingDatagrams()){ // xddd | ||
int len = commsocket->pendingDatagramSize(); | ||
char *response = (char *)malloc(len); | ||
memset(response, 0, len); | ||
QHostAddress sender; | ||
quint16 senderPort; | ||
commsocket->readDatagram(response, len, &sender, &senderPort); | ||
if (/*(sender != ip) ||*/ (senderPort != port)){ | ||
continue; | ||
} | ||
map = new QMap < QString, QString >; | ||
|
||
QString data(response); | ||
DecodeMessage(data); | ||
QChar delim('\\'); | ||
QStringList list = data.split(delim); | ||
for (int i = 1; i < list.count(); i++ , i++){ // i++ tw0 times | ||
map->insert(list[i], list[i + 1]); | ||
} | ||
} | ||
return map; /// | ||
} | ||
|
||
QMap<QString, QString>* ServerAPI::GetInfo(void){ | ||
if (ip.isNull()) return nullptr; | ||
|
||
QMap<QString, QString>* map; | ||
const char *str = "\xFF\xFF\xFF\xFFgetinfo"; | ||
|
||
commsocket->writeDatagram(str, ip, port); | ||
|
||
QTime sendtime = QTime::currentTime(); | ||
sendtime.addMSecs(SERVER_TIMEOUT); | ||
|
||
while (!commsocket->hasPendingDatagrams()) { | ||
if (sendtime <= QTime::currentTime()) return nullptr; | ||
} | ||
while (commsocket->hasPendingDatagrams()){ // xddd | ||
int len = commsocket->pendingDatagramSize(); | ||
char *response = (char *)malloc(len); | ||
memset(response, 0, len); | ||
QHostAddress sender; | ||
quint16 senderPort; | ||
commsocket->readDatagram(response, len, &sender, &senderPort); | ||
if (/*(sender != ip) ||*/ (senderPort != port)){ | ||
continue; | ||
} | ||
map = new QMap < QString, QString >; | ||
|
||
QString data(response); | ||
DecodeMessage(data); | ||
QChar delim('\\'); | ||
QStringList list = data.split(delim); | ||
for (int i = 1; i < list.count(); i++, i++){ // i++ tw0 times | ||
map->insert(list[i], list[i + 1]); | ||
} | ||
} | ||
return map; /// | ||
} | ||
|
||
void ServerAPI::SendCommand(QString &command){ | ||
if (ip.isNull()) return; | ||
EncodeMessage(command); | ||
commsocket->writeDatagram(command.toLocal8Bit(), ip, port); | ||
} | ||
|
||
int ServerAPI::Ping(void){ | ||
if (ip.isNull()) return -1; | ||
|
||
const char *str = "\xFF\xFF\xFF\xFFjknet ping"; | ||
|
||
commsocket->writeDatagram(str, ip, port); | ||
|
||
QTime sendtime = QTime::currentTime(); | ||
int receivetime = 0; | ||
sendtime.addMSecs(SERVER_TIMEOUT); | ||
sendtime.start(); | ||
|
||
while (!commsocket->hasPendingDatagrams()) { | ||
if (sendtime<= QTime::currentTime()) return -1; | ||
} | ||
while (commsocket->hasPendingDatagrams()){ // xddd | ||
int len = commsocket->pendingDatagramSize(); | ||
receivetime = sendtime.elapsed(); | ||
QHostAddress sender; | ||
quint16 senderPort; | ||
commsocket->readDatagram(NULL, len, &sender, &senderPort); | ||
if ((sender != ip) || (senderPort != port)){ | ||
receivetime = 0; //still zero | ||
continue; | ||
} | ||
} | ||
return receivetime; | ||
} | ||
|
||
void ServerAPI::EncodeMessage(QString &message){ | ||
message.insert(0, QString("\xFF\xFF\xFF\xFF")); | ||
} | ||
|
||
void ServerAPI::DecodeMessage(QString &message){ | ||
message.replace(0, 4, ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
|
||
class ServerAPI : public QObject{ | ||
private: | ||
QUdpSocket *commsocket; | ||
|
||
public: | ||
typedef enum{ | ||
SERVER_NULL = 0, | ||
SERVER_NORMAL, | ||
SERVER_JKNET, | ||
}ServerType; | ||
|
||
QHostAddress ip; | ||
quint16 port; | ||
ServerType type; | ||
|
||
ServerAPI(QString &ip, quint16 port = 29070); | ||
ServerAPI(QHostAddress &ip, quint16 port = 29070); | ||
~ServerAPI(); | ||
|
||
int Ping(void); | ||
void SendCommand(QString &command); | ||
QMap<QString, QString>* GetStatus(void); | ||
QMap<QString, QString>* GetInfo(void); | ||
ServerType GetType(void); | ||
|
||
static void EncodeMessage(QString &message); | ||
static void DecodeMessage(QString &message); | ||
}; |
Oops, something went wrong.