1
0
mirror of https://github.com/solemnwarning/directplay-lite synced 2024-12-30 16:45:37 +01:00
directplay-lite/src/HostEnumerator.hpp
Daniel Collins b1289366be Address handling improvements.
- IDirectPlay8Peer::EnumHosts() requires a device address to specify
  the service provider to emulate.

- IDirectPlay8Peer::EnumHosts() allows overriding the address/port
  that discovery messages are sent to.

- IDirectPlay8Peer::Host() requires at least one address. Addresses
  with different service providers are not supported yet.

- Implement IDirectPlay8Peer::GetPeerAddress() method.

- Populate pAddressSender in DPNMSG_ENUM_HOSTS_QUERY message.

- Popupate pAddressPlayer in DPNMSG_INDICATE_CONNECT message.

- Base host addresses created by IDirectPlay8Peer on service provider
  of device address given to Host() method.
2018-10-03 21:21:56 +01:00

84 lines
2.2 KiB
C++

#ifndef DPLITE_HOSTENUMERATOR_HPP
#define DPLITE_HOSTENUMERATOR_HPP
#include <winsock2.h>
#include <dplay8.h>
#include <functional>
#include <thread>
#include <vector>
#include <windows.h>
#include "network.hpp"
#define DEFAULT_ENUM_COUNT 5
#define DEFAULT_ENUM_INTERVAL 1500
#define DEFAULT_ENUM_TIMEOUT 1500
class HostEnumerator
{
private:
/* No copy c'tor. */
HostEnumerator(const HostEnumerator&) = delete;
/* Pointer to the global refcount (if in use), for instantiating DirectPlay8Address objects. */
std::atomic<unsigned int> * const global_refcount;
/* DirectPlay message handler and context value */
PFNDPNMESSAGEHANDLER message_handler;
PVOID message_handler_ctx;
std::function<void(HRESULT)> complete_cb;
GUID service_provider;
struct sockaddr_in send_addr;
GUID application_guid; /* GUID of application to search for, or GUID_NULL */
std::vector<unsigned char> user_data; /* Data to include in request. */
DWORD tx_remain; /* Number of remaining requests to transmit, may be INFINITE. */
DWORD tx_interval; /* Number of milliseconds to wait between transmits. */
DWORD rx_timeout; /* Number of milliseconds to wait for replies to a request. */
void *user_context; /* DPNMSG_ENUM_HOSTS_REPONSE.pvUserContext */
DWORD next_tx_at;
DWORD stop_at;
int sock;
HANDLE wake_thread;
std::thread *thread;
bool req_cancel;
unsigned char recv_buf[MAX_PACKET_SIZE];
void main();
void handle_packet(const void *data, size_t size, struct sockaddr_in *from_addr);
public:
HostEnumerator(
std::atomic<unsigned int> * const global_refcount,
PFNDPNMESSAGEHANDLER message_handler,
PVOID message_handler_ctx,
PDPN_APPLICATION_DESC const pApplicationDesc,
IDirectPlay8Address *const pdpaddrHost,
IDirectPlay8Address *const pdpaddrDeviceInfo,
PVOID const pvUserEnumData,
const DWORD dwUserEnumDataSize,
const DWORD dwEnumCount,
const DWORD dwRetryInterval,
const DWORD dwTimeOut,
PVOID const pvUserContext,
std::function<void(HRESULT)> complete_cb
);
~HostEnumerator();
void cancel();
void wait();
};
#endif /* !DPLITE_HOSTENUMERATOR_HPP */