swift
directplaypeer.h
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_SIMPLUGIN_FS9_DIRECTPLAY_PEER_H
5 #define SWIFT_SIMPLUGIN_FS9_DIRECTPLAY_PEER_H
6 
7 #include <dplay8.h>
8 
9 #include <atomic>
10 #include <functional>
11 
12 #include <QList>
13 #include <QObject>
14 #include <QScopedPointer>
15 
16 #include "callbackwrapper.h"
17 #include "fs9.h"
18 #include "hostnode.h"
19 
20 #include "misc/aviation/callsign.h"
21 #include "misc/logcategorylist.h"
22 
23 namespace swift::simplugin::fs9
24 {
25  HRESULT inline s_success_pending() { return DPNSUCCESS_PENDING; }
26  bool inline isPending(HRESULT hr) { return hr == s_success_pending(); }
27 
31  class CDirectPlayPeer : public QObject
32  {
33  Q_OBJECT
34 
35  public:
37  CDirectPlayPeer(const swift::misc::aviation::CCallsign &callsign, QObject *parent = nullptr);
38 
40  virtual ~CDirectPlayPeer() override;
41 
43  DPNID getPlayerUserId() const { return m_playerUser; }
44 
46  void setPlayerUserId(DPNID id) { m_playerUser = id; }
47 
49  static const QStringList &getLogCategories();
50 
51  public slots:
53  HRESULT sendMessage(const QByteArray &data);
54 
56  void reset();
57 
58  signals:
60  void customPacketReceived(const QByteArray &data);
61 
64 
65  protected:
67  HRESULT directPlayMessageHandler(DWORD messageId, void *msgBuffer);
68 
70  HRESULT initDirectPlay();
71 
73  bool isServiceProviderValid(const GUID *pGuidSP);
74 
76  HRESULT createDeviceAddress();
77 
79  HRESULT createHostAddress();
80 
82 
83  IDirectPlay8Peer *m_directPlayPeer = nullptr;
84  IDirectPlay8Address *m_deviceAddress = nullptr;
85 
86  QList<CHostNode> m_hostNodeList;
87  quint32 m_packetIndex = 0;
88 
89  // DirectPlay Player Id's
90  std::atomic<DPNID> m_playerLocal = { 0 };
91  // We need the Id of the users player, because we are sending packets only to him
92  std::atomic<DPNID> m_playerUser = { 0 };
93 
97 
98  private:
99  bool m_coInitializeSucceeded = false;
100  };
101 } // namespace swift::simplugin::fs9
102 
103 #endif // SWIFT_SIMPLUGIN_FS9_DIRECTPLAY_PEER_H
Value object encapsulating information of a callsign.
Definition: callsign.h:30
DirectPlay peer implementation More information can be found in the DirectX9 SDK documentation http:/...
HRESULT directPlayMessageHandler(DWORD messageId, void *msgBuffer)
DirectPlay message handler.
std::atomic< DPNID > m_playerLocal
Local player Id.
bool isServiceProviderValid(const GUID *pGuidSP)
Returns true of the service provider is a valid on this machine.
HRESULT createHostAddress()
Creates a new DirectPlay device address.
QList< CHostNode > m_hostNodeList
List of enumerated hosts.
std::atomic< DPNID > m_playerUser
User player Id.
static const QStringList & getLogCategories()
Log categories.
IDirectPlay8Peer * m_directPlayPeer
DirectPlay peer address.
HRESULT initDirectPlay()
Initialize DirectPlay.
IDirectPlay8Address * m_deviceAddress
DirectPlay device address.
void connectionComplete()
Async operatione complete.
CDirectPlayPeer(const swift::misc::aviation::CCallsign &callsign, QObject *parent=nullptr)
Constructor.
HRESULT sendMessage(const QByteArray &data)
Send a custom DirectPlay message.
DPNID getPlayerUserId() const
Returns users DirectPlay ID.
quint32 m_packetIndex
Multiplayer packet index.
TCallbackWrapper m_callbackWrapper
Callback wrapper.
const swift::misc::aviation::CCallsign m_callsign
Peer callsign.
void customPacketReceived(const QByteArray &data)
Received custom FS9 packet.
void setPlayerUserId(DPNID id)
Sets users DirectPlay ID.
HRESULT createDeviceAddress()
Creates a new DirectPlay device address.
unsigned long DWORD
Fake Windows DWORD.