Skip to content

Commit

Permalink
feature: allow unblocking while overwatch is open
Browse files Browse the repository at this point in the history
  • Loading branch information
stowmyy committed Oct 26, 2023
1 parent 968542b commit 33a1b33
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dropship/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ AppStore __default__appStore
.dashboard =
{
.title = "Servers",
.heading = "Changes will be applied immediately."
.heading = "Changes will be applied immediately. You do not need to keep this app open."
},
.application_open = false
};
Expand Down
5 changes: 2 additions & 3 deletions dropship/src/DashboardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ DashboardManager::DashboardManager() :

if (!__previous__application_open && appStore.application_open)
{
appStore.dashboard.heading = "Changes will be applied after closing the game";
appStore.dashboard.heading = "Blocking new servers won't take effect until Overwatch is relaunched.";
}

if (this->processes[process_name].icon.texture == nullptr)
Expand Down Expand Up @@ -698,8 +698,7 @@ void DashboardManager::RenderInline()
if (action)
{
// std::thread([&]() {
if (!appStore.application_open)
firewallManager.sync(&(this->endpoints));
firewallManager.sync(&(this->endpoints), appStore.application_open);
// }).detach();

// fill missing frame
Expand Down
14 changes: 7 additions & 7 deletions dropship/src/FirewallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ bool FirewallManager::AddFirewallRule(Endpoint* e, bool enabled)


// mirrors endpoint state
void FirewallManager::_syncEndpointsWithFirewall(std::vector<Endpoint>* endpoints)
void FirewallManager::_syncEndpointsWithFirewall(std::vector<Endpoint>* endpoints, bool only_unblocks)
{
this->_windowsFirewall->syncFirewallEndpointState(endpoints, true);
this->_windowsFirewall->syncFirewallEndpointState(endpoints, true, only_unblocks);
}

// mirrors firewall state
void FirewallManager::_syncFirewallWithEndpoints(std::vector<Endpoint>* endpoints)
void FirewallManager::_syncFirewallWithEndpoints(std::vector<Endpoint>* endpoints, bool only_unblocks)
{
this->_windowsFirewall->syncFirewallEndpointState(endpoints, false);
this->_windowsFirewall->syncFirewallEndpointState(endpoints, false, only_unblocks);
}

/*
0) set firewall state to mirror endpoint state
2) ..
4) then set endpoint state to mirror firewall state
*/
void FirewallManager::sync(std::vector<Endpoint>* endpoints)
void FirewallManager::sync(std::vector<Endpoint>* endpoints, bool only_unblocks)
{
printf("sync()\n");
this->_syncEndpointsWithFirewall(endpoints);
this->_syncFirewallWithEndpoints(endpoints);
this->_syncEndpointsWithFirewall(endpoints, only_unblocks);
this->_syncFirewallWithEndpoints(endpoints, only_unblocks);
}

// destroys previous rules
Expand Down
6 changes: 3 additions & 3 deletions dropship/src/FirewallManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class FirewallManager : public failable


//bool isWindowsFirewallEnabled();
void sync(std::vector<Endpoint>* endpoints);
void sync(std::vector<Endpoint>* endpoints, bool only_unblocks = false);

// mirrors endpoint state
void _syncEndpointsWithFirewall(std::vector<Endpoint>* endpoints);
void _syncEndpointsWithFirewall(std::vector<Endpoint>* endpoints, bool only_unblocks = false);

// mirrors firewall state
void _syncFirewallWithEndpoints(std::vector<Endpoint>* endpoints);
void _syncFirewallWithEndpoints(std::vector<Endpoint>* endpoints, bool only_unblocks = false);

private:

Expand Down
4 changes: 2 additions & 2 deletions dropship/src/_WindowsFirewallUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ class _WindowsFirewallUtil : public failable

// NOTE - don't use the microsoft examples any more from the official site. they have memory leaks. ugh.
// https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/security/windowsfirewall/enumeratefirewallrules/EnumerateFirewallRules.cpp
void syncFirewallEndpointState(std::vector<Endpoint>* endpoints, bool endpointDominant)
void syncFirewallEndpointState(std::vector<Endpoint>* endpoints, bool endpointDominant, bool only_unblocks = false)
{
HRESULT hr;

Expand Down Expand Up @@ -1327,7 +1327,7 @@ class _WindowsFirewallUtil : public failable

if (e.title == s_ruleName)
{
if (!e.active_desired_state != ruleEnabled)
if (!e.active_desired_state != ruleEnabled && (!only_unblocks || (only_unblocks && (!e.active && e.active_desired_state))))
{

// if endpointDominant, set firewall to mirror endpoint state
Expand Down

0 comments on commit 33a1b33

Please sign in to comment.