mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
Add bandwidth limit of 10kb/s(#863)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "dServer.h"
|
||||
#include "dNetCommon.h"
|
||||
#include "dLogger.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
#include "RakNetworkFactory.h"
|
||||
#include "MessageIdentifiers.h"
|
||||
@@ -35,7 +36,7 @@ public:
|
||||
}
|
||||
} ReceiveDownloadCompleteCB;
|
||||
|
||||
dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, dLogger* logger, const std::string masterIP, int masterPort, ServerType serverType, unsigned int zoneID) {
|
||||
dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, dLogger* logger, const std::string masterIP, int masterPort, ServerType serverType, dConfig* config, unsigned int zoneID) {
|
||||
mIP = ip;
|
||||
mPort = port;
|
||||
mZoneID = zoneID;
|
||||
@@ -50,6 +51,7 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect
|
||||
mNetIDManager = nullptr;
|
||||
mReplicaManager = nullptr;
|
||||
mServerType = serverType;
|
||||
mConfig = config;
|
||||
//Attempt to start our server here:
|
||||
mIsOkay = Startup();
|
||||
|
||||
@@ -181,7 +183,7 @@ bool dServer::Startup() {
|
||||
if (mIsInternal) {
|
||||
mPeer->SetIncomingPassword("3.25 DARKFLAME1", 15);
|
||||
} else {
|
||||
//mPeer->SetPerConnectionOutgoingBandwidthLimit(800000); //100Kb/s
|
||||
UpdateBandwidthLimit();
|
||||
mPeer->SetIncomingPassword("3.25 ND1", 8);
|
||||
}
|
||||
|
||||
@@ -191,6 +193,11 @@ bool dServer::Startup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void dServer::UpdateBandwidthLimit() {
|
||||
auto newBandwidth = mConfig->GetValue("maximum_outgoing_bandwidth");
|
||||
mPeer->SetPerConnectionOutgoingBandwidthLimit(!newBandwidth.empty() ? std::stoi(newBandwidth) : 0);
|
||||
}
|
||||
|
||||
void dServer::Shutdown() {
|
||||
if (mPeer) {
|
||||
mPeer->Shutdown(1000);
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "NetworkIDManager.h"
|
||||
|
||||
class dLogger;
|
||||
class dConfig;
|
||||
|
||||
enum class ServerType : uint32_t {
|
||||
Master,
|
||||
@@ -17,7 +18,7 @@ class dServer {
|
||||
public:
|
||||
// Default constructor should only used for testing!
|
||||
dServer() {};
|
||||
dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, dLogger* logger, const std::string masterIP, int masterPort, ServerType serverType, unsigned int zoneID = 0);
|
||||
dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, dLogger* logger, const std::string masterIP, int masterPort, ServerType serverType, dConfig* config, unsigned int zoneID = 0);
|
||||
~dServer();
|
||||
|
||||
Packet* ReceiveFromMaster();
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
const int GetInstanceID() const { return mInstanceID; }
|
||||
ReplicaManager* GetReplicaManager() { return mReplicaManager; }
|
||||
void UpdateReplica();
|
||||
void UpdateBandwidthLimit();
|
||||
|
||||
int GetPing(const SystemAddress& sysAddr) const;
|
||||
int GetLatestPing(const SystemAddress& sysAddr) const;
|
||||
@@ -58,6 +60,7 @@ private:
|
||||
|
||||
private:
|
||||
dLogger* mLogger = nullptr;
|
||||
dConfig* mConfig = nullptr;
|
||||
RakPeerInterface* mPeer = nullptr;
|
||||
ReplicaManager* mReplicaManager = nullptr;
|
||||
NetworkIDManager* mNetIDManager = nullptr;
|
||||
|
Reference in New Issue
Block a user