Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
Updated API to 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Dec 22, 2018
1 parent a46edc8 commit ee656fc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 32 deletions.
127 changes: 97 additions & 30 deletions VPNShield/VPNShield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ namespace VPNShield
name = "VPNShield",
description = "Blocks users connecting using VPNs.",
id = "karlofduty.vpnshield",
version = "3.0.0",
version = "3.0.1-B",
SmodMajor = 3,
SmodMinor = 1,
SmodRevision = 19
SmodMinor = 2,
SmodRevision = 0
)]
public class VPNShield : Plugin
{
public JObject config;
public HashSet<string> autoWhitelist;
public HashSet<string> autoBlacklist;
public bool whitelistUpdated = false;
public bool blacklistUpdated = false;
public HashSet<string> whitelist;

public bool autoWhitelistUpdated = false;
public bool autoBlacklistUpdated = false;

readonly string defaultConfig =
"{\n" +
Expand All @@ -57,43 +59,63 @@ public override void Register()
this.AddCommand("vs_reload", new ReloadCommand(this));
this.AddCommand("vs_enable", new EnableCommand(this));
this.AddCommand("vs_disable", new DisableCommand(this));
this.AddCommand("vs_whitelist", new WhitelistCommand(this));
}

public override void OnEnable()
{
SetUpFileSystem();

config = JObject.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/config.json"));
autoWhitelist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/auto-whitelist.json")).Values<string>());
autoBlacklist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/auto-blacklist.json")).Values<string>());
config = JObject.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/config.json"));
autoWhitelist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/auto-whitelist.json")).Values<string>());
autoBlacklist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/auto-blacklist.json")).Values<string>());
whitelist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/whitelist.json")).Values<string>());

this.Info("VPNShield enabled.");
}

public void SetUpFileSystem()
{
if (!Directory.Exists(FileManager.AppFolder + "VPNShield"))
if (!Directory.Exists(FileManager.GetAppFolder() + "VPNShield"))
{
Directory.CreateDirectory(FileManager.GetAppFolder() + "VPNShield");
}

if (!File.Exists(FileManager.GetAppFolder() + "VPNShield/config.json"))
{
Directory.CreateDirectory(FileManager.AppFolder + "VPNShield");
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/config.json", defaultConfig);
}

if (!File.Exists(FileManager.AppFolder + "VPNShield/config.json"))
if (!File.Exists(FileManager.GetAppFolder() + "VPNShield/auto-whitelist.json"))
{
File.WriteAllText(FileManager.AppFolder + "VPNShield/config.json", defaultConfig);
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/auto-whitelist.json", defaultlist);
}

if (!File.Exists(FileManager.AppFolder + "VPNShield/auto-whitelist.json"))
if (!File.Exists(FileManager.GetAppFolder() + "VPNShield/auto-blacklist.json"))
{
File.WriteAllText(FileManager.AppFolder + "VPNShield/auto-whitelist.json", defaultlist);
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/auto-blacklist.json", defaultlist);
}

if (!File.Exists(FileManager.AppFolder + "VPNShield/auto-blacklist.json"))
if (!File.Exists(FileManager.GetAppFolder() + "VPNShield/whitelist.json"))
{
File.WriteAllText(FileManager.AppFolder + "VPNShield/auto-blacklist.json", defaultlist);
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/whitelist.json", defaultlist);
}
}

public void SaveWhitelistToFile()
{
// Save the state to file
StringBuilder builder = new StringBuilder();
builder.Append("[\n");
foreach (string line in whitelist)
{
builder.Append(" \"" + line + "\"," + "\n");
}
builder.Append("]\n");
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/whitelist.json", builder.ToString());
}

public void SaveAutoWhitelistToFile()
{
// Save the state to file
StringBuilder builder = new StringBuilder();
Expand All @@ -103,10 +125,10 @@ public void SaveWhitelistToFile()
builder.Append(" \"" + line + "\"," + "\n");
}
builder.Append("]\n");
File.WriteAllText(FileManager.AppFolder + "VPNShield/auto-whitelist.json", builder.ToString());
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/auto-whitelist.json", builder.ToString());
}

public void SaveBlacklistToFile()
public void SaveAutoBlacklistToFile()
{
// Save the state to file
StringBuilder builder = new StringBuilder();
Expand All @@ -116,7 +138,7 @@ public void SaveBlacklistToFile()
builder.Append(" \"" + line + "\"," + "\n");
}
builder.Append("]\n");
File.WriteAllText(FileManager.AppFolder + "VPNShield/auto-blacklist.json", builder.ToString());
File.WriteAllText(FileManager.GetAppFolder() + "VPNShield/auto-blacklist.json", builder.ToString());
}

public bool CheckVPN(PlayerJoinEvent ev)
Expand Down Expand Up @@ -162,13 +184,13 @@ public bool CheckVPN(PlayerJoinEvent ev)
this.Info(ev.Player.Name + " is not using a detectable VPN.");
}
autoWhitelist.Add(ipAddress);
whitelistUpdated = true;
autoWhitelistUpdated = true;
}
else if (verificationLevel == 1)
{
this.Info(ev.Player.Name + " is using a VPN.");
autoBlacklist.Add(ipAddress);
blacklistUpdated = true;
autoBlacklistUpdated = true;
ev.Player.Ban(0, "This server does not allow VPNs or proxy connections.");
response.Close();
return true;
Expand Down Expand Up @@ -365,6 +387,45 @@ public string[] OnCall(ICommandSender sender, string[] args)
}
}

class WhitelistCommand : ICommandHandler
{
private VPNShield plugin;
public WhitelistCommand(VPNShield plugin)
{
this.plugin = plugin;
}

public string GetCommandDescription()
{
return "Whitelists a player's SteamID";
}

public string GetUsage()
{
return "vs_whitelist <SteamID>";
}

public string[] OnCall(ICommandSender sender, string[] args)
{
if (args.Length > 0)
{
if (plugin.whitelist.Contains(args[0]))
{
plugin.whitelist.Remove(args[0]);
plugin.SaveWhitelistToFile();
return new string[] { "Player removed from whitelist." };
}
else
{
plugin.whitelist.Add(args[0]);
plugin.SaveWhitelistToFile();
return new string[] { "Player added to whitelist." };
}
}
return new string[] { "Invalid arguments, usage: \"" + GetUsage() + "\"" };
}
}

class ReloadCommand : ICommandHandler
{
private VPNShield plugin;
Expand All @@ -386,9 +447,10 @@ public string GetUsage()
public string[] OnCall(ICommandSender sender, string[] args)
{
plugin.SetUpFileSystem();
plugin.config = JObject.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/config.json"));
plugin.autoWhitelist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/auto-whitelist.json")).Values<string>());
plugin.autoBlacklist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/auto-blacklist.json")).Values<string>());
plugin.config = JObject.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/config.json"));
plugin.autoWhitelist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/auto-whitelist.json")).Values<string>());
plugin.autoBlacklist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/auto-blacklist.json")).Values<string>());
plugin.whitelist = new HashSet<string>(JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "VPNShield/whitelist.json")).Values<string>());
return new string[] { "VPNShield has been reloaded." };
}
}
Expand All @@ -403,15 +465,15 @@ public SaveData(VPNShield plugin)

public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
{
if(plugin.whitelistUpdated)
if(plugin.autoWhitelistUpdated)
{
plugin.SaveWhitelistToFile();
plugin.whitelistUpdated = false;
plugin.SaveAutoWhitelistToFile();
plugin.autoWhitelistUpdated = false;
}
if (plugin.blacklistUpdated)
if (plugin.autoBlacklistUpdated)
{
plugin.SaveBlacklistToFile();
plugin.blacklistUpdated = false;
plugin.SaveAutoBlacklistToFile();
plugin.autoBlacklistUpdated = false;
}
}
}
Expand All @@ -430,6 +492,11 @@ public void OnPlayerJoin(PlayerJoinEvent ev)
return;
}

if (plugin.whitelist.Contains(ev.Player.SteamId))
{
return;
}

if (plugin.CheckSteamAccount(ev))
{
return;
Expand Down
8 changes: 6 additions & 2 deletions VPNShield/VPNShield.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VPNShield</RootNamespace>
<AssemblyName>VPNShield</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -22,6 +23,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,6 +33,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
Expand Down Expand Up @@ -58,7 +61,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>cd $(ProjectDir)
<PostBuildEvent>taskkill /F /IM SCPSL.exe /T 2&gt;nul &amp;set errorlevel=0
cd $(ProjectDir)
copy /y bin\VPNShield.dll ..\..\..\scpserver\sm_plugins\
mkdir ..\..\..\scpserver\sm_plugins\dependencies
copy /y bin\Newtonsoft.Json.dll ..\..\..\scpserver\sm_plugins\dependencies\</PostBuildEvent>
Expand Down
Binary file modified VPNShield/lib/Assembly-CSharp.dll
Binary file not shown.
Binary file modified VPNShield/lib/Smod2.dll
Binary file not shown.

0 comments on commit ee656fc

Please sign in to comment.