Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetSession.cpp
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | CNetClientSession::~CNetClientSession() | ||||
delete m_Stats; | delete m_Stats; | ||||
if (m_Host && m_Server) | if (m_Host && m_Server) | ||||
{ | { | ||||
// Disconnect immediately (we can't wait for acks) | // Disconnect immediately (we can't wait for acks) | ||||
enet_peer_disconnect_now(m_Server, NDR_SERVER_SHUTDOWN); | enet_peer_disconnect_now(m_Server, NDR_SERVER_SHUTDOWN); | ||||
enet_host_destroy(m_Host); | enet_host_destroy(m_Host); | ||||
m_Host = NULL; | m_Host = nullptr; | ||||
m_Server = NULL; | m_Server = nullptr; | ||||
} | } | ||||
} | } | ||||
bool CNetClientSession::Connect(const CStr& server, const u16 port, const bool isLocalClient, ENetHost* enetClient) | bool CNetClientSession::Connect(const CStr& server, const u16 port, const bool isLocalClient, ENetHost* enetClient) | ||||
{ | { | ||||
ENSURE(!m_Host); | ENSURE(!m_Host); | ||||
ENSURE(!m_Server); | ENSURE(!m_Server); | ||||
// Create ENet host | // Create ENet host | ||||
ENetHost* host; | ENetHost* host; | ||||
if (enetClient != nullptr) | if (enetClient != nullptr) | ||||
host = enetClient; | host = enetClient; | ||||
else | else | ||||
host = enet_host_create(NULL, 1, CHANNEL_COUNT, 0, 0); | host = enet_host_create(nullptr, 1, CHANNEL_COUNT, 0, 0); | ||||
if (!host) | if (!host) | ||||
return false; | return false; | ||||
// Bind to specified host | // Bind to specified host | ||||
ENetAddress addr; | ENetAddress addr; | ||||
addr.port = port; | addr.port = port; | ||||
if (enet_address_set_host(&addr, server.c_str()) < 0) | if (enet_address_set_host(&addr, server.c_str()) < 0) | ||||
Show All 24 Lines | |||||
void CNetClientSession::Disconnect(u32 reason) | void CNetClientSession::Disconnect(u32 reason) | ||||
{ | { | ||||
ENSURE(m_Host && m_Server); | ENSURE(m_Host && m_Server); | ||||
// TODO: ought to do reliable async disconnects, probably | // TODO: ought to do reliable async disconnects, probably | ||||
enet_peer_disconnect_now(m_Server, reason); | enet_peer_disconnect_now(m_Server, reason); | ||||
enet_host_destroy(m_Host); | enet_host_destroy(m_Host); | ||||
m_Host = NULL; | m_Host = nullptr; | ||||
m_Server = NULL; | m_Server = nullptr; | ||||
SAFE_DELETE(m_Stats); | SAFE_DELETE(m_Stats); | ||||
} | } | ||||
void CNetClientSession::Poll() | void CNetClientSession::Poll() | ||||
{ | { | ||||
PROFILE3("net client poll"); | PROFILE3("net client poll"); | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | u32 CNetServerSession::GetMeanRTT() const | ||||
if (!m_Peer) | if (!m_Peer) | ||||
return 0; | return 0; | ||||
return m_Peer->roundTripTime; | return m_Peer->roundTripTime; | ||||
} | } | ||||
void CNetServerSession::Disconnect(u32 reason) | void CNetServerSession::Disconnect(u32 reason) | ||||
{ | { | ||||
Update((uint)NMT_CONNECTION_LOST, NULL); | Update((uint)NMT_CONNECTION_LOST, nullptr); | ||||
enet_peer_disconnect(m_Peer, reason); | enet_peer_disconnect(m_Peer, reason); | ||||
} | } | ||||
void CNetServerSession::DisconnectNow(u32 reason) | void CNetServerSession::DisconnectNow(u32 reason) | ||||
{ | { | ||||
enet_peer_disconnect_now(m_Peer, reason); | enet_peer_disconnect_now(m_Peer, reason); | ||||
} | } | ||||
Show All 28 Lines |
Wildfire Games · Phabricator