forked from Freenex1911/FeexLimiter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeexLimiter.cs
185 lines (171 loc) · 7.84 KB
/
FeexLimiter.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned.Permissions;
using SDG.Unturned;
using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml;
namespace Freenex.FeexLimiter
{
public class FeexLimiter : RocketPlugin<FeexLimiterConfiguration>
{
public static FeexLimiter Instance;
protected override void Load()
{
Instance = this;
UnturnedPermissions.OnJoinRequested += UnturnedPermissions_OnJoinRequested;
Logger.Log("Freenex's FeexLimiter has been loaded!");
}
protected override void Unload()
{
UnturnedPermissions.OnJoinRequested -= UnturnedPermissions_OnJoinRequested;
Logger.Log("Freenex's FeexLimiter has been unloaded!");
}
public ESteamRejection GetSteamRejection()
{
var RejectionReason = ESteamRejection.AUTH_VERIFICATION;
try
{
RejectionReason = (ESteamRejection)Enum.Parse(typeof(ESteamRejection), Configuration.Instance.accRejectionReason, true);
}
catch { }
return RejectionReason;
}
private void UnturnedPermissions_OnJoinRequested(Steamworks.CSteamID player, ref ESteamRejection? rejectionReason)
{
for (int i = 0; i < Configuration.Instance.Whitelist.Length; i++)
{
if (Configuration.Instance.Whitelist[i].WhitelistUser == player.ToString())
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access granted: " + player + " // Reason: Whitelist."); }
return;
}
}
string steamID = string.Empty;
string privacyState = string.Empty;
string vacBanned = string.Empty;
string isLimitedAccount = string.Empty;
string memberSince = string.Empty;
try
{
var WR = WebRequest.Create(new Uri("http://steamcommunity.com/profiles/" + player + "?xml=1"));
WR.Timeout = Configuration.Instance.Timeout;
using (var WRresponse = WR.GetResponse())
using (var WRstream = WRresponse.GetResponseStream())
using (var sreader = new StreamReader(WRstream))
using (XmlReader xreader = XmlReader.Create(new StringReader(sreader.ReadToEnd())))
{
while (xreader.Read())
{
if (xreader.IsStartElement())
{
if (xreader.Name == "steamID")
{
if (xreader.Read()) { steamID = xreader.Value; }
}
else if (xreader.Name == "privacyState")
{
if (xreader.Read()) { privacyState = xreader.Value; }
}
else if (xreader.Name == "vacBanned")
{
if (xreader.Read()) { vacBanned = xreader.Value; }
}
else if (xreader.Name == "isLimitedAccount")
{
if (xreader.Read()) { isLimitedAccount = xreader.Value; }
if (privacyState == "private" || privacyState == "friendsonly") { xreader.Close(); }
}
else if (xreader.Name == "memberSince")
{
if (xreader.Read()) { memberSince = xreader.Value; }
xreader.Close();
}
}
}
}
}
catch
{
if (Configuration.Instance.KickOnTimeout)
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " // Reason: Timeout."); }
rejectionReason = GetSteamRejection();
}
else
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access granted: " + player + " // Reason: Timeout."); }
}
return;
}
if (isLimitedAccount == string.Empty)
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " // Reason: No profile."); }
rejectionReason = GetSteamRejection();
return;
}
if ((privacyState == "private" || privacyState == "friendsonly") && Configuration.Instance.accKickPrivateProfiles)
{
if (Configuration.Instance.accNonLimitedOverwrites)
{
if (isLimitedAccount == "1")
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " (" + steamID + ") // Reason: Private profile."); }
rejectionReason = GetSteamRejection();
return;
}
}
else
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " (" + steamID + ") // Reason: Private profile."); }
rejectionReason = GetSteamRejection();
return;
}
}
if (vacBanned == "1" && Configuration.Instance.accKickVACBannedAccounts)
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " (" + steamID + ") // Reason: VAC banned."); }
rejectionReason = GetSteamRejection();
return;
}
if (isLimitedAccount == "1" && Configuration.Instance.accKickLimitedAccounts)
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " (" + steamID + ") // Reason: Limited account."); }
rejectionReason = GetSteamRejection();
return;
}
if (memberSince != string.Empty)
{
try
{
string[] MemberSince = memberSince.Split(' ');
MemberSince[1] = Regex.Match(MemberSince[1], @"\d+").Value;
DateTime dtSteamUser = DateTime.ParseExact(MemberSince[1] + MemberSince[0] + MemberSince[2], "dMMMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None);
TimeSpan tsSteamUser = DateTime.Now - dtSteamUser;
if (tsSteamUser.Days <= Configuration.Instance.accMinimumDays)
{
if (Configuration.Instance.accNonLimitedOverwrites)
{
if (isLimitedAccount == "1")
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " (" + steamID + ") // Reason: Account too new."); }
rejectionReason = GetSteamRejection();
return;
}
}
else
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " (" + steamID + ") // Reason: Account too new."); }
rejectionReason = GetSteamRejection();
return;
}
}
}
catch (Exception ex) { Logger.LogException(ex); }
}
}
}
}