-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServers.cs
56 lines (48 loc) · 1.6 KB
/
Servers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Newtonsoft.Json;
using System.Net;
namespace StatusBot
{
public class Servers
{
const string serverListUri = "https://publicapi.battlebit.cloud/Servers/GetServerList";
public static ServerList GetServerList()
{
string response = Get(serverListUri);
ServerData[] serverList = JsonConvert.DeserializeObject<ServerData[]>(response);
ServerList serverListInstance = new ServerList();
serverListInstance.serverData = serverList.ToList();
return serverListInstance;
}
private static string Get(string uri)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
public class ServerData
{
public string Name;
public string Map;
public string Gamemode;
public string Region;
public int Players;
public int QueuePlayers;
public int MaxPlayers;
public int Hz;
public string DayNight;
public bool IsOfficial;
public bool HasPassword;
public string AntiCheat;
public string Build;
}
public class ServerList
{
public List<ServerData> serverData;
}
}