This repository was archived by the owner on Dec 23, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-10
lines changed
Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,16 @@ public void TestAuthFail()
1212 server . StartListening ( ) ;
1313
1414 var client = new RemoteConClient ( ) ;
15- client . OnAuthResult += Assert . False ;
15+ client . OnAuthResult += success =>
16+ {
17+ Assert . False ( success ) ;
18+
19+ client . Disconnect ( ) ;
20+ server . StopListening ( ) ;
21+ } ;
1622
1723 client . Connect ( "127.0.0.1" , 27015 ) ;
1824 client . Authenticate ( "unitfail" ) ;
19-
20- client . Disconnect ( ) ;
21- server . StopListening ( ) ;
2225 }
2326
2427 [ Fact ]
Original file line number Diff line number Diff line change 33using System . Linq ;
44using System . Net ;
55using System . Net . Sockets ;
6+ using System . Threading ;
67using RCONServerLib . Utils ;
78
89namespace RCONServerLib
@@ -148,7 +149,11 @@ public void StartListening()
148149
149150 public void StopListening ( )
150151 {
151- _listener . Stop ( ) ;
152+ if ( ! _listener . Server . IsBound )
153+ return ;
154+
155+ _listener . Server . Shutdown ( SocketShutdown . Both ) ;
156+ _listener . Server . Close ( 0 ) ;
152157 }
153158
154159 private void OnAccept ( IAsyncResult result )
@@ -223,5 +228,10 @@ internal void LogDebug(string message)
223228 System . Diagnostics . Debug . WriteLine ( message ) ;
224229 Console . WriteLine ( message ) ;
225230 }
231+
232+ internal void RemoveClient ( TcpClient client )
233+ {
234+ _clients . Remove ( client ) ;
235+ }
226236 }
227237}
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ private void CloseConnection()
9999 {
100100 if ( _isUnitTest )
101101 return ;
102+ _remoteConServer . RemoveClient ( _tcp ) ;
102103 _remoteConServer . LogDebug ( ( ( IPEndPoint ) _tcp . Client . RemoteEndPoint ) . Address + " connection closed." ) ;
103104
104105 _connected = false ;
@@ -167,10 +168,7 @@ private void OnPacket(IAsyncResult result)
167168
168169 ParsePacket ( _buffer ) ;
169170
170- if ( ! _tcp . Connected )
171- return ;
172-
173- if ( ! _connected )
171+ if ( ! _connected || ! _tcp . Connected )
174172 {
175173 _remoteConServer . LogDebug ( ( ( IPEndPoint ) _tcp . Client . RemoteEndPoint ) . Address + " lost connection." ) ;
176174 CloseConnection ( ) ;
@@ -182,8 +180,8 @@ private void OnPacket(IAsyncResult result)
182180 }
183181 catch ( IOException )
184182 {
185- _connected = false ;
186183 _remoteConServer . LogDebug ( ( ( IPEndPoint ) _tcp . Client . RemoteEndPoint ) . Address + " lost connection." ) ;
184+ CloseConnection ( ) ;
187185 }
188186 catch ( RconServerException )
189187 {
You can’t perform that action at this time.
0 commit comments