Make monitor parameters configurable

This commit is contained in:
dongresource 2020-12-02 23:42:33 +01:00
parent 15b63f3cbd
commit c8b011913a
4 changed files with 19 additions and 3 deletions

View File

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

View File

@ -2,6 +2,7 @@
#include "PlayerManager.hpp"
#include "CNStructs.hpp"
#include "Monitor.hpp"
#include "settings.hpp"
#include <cstdio>
@ -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<int>::iterator& it, char *buff, int len) {

View File

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

View File

@ -25,6 +25,8 @@ namespace settings {
extern std::string GRUNTWORKJSON;
extern int EVENTMODE;
extern int EVENTCRATECHANCE;
extern int MONITORPORT;
extern int MONITORINTERVAL;
void init();
}