mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-28 16:49:58 -06:00
Switched tcp over to enet
This commit is contained in:
@ -7,6 +7,8 @@
|
||||
|
||||
#include "Common/StdMakeUnique.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/HW/EXI_DeviceIPL.h"
|
||||
#include "Core/NetPlayClient.h" //for NetPlayUI
|
||||
#include "Core/NetPlayServer.h"
|
||||
#include "InputCommon/GCPadStatus.h"
|
||||
|
||||
@ -16,7 +18,7 @@ NetPlayServer::~NetPlayServer()
|
||||
{
|
||||
m_do_loop = false;
|
||||
m_thread.join();
|
||||
m_socket.close();
|
||||
enet_host_destroy(m_server);
|
||||
}
|
||||
|
||||
#ifdef USE_UPNP
|
||||
@ -28,15 +30,35 @@ NetPlayServer::~NetPlayServer()
|
||||
}
|
||||
|
||||
// called from ---GUI--- thread
|
||||
NetPlayServer::NetPlayServer(const u16 port) : is_connected(false), m_is_running(false)
|
||||
NetPlayServer::NetPlayServer(const u16 port)
|
||||
: is_connected(false)
|
||||
, m_is_running(false)
|
||||
, m_do_loop(false)
|
||||
, m_ping_key(0)
|
||||
, m_update_pings(false)
|
||||
, m_current_game(0)
|
||||
, m_target_buffer_size(0)
|
||||
, m_selected_game("")
|
||||
, m_server(nullptr)
|
||||
{
|
||||
//--use server time
|
||||
if (enet_initialize() != 0)
|
||||
{
|
||||
PanicAlertT("Enet Didn't Initialize");
|
||||
}
|
||||
|
||||
memset(m_pad_map, -1, sizeof(m_pad_map));
|
||||
memset(m_wiimote_map, -1, sizeof(m_wiimote_map));
|
||||
if (m_socket.listen(port) == sf::Socket::Done)
|
||||
|
||||
ENetAddress serverAddr;
|
||||
serverAddr.host = ENET_HOST_ANY;
|
||||
serverAddr.port = port;
|
||||
m_server = enet_host_create(&serverAddr, 10, 3, 0, 0);
|
||||
|
||||
if (m_server != nullptr)
|
||||
{
|
||||
is_connected = true;
|
||||
m_do_loop = true;
|
||||
m_selector.add(m_socket);
|
||||
m_thread = std::thread(&NetPlayServer::ThreadFunc, this);
|
||||
m_target_buffer_size = 5;
|
||||
}
|
||||
@ -48,10 +70,9 @@ void NetPlayServer::ThreadFunc()
|
||||
while (m_do_loop)
|
||||
{
|
||||
// update pings every so many seconds
|
||||
|
||||
if ((m_ping_timer.GetTimeElapsed() > 1000) || m_update_pings)
|
||||
{
|
||||
//PanicAlertT("Sending pings");
|
||||
|
||||
m_ping_key = Common::Timer::GetTimeMs();
|
||||
|
||||
sf::Packet spac;
|
||||
@ -61,23 +82,26 @@ void NetPlayServer::ThreadFunc()
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
m_ping_timer.Start();
|
||||
SendToClients(spac);
|
||||
|
||||
m_update_pings = false;
|
||||
}
|
||||
|
||||
// check if any sockets need attention
|
||||
if (m_selector.wait(sf::milliseconds(10)))
|
||||
ENetEvent netEvent;
|
||||
int net;
|
||||
{
|
||||
// listening socket
|
||||
if (m_selector.isReady(m_socket))
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
net = enet_host_service(m_server, &netEvent, 4);
|
||||
}
|
||||
if (net > 0)
|
||||
{
|
||||
switch (netEvent.type)
|
||||
{
|
||||
auto accept_socket = std::make_unique<sf::TcpSocket>();
|
||||
m_socket.accept(*accept_socket);
|
||||
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
{
|
||||
ENetPeer* accept_peer = netEvent.peer;
|
||||
unsigned int error;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
|
||||
error = OnConnect(accept_socket);
|
||||
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
|
||||
error = OnConnect(accept_peer);
|
||||
}
|
||||
|
||||
if (error)
|
||||
@ -85,51 +109,61 @@ void NetPlayServer::ThreadFunc()
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)error;
|
||||
// don't need to lock, this client isn't in the client map
|
||||
accept_socket->send(spac);
|
||||
accept_socket->disconnect();
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
Send(accept_peer, spac);
|
||||
|
||||
enet_peer_disconnect(accept_peer, 0);
|
||||
}
|
||||
}
|
||||
// client sockets
|
||||
for (auto it = m_players.begin(); it != m_players.end();)
|
||||
break;
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
{
|
||||
// move iterator on immediately so client can be removed
|
||||
Client& client = *it;
|
||||
it++;
|
||||
sf::Packet rpac;
|
||||
rpac.append(netEvent.packet->data, netEvent.packet->dataLength);
|
||||
|
||||
if (m_selector.isReady(*client.socket))
|
||||
auto it = m_players.find(netEvent.peer->connectID);
|
||||
Client& client = it->second;
|
||||
if (OnData(rpac, client) != 0)
|
||||
{
|
||||
sf::Packet rpac;
|
||||
switch (client.socket->receive(rpac))
|
||||
{
|
||||
case sf::Socket::Done :
|
||||
// if a bad packet is received, disconnect the client
|
||||
if (0 == OnData(rpac, client))
|
||||
break;
|
||||
|
||||
//case sf::Socket::Disconnected :
|
||||
default :
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
|
||||
OnDisconnect(client);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if a bad packet is received, disconnect the client
|
||||
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
|
||||
OnDisconnect(client);
|
||||
}
|
||||
enet_packet_destroy(netEvent.packet);
|
||||
}
|
||||
break;
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
|
||||
auto it = m_players.find(netEvent.peer->connectID);
|
||||
if (it != m_players.end())
|
||||
{
|
||||
Client& client = it->second;
|
||||
OnDisconnect(client);
|
||||
|
||||
netEvent.peer->data = nullptr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close listening socket and client sockets
|
||||
for (auto& player_entry : m_players)
|
||||
player_entry.socket->disconnect();
|
||||
enet_peer_disconnect(player_entry.second.socket, 0);
|
||||
}
|
||||
|
||||
// called from ---NETPLAY--- thread
|
||||
unsigned int NetPlayServer::OnConnect(std::unique_ptr<sf::TcpSocket>& socket)
|
||||
unsigned int NetPlayServer::OnConnect(ENetPeer* socket)
|
||||
{
|
||||
sf::Packet rpac;
|
||||
// TODO: make this not hang / check if good packet
|
||||
socket->receive(rpac);
|
||||
ENetPacket* epack;
|
||||
do
|
||||
{
|
||||
epack = enet_peer_receive(socket, 0);
|
||||
} while (epack == nullptr);
|
||||
rpac.append(epack->data, epack->dataLength);
|
||||
|
||||
std::string npver;
|
||||
rpac >> npver;
|
||||
@ -149,15 +183,17 @@ unsigned int NetPlayServer::OnConnect(std::unique_ptr<sf::TcpSocket>& socket)
|
||||
m_update_pings = true;
|
||||
|
||||
Client player;
|
||||
player.socket = std::move(socket);
|
||||
player.socket = socket;
|
||||
rpac >> player.revision;
|
||||
rpac >> player.name;
|
||||
|
||||
enet_packet_destroy(epack);
|
||||
|
||||
// give new client first available id
|
||||
PlayerId pid = 1;
|
||||
for (auto i = m_players.begin(); i != m_players.end(); ++i)
|
||||
{
|
||||
if (i->pid == pid)
|
||||
if (i->second.pid == pid)
|
||||
{
|
||||
pid++;
|
||||
i = m_players.begin();
|
||||
@ -176,56 +212,53 @@ unsigned int NetPlayServer::OnConnect(std::unique_ptr<sf::TcpSocket>& socket)
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
|
||||
// send join message to already connected clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_PLAYER_JOIN;
|
||||
spac << player.pid << player.name << player.revision;
|
||||
SendToClients(spac);
|
||||
|
||||
// send new client success message with their id
|
||||
spac.clear();
|
||||
spac << (MessageId)0;
|
||||
spac << player.pid;
|
||||
player.socket->send(spac);
|
||||
|
||||
// send new client the selected game
|
||||
if (m_selected_game != "")
|
||||
{
|
||||
spac.clear();
|
||||
spac << (MessageId)NP_MSG_CHANGE_GAME;
|
||||
spac << m_selected_game;
|
||||
player.socket->send(spac);
|
||||
}
|
||||
|
||||
// send the pad buffer value
|
||||
spac.clear();
|
||||
spac << (MessageId)NP_MSG_PAD_BUFFER;
|
||||
spac << (u32)m_target_buffer_size;
|
||||
player.socket->send(spac);
|
||||
|
||||
// sync values with new client
|
||||
for (const auto& p : m_players)
|
||||
{
|
||||
spac.clear();
|
||||
// send join message to already connected clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_PLAYER_JOIN;
|
||||
spac << p.pid << p.name << p.revision;
|
||||
player.socket->send(spac);
|
||||
}
|
||||
spac << player.pid << player.name << player.revision;
|
||||
SendToClients(spac);
|
||||
|
||||
// send new client success message with their id
|
||||
spac.clear();
|
||||
spac << (MessageId)0;
|
||||
spac << player.pid;
|
||||
Send(player.socket, spac);
|
||||
|
||||
// send new client the selected game
|
||||
if (m_selected_game != "")
|
||||
{
|
||||
spac.clear();
|
||||
spac << (MessageId)NP_MSG_CHANGE_GAME;
|
||||
spac << m_selected_game;
|
||||
Send(player.socket, spac);
|
||||
}
|
||||
|
||||
// send the pad buffer value
|
||||
spac.clear();
|
||||
spac << (MessageId)NP_MSG_PAD_BUFFER;
|
||||
spac << (u32)m_target_buffer_size;
|
||||
Send(player.socket, spac);
|
||||
|
||||
// sync values with new client
|
||||
for (const auto& p : m_players)
|
||||
{
|
||||
spac.clear();
|
||||
spac << (MessageId)NP_MSG_PLAYER_JOIN;
|
||||
spac << p.second.pid << p.second.name << p.second.revision;
|
||||
Send(player.socket, spac);
|
||||
}
|
||||
|
||||
} // unlock send
|
||||
|
||||
// add client to selector/ used for receiving
|
||||
m_selector.add(*player.socket);
|
||||
|
||||
// add client to the player list
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
||||
m_players.push_back(std::move(player));
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
UpdatePadMapping(); // sync pad mappings with everyone
|
||||
UpdateWiimoteMapping();
|
||||
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
||||
m_players.emplace(player.socket->connectID, player);
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
UpdatePadMapping(); // sync pad mappings with everyone
|
||||
UpdateWiimoteMapping();
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -260,10 +293,12 @@ unsigned int NetPlayServer::OnDisconnect(Client& player)
|
||||
spac << (MessageId)NP_MSG_PLAYER_LEAVE;
|
||||
spac << pid;
|
||||
|
||||
m_selector.remove(*player.socket);
|
||||
enet_peer_disconnect(player.socket, 0);
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
||||
m_players.remove(player);
|
||||
auto it = m_players.find(player.pid);
|
||||
if (it != m_players.end())
|
||||
m_players.erase(it);
|
||||
|
||||
// alert other players of disconnect
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
@ -371,124 +406,124 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
|
||||
|
||||
switch (mid)
|
||||
{
|
||||
case NP_MSG_CHAT_MESSAGE :
|
||||
case NP_MSG_CHAT_MESSAGE:
|
||||
{
|
||||
std::string msg;
|
||||
packet >> msg;
|
||||
|
||||
// send msg to other clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_CHAT_MESSAGE;
|
||||
spac << player.pid;
|
||||
spac << msg;
|
||||
|
||||
{
|
||||
std::string msg;
|
||||
packet >> msg;
|
||||
|
||||
// send msg to other clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_CHAT_MESSAGE;
|
||||
spac << player.pid;
|
||||
spac << msg;
|
||||
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac, player.pid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_PAD_DATA :
|
||||
{
|
||||
// if this is pad data from the last game still being received, ignore it
|
||||
if (player.current_game != m_current_game)
|
||||
break;
|
||||
|
||||
PadMapping map = 0;
|
||||
GCPadStatus pad;
|
||||
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;
|
||||
|
||||
// If the data is not from the correct player,
|
||||
// then disconnect them.
|
||||
if (m_pad_map[map] != player.pid)
|
||||
return 1;
|
||||
|
||||
// Relay to clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_PAD_DATA;
|
||||
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac, player.pid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_WIIMOTE_DATA :
|
||||
case NP_MSG_PAD_DATA:
|
||||
{
|
||||
// if this is pad data from the last game still being received, ignore it
|
||||
if (player.current_game != m_current_game)
|
||||
break;
|
||||
|
||||
PadMapping map = 0;
|
||||
GCPadStatus pad;
|
||||
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;
|
||||
|
||||
// If the data is not from the correct player,
|
||||
// then disconnect them.
|
||||
if (m_pad_map[map] != player.pid)
|
||||
return 1;
|
||||
|
||||
// Relay to clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_PAD_DATA;
|
||||
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac, player.pid);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_WIIMOTE_DATA:
|
||||
{
|
||||
// if this is Wiimote data from the last game still being received, ignore it
|
||||
if (player.current_game != m_current_game)
|
||||
break;
|
||||
|
||||
PadMapping map = 0;
|
||||
u8 size;
|
||||
packet >> map >> size;
|
||||
std::vector<u8> data(size);
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
packet >> data[i];
|
||||
|
||||
// If the data is not from the correct player,
|
||||
// then disconnect them.
|
||||
if (m_wiimote_map[map] != player.pid)
|
||||
{
|
||||
// if this is Wiimote data from the last game still being received, ignore it
|
||||
if (player.current_game != m_current_game)
|
||||
break;
|
||||
|
||||
PadMapping map = 0;
|
||||
u8 size;
|
||||
packet >> map >> size;
|
||||
std::vector<u8> data(size);
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
packet >> data[i];
|
||||
|
||||
// If the data is not from the correct player,
|
||||
// then disconnect them.
|
||||
if (m_wiimote_map[map] != player.pid)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// relay to clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_WIIMOTE_DATA;
|
||||
spac << map;
|
||||
spac << size;
|
||||
for (const u8& byte : data)
|
||||
spac << byte;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac, player.pid);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_PONG :
|
||||
// relay to clients
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_WIIMOTE_DATA;
|
||||
spac << map;
|
||||
spac << size;
|
||||
for (const u8& byte : data)
|
||||
spac << byte;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac, player.pid);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_PONG:
|
||||
{
|
||||
const u32 ping = (u32)m_ping_timer.GetTimeElapsed();
|
||||
u32 ping_key = 0;
|
||||
packet >> ping_key;
|
||||
|
||||
if (m_ping_key == ping_key)
|
||||
{
|
||||
const u32 ping = (u32)m_ping_timer.GetTimeElapsed();
|
||||
u32 ping_key = 0;
|
||||
packet >> ping_key;
|
||||
|
||||
if (m_ping_key == ping_key)
|
||||
{
|
||||
player.ping = ping;
|
||||
}
|
||||
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_PLAYER_PING_DATA;
|
||||
spac << player.pid;
|
||||
spac << player.ping;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac);
|
||||
player.ping = ping;
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_START_GAME :
|
||||
{
|
||||
packet >> player.current_game;
|
||||
}
|
||||
break;
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_PLAYER_PING_DATA;
|
||||
spac << player.pid;
|
||||
spac << player.ping;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_START_GAME:
|
||||
{
|
||||
packet >> player.current_game;
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_MSG_STOP_GAME:
|
||||
{
|
||||
// tell clients to stop game
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_STOP_GAME;
|
||||
{
|
||||
// tell clients to stop game
|
||||
sf::Packet spac;
|
||||
spac << (MessageId)NP_MSG_STOP_GAME;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac);
|
||||
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||
SendToClients(spac);
|
||||
|
||||
m_is_running = false;
|
||||
}
|
||||
break;
|
||||
m_is_running = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
default:
|
||||
PanicAlertT("Unknown message with id:%d received from player:%d Kicking player!", mid, player.pid);
|
||||
// unknown message, kick the client
|
||||
return 1;
|
||||
@ -573,25 +608,36 @@ void NetPlayServer::SendToClients(sf::Packet& packet, const PlayerId skip_pid)
|
||||
{
|
||||
for (auto& p : m_players)
|
||||
{
|
||||
if (p.pid && p.pid != skip_pid)
|
||||
if (p.second.pid && p.second.pid != skip_pid)
|
||||
{
|
||||
p.socket->send(packet);
|
||||
Send(p.second.socket, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetPlayServer::KickPlayer(u8 player)
|
||||
void NetPlayServer::Send(ENetPeer* socket, sf::Packet& packet)
|
||||
{
|
||||
ENetPacket* epac = enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(socket, 0, epac);
|
||||
}
|
||||
|
||||
void NetPlayServer::KickPlayer(PlayerId player)
|
||||
{
|
||||
for (auto& current_player : m_players)
|
||||
{
|
||||
if (current_player.pid == player)
|
||||
if (current_player.second.pid == player)
|
||||
{
|
||||
current_player.socket->disconnect();
|
||||
enet_peer_disconnect(current_player.second.socket, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u16 NetPlayServer::GetPort()
|
||||
{
|
||||
return m_server->address.port;
|
||||
}
|
||||
|
||||
#ifdef USE_UPNP
|
||||
#include <miniwget.h>
|
||||
#include <miniupnpc.h>
|
||||
@ -615,7 +661,11 @@ void NetPlayServer::TryPortmapping(u16 port)
|
||||
// UPnP thread: try to map a port
|
||||
void NetPlayServer::mapPortThread(const u16 port)
|
||||
{
|
||||
std::string ourIP = sf::IpAddress::getLocalAddress().toString();
|
||||
ENetAddress adr;
|
||||
char cIP[20];
|
||||
|
||||
enet_address_get_host_ip(&adr, cIP, 20);
|
||||
std::string ourIP(cIP);
|
||||
|
||||
if (!m_upnp_inited)
|
||||
if (!initUPnP())
|
||||
@ -677,7 +727,7 @@ bool NetPlayServer::initUPnP()
|
||||
|
||||
for (const UPNPDev* dev : igds)
|
||||
{
|
||||
char* descXML = (char*) miniwget(dev->descURL, &descXMLsize, 0);
|
||||
char* descXML = (char*)miniwget(dev->descURL, &descXMLsize, 0);
|
||||
if (descXML)
|
||||
{
|
||||
parserootdesc(descXML, descXMLsize, &m_upnp_data);
|
||||
@ -708,9 +758,9 @@ bool NetPlayServer::UPnPMapPort(const std::string& addr, const u16 port)
|
||||
|
||||
std::string port_str = StringFromFormat("%d", port);
|
||||
int result = UPNP_AddPortMapping(m_upnp_urls.controlURL, m_upnp_data.first.servicetype,
|
||||
port_str.c_str(), port_str.c_str(), addr.c_str(),
|
||||
(std::string("dolphin-emu TCP on ") + addr).c_str(),
|
||||
"TCP", nullptr, nullptr);
|
||||
port_str.c_str(), port_str.c_str(), addr.c_str(),
|
||||
(std::string("dolphin-emu TCP on ") + addr).c_str(),
|
||||
"TCP", nullptr, nullptr);
|
||||
|
||||
if (result != 0)
|
||||
return false;
|
||||
@ -732,7 +782,7 @@ bool NetPlayServer::UPnPUnmapPort(const u16 port)
|
||||
{
|
||||
std::string port_str = StringFromFormat("%d", port);
|
||||
UPNP_DeletePortMapping(m_upnp_urls.controlURL, m_upnp_data.first.servicetype,
|
||||
port_str.c_str(), "TCP", nullptr);
|
||||
port_str.c_str(), "TCP", nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user