Skip to content

Commit fd233ac

Browse files
committed
override Close method from Connection in Rcon class
1 parent 7078e4c commit fd233ac

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

MCQuery-Console/Program.cs

+8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ static void Main(string[] args)
1818
if (port != 0)
1919
{
2020
//Connection connection = new Connection(ipAddress, port); //This should give us a challenge token needed for getting data from the sever.
21+
22+
using (Query query = new Query(ipAddress, port))
23+
{
24+
25+
}
26+
2127
Query serverQuery = new Query(ipAddress, port);
2228
Server basicServer = serverQuery.GetBasicServerInfo();
29+
serverQuery.Close();
30+
Rcon rconServer = new Rcon(ipAddress, port, "yolo");
2331

2432
Console.WriteLine("Printing out server info: ");
2533
Console.WriteLine("Server MOTD: {0}", basicServer.Motd);

MCQuery/Connection.cs

+3-17
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace MCQuery
1010
{
1111
public abstract class Connection : IDisposable
1212
{
13-
private string _address = "";
14-
private int _port = 0;
13+
protected internal string _address = "";
14+
protected internal int _port = 0;
1515

1616
private UdpClient _udpClient;
1717
private TcpClient _tcpClient;
@@ -22,16 +22,6 @@ public Connection(string address, int port)
2222
_port = port;
2323
}
2424

25-
//public Query GetQueryConnection()
26-
//{
27-
// return new Query(_address, _port);
28-
//}
29-
30-
//public Rcon GetRconConnection(string password)
31-
//{
32-
// return new Rcon(_address, _port, password);
33-
//}
34-
3525
protected byte[] SendByUdp(string address, int port, byte[] data)
3626
{
3727
try
@@ -49,10 +39,6 @@ protected byte[] SendByUdp(string address, int port, byte[] data)
4939
_udpClient.Connect(address, port);
5040
_udpClient.Client.SendTimeout = 10000; //Timeout after 10 seconds
5141
_udpClient.Client.ReceiveTimeout = 10000; //Timeout after 10 seconds
52-
53-
_challengeTimer.Elapsed += RegenerateChallengeToken;
54-
_challengeTimer.Interval = 30000;
55-
_challengeTimer.Start();
5642
}
5743

5844
_udpClient.Send(data, data.Length);
@@ -113,7 +99,7 @@ protected byte[] SendByTcp(string address, int port)
11399
return new byte[] { };
114100
}
115101

116-
protected virtual void Close()
102+
public virtual void Close()
117103
{
118104
if(_udpClient != null)
119105
{

MCQuery/Query.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ private void Handshake(string address, int port)
4949
}
5050
else
5151
{
52-
_address = address;
53-
_port = port;
54-
_challengeToken = GetChallengeToken(udpResponse);
52+
_challengeTimer.Elapsed += RegenerateChallengeToken;
53+
_challengeTimer.Interval = 30000;
54+
_challengeTimer.Start();
55+
_challengeToken = GetChallengeToken(udpResponse);
5556
}
5657
}
5758

@@ -234,5 +235,10 @@ private void RegenerateChallengeToken(Object sender, ElapsedEventArgs e)
234235
//Run handshake again to obtain new challenge token.
235236
Handshake(_address, _port);
236237
}
237-
}
238+
239+
public override void Close()
240+
{
241+
base.Close();
242+
}
243+
}
238244
}

MCQuery/Rcon.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
namespace MCQuery
22
{
3-
internal class Rcon : Connection
3+
public class Rcon : Connection
44
{
5-
internal Rcon(string address, int port, string password) : base(address, port)
5+
public Rcon(string address, int port, string password) : base(address, port)
66
{
77

88
}
9-
}
9+
10+
public override void Close()
11+
{
12+
base.Close();
13+
}
14+
}
1015
}

0 commit comments

Comments
 (0)