Prevent the local client of the host from becoming disconnected in case of lag, fixes #2854.
This was SVN commit r17772.
This commit is contained in:
parent
f8b20d181d
commit
2e7e1c0b2b
@ -486,6 +486,10 @@ bool CNetServerWorker::RunStep()
|
|||||||
|
|
||||||
CNetServerSession* session = new CNetServerSession(*this, event.peer);
|
CNetServerSession* session = new CNetServerSession(*this, event.peer);
|
||||||
|
|
||||||
|
// Prevent the local client of the host from timing out too quickly
|
||||||
|
if (session->GetIPAddress() == "127.0.0.1")
|
||||||
|
enet_peer_timeout(event.peer, 0, MAXIMUM_HOST_TIMEOUT, MAXIMUM_HOST_TIMEOUT);
|
||||||
|
|
||||||
m_Sessions.push_back(session);
|
m_Sessions.push_back(session);
|
||||||
|
|
||||||
SetupSession(session);
|
SetupSession(session);
|
||||||
@ -679,8 +683,7 @@ void CNetServerWorker::OnUserJoin(CNetServerSession* session)
|
|||||||
{
|
{
|
||||||
AddPlayer(session->GetGUID(), session->GetUserName());
|
AddPlayer(session->GetGUID(), session->GetUserName());
|
||||||
|
|
||||||
// Host is the first to join
|
if (m_HostGUID.empty() && session->GetIPAddress() == "127.0.0.1")
|
||||||
if (m_HostGUID.empty())
|
|
||||||
m_HostGUID = session->GetGUID();
|
m_HostGUID = session->GetGUID();
|
||||||
|
|
||||||
CGameSetupMessage gameSetupMessage(GetScriptInterface());
|
CGameSetupMessage gameSetupMessage(GetScriptInterface());
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
const u32 NETWORK_WARNING_TIMEOUT = 4000;
|
const u32 NETWORK_WARNING_TIMEOUT = 4000;
|
||||||
|
|
||||||
|
const u32 MAXIMUM_HOST_TIMEOUT = std::numeric_limits<u32>::max();
|
||||||
|
|
||||||
static const int CHANNEL_COUNT = 1;
|
static const int CHANNEL_COUNT = 1;
|
||||||
|
|
||||||
CNetClientSession::CNetClientSession(CNetClient& client) :
|
CNetClientSession::CNetClientSession(CNetClient& client) :
|
||||||
@ -73,6 +75,10 @@ bool CNetClientSession::Connect(u16 port, const CStr& server)
|
|||||||
m_Host = host;
|
m_Host = host;
|
||||||
m_Server = peer;
|
m_Server = peer;
|
||||||
|
|
||||||
|
// Prevent the local client of the host from timing out too quickly.
|
||||||
|
if (GetIPAddress() == "127.0.0.1")
|
||||||
|
enet_peer_timeout(peer, 1, MAXIMUM_HOST_TIMEOUT, MAXIMUM_HOST_TIMEOUT);
|
||||||
|
|
||||||
m_Stats = new CNetStatsTable(m_Server);
|
m_Stats = new CNetStatsTable(m_Server);
|
||||||
if (CProfileViewer::IsInitialised())
|
if (CProfileViewer::IsInitialised())
|
||||||
g_ProfileViewer.AddRootTable(m_Stats);
|
g_ProfileViewer.AddRootTable(m_Stats);
|
||||||
@ -170,6 +176,15 @@ bool CNetClientSession::SendMessage(const CNetMessage* message)
|
|||||||
return CNetHost::SendMessage(message, m_Server, "server");
|
return CNetHost::SendMessage(message, m_Server, "server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CStr CNetClientSession::GetIPAddress() const
|
||||||
|
{
|
||||||
|
char ipAddress[256] = "";
|
||||||
|
if (enet_address_get_host_ip(&m_Server->address, ipAddress, ARRAY_SIZE(ipAddress)) < 0)
|
||||||
|
LOGMESSAGE("Could not get IP address of the server!");
|
||||||
|
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
u32 CNetClientSession::GetLastReceivedTime() const
|
u32 CNetClientSession::GetLastReceivedTime() const
|
||||||
{
|
{
|
||||||
if (!m_Server)
|
if (!m_Server)
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
*/
|
*/
|
||||||
extern const u32 NETWORK_WARNING_TIMEOUT;
|
extern const u32 NETWORK_WARNING_TIMEOUT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum timeout of the local client of the host (milliseconds).
|
||||||
|
*/
|
||||||
|
extern const u32 MAXIMUM_HOST_TIMEOUT;
|
||||||
|
|
||||||
class CNetClient;
|
class CNetClient;
|
||||||
class CNetServerWorker;
|
class CNetServerWorker;
|
||||||
|
|
||||||
@ -88,6 +93,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool SendMessage(const CNetMessage* message);
|
virtual bool SendMessage(const CNetMessage* message);
|
||||||
|
|
||||||
|
CStr GetIPAddress() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of milliseconds since the most recent packet of the server was received.
|
* Number of milliseconds since the most recent packet of the server was received.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user