Skip to content

Commit

Permalink
tweak(glue): disconnect from network if system encounters a power sta…
Browse files Browse the repository at this point in the history
…te change

Also, prevent these events from being handled by game code, since game code probably does weird.
  • Loading branch information
blattersturm committed Dec 20, 2021
1 parent db07118 commit 796f31f
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions code/components/glue/src/ConnectToNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,21 @@ static void UpdatePendingAuthPayload()
}
}

static void DisconnectCmd()
{
if (netLibrary->GetConnectionState() != 0)
{
OnKillNetwork("Disconnected.");
OnMsgConfirm();
}
}

static InitFunction initFunction([] ()
{
static std::function<void()> g_onYesCallback;
static std::function<void()> backfillDoneEvent;
static bool mpMenuExpectsBackfill;
static bool disconnect;

static ipc::Endpoint ep("launcherTalk", false);

Expand All @@ -494,6 +504,12 @@ static InitFunction initFunction([] ()

OnGameFrame.Connect([]()
{
if (disconnect)
{
DisconnectCmd();
disconnect = false;
}

ep.RunFrame();
});

Expand All @@ -502,6 +518,22 @@ static InitFunction initFunction([] ()
ep.Call("loading");
});

InputHook::DeprecatedOnWndProc.Connect([](HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, bool& pass, LRESULT& lresult)
{
// we don't want the game to be informed about the system entering a low-power state
if (msg == WM_POWERBROADCAST)
{
// if the system is resumed, we do want to try to manually disconnect
if (wParam == PBT_APMRESUMEAUTOMATIC || wParam == PBT_APMRESUMESUSPEND)
{
disconnect = true;
}

pass = false;
lresult = true;
}
});

NetLibrary::OnNetLibraryCreate.Connect([] (NetLibrary* lib)
{
netLibrary = lib;
Expand Down Expand Up @@ -913,11 +945,7 @@ static InitFunction initFunction([] ()

static ConsoleCommand disconnectCommand("disconnect", []()
{
if (netLibrary->GetConnectionState() != 0)
{
OnKillNetwork("Disconnected.");
OnMsgConfirm();
}
DisconnectCmd();
});

static std::string curChannel;
Expand Down

0 comments on commit 796f31f

Please sign in to comment.