mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Change FS9 plugin to new logging system
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "fs9_host.h"
|
||||
#include "fs9_client.h"
|
||||
#include "blackmisc/mathematics.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
@@ -167,45 +168,48 @@ namespace BlackSimPlugin
|
||||
|
||||
HRESULT printDirectPlayError(HRESULT error)
|
||||
{
|
||||
QString errorMessage;
|
||||
switch(error)
|
||||
{
|
||||
case DPNERR_BUFFERTOOSMALL:
|
||||
qWarning() << "The supplied buffer is not large enough to contain the requested data.";
|
||||
errorMessage = "The supplied buffer is not large enough to contain the requested data.";
|
||||
break;
|
||||
case DPNERR_DOESNOTEXIST:
|
||||
qWarning() << "Requested element is not part of the address.";
|
||||
errorMessage = "Requested element is not part of the address.";
|
||||
break;
|
||||
case DPNERR_INVALIDFLAGS:
|
||||
qWarning() << "The flags passed to this method are invalid.";
|
||||
errorMessage = "The flags passed to this method are invalid.";
|
||||
break;
|
||||
case DPNERR_INVALIDPARAM:
|
||||
qWarning() << "One or more of the parameters passed to the method are invalid.";
|
||||
errorMessage = "One or more of the parameters passed to the method are invalid.";
|
||||
break;
|
||||
case DPNERR_INVALIDPOINTER:
|
||||
qWarning() << "Pointer specified as a parameter is invalid.";
|
||||
errorMessage = "Pointer specified as a parameter is invalid.";
|
||||
break;
|
||||
case DPNERR_INVALIDURL:
|
||||
qWarning() << "Specified string is not a valid DirectPlayURL.";
|
||||
errorMessage = "Specified string is not a valid DirectPlayURL.";
|
||||
break;
|
||||
case DPNERR_NOTALLOWED:
|
||||
qWarning() << "This function is not allowed on this object.";
|
||||
errorMessage = "This function is not allowed on this object.";
|
||||
break;
|
||||
case DPNERR_INVALIDOBJECT:
|
||||
qWarning() << "The Microsoft DirectPlay object pointer is invalid.";
|
||||
errorMessage = "The Microsoft DirectPlay object pointer is invalid.";
|
||||
break;
|
||||
case DPNERR_UNINITIALIZED:
|
||||
qWarning() << "This function is not allowed on this object.";
|
||||
errorMessage = "This function is not allowed on this object.";
|
||||
break;
|
||||
case DPNERR_UNSUPPORTED:
|
||||
qWarning() << "The function or feature is not available in this implementation or on this service provider.";
|
||||
errorMessage = "The function or feature is not available in this implementation or on this service provider.";
|
||||
break;
|
||||
case DPNERR_NOTHOST:
|
||||
qWarning() << "The client attempted to connect to a nonhost computer. Additionally, this error value may be returned by a nonhost that tried to set the application description.";
|
||||
errorMessage = "The client attempted to connect to a nonhost computer. Additionally, this error value may be returned by a nonhost that tried to set the application description.";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
BlackMisc::CLogMessage().error(errorMessage);
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blacksimplugin_freefunctions.h"
|
||||
#include "blackmisc/avaircraftsituation.h"
|
||||
#include "blackmisc/coordinategeodetic.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QScopedArrayPointer>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -149,8 +150,7 @@ namespace BlackSimPlugin
|
||||
nullptr, // pAsyncHandle
|
||||
DPNENUMHOSTS_SYNC ) ) ) // dwFlags
|
||||
{
|
||||
qWarning() << "Failed to enum hosts!";
|
||||
return hr;
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
@@ -165,15 +165,13 @@ namespace BlackSimPlugin
|
||||
IID_IDirectPlay8Address,
|
||||
reinterpret_cast<void **>(&m_hostAddress) ) ) )
|
||||
{
|
||||
qWarning() << "Failed to create DirectPlay8Address!";
|
||||
return hr;
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Set the SP for our Host Address
|
||||
if( FAILED( hr = m_hostAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
|
||||
{
|
||||
qWarning() << "Failed to set SP!";
|
||||
return hr;
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// FIXME: Test if this is also working via network or if we have to use the IP address
|
||||
@@ -184,8 +182,7 @@ namespace BlackSimPlugin
|
||||
2*(wcslen(hostname) + 1), /*bytes*/
|
||||
DPNA_DATATYPE_STRING ) ) )
|
||||
{
|
||||
qWarning() << "Failed to add component!";
|
||||
return hr;
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
|
||||
return hr;
|
||||
@@ -217,8 +214,7 @@ namespace BlackSimPlugin
|
||||
m_player.pwszName = wszPlayername.data();
|
||||
if( FAILED( hr = m_directPlayPeer->SetPeerInfo( &m_player, nullptr, nullptr, DPNSETPEERINFO_SYNC ) ) )
|
||||
{
|
||||
qWarning() << "Failed to set peer info!";
|
||||
return hr;
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Now set up the Application Description
|
||||
@@ -239,8 +235,7 @@ namespace BlackSimPlugin
|
||||
nullptr,
|
||||
DPNCONNECT_SYNC ) ) )
|
||||
{
|
||||
qWarning() << "Failed to connect to host!";
|
||||
return hr;
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
|
||||
MPChangePlayerPlane mpChangePlayerPlane;
|
||||
@@ -267,10 +262,10 @@ namespace BlackSimPlugin
|
||||
|
||||
if (m_clientStatus == Disconnected) return hr;
|
||||
|
||||
qDebug() << "Closing connection for " << m_callsign;
|
||||
BlackMisc::CLogMessage(this).debug() << "Closing DirectPlay connection for " << m_callsign;
|
||||
if( FAILED( hr = m_directPlayPeer->Close(0) ))
|
||||
{
|
||||
qWarning() << "Failed to close connection!";
|
||||
return printDirectPlayError(hr);
|
||||
}
|
||||
|
||||
m_clientStatus = Disconnected;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "multiplayer_packet_parser.h"
|
||||
#include "multiplayer_packets.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QScopedArrayPointer>
|
||||
#include <QVector>
|
||||
|
||||
@@ -120,7 +121,7 @@ namespace BlackSimPlugin
|
||||
player.pwszName = wszPlayername.data();
|
||||
if (FAILED(hr = m_directPlayPeer->SetPeerInfo(&player, nullptr, nullptr, DPNSETPEERINFO_SYNC)))
|
||||
{
|
||||
qWarning() << "Failed to set peer info!";
|
||||
printDirectPlayError(hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -138,12 +139,12 @@ namespace BlackSimPlugin
|
||||
nullptr, // Player Context
|
||||
0))) // dwFlags
|
||||
{
|
||||
qWarning() << "Failed to start hosting!";
|
||||
printDirectPlayError(hr);
|
||||
return hr;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Host successfully started";
|
||||
BlackMisc::CLogMessage(this).info("Hosting successfully started");
|
||||
m_hostStatus = Hosting;
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ namespace BlackSimPlugin
|
||||
|
||||
if (m_hostStatus == Terminated) return hr;
|
||||
|
||||
qDebug() << "Terminating host";
|
||||
BlackMisc::CLogMessage(this).info("Hosting terminated!");
|
||||
hr = m_directPlayPeer->TerminateSession(nullptr, 0, 0);
|
||||
hr = m_directPlayPeer->Close(0);
|
||||
m_hostStatus = Terminated;
|
||||
|
||||
Reference in New Issue
Block a user