@@ -35,6 +35,7 @@ Maryland 20850 USA.
35
35
#include " qcommon/q_shared.h"
36
36
#include " qcommon/qcommon.h"
37
37
#include < common/FileSystem.h>
38
+ #include " engine/framework/Application.h"
38
39
#include " engine/framework/Network.h"
39
40
#include " server/server.h"
40
41
@@ -120,11 +121,6 @@ namespace net {
120
121
121
122
static bool usingSocks = false ;
122
123
static bool networkingEnabled = false ;
123
- #ifndef BUILD_SERVER
124
- static bool serverMode = false ;
125
- #else
126
- static const bool serverMode = true ;
127
- #endif
128
124
129
125
cvar_t *net_enabled;
130
126
@@ -1598,7 +1594,7 @@ static int NET_EnsureValidPortNo( int port )
1598
1594
NET_OpenIP
1599
1595
====================
1600
1596
*/
1601
- static void NET_OpenIP ()
1597
+ static void NET_OpenIP ( bool serverMode )
1602
1598
{
1603
1599
int i;
1604
1600
int err = 0 ;
@@ -1689,10 +1685,8 @@ static void NET_OpenIP()
1689
1685
NET_GetCvars
1690
1686
====================
1691
1687
*/
1692
- static bool NET_GetCvars ()
1688
+ static void NET_GetCvars ()
1693
1689
{
1694
- int modified;
1695
-
1696
1690
#ifdef BUILD_SERVER
1697
1691
// I want server owners to explicitly turn on IPv6 support.
1698
1692
net_enabled = Cvar_Get ( " net_enabled" , " 1" , CVAR_LATCH );
@@ -1702,147 +1696,82 @@ static bool NET_GetCvars()
1702
1696
* used if available due to ping */
1703
1697
net_enabled = Cvar_Get ( " net_enabled" , " 3" , CVAR_LATCH );
1704
1698
#endif
1705
- modified = net_enabled->modified ;
1706
- net_enabled->modified = false ;
1707
1699
1708
1700
net_ip = Cvar_Get ( " net_ip" , " 0.0.0.0" , CVAR_LATCH );
1709
- modified += net_ip->modified ;
1710
- net_ip->modified = false ;
1711
-
1712
1701
net_ip6 = Cvar_Get ( " net_ip6" , " ::" , CVAR_LATCH );
1713
- modified += net_ip6->modified ;
1714
- net_ip6->modified = false ;
1715
-
1716
1702
net_port = Cvar_Get ( " net_port" , va ( " %i" , PORT_SERVER ), CVAR_LATCH );
1717
- modified += net_port->modified ;
1718
- net_port->modified = false ;
1719
-
1720
1703
net_port6 = Cvar_Get ( " net_port6" , va ( " %i" , PORT_SERVER ), CVAR_LATCH );
1721
- modified += net_port6->modified ;
1722
- net_port6->modified = false ;
1723
1704
1724
1705
// Some cvars for configuring multicast options which facilitates scanning for servers on local subnets.
1725
1706
net_mcast6addr = Cvar_Get ( " net_mcast6addr" , NET_MULTICAST_IP6, CVAR_LATCH );
1726
- modified += net_mcast6addr->modified ;
1727
- net_mcast6addr->modified = false ;
1728
-
1729
1707
#ifdef _WIN32
1730
1708
net_mcast6iface = Cvar_Get ( " net_mcast6iface" , " 0" , CVAR_LATCH );
1731
1709
#else
1732
1710
net_mcast6iface = Cvar_Get ( " net_mcast6iface" , " " , CVAR_LATCH );
1733
1711
#endif
1734
- modified += net_mcast6iface->modified ;
1735
- net_mcast6iface->modified = false ;
1736
1712
1737
1713
net_socksEnabled = Cvar_Get ( " net_socksEnabled" , " 0" , CVAR_LATCH );
1738
- modified += net_socksEnabled->modified ;
1739
- net_socksEnabled->modified = false ;
1740
-
1741
1714
net_socksServer = Cvar_Get ( " net_socksServer" , " " , CVAR_LATCH );
1742
- modified += net_socksServer->modified ;
1743
- net_socksServer->modified = false ;
1744
-
1745
1715
net_socksPort = Cvar_Get ( " net_socksPort" , " 1080" , CVAR_LATCH );
1746
- modified += net_socksPort->modified ;
1747
- net_socksPort->modified = false ;
1748
-
1749
1716
net_socksUsername = Cvar_Get ( " net_socksUsername" , " " , CVAR_LATCH );
1750
- modified += net_socksUsername->modified ;
1751
- net_socksUsername->modified = false ;
1752
-
1753
1717
net_socksPassword = Cvar_Get ( " net_socksPassword" , " " , CVAR_LATCH );
1754
- modified += net_socksPassword->modified ;
1755
- net_socksPassword->modified = false ;
1756
-
1757
- return modified ? true : false ;
1758
1718
}
1759
1719
1760
- /*
1761
- ====================
1762
- NET_Config
1763
- ====================
1764
- */
1765
- void NET_Config ( bool enableNetworking )
1720
+ void NET_EnableNetworking ( bool serverMode )
1766
1721
{
1767
- bool modified;
1768
- bool stop;
1769
- bool start;
1770
- #ifndef BUILD_SERVER
1771
- bool svRunning;
1772
- #endif
1773
-
1774
1722
// get any latched changes to cvars
1775
- modified = NET_GetCvars ();
1776
- #ifndef BUILD_SERVER
1777
- svRunning = !!com_sv_running->integer ;
1778
- modified |= ( svRunning != serverMode );
1779
- #endif
1723
+ NET_GetCvars ();
1780
1724
1781
- if ( !net_enabled->integer )
1782
- {
1783
- enableNetworking = false ;
1784
- }
1725
+ // always cycle off and on because this function is only called on a state change or forced restart
1726
+ NET_DisableNetworking ();
1785
1727
1786
- // if enable state is the same and no cvars were modified, we have nothing to do
1787
- if ( enableNetworking == networkingEnabled && !modified )
1728
+ if ( !( net_enabled->integer & ( NET_ENABLEV4 | NET_ENABLEV6 ) ) )
1788
1729
{
1789
1730
return ;
1790
1731
}
1791
1732
1792
- start = enableNetworking;
1793
- if ( enableNetworking == networkingEnabled )
1794
- {
1795
- stop = enableNetworking;
1796
- }
1797
- else
1733
+ networkingEnabled = true ;
1734
+
1735
+ NET_OpenIP ( serverMode );
1736
+ NET_SetMulticast6 ();
1737
+ SV_NET_Config ();
1738
+ }
1739
+
1740
+ void NET_DisableNetworking ()
1741
+ {
1742
+ if ( !networkingEnabled )
1798
1743
{
1799
- stop = !enableNetworking ;
1744
+ return ;
1800
1745
}
1801
1746
1802
- #ifndef BUILD_SERVER
1803
- serverMode = svRunning;
1804
- #endif
1805
- networkingEnabled = enableNetworking;
1747
+ networkingEnabled = false ;
1806
1748
1807
- if ( stop )
1749
+ if ( ip_socket != INVALID_SOCKET )
1808
1750
{
1809
- if ( ip_socket != INVALID_SOCKET )
1810
- {
1811
- closesocket ( ip_socket );
1812
- ip_socket = INVALID_SOCKET;
1813
- }
1751
+ closesocket ( ip_socket );
1752
+ ip_socket = INVALID_SOCKET;
1753
+ }
1814
1754
1815
- if ( multicast6_socket != INVALID_SOCKET )
1755
+ if ( multicast6_socket != INVALID_SOCKET )
1756
+ {
1757
+ if ( multicast6_socket != ip6_socket )
1816
1758
{
1817
- if ( multicast6_socket != ip6_socket )
1818
- {
1819
- closesocket ( multicast6_socket );
1820
- }
1821
-
1822
- multicast6_socket = INVALID_SOCKET;
1759
+ closesocket ( multicast6_socket );
1823
1760
}
1824
1761
1825
- if ( ip6_socket != INVALID_SOCKET )
1826
- {
1827
- closesocket ( ip6_socket );
1828
- ip6_socket = INVALID_SOCKET;
1829
- }
1762
+ multicast6_socket = INVALID_SOCKET;
1763
+ }
1830
1764
1831
- if ( socks_socket != INVALID_SOCKET )
1832
- {
1833
- closesocket ( socks_socket );
1834
- socks_socket = INVALID_SOCKET;
1835
- }
1765
+ if ( ip6_socket != INVALID_SOCKET )
1766
+ {
1767
+ closesocket ( ip6_socket );
1768
+ ip6_socket = INVALID_SOCKET;
1836
1769
}
1837
1770
1838
- if ( start )
1771
+ if ( socks_socket != INVALID_SOCKET )
1839
1772
{
1840
- if ( net_enabled->integer )
1841
- {
1842
- NET_OpenIP ();
1843
- NET_SetMulticast6 ();
1844
- SV_NET_Config ();
1845
- }
1773
+ closesocket ( socks_socket );
1774
+ socks_socket = INVALID_SOCKET;
1846
1775
}
1847
1776
}
1848
1777
@@ -1868,7 +1797,7 @@ void NET_Init()
1868
1797
Log::Notice ( " Winsock Initialized" );
1869
1798
#endif
1870
1799
1871
- NET_Config ( true );
1800
+ NET_EnableNetworking ( Application::GetTraits (). isServer );
1872
1801
1873
1802
Cmd_AddCommand ( " net_restart" , NET_Restart_f );
1874
1803
}
@@ -1885,7 +1814,7 @@ void NET_Shutdown()
1885
1814
return ;
1886
1815
}
1887
1816
1888
- NET_Config ( false );
1817
+ NET_DisableNetworking ( );
1889
1818
1890
1819
#ifdef _WIN32
1891
1820
WSACleanup ();
@@ -1948,8 +1877,12 @@ NET_Restart_f
1948
1877
*/
1949
1878
void NET_Restart_f ()
1950
1879
{
1951
- NET_Config ( false );
1880
+ NET_DisableNetworking ( );
1952
1881
SV_NET_Config ();
1953
1882
Net::ShutDownDNS ();
1954
- NET_Config ( true );
1883
+ #ifdef BUILD_SERVER
1884
+ NET_EnableNetworking ( true );
1885
+ #else
1886
+ NET_EnableNetworking ( !!com_sv_running->integer );
1887
+ #endif
1955
1888
}
0 commit comments