1- Imports System.Net
1+ Imports System.IO
2+ Imports System.Net
23Imports Newtonsoft.Json.Linq
34Module ServerService
45
@@ -9,6 +10,8 @@ Module ServerService
910 { "India" , "Chennai,Mumbai" }
1011 }
1112
13+ Private netshPath As String = Path.Combine(Environment.SystemDirectory, "netsh.exe" )
14+
1215 Public Async Function Fetch_Server_Data() As Task( Of String )
1316 Try
1417 Dim webReq As String = Await New WebClient().DownloadStringTaskAsync( "https://api.steampowered.com/ISteamApps/GetSDRConfig/v1/?appid=730" )
@@ -106,7 +109,7 @@ Module ServerService
106109 Await Block_Unblock_All_Servers( False , False )
107110
108111 ' is passed as a reference, should be cloned in case of unwanted modification
109- Dim serverDIctionary As Dictionary( Of String , String ) = IIf(App.Get_Is_Clustered(), App.Get_Server_Dictionary_Clustered(), App.Get_Server_Dictionary_Unclustered())
112+ Dim serverDictionary As Dictionary( Of String , String ) = IIf(App.Get_Is_Clustered(), App.Get_Server_Dictionary_Clustered(), App.Get_Server_Dictionary_Unclustered())
110113
111114 Dim presetServersDataGridView As DataGridView = Presets.PresetServerListDataGridView
112115
@@ -115,7 +118,7 @@ Module ServerService
115118 Cancel_Pending_Ping()
116119
117120 ' offload this blocking task into a seperate thread from the thread pool to lessen load in the UI thread
118- Await Task.Run( Sub () Handle_Block_Except_Preset_Servers(presetServersDataGridView, serverDIctionary , exceptPresetServers))
121+ Await Task.Run( Sub () Handle_Block_Except_Preset_Servers(presetServersDataGridView, serverDictionary , exceptPresetServers))
119122
120123 App.Set_Pending_Operation( False )
121124
@@ -145,7 +148,7 @@ Module ServerService
145148 End If
146149
147150 Try
148- proc.StartInfo.Arguments = "/c netsh advfirewall firewall add rule " +
151+ proc.StartInfo.Arguments = $ "/c {netshPath} advfirewall firewall add rule " +
149152 "name=CS2ServerPicker_" + serverKvp.Key.Replace( " " , "" ) + " dir=out action=block protocol=ANY " +
150153 "remoteip=" + serverKvp.Value
151154 proc.Start()
@@ -168,7 +171,7 @@ Module ServerService
168171
169172 Public Async Sub Block_Unblock_Selected_Servers(block As Boolean )
170173 Dim mainDataGridView As DataGridView = App.Get_DataGridView_Control()
171- Dim serverDIctionary As Dictionary( Of String , String ) = IIf(App.Get_Is_Clustered(), App.Get_Server_Dictionary_Clustered(), App.Get_Server_Dictionary_Unclustered())
174+ Dim serverDictionary As Dictionary( Of String , String ) = IIf(App.Get_Is_Clustered(), App.Get_Server_Dictionary_Clustered(), App.Get_Server_Dictionary_Unclustered())
172175
173176 Dim selectedRows As DataGridViewSelectedRowCollection = mainDataGridView.SelectedRows
174177
@@ -189,14 +192,14 @@ Module ServerService
189192 Cancel_Pending_Ping()
190193
191194 ' offload this blocking task into a seperate thread from the thread pool to lessen load in the UI thread
192- Await Task.Run( Sub () Handle_Block_Unblock_Selected_Servers(mainDataGridView, serverDIctionary , block))
195+ Await Task.Run( Sub () Handle_Block_Unblock_Selected_Servers(mainDataGridView, serverDictionary , block))
193196
194197 App.Set_Pending_Operation( False )
195198
196199 Ping_Servers(selectedRows)
197200 End Sub
198201
199- Private Sub Handle_Block_Unblock_Selected_Servers(mainDataGridView As DataGridView, serverDIctionary As Dictionary( Of String , String ), block As Boolean )
202+ Private Sub Handle_Block_Unblock_Selected_Servers(mainDataGridView As DataGridView, serverDictionary As Dictionary( Of String , String ), block As Boolean )
200203 Dim proc As Process = Create_Custom_CMD_Process()
201204
202205 ' traverse every datagrid row and block/unblock selected servers
@@ -208,9 +211,9 @@ Module ServerService
208211 Try
209212 Dim region As String = row.Cells( 1 ).Value
210213
211- proc.StartInfo.Arguments = "/c netsh advfirewall firewall " + If (block, "add" , "delete" ) + " rule " +
214+ proc.StartInfo.Arguments = $ "/c {netshPath} advfirewall firewall " + If (block, "add" , "delete" ) + " rule " +
212215 "name=CS2ServerPicker_" + region.Replace( " " , "" ) + If (block, " dir=out action=block protocol=ANY " +
213- "remoteip=" + serverDIctionary .Item(region), "" )
216+ "remoteip=" + serverDictionary .Item(region), "" )
214217 proc.Start()
215218 proc.WaitForExit()
216219
@@ -232,7 +235,7 @@ Module ServerService
232235 Public Async Function Block_Unblock_All_Servers(block As Boolean , Optional pingServers As Boolean = True ) As Task
233236 ' this method was converted async since its invoked by other methods/tasks and
234237 ' it does not evaluate synchronously due to its async operation that must be awaited
235- Dim serverDIctionary As Dictionary( Of String , String ) = IIf(App.Get_Is_Clustered(), App.Get_Server_Dictionary_Clustered(), App.Get_Server_Dictionary_Unclustered())
238+ Dim serverDictionary As Dictionary( Of String , String ) = IIf(App.Get_Is_Clustered(), App.Get_Server_Dictionary_Clustered(), App.Get_Server_Dictionary_Unclustered())
236239 Dim mainDataGridView As DataGridView = App.Get_DataGridView_Control()
237240
238241 If App.Get_Pending_Operation() Then
@@ -246,7 +249,7 @@ Module ServerService
246249 Cancel_Pending_Ping()
247250
248251 ' offload this blocking task into a seperate thread from the thread pool to lessen load in the UI thread
249- Await Task.Run( Sub () Handle_Block_Unblock_All_Servers(mainDataGridView, serverDIctionary , block))
252+ Await Task.Run( Sub () Handle_Block_Unblock_All_Servers(mainDataGridView, serverDictionary , block))
250253
251254 App.Set_Pending_Operation( False )
252255
@@ -255,7 +258,7 @@ Module ServerService
255258 End If
256259 End Function
257260
258- Private Sub Handle_Block_Unblock_All_Servers(mainDataGridView As DataGridView, serverDIctionary As Dictionary( Of String , String ), block As Boolean )
261+ Private Sub Handle_Block_Unblock_All_Servers(mainDataGridView As DataGridView, serverDictionary As Dictionary( Of String , String ), block As Boolean )
259262 Dim proc As Process = Create_Custom_CMD_Process()
260263
261264 ' traverse every datagrid row and block/unblock all servers
@@ -267,9 +270,9 @@ Module ServerService
267270 End If
268271
269272 Try
270- proc.StartInfo.Arguments = "/c netsh advfirewall firewall " + If (block, "add" , "delete" ) + " rule " +
273+ proc.StartInfo.Arguments = $ "/c {netshPath} advfirewall firewall " + If (block, "add" , "delete" ) + " rule " +
271274 "name=CS2ServerPicker_" + region.Replace( " " , "" ) + If (block, " dir=out action=block protocol=ANY " +
272- "remoteip=" + serverDIctionary .Item(region), "" )
275+ "remoteip=" + serverDictionary .Item(region), "" )
273276 proc.Start()
274277 proc.WaitForExit()
275278
@@ -294,8 +297,7 @@ Module ServerService
294297 Dim is_rule_exist As Boolean
295298 Dim region_trimmed As String = region.Replace( " " , "" )
296299
297- proc.StartInfo.Arguments = "/c netsh advfirewall firewall show rule name=CS2ServerPicker_" +
298- region_trimmed + " | findstr CS2ServerPicker_" + region_trimmed
300+ proc.StartInfo.Arguments = $"/c {netshPath} advfirewall firewall show rule name=CS2ServerPicker_" + region_trimmed
299301 proc.Start()
300302 proc.WaitForExit()
301303
0 commit comments