Disconnect android player from wan race when the window is not active anymore

This commit is contained in:
Deve 2018-09-18 23:03:32 +02:00
parent 18c108c99a
commit e80e0555e1
3 changed files with 39 additions and 1 deletions

View File

@ -34,6 +34,8 @@
#include "input/input_manager.hpp"
#include "modes/demo_world.hpp"
#include "modes/world.hpp"
#include "network/network_config.hpp"
#include "network/stk_host.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/debug.hpp"
#include "utils/profiler.hpp"
@ -184,6 +186,21 @@ bool EventHandler::OnEvent (const SEvent &event)
SFXManager::get()->resumeAll();
}
}
else if (cmd == APP_CMD_TERM_WINDOW)
{
if (STKHost::existHost() && NetworkConfig::get()->isWAN())
{
STKHost::get()->requestShutdownDelayed(10000);
}
}
else if (cmd == APP_CMD_INIT_WINDOW)
{
if (STKHost::existHost() && NetworkConfig::get()->isWAN() &&
!STKHost::get()->requestedShutdown())
{
STKHost::get()->cancelShutdown();
}
}
else if (cmd == APP_CMD_LOW_MEMORY)
{
Log::warn("EventHandler", "Low memory event received");

View File

@ -308,6 +308,7 @@ void STKHost::init()
{
m_network_timer.store(StkTime::getRealTimeMs());
m_shutdown = false;
m_shutdown_delay = 0;
m_authorised = false;
m_network = NULL;
m_exit_timeout.store(std::numeric_limits<uint64_t>::max());

View File

@ -117,6 +117,9 @@ private:
* triggers a shutdown of the STKHost (and the Protocolmanager). */
std::atomic_bool m_shutdown;
/** Used as a timeout for shedule shutdown. */
std::atomic<uint64_t> m_shutdown_delay;
/** True if this local host is authorised to control a server. */
std::atomic_bool m_authorised;
@ -208,8 +211,21 @@ public:
void requestShutdown()
{
m_shutdown.store(true);
m_shutdown_delay.store(0);
} // requestExit
//-------------------------------------------------------------------------
void requestShutdownDelayed(int delay)
{
m_shutdown.store(true);
m_shutdown_delay.store(StkTime::getRealTimeMs() + delay);
}
//-------------------------------------------------------------------------
void cancelShutdown()
{
m_shutdown.store(false);
m_shutdown_delay.store(0);
}
//-------------------------------------------------------------------------
void shutdown();
//-------------------------------------------------------------------------
void sendPacketToAllPeersInServer(NetworkString *data,
@ -266,7 +282,11 @@ public:
// ------------------------------------------------------------------------
/** Returns true if a shutdown of the network infrastructure was
* requested. */
bool requestedShutdown() const { return m_shutdown.load(); }
bool requestedShutdown() const
{
return m_shutdown.load() &&
m_shutdown_delay.load() < StkTime::getRealTimeMs();
}
// ------------------------------------------------------------------------
int receiveRawPacket(char *buffer, int buffer_len,
TransportAddress* sender, int max_tries = -1)