/* * Copyright (C) 2010,2011 by Jonathan Naylor G4KLX * Copyright (c) 2017,2018 by Thomas A. Early N7TAE * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include "SGSXLConfig.h" #include "SGSXLApp.h" #include "Version.h" #include "IRCDDBMultiClient.h" #include "IRCDDBClient.h" #include "Utils.h" #include "GitVersion.h" int main(int argc, char *argv[]) { setbuf(stdout, NULL); if (2 != argc) { printf("usage: %s path_to_config_file\n", argv[0]); printf(" %s --version\n", argv[0]); return 1; } if ('-' == argv[1][0]) { printf("\nSmart Group Server Version %s (GitID #%.7s) Copyright (C) %s\n", VERSION.c_str(), gitversion, VENDOR_NAME.c_str()); printf("Smart Group Server XL comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); return 0; } std::string cfgFile(argv[1]); CSGSXLApp gateway(cfgFile); if (!gateway.init()) { return 1; } gateway.run(); return 0; } CSGSXLApp::CSGSXLApp(const std::string &configFile) : m_configFile(configFile), m_thread(NULL) { } CSGSXLApp::~CSGSXLApp() { } bool CSGSXLApp::init() { return createThread(); } void CSGSXLApp::run() { m_thread->run(); printf("exiting\n"); } bool CSGSXLApp::createThread() { printf("\nSmart Group Server Version %s (GitID #%.7s) Copyright (C) %s\n", VERSION.c_str(), gitversion, VENDOR_NAME.c_str()); printf("Smart Group Server XL comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); CSGSXLConfig config(m_configFile); if(config.hasErrors()) { printf("Configuration has one or more errors. Aborting.\n"); return false; } m_thread = new CSGSXLThread(config.getLinkCount("XRF"), config.getLinkCount("DCS")); std::string CallSign, address; config.getGateway(CallSign, address); CallSign.resize(7, ' '); CallSign.push_back('G'); bool audioEnabled; TEXT_LANG audioLang; config.getAudio(audioEnabled, audioLang); m_thread->setLanguage(audioEnabled, audioLang); printf("Gateway callsign set to %s, local address set to %s\n", CallSign.c_str(), address.c_str()); CIRCDDB_Array clients; for(unsigned int i=0; i < config.getIrcDDBCount(); i++) { std::string hostname, username, password; config.getIrcDDB(i, hostname, username, password); std::cout << "ircDDB " << i + 1 << " set to " << hostname << " username set to " << username << std::endl; CIRCDDB *ircDDB = new CIRCDDBClient(hostname, 9007U, username, password, std::string("linux_SmartGroupServerXL-") + VERSION, address); clients.push_back(ircDDB); } CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients); bool res = multiClient->open(); if (!res) { printf("Cannot initialise the ircDDB protocol handler\n"); return false; } m_thread->setIRC(multiClient); for (unsigned int i=0; iaddGroup(callsign, logoff, repeater, info, permanent, usertimeout, callsignswitch, txmsgswitch, reflector); printf("Group %d: %s/%s using %s, \"%s\", perm: %s, timeout: %u mins, c/s switch: %s, msg switch: %s, Linked: %s\n", i, callsign.c_str(), logoff.c_str(), repeater.c_str(), info.c_str(), permanent.c_str(), usertimeout, SCS_GROUP_CALLSIGN==callsignswitch ? "Group" : "User", txmsgswitch ? "true" : "false", reflector.c_str()); } } bool remoteEnabled; std::string remotePassword; unsigned int remotePort; config.getRemote(remoteEnabled, remotePassword, remotePort); printf("Remote enabled set to %d, port set to %u\n", int(remoteEnabled), remotePort); m_thread->setRemote(remoteEnabled, remotePassword, remotePort); m_thread->setAddress(address); m_thread->setCallsign(CallSign); return true; }