From 60e70fa55466df987b33b8de0b341da15a8df9aa Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 29 Apr 2020 22:13:38 +0100 Subject: [PATCH] Add an optional explicit Id. --- YSFReflector/Conf.cpp | 12 ++++++++++-- YSFReflector/Conf.h | 4 +++- YSFReflector/Network.cpp | 27 +++++++++++++++------------ YSFReflector/Network.h | 5 +++-- YSFReflector/Version.h | 4 ++-- YSFReflector/YSFReflector.cpp | 4 ++-- YSFReflector/YSFReflector.ini | 1 + 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/YSFReflector/Conf.cpp b/YSFReflector/Conf.cpp index 2e25b16..1779b7a 100644 --- a/YSFReflector/Conf.cpp +++ b/YSFReflector/Conf.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX * * 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 @@ -37,6 +37,7 @@ enum SECTION { CConf::CConf(const std::string& file) : m_file(file), m_daemon(false), +m_id(0U), m_name(), m_description(), m_logDisplayLevel(0U), @@ -91,7 +92,9 @@ bool CConf::read() if (::strcmp(key, "Daemon") == 0) m_daemon = ::atoi(value) == 1; } else if (section == SECTION_INFO) { - if (::strcmp(key, "Name") == 0) + if (::strcmp(key, "Id") == 0) + m_id = (unsigned int)::atoi(value); + else if (::strcmp(key, "Name") == 0) m_name = value; else if (::strcmp(key, "Description") == 0) m_description = value; @@ -122,6 +125,11 @@ bool CConf::getDaemon() const return m_daemon; } +unsigned int CConf::getId() const +{ + return m_id; +} + std::string CConf::getName() const { return m_name; diff --git a/YSFReflector/Conf.h b/YSFReflector/Conf.h index e2cdc4d..b3b7faa 100644 --- a/YSFReflector/Conf.h +++ b/YSFReflector/Conf.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX * * 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 @@ -34,6 +34,7 @@ public: bool getDaemon() const; // The Info section + unsigned int getId() const; std::string getName() const; std::string getDescription() const; @@ -51,6 +52,7 @@ private: std::string m_file; bool m_daemon; + unsigned int m_id; std::string m_name; std::string m_description; diff --git a/YSFReflector/Network.cpp b/YSFReflector/Network.cpp index d9887ce..8fa747c 100644 --- a/YSFReflector/Network.cpp +++ b/YSFReflector/Network.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2020 by Jonathan Naylor G4KLX * * 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 @@ -24,8 +24,9 @@ #include #include -CNetwork::CNetwork(unsigned int port, const std::string& name, const std::string& description, bool debug) : +CNetwork::CNetwork(unsigned int port, unsigned int id, const std::string& name, const std::string& description, bool debug) : m_socket(port), +m_id(id), m_name(name), m_description(description), m_callsign(), @@ -112,18 +113,20 @@ void CNetwork::setCount(unsigned int count) if (count > 999U) count = 999U; - unsigned int hash = 0U; + unsigned int hash = m_id; - for (unsigned int i = 0U; i < m_name.size(); i++) { - hash += m_name.at(i); - hash += (hash << 10); - hash ^= (hash >> 6); - } + if (hash == 0U) { + for (unsigned int i = 0U; i < m_name.size(); i++) { + hash += m_name.at(i); + hash += (hash << 10); + hash ^= (hash >> 6); + } - // Final avalanche - hash += (hash << 3); - hash ^= (hash >> 11); - hash += (hash << 15); + // Final avalanche + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + } ::sprintf((char*)m_status, "YSFS%05u%16.16s%14.14s%03u", hash % 100000U, m_name.c_str(), m_description.c_str(), count); } diff --git a/YSFReflector/Network.h b/YSFReflector/Network.h index ef1064e..468869e 100644 --- a/YSFReflector/Network.h +++ b/YSFReflector/Network.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2020 by Jonathan Naylor G4KLX * * 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 @@ -28,7 +28,7 @@ class CNetwork { public: - CNetwork(unsigned int port, const std::string& name, const std::string& description, bool debug); + CNetwork(unsigned int port, unsigned int id, const std::string& name, const std::string& description, bool debug); ~CNetwork(); bool open(); @@ -44,6 +44,7 @@ public: private: CUDPSocket m_socket; + unsigned int m_id; std::string m_name; std::string m_description; std::string m_callsign; diff --git a/YSFReflector/Version.h b/YSFReflector/Version.h index 865c176..6be6bc6 100644 --- a/YSFReflector/Version.h +++ b/YSFReflector/Version.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX * * 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 @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20161021"; +const char* VERSION = "20200429"; #endif diff --git a/YSFReflector/YSFReflector.cpp b/YSFReflector/YSFReflector.cpp index 5ee9bef..334f686 100644 --- a/YSFReflector/YSFReflector.cpp +++ b/YSFReflector/YSFReflector.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016,2018 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2018,2020 by Jonathan Naylor G4KLX * * 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 @@ -162,7 +162,7 @@ void CYSFReflector::run() } #endif - CNetwork network(m_conf.getNetworkPort(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug()); + CNetwork network(m_conf.getNetworkPort(), m_conf.getId(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug()); ret = network.open(); if (!ret) { diff --git a/YSFReflector/YSFReflector.ini b/YSFReflector/YSFReflector.ini index 7402a25..5b0836c 100644 --- a/YSFReflector/YSFReflector.ini +++ b/YSFReflector/YSFReflector.ini @@ -4,6 +4,7 @@ Daemon=1 [Info] # Remember to register your YSFReflector at: # https://register.ysfreflector.de +# Id=5 digits only Name=16 characters max Description=14 characters max