mirror of
https://github.com/xtjoeytx/GServer-v2.git
synced 2026-05-09 09:10:04 -04:00
deb5d3b7df
Added BabyDI and migrated Server into it. Replaced pointers of server being passed around with calls to BabyDI.
69 lines
1.2 KiB
C++
69 lines
1.2 KiB
C++
#ifndef CUPNP_H
|
|
#define CUPNP_H
|
|
|
|
#ifdef UPNP
|
|
|
|
#include <memory.h>
|
|
#include <set>
|
|
|
|
#include <CString.h>
|
|
#include "BabyDI.h"
|
|
|
|
#include <miniupnpc.h>
|
|
#include <miniwget.h>
|
|
#include <upnpcommands.h>
|
|
|
|
class Server;
|
|
|
|
class UPNP
|
|
{
|
|
public:
|
|
// Allows std::thread to work.
|
|
void operator()()
|
|
{
|
|
discover();
|
|
addPortForward(m_localIp, port);
|
|
}
|
|
|
|
void initialize(const char* m_localIp, const char* port)
|
|
{
|
|
m_localIp = m_localIp;
|
|
m_port = port;
|
|
}
|
|
|
|
// Finds a valid UPNP device.
|
|
void discover();
|
|
|
|
// Adds a port forward.
|
|
void addPortForward(const CString& addr, const CString& port);
|
|
|
|
// Removes a port forward.
|
|
void removePortForward(const CString& port);
|
|
|
|
// Removes all the port forwards created by the addPortForward command.
|
|
void removeAllForwardedPorts()
|
|
{
|
|
while (!m_portsForwarded.empty())
|
|
removePortForward(*m_portsForwarded.rbegin());
|
|
m_portsForwarded.clear();
|
|
}
|
|
|
|
// Returns true if the port was successfully forwarded.
|
|
bool wasPortForwarded(const CString& port)
|
|
{
|
|
return m_portsForwarded.find(port) != m_portsForwarded.end();
|
|
}
|
|
|
|
private:
|
|
BabyDI_INJECT(Server, m_server);
|
|
|
|
std::set<CString> m_portsForwarded;
|
|
CString m_localIp;
|
|
CString m_port;
|
|
struct UPNPUrls m_urls;
|
|
struct IGDdatas m_data;
|
|
};
|
|
|
|
#endif
|
|
#endif
|