Add bandwidth limit of 10kb/s(#863)

This commit is contained in:
David Markowitz 2022-12-05 16:08:47 -08:00 committed by GitHub
parent 0a616f891f
commit 18a0ae599b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 7 deletions

View File

@ -83,7 +83,7 @@ int main(int argc, char** argv) {
if (config.GetValue("max_clients") != "") maxClients = std::stoi(config.GetValue("max_clients"));
if (config.GetValue("port") != "") ourPort = std::atoi(config.GetValue("port").c_str());
Game::server = new dServer(config.GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth);
Game::server = new dServer(config.GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth, Game::config);
//Run it until server gets a kill message from Master:
auto t = std::chrono::high_resolution_clock::now();

View File

@ -103,7 +103,7 @@ int main(int argc, char** argv) {
if (config.GetValue("max_clients") != "") maxClients = std::stoi(config.GetValue("max_clients"));
if (config.GetValue("port") != "") ourPort = std::atoi(config.GetValue("port").c_str());
Game::server = new dServer(config.GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat);
Game::server = new dServer(config.GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat, Game::config);
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(config.GetValue("dont_generate_dcf"))));

View File

@ -1778,6 +1778,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
scriptedActivityComponent->ReloadConfig();
}
Game::server->UpdateBandwidthLimit();
ChatPackets::SendSystemMessage(sysAddr, u"Successfully reloaded config for world!");
}

View File

@ -216,7 +216,7 @@ int main(int argc, char** argv) {
if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients"));
if (Game::config->GetValue("port") != "") ourPort = std::stoi(Game::config->GetValue("port"));
Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master);
Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config);
//Query for the database for a server labeled "master"
auto* masterLookupStatement = Database::CreatePreppedStmt("SELECT id FROM `servers` WHERE `name` = 'master'");

View File

@ -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);

View File

@ -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;

View File

@ -208,7 +208,7 @@ int main(int argc, char** argv) {
LootGenerator::Instance();
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(config.GetValue("dont_generate_dcf"))));
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, zoneID);
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, zoneID);
//Connect to the chat server:
int chatPort = 1501;

View File

@ -25,3 +25,6 @@ dump_folder=
# The location of the client
# Either the folder with /res or with /client and /versions
client_location=
# The maximum outgoing bandwidth in bits
maximum_outgoing_bandwidth=80000