Disconnect android player from wan race when the window is not active anymore
This commit is contained in:
parent
18c108c99a
commit
e80e0555e1
@ -34,6 +34,8 @@
|
|||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
#include "modes/demo_world.hpp"
|
#include "modes/demo_world.hpp"
|
||||||
#include "modes/world.hpp"
|
#include "modes/world.hpp"
|
||||||
|
#include "network/network_config.hpp"
|
||||||
|
#include "network/stk_host.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "utils/debug.hpp"
|
#include "utils/debug.hpp"
|
||||||
#include "utils/profiler.hpp"
|
#include "utils/profiler.hpp"
|
||||||
@ -184,6 +186,21 @@ bool EventHandler::OnEvent (const SEvent &event)
|
|||||||
SFXManager::get()->resumeAll();
|
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)
|
else if (cmd == APP_CMD_LOW_MEMORY)
|
||||||
{
|
{
|
||||||
Log::warn("EventHandler", "Low memory event received");
|
Log::warn("EventHandler", "Low memory event received");
|
||||||
|
@ -308,6 +308,7 @@ void STKHost::init()
|
|||||||
{
|
{
|
||||||
m_network_timer.store(StkTime::getRealTimeMs());
|
m_network_timer.store(StkTime::getRealTimeMs());
|
||||||
m_shutdown = false;
|
m_shutdown = false;
|
||||||
|
m_shutdown_delay = 0;
|
||||||
m_authorised = false;
|
m_authorised = false;
|
||||||
m_network = NULL;
|
m_network = NULL;
|
||||||
m_exit_timeout.store(std::numeric_limits<uint64_t>::max());
|
m_exit_timeout.store(std::numeric_limits<uint64_t>::max());
|
||||||
|
@ -117,6 +117,9 @@ private:
|
|||||||
* triggers a shutdown of the STKHost (and the Protocolmanager). */
|
* triggers a shutdown of the STKHost (and the Protocolmanager). */
|
||||||
std::atomic_bool m_shutdown;
|
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. */
|
/** True if this local host is authorised to control a server. */
|
||||||
std::atomic_bool m_authorised;
|
std::atomic_bool m_authorised;
|
||||||
|
|
||||||
@ -208,8 +211,21 @@ public:
|
|||||||
void requestShutdown()
|
void requestShutdown()
|
||||||
{
|
{
|
||||||
m_shutdown.store(true);
|
m_shutdown.store(true);
|
||||||
|
m_shutdown_delay.store(0);
|
||||||
} // requestExit
|
} // 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 shutdown();
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
void sendPacketToAllPeersInServer(NetworkString *data,
|
void sendPacketToAllPeersInServer(NetworkString *data,
|
||||||
@ -266,7 +282,11 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns true if a shutdown of the network infrastructure was
|
/** Returns true if a shutdown of the network infrastructure was
|
||||||
* requested. */
|
* 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,
|
int receiveRawPacket(char *buffer, int buffer_len,
|
||||||
TransportAddress* sender, int max_tries = -1)
|
TransportAddress* sender, int max_tries = -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user