mirror of
https://github.com/SWG-Source/stationapi.git
synced 2026-01-15 22:04:17 -05:00
Added an option that allows the stationchat to bind to its config address instead of the default option of binding to any interface
This commit is contained in:
@@ -12,3 +12,9 @@ registrar_port = 5000
|
||||
|
||||
# Path to the application database
|
||||
database_path = chat.db
|
||||
|
||||
# Path to the application database
|
||||
database_path = chat.db
|
||||
|
||||
# When set to true, binds to the config address; otherwise, binds on any interface
|
||||
bind_to_ip = false
|
||||
|
||||
@@ -11,13 +11,21 @@
|
||||
template <typename NodeT, typename ClientT>
|
||||
class Node : public UdpManagerHandler {
|
||||
public:
|
||||
explicit Node(NodeT* node, const std::string& listenAddress, uint16_t listenPort)
|
||||
explicit Node(NodeT* node, const std::string& listenAddress, uint16_t listenPort, bool bindToIp = false)
|
||||
: node_{node} {
|
||||
|
||||
UdpManager::Params params;
|
||||
params.handler = this;
|
||||
params.port = listenPort;
|
||||
|
||||
if (bindToIp) {
|
||||
if (listenAddress.length() > sizeof(params.bindIpAddress)) {
|
||||
throw std::runtime_error{"Invalid bind ip specified: " + listenAddress};
|
||||
}
|
||||
|
||||
std::copy(std::begin(listenAddress), std::end(listenAddress), params.bindIpAddress);
|
||||
}
|
||||
|
||||
udpManager_ = new UdpManager(¶ms);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <sqlite3.h>
|
||||
|
||||
GatewayNode::GatewayNode(StationChatConfig& config)
|
||||
: Node(this, config.gatewayAddress, config.gatewayPort)
|
||||
: Node(this, config.gatewayAddress, config.gatewayPort, config.bindToIp)
|
||||
, config_{config} {
|
||||
if (sqlite3_open(config.chatDatabasePath.c_str(), &db_) != SQLITE_OK) {
|
||||
throw std::runtime_error("Can't open database: " + std::string{sqlite3_errmsg(db_)});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "StationChatConfig.hpp"
|
||||
|
||||
RegistrarNode::RegistrarNode(StationChatConfig& config)
|
||||
: Node(this, config.registrarAddress, config.registrarPort)
|
||||
: Node(this, config.registrarAddress, config.registrarPort, config.bindToIp)
|
||||
, config_{config} {}
|
||||
|
||||
RegistrarNode::~RegistrarNode() {}
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
struct StationChatConfig {
|
||||
StationChatConfig() = default;
|
||||
StationChatConfig(const std::string& gatewayAddress_, uint16_t gatewayPort_,
|
||||
const std::string& registrarAddress_, uint16_t registrarPort_, const std::string& chatDatabasePath_)
|
||||
const std::string& registrarAddress_, uint16_t registrarPort_, const std::string& chatDatabasePath_,
|
||||
bool bindToIp_)
|
||||
: gatewayAddress{gatewayAddress_}
|
||||
, gatewayPort{gatewayPort_}
|
||||
, registrarAddress{registrarAddress_}
|
||||
, registrarPort{registrarPort_}
|
||||
, chatDatabasePath{chatDatabasePath_} {}
|
||||
, chatDatabasePath{chatDatabasePath_}
|
||||
, bindToIp{bindToIp_} {}
|
||||
|
||||
const uint32_t version = 2;
|
||||
std::string gatewayAddress;
|
||||
@@ -21,4 +23,5 @@ struct StationChatConfig {
|
||||
uint16_t registrarPort;
|
||||
std::string chatDatabasePath;
|
||||
std::string loggerConfig;
|
||||
bool bindToIp;
|
||||
};
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
|
||||
INITIALIZE_EASYLOGGINGPP
|
||||
|
||||
StationChatConfig BuildConfiguration(int argc, char* argv[]);
|
||||
StationChatConfig BuildConfiguration(int argc, const char* argv[]);
|
||||
|
||||
#ifdef __GNUC__
|
||||
void SignalHandler(int sig);
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
#ifdef __GNUC__
|
||||
signal(SIGSEGV, SignalHandler);
|
||||
#endif
|
||||
@@ -46,7 +46,7 @@ int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
StationChatConfig BuildConfiguration(int argc, char* argv[]) {
|
||||
StationChatConfig BuildConfiguration(int argc, const char* argv[]) {
|
||||
namespace po = boost::program_options;
|
||||
StationChatConfig config;
|
||||
std::string configFile;
|
||||
@@ -72,6 +72,8 @@ StationChatConfig BuildConfiguration(int argc, char* argv[]) {
|
||||
"address for registrar connections")
|
||||
("registrar_port", po::value<uint16_t>(&config.registrarPort)->default_value(5000),
|
||||
"port for registrar connections")
|
||||
("bind_to_ip", po::value<bool>(&config.bindToIp)->default_value(false),
|
||||
"when set to true, binds to the config address; otherwise, binds on any interface")
|
||||
("database_path", po::value<std::string>(&config.chatDatabasePath)->default_value("chat.db"),
|
||||
"path to the sqlite3 database file")
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user