This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnti-VPN.cs
More file actions
118 lines (105 loc) · 4.25 KB
/
Anti-VPN.cs
File metadata and controls
118 lines (105 loc) · 4.25 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using BrokeProtocol.API;
using BrokeProtocol.Entities;
using BrokeProtocol.Utility.Networking;
using System.Net;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
namespace AntiVPN
{
internal class AntiVPN
{
[Target(GameSourceEvent.PlayerInitialize, ExecutionMode.Event)]
public async void OnEvent(ShPlayer player)
{
if (!player.isHuman)
return;
if (!IsLocalIpAddress(player.svPlayer.connection.IP))
{
player.svPlayer.SendGameMessage("〔<color=#546eff>Anti-VPN</color>〕 | Checking your connection...");
IpInfo ipInfo = await IpInfoFetcher.CheckIfProxy(player.svPlayer.connection.IP);
if (ipInfo != null)
{
if (ipInfo.Status != "success")
{
try
{
if (ipInfo.Proxy || ipInfo.Hosting)
{
player.svPlayer.SendGameMessage("〔<color=#546eff>Anti-VPN</color>〕 | You will be kicked for using vpn!");
await Task.Delay(3000);
player.svPlayer.svManager.Disconnect(player.svPlayer.connection, DisconnectTypes.Kicked);
}
else
{
player.svPlayer.SendGameMessage("〔<color=#546eff>Anti-VPN</color>〕 | You passed the check!");
}
}
catch { }
}
else if (ipInfo.Status == "fail")
{
player.svPlayer.SendGameMessage("〔<color=#546eff>Anti-VPN</color>〕 | You passed temporary check due to endpoint error!");
}
}
}
else if (IsLocalIpAddress(player.svPlayer.connection.IP) || player.svPlayer.HasPermission("avpn.bypass"))
{
player.svPlayer.SendGameMessage("〔<color=#546eff>Anti-VPN</color>〕 | Bypassed!");
}
}
// Class to store information about the IP
public class IpInfo
{
public string Status;
public bool Proxy;
public bool Hosting;
}
// Class to fetch IP information from an API
public static class IpInfoFetcher
{
public static async Task<IpInfo> CheckIfProxy(string ip)
{
string apiUrl = $"https://thingproxy.freeboard.io/fetch/http://ip-api.com/json/{ip}?fields=query,status,proxy,hosting";
using (UnityWebRequest request = UnityWebRequest.Get(apiUrl))
{
var tcs = new TaskCompletionSource<IpInfo>();
request.SendWebRequest().completed += operation =>
{
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Request failed: {request.error}");
tcs.SetResult(null);
return;
}
string responseBody = request.downloadHandler.text;
IpInfo ipInfo = JsonUtility.FromJson<IpInfo>(responseBody);
tcs.SetResult(ipInfo);
};
return await tcs.Task;
}
}
}
// Check if an IP address is local
public static bool IsLocalIpAddress(string host)
{
try
{
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress hostIP in hostIPs)
{
if (IPAddress.IsLoopback(hostIP))
return true;
foreach (IPAddress localIP in localIPs)
{
if (hostIP.Equals(localIP))
return true;
}
}
}
catch { }
return false;
}
}
}