mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T761, use "preset" callsign if available
Avoids issue with partner callsign
This commit is contained in:
committed by
Mat Sutcliffe
parent
36d77b7785
commit
4e2a47fc41
@@ -242,7 +242,7 @@ namespace BlackCore
|
||||
|
||||
this->getIContextOwnAircraft()->updateOwnAircraftPilot(server.getUser());
|
||||
const CSimulatedAircraft ownAircraft(this->ownAircraft());
|
||||
m_fsdClient->setPartnerCallsign(partnerCallsign);
|
||||
m_fsdClient->setPartnerCallsign(isValidPartnerCallsign(ownAircraft.getCallsign(), partnerCallsign) ? partnerCallsign : CCallsign());
|
||||
|
||||
// Fall back to observer mode, if no simulator is available or not simulating
|
||||
if (!CBuildConfig::isLocalDeveloperDebugBuild() && !this->getIContextSimulator()->isSimulatorSimulating())
|
||||
@@ -346,16 +346,25 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
// set receiver
|
||||
const QString receiver = parser.part(1).trimmed().toLower(); // receiver
|
||||
const CSimulatedAircraft ownAircraft(this->getIContextOwnAircraft()->getOwnAircraft());
|
||||
if (ownAircraft.getCallsign().isEmpty())
|
||||
const QString receiver = parser.part(1).trimmed().toLower(); // receiver
|
||||
CCallsign ownCallsign = ownAircraft.getCallsign();
|
||||
if (m_fsdClient)
|
||||
{
|
||||
// override with the preset callsign, as the own callsign can be different for partner callsign scenarios
|
||||
// copilot scenarios
|
||||
const CCallsign presetCallsign = m_fsdClient->getPresetCallsign();
|
||||
if (!presetCallsign.isEmpty()) { ownCallsign = presetCallsign; }
|
||||
}
|
||||
|
||||
if (ownCallsign.isEmpty())
|
||||
{
|
||||
CLogMessage(this).validationError(u"No own callsign");
|
||||
return false;
|
||||
}
|
||||
|
||||
CTextMessage tm;
|
||||
tm.setSenderCallsign(ownAircraft.getCallsign());
|
||||
tm.setSenderCallsign(ownCallsign);
|
||||
|
||||
// based on the CPZ bug https://discordapp.com/channels/539048679160676382/539486309882789888/576765888401768449
|
||||
// no longer use starts/ends with
|
||||
@@ -714,7 +723,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
// part to send to partner "forward"
|
||||
const CCallsign partnerCallsign = m_fsdClient ? m_fsdClient->getPresetPartnerCallsign() : CCallsign();
|
||||
const CCallsign partnerCallsign = this->getPartnerCallsign();
|
||||
if (!partnerCallsign.isEmpty())
|
||||
{
|
||||
// IMPORTANT: use messages AND NOT textMessages here, exclude messages from partner to avoid infinite roundtrips
|
||||
@@ -742,6 +751,24 @@ namespace BlackCore
|
||||
if (message.isEmpty()) { return; }
|
||||
if (message.isRelayedMessage()) { return; }
|
||||
|
||||
if (message.isPrivateMessage())
|
||||
{
|
||||
const CCallsign partnerCallsign = this->getPartnerCallsign();
|
||||
if (!partnerCallsign.isEmpty())
|
||||
{
|
||||
QPointer<CContextNetwork> myself(this);
|
||||
CTextMessageList relayedMessages;
|
||||
this->createRelayMessageToPartnerCallsign(message, partnerCallsign, relayedMessages);
|
||||
if (!relayedMessages.isEmpty())
|
||||
{
|
||||
QTimer::singleShot(10, this, [ = ]
|
||||
{
|
||||
if (myself) { myself->sendTextMessages(relayedMessages); }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit this->textMessageSent(message);
|
||||
}
|
||||
|
||||
@@ -752,6 +779,18 @@ namespace BlackCore
|
||||
return this->getRuntime()->getCContextOwnAircraft()->getOwnAircraft();
|
||||
}
|
||||
|
||||
CCallsign CContextNetwork::getPartnerCallsign() const
|
||||
{
|
||||
return m_fsdClient ? m_fsdClient->getPresetPartnerCallsign() : CCallsign();
|
||||
}
|
||||
|
||||
bool CContextNetwork::isValidPartnerCallsign(const CCallsign &ownCallsign, const CCallsign &partnerCallsign)
|
||||
{
|
||||
if (partnerCallsign.isEmpty()) { return false; }
|
||||
if (ownCallsign == partnerCallsign) { return false; } // MUST NOT be the same
|
||||
return true;
|
||||
}
|
||||
|
||||
CAtcStationList CContextNetwork::getAtcStationsOnline(bool recalculateDistance) const
|
||||
{
|
||||
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
|
||||
@@ -313,6 +313,12 @@ namespace BlackCore
|
||||
//! Own aircraft from \sa CContextOwnAircraft
|
||||
const BlackMisc::Simulation::CSimulatedAircraft ownAircraft() const;
|
||||
|
||||
//! Get the partner callsign if any
|
||||
BlackMisc::Aviation::CCallsign getPartnerCallsign() const;
|
||||
|
||||
//! Check if a callsign is a valid partner callsign
|
||||
bool isValidPartnerCallsign(const BlackMisc::Aviation::CCallsign &ownCallsign, const BlackMisc::Aviation::CCallsign &partnerCallsign);
|
||||
|
||||
//! Update METAR collection
|
||||
void updateMetars(const BlackMisc::Weather::CMetarList &metars);
|
||||
|
||||
|
||||
@@ -116,7 +116,10 @@ namespace BlackCore
|
||||
//! List of all preset values
|
||||
QStringList getPresetValues() const;
|
||||
|
||||
//! Callsign
|
||||
//! Callsign if any
|
||||
BlackMisc::Aviation::CCallsign getPresetCallsign() const { QReadLocker l(&m_lockUserClientBuffered); return m_ownCallsign; }
|
||||
|
||||
//! Partner callsign if any
|
||||
BlackMisc::Aviation::CCallsign getPresetPartnerCallsign() const { QReadLocker l(&m_lockUserClientBuffered); return m_partnerCallsign; }
|
||||
|
||||
//! Mode
|
||||
|
||||
Reference in New Issue
Block a user