Пример #1
0
void CXReflectorDPlusHandler::processInt(CHeaderData& header)
{
    wxString   rpt1 = header.getRptCall1();
    wxString   rpt2 = header.getRptCall2();
    unsigned int id = header.getId();

    if (!m_linked)
        return;

    // Convert the callsign(s) from the DPlus call to the repeater call
    wxString rpt = m_dplusCallsign;

    wxChar band = rpt2.GetChar(LONG_CALLSIGN_LENGTH - 1U);
    rpt.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);

    // Check the destination callsign
    m_destination = CXReflectorReflectorHandler::findReflector(rpt);
    if (m_destination == NULL) {
        band = rpt1.GetChar(LONG_CALLSIGN_LENGTH - 1U);
        rpt.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);

        m_destination = CXReflectorReflectorHandler::findReflector(rpt);
        if (m_destination == NULL) {
            wxLogMessage(wxT("Incoming unmatched D-Plus header, RPT1=%s, RPT2=%s"), rpt1.c_str(), rpt2.c_str());
            return;
        }
    }

    if (m_dPlusId != 0x00)
        return;

    m_dPlusId = id;
    m_inactivityTimer.start();
    m_pollInactivityTimer.reset();

    header.setCQCQCQ();
    header.setFlag1(0x00U);
    bool ret = m_destination->process(m_dPlusId, header);

    // Write to Users.log if it's enabled
    if (ret && m_userLogger != NULL)
        m_userLogger->write(header.getMyCall1(), header.getRptCall2(), m_reflector, PROTO_DPLUS);
}
bool CStarNetHandler::process(CHeaderData &header, AUDIO_SOURCE source)
{
	if (m_id != 0x00U)
		return false;

	wxString my = header.getMyCall1();
	m_id = header.getId();

	m_linkTimer.start();

	// Change the Your callsign to CQCQCQ
	header.setCQCQCQ();

	header.setFlag1(0x00);
	header.setFlag2(0x00);
	header.setFlag3(0x00);

	// Build new repeater list
	for (CStarNetUsersHashMap::const_iterator it = m_users.begin(); it != m_users.end(); ++it) {
		CStarNetUser* user = it->second;
		if (user != NULL) {
			// Find the user in the cache
			CUserData* userData = m_cache->findUser(user->getCallsign());

			if (userData != NULL) {
				// Find the users repeater in the repeater list, add it otherwise
				CStarNetRepeater* repeater = m_repeaters[userData->getRepeater()];
				if (repeater == NULL) {
					// Add a new repeater entry
					repeater = new CStarNetRepeater;
					repeater->m_destination = wxT("/") + userData->getRepeater().Left(6U) + userData->getRepeater().Right(1U);
					repeater->m_repeater    = userData->getRepeater();
					repeater->m_gateway     = userData->getGateway();
					repeater->m_address     = userData->getAddress();
					repeater->m_local       = CRepeaterHandler::findDVRepeater(userData->getRepeater());
					m_repeaters[userData->getRepeater()] = repeater;
				}

				delete userData;
				userData = NULL;
			}
		}
	}

	switch (m_callsignSwitch) {
		case SCS_GROUP_CALLSIGN:
			// Change the My Callsign 1 to be that of the StarNet group
			header.setMyCall1(m_groupCallsign);
			header.setMyCall2(wxT("SNET"));
			break;
		case SCS_USER_CALLSIGN:
			// Change the My Callsign 2 to be that of the StarNet group
			header.setMyCall1(my);
			header.setMyCall2(m_shortCallsign);
			break;
		default:
			break;
	}

	sendToRepeaters(header);

	if (m_txMsgSwitch)
		sendFromText(my);

	return true;
}
void CStarNetHandler::process(CHeaderData &header)
{
	wxString my   = header.getMyCall1();
	wxString your = header.getYourCall();

	unsigned int id = header.getId();

	CStarNetUser* user = m_users[my];

	// Ensure that this user is in the cache
	CUserData* userData = m_cache->findUser(my);
	if (userData == NULL)
		m_irc->findUser(my);

	if (your.IsSameAs(m_groupCallsign)) {
		// This is a normal message for logging in/relaying
		if (user == NULL) {
			// This is a new user, add them to the list
			if (m_logFile != NULL) {
				time_t timeNow = ::time(NULL);
				struct tm* tm = ::gmtime(&timeNow);

				wxString text;
				text.Printf(wxT("%04d-%02d-%02d %02d:%02d:%02d: Adding %s to StarNet group %s\n"),
					tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
					my.c_str(), m_groupCallsign.c_str());

				m_logFile->Write(text);
				m_logFile->Flush();
			}

			// Start the StarNet group timer if not already running
			if (!m_groupTimer.isRunning())
				m_groupTimer.start();

			user = new CStarNetUser(my, m_userTimeout * 60U);
			m_users[my] = user;

			CStarNetId* tx = new CStarNetId(id, MESSAGE_DELAY, user);
			tx->setLogin();
			m_ids[id] = tx;
		} else {
			user->reset();

			// Check that it isn't a duplicate header
			CStarNetId* tx = m_ids[id];
			if (tx != NULL) {
				delete userData;
				return;
			}

			m_ids[id] = new CStarNetId(id, MESSAGE_DELAY, user);
		}
	} else {
		delete userData;
		userData = NULL;

		// This is a logoff message
		if (user == NULL)				// Not a known user, ignore
			return;

		if (m_logFile != NULL) {
			time_t timeNow = ::time(NULL);
			struct tm* tm = ::gmtime(&timeNow);

			wxString text;
			text.Printf(wxT("%04d-%02d-%02d %02d:%02d:%02d: Removing %s from StarNet group %s, logged off\n"),
				tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
				user->getCallsign().c_str(), m_groupCallsign.c_str());

			m_logFile->Write(text);
			m_logFile->Flush();
		}

		// Remove the user from the user list
		m_users.erase(my);

		CStarNetId* tx = new CStarNetId(id, MESSAGE_DELAY, user);
		tx->setLogoff();
		m_ids[id] = tx;

		return;
	}

	m_groupTimer.reset();

	if (m_id != 0x00U) {
		delete userData;
		return;
	}

	m_id = id;

	// Change the Your callsign to CQCQCQ
	header.setCQCQCQ();

	header.setFlag1(0x00);
	header.setFlag2(0x00);
	header.setFlag3(0x00);

#if defined(DEXTRA_LINK)
	header.setRepeaters(m_linkGateway, m_linkReflector);
	CDExtraHandler::writeHeader(this, header, DIR_OUTGOING);
#endif
#if defined(DCS_LINK)
	header.setRepeaters(m_linkGateway, m_linkReflector);
	CDCSHandler::writeHeader(this, header, DIR_OUTGOING);
#endif

	// Get the home repeater of the user
	wxString exclude;
	if (userData != NULL) {
		exclude = userData->getRepeater();
		delete userData;
		userData = NULL;
	}

	// Build new repeater list
	for (CStarNetUsersHashMap::const_iterator it = m_users.begin(); it != m_users.end(); ++it) {
		CStarNetUser* user = it->second;
		if (user != NULL) {
			// Find the user in the cache
			CUserData* userData = m_cache->findUser(user->getCallsign());

			if (userData != NULL) {
				// Check for the excluded repeater
				if (!userData->getRepeater().IsSameAs(exclude)) {
					// Find the users repeater in the repeater list, add it otherwise
					CStarNetRepeater* repeater = m_repeaters[userData->getRepeater()];
					if (repeater == NULL) {
						// Add a new repeater entry
						repeater = new CStarNetRepeater;
						repeater->m_destination = wxT("/") + userData->getRepeater().Left(6U) + userData->getRepeater().Right(1U);
						repeater->m_repeater    = userData->getRepeater();
						repeater->m_gateway     = userData->getGateway();
						repeater->m_address     = userData->getAddress();
						repeater->m_local       = CRepeaterHandler::findDVRepeater(userData->getRepeater());
						m_repeaters[userData->getRepeater()] = repeater;
					}
				}

				delete userData;
				userData = NULL;
			}
		}
	}

	switch (m_callsignSwitch) {
		case SCS_GROUP_CALLSIGN:
			// Change the My Callsign 1 to be that of the StarNet group
			header.setMyCall1(m_groupCallsign);
			header.setMyCall2(wxT("SNET"));
			break;
		case SCS_USER_CALLSIGN:
			// Change the My Callsign 2 to be that of the StarNet group
			header.setMyCall1(my);
			header.setMyCall2(m_shortCallsign);
			break;
		default:
			break;
	}

	sendToRepeaters(header);

	if (m_txMsgSwitch)
		sendFromText(my);
}