diff --git a/YSFReflector/BlockList.cpp b/YSFReflector/BlockList.cpp index b0b2803..85ff774 100644 --- a/YSFReflector/BlockList.cpp +++ b/YSFReflector/BlockList.cpp @@ -54,6 +54,9 @@ bool CBlockList::check(const unsigned char* callsign) const { assert(callsign != NULL); + if (m_callsigns.empty()) + return false; + std::string call = std::string((char*)callsign, YSF_CALLSIGN_LENGTH); std::for_each(call.begin(), call.end(), [](char& c) { c = std::toupper(c); @@ -62,10 +65,10 @@ bool CBlockList::check(const unsigned char* callsign) const for (std::vector::const_iterator it = m_callsigns.cbegin(); it != m_callsigns.cend(); ++it) { const std::string blocked = *it; if (call.find(blocked) != std::string::npos) - return false; + return true; } - return true; + return false; } void CBlockList::clock(unsigned int ms) diff --git a/YSFReflector/Version.h b/YSFReflector/Version.h index 75c23cd..a3f6e82 100644 --- a/YSFReflector/Version.h +++ b/YSFReflector/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20210213"; +const char* VERSION = "20210214"; #endif diff --git a/YSFReflector/YSFReflector.cpp b/YSFReflector/YSFReflector.cpp index 17236fe..4bce30c 100644 --- a/YSFReflector/YSFReflector.cpp +++ b/YSFReflector/YSFReflector.cpp @@ -199,17 +199,16 @@ void CYSFReflector::run() unsigned char src[YSF_CALLSIGN_LENGTH]; unsigned char dst[YSF_CALLSIGN_LENGTH]; - for (;;) { - bool blocked; + bool blocked = false; + bool checked = false; + for (;;) { unsigned char buffer[200U]; sockaddr_storage addr; unsigned int addrLen; unsigned int len = network.readData(buffer, 200U, addr, addrLen); if (len > 0U) { - blocked = false; - CYSFRepeater* rpt = findRepeater(addr); if (::memcmp(buffer, "YSFP", 4U) == 0) { if (rpt == NULL) { @@ -238,8 +237,25 @@ void CYSFReflector::run() } network.setCount(m_repeaters.size()); } else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0 && rpt != NULL) { + // Check for a change of user + if (watchdogTimer.isRunning() && ::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) { + if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0) + checked = false; + + if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0) + checked = false; + } + // Is this user allowed? - if (blockList.check(buffer + 14U)) { + if (!checked) { + blocked = blockList.check(buffer + 14U); + checked = true; + + if (blocked) + LogDebug("Data from %10.10s at %10.10s blocked", buffer + 14U, buffer + 4U); + } + + if (!blocked) { if (!watchdogTimer.isRunning()) { ::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH); @@ -272,12 +288,7 @@ void CYSFReflector::run() LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U); } } - } else { - LogDebug("Data from %10.10s at %10.10s blocked", buffer + 14U, buffer + 4U); - blocked = true; - } - if (!blocked) { watchdogTimer.start(); for (std::vector::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { @@ -286,6 +297,9 @@ void CYSFReflector::run() } if ((buffer[34U] & 0x01U) == 0x01U) { + blocked = false; + checked = false; + LogMessage("Received end of transmission"); watchdogTimer.stop(); } @@ -322,6 +336,9 @@ void CYSFReflector::run() watchdogTimer.clock(ms); if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) { + checked = false; + blocked = false; + LogMessage("Network watchdog has expired"); watchdogTimer.stop(); }