From c8b011913a9e161fa5acc017b2e718c3f4ae70cd Mon Sep 17 00:00:00 2001 From: dongresource Date: Wed, 2 Dec 2020 23:42:33 +0100 Subject: [PATCH] Make monitor parameters configurable --- config.ini | 7 +++++++ src/Monitor.cpp | 7 ++++--- src/settings.cpp | 6 ++++++ src/settings.hpp | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/config.ini b/config.ini index ed3d154..6d39c93 100644 --- a/config.ini +++ b/config.ini @@ -65,3 +65,10 @@ eventcratechance=10 spawnx=632032 spawny=187177 spawnz=-5500 + +# Player location monitor interface configuration +[monitor] +# the port to listen for connections on +port=8003 +# how often the listeners should be updated (in milliseconds) +interval=5000 diff --git a/src/Monitor.cpp b/src/Monitor.cpp index 8db00c1..b0501eb 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -2,6 +2,7 @@ #include "PlayerManager.hpp" #include "CNStructs.hpp" #include "Monitor.hpp" +#include "settings.hpp" #include @@ -26,7 +27,7 @@ void Monitor::init() { address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = htons(8003); + address.sin_port = htons(settings::MONITORPORT); if (bind(listener, (struct sockaddr*)&address, sizeof(address)) < 0) { perror("bind"); @@ -38,9 +39,9 @@ void Monitor::init() { exit(1); } - std::cout << "[INFO] Monitor listening on *:8003" << std::endl; + std::cout << "[INFO] Monitor listening on *:" << settings::MONITORPORT << std::endl; - REGISTER_SHARD_TIMER(tick, 5000); + REGISTER_SHARD_TIMER(tick, settings::MONITORINTERVAL); } static bool transmit(std::list::iterator& it, char *buff, int len) { diff --git a/src/settings.cpp b/src/settings.cpp index df2f8fc..c4db43f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -30,6 +30,10 @@ std::string settings::GRUNTWORKJSON = "tdata/gruntwork.json"; std::string settings::MOTDSTRING = "Welcome to OpenFusion!"; int settings::ACCLEVEL = 1; +// monitor settings +int settings::MONITORPORT = 8003; +int settings::MONITORINTERVAL = 5000; + // event mode settings int settings::EVENTMODE = 0; int settings::EVENTCRATECHANCE = 10; @@ -70,4 +74,6 @@ void settings::init() { ACCLEVEL = reader.GetInteger("shard", "accountlevel", ACCLEVEL); EVENTMODE = reader.GetInteger("shard", "eventmode", EVENTMODE); EVENTCRATECHANCE = reader.GetInteger("shard", "eventcratechance", EVENTCRATECHANCE); + MONITORPORT = reader.GetInteger("monitor", "port", MONITORPORT); + MONITORINTERVAL = reader.GetInteger("monitor", "interval", MONITORINTERVAL); } diff --git a/src/settings.hpp b/src/settings.hpp index 73c2ec2..60476f6 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -25,6 +25,8 @@ namespace settings { extern std::string GRUNTWORKJSON; extern int EVENTMODE; extern int EVENTCRATECHANCE; + extern int MONITORPORT; + extern int MONITORINTERVAL; void init(); }