61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
#ifndef SERVERPROCESS_H
|
|
#define SERVERPROCESS_H
|
|
|
|
#include <QObject>
|
|
#include <QProcess>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QTcpSocket>
|
|
|
|
class ServerProcess : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ServerProcess(QObject *parent = nullptr);
|
|
~ServerProcess();
|
|
|
|
void start(const QString &configPath);
|
|
void stop();
|
|
void fetchStats();
|
|
bool kickPlayer(int playerId, const QString &reason = QString());
|
|
bool banPlayer(int playerId, const QString &reason = QString());
|
|
bool unbanIp(const QString &ip);
|
|
QJsonArray listBans();
|
|
bool isRunning() const;
|
|
QString serverDirectory() const;
|
|
void setAdminPort(int port);
|
|
int adminPort() const;
|
|
|
|
signals:
|
|
void started();
|
|
void stopped();
|
|
void logMessage(const QString &message);
|
|
void clientsUpdated(const QJsonArray &clients);
|
|
void statsUpdated(const QJsonObject &stats);
|
|
void error(const QString &message);
|
|
void adminCommandFinished(bool ok, const QString &message);
|
|
|
|
private slots:
|
|
void onProcessStarted();
|
|
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
|
void onProcessError(QProcess::ProcessError error);
|
|
void onReadyReadStandardOutput();
|
|
void onReadyReadStandardError();
|
|
|
|
private:
|
|
QString findPythonExecutable();
|
|
QString findServerDirectory();
|
|
void parseLogLine(const QString &line);
|
|
QJsonObject sendAdminCommand(const QJsonObject &request);
|
|
|
|
QProcess *process;
|
|
QString pythonPath;
|
|
QString serverDir;
|
|
bool running;
|
|
QString outputBuffer;
|
|
int m_adminPort;
|
|
int adminFailCount;
|
|
};
|
|
|
|
#endif // SERVERPROCESS_H
|