diff options
| author | Dark1-dev <shansarkar272@gmail.com> | 2023-03-01 21:30:57 +0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-01 21:30:57 +0600 |
| commit | 60a301a93b6057bb2c54ac04a7c38c38389037b3 (patch) | |
| tree | b09c5f8bc0045828c660654d8ed6744663856202 /src/TcpTasks/Updater | |
| parent | c784240d1af68dbd8d0466822b34fd05d6ccdda1 (diff) | |
| download | Masterserver-Qt5-60a301a93b6057bb2c54ac04a7c38c38389037b3.tar.gz Masterserver-Qt5-60a301a93b6057bb2c54ac04a7c38c38389037b3.zip | |
Add files via upload
Diffstat (limited to 'src/TcpTasks/Updater')
| -rw-r--r-- | src/TcpTasks/Updater/onsynctickeraction.cpp | 20 | ||||
| -rw-r--r-- | src/TcpTasks/Updater/scheduleupdater.cpp | 29 | ||||
| -rw-r--r-- | src/TcpTasks/Updater/syncupdater.cpp | 7 | ||||
| -rw-r--r-- | src/TcpTasks/Updater/syncupdater.h | 33 |
4 files changed, 89 insertions, 0 deletions
diff --git a/src/TcpTasks/Updater/onsynctickeraction.cpp b/src/TcpTasks/Updater/onsynctickeraction.cpp new file mode 100644 index 0000000..53214ce --- /dev/null +++ b/src/TcpTasks/Updater/onsynctickeraction.cpp @@ -0,0 +1,20 @@ +#include "syncupdater.h" + +void SyncUpdater::onSyncTickerAction() +{ + // exists? + if ( _syncIndex < _coreObject->Settings.SyncerSettings.syncServers.length() ) + { + // retrieve sync settings from config + SyncServer syncServ = _coreObject->Settings.SyncerSettings.syncServers.at(_syncIndex); + _syncIndex++; + + // execute sync with remote masterserver + new SyncClient(_coreObject, syncServ.remoteAddress, syncServ.listenPort); + } + else + { + // last entry. turn off timer + _syncTicker.stop(); + } +} diff --git a/src/TcpTasks/Updater/scheduleupdater.cpp b/src/TcpTasks/Updater/scheduleupdater.cpp new file mode 100644 index 0000000..7a96d6e --- /dev/null +++ b/src/TcpTasks/Updater/scheduleupdater.cpp @@ -0,0 +1,29 @@ +#include "syncupdater.h" + +bool SyncUpdater::scheduleUpdater() +{ + // schedule sync X seconds apart (prevent network spikes) + connect(&_syncTicker, &QTimer::timeout, this, &SyncUpdater::onSyncTickerAction); + _syncTicker.setInterval( _graceTime_ms ); + + // set update timer + connect(&_updaterTimer, &QTimer::timeout, [this] + { + // reset and start ticker + _syncIndex = 0; + _syncTicker.start(); + }); + + _updaterTimer.setInterval( _coreObject->Settings.SyncerSettings.syncInterval_s * 1000); + _updaterTimer.start(); + + // complete startup + _coreObject->Log.logEvent("info", QStringLiteral("sync with other masterservers every %1 seconds") + .arg(_coreObject->Settings.SyncerSettings.syncInterval_s)); + + // run immediately at startup + _syncIndex = 0; + _syncTicker.start(); + + return true; +} diff --git a/src/TcpTasks/Updater/syncupdater.cpp b/src/TcpTasks/Updater/syncupdater.cpp new file mode 100644 index 0000000..da52f12 --- /dev/null +++ b/src/TcpTasks/Updater/syncupdater.cpp @@ -0,0 +1,7 @@ +#include "syncupdater.h" + +SyncUpdater::SyncUpdater(const QSharedPointer<CoreObject> &coreObject) +{ + // create local access + this->_coreObject = coreObject; +} diff --git a/src/TcpTasks/Updater/syncupdater.h b/src/TcpTasks/Updater/syncupdater.h new file mode 100644 index 0000000..9bd2299 --- /dev/null +++ b/src/TcpTasks/Updater/syncupdater.h @@ -0,0 +1,33 @@ +#ifndef SYNCUPDATER_H +#define SYNCUPDATER_H + +#include <QTimer> +#include <QHostInfo> + +#include "Core/CoreObject/coreobject.h" +#include "Database/Common/commonactions.h" +#include "TcpTasks/SyncClient/syncclient.h" + +class SyncUpdater: public QObject +{ + Q_OBJECT +public: + SyncUpdater(const QSharedPointer<CoreObject> &coreObject); + bool scheduleUpdater(); + +private: + QSharedPointer<CoreObject> _coreObject; + const int _graceTime_ms = 5000; + + // update/ticker timer + QTimer _updaterTimer; + QTimer _syncTicker; + + // index + int _syncIndex = 0; + +private slots: + void onSyncTickerAction(); +}; + +#endif // SYNCUPDATER_H |
